def LanguageServerCompleter_ExtraConf_NonGlobal_test( app ): filepath = PathToTestFile( 'project', 'settings_extra_conf', 'foo' ) completer = MockCompleter() request_data = RequestWrap( BuildRequest( filepath = filepath, filetype = 'ycmtest', # ignored; ycm conf path used working_dir = 'ignore_this', contents = '' ) ) assert_that( {}, equal_to( completer._settings.get( 'ls', {} ) ) ) completer.OnFileReadyToParse( request_data ) assert_that( { 'java.rename.enabled' : False }, equal_to( completer._settings.get( 'ls', {} ) ) ) # Simulate receipt of response and initialization complete initialize_response = { 'result': { 'capabilities': {} } } completer._HandleInitializeInPollThread( initialize_response ) assert_that( PathToTestFile( 'project', 'settings_extra_conf' ), equal_to( completer._project_directory ) )
def LanguageServerCompleter_Diagnostics_PercentEncodeCannonical_test( app ): completer = MockCompleter() filepath = os.path.realpath( '/foo?' ) uri = lsp.FilePathToUri( filepath ) assert_that( uri, ends_with( '%3F' ) ) request_data = RequestWrap( BuildRequest( line_num = 1, column_num = 1, filepath = filepath, contents = '' ) ) notification = { 'jsonrpc': '2.0', 'method': 'textDocument/publishDiagnostics', 'params': { 'uri': uri.replace( '%3F', '%3f' ), 'diagnostics': [ { 'range': { 'start': { 'line': 3, 'character': 10 }, 'end': { 'line': 3, 'character': 11 } }, 'severity': 1, 'message': 'First error' } ] } } completer.GetConnection()._notifications.put( notification ) completer.HandleNotificationInPollThread( notification ) with patch.object( completer, '_ServerIsInitialized', return_value = True ): completer.OnFileReadyToParse( request_data ) # Simulate receipt of response and initialization complete initialize_response = { 'result': { 'capabilities': {} } } completer._HandleInitializeInPollThread( initialize_response ) diagnostics = contains_exactly( has_entries( { 'kind': equal_to( 'ERROR' ), 'location': LocationMatcher( filepath, 4, 11 ), 'location_extent': RangeMatcher( filepath, ( 4, 11 ), ( 4, 12 ) ), 'ranges': contains_exactly( RangeMatcher( filepath, ( 4, 11 ), ( 4, 12 ) ) ), 'text': equal_to( 'First error' ), 'fixit_available': False } ) ) assert_that( completer.OnFileReadyToParse( request_data ), diagnostics ) assert_that( completer.PollForMessages( request_data ), contains_exactly( has_entries( { 'diagnostics': diagnostics, 'filepath': filepath } ) ) )
def LanguageServerCompleter_OnFileReadyToParse_InvalidURI_test( app ): completer = MockCompleter() filepath = os.path.realpath( '/foo?' ) uri = lsp.FilePathToUri( filepath ) request_data = RequestWrap( BuildRequest( line_num = 1, column_num = 1, filepath = filepath, contents = '' ) ) notification = { 'jsonrpc': '2.0', 'method': 'textDocument/publishDiagnostics', 'params': { 'uri': uri, 'diagnostics': [ { 'range': { 'start': { 'line': 3, 'character': 10 }, 'end': { 'line': 3, 'character': 11 } }, 'severity': 1, 'message': 'First error' } ] } } completer.GetConnection()._notifications.put( notification ) completer.HandleNotificationInPollThread( notification ) with patch.object( completer, '_ServerIsInitialized', return_value = True ): completer.OnFileReadyToParse( request_data ) # Simulate receipt of response and initialization complete initialize_response = { 'result': { 'capabilities': {} } } completer._HandleInitializeInPollThread( initialize_response ) diagnostics = contains_exactly( has_entries( { 'kind': equal_to( 'ERROR' ), 'location': LocationMatcher( '', 4, 11 ), 'location_extent': RangeMatcher( '', ( 4, 11 ), ( 4, 12 ) ), 'ranges': contains_exactly( RangeMatcher( '', ( 4, 11 ), ( 4, 12 ) ) ), 'text': equal_to( 'First error' ), 'fixit_available': False } ) ) with patch( 'ycmd.completers.language_server.language_server_protocol.' 'UriToFilePath', side_effect = lsp.InvalidUriException ) as \ uri_to_filepath: assert_that( completer.OnFileReadyToParse( request_data ), diagnostics ) uri_to_filepath.assert_called()
def LanguageServerCompleter_DelayedInitialization_test( app ): completer = MockCompleter() request_data = RequestWrap( BuildRequest( filepath = 'Test.ycmtest' ) ) with patch.object( completer, '_UpdateServerWithFileContents' ) as update: with patch.object( completer, '_PurgeFileFromServer' ) as purge: completer.OnFileReadyToParse( request_data ) completer.OnBufferUnload( request_data ) update.assert_not_called() purge.assert_not_called() # Simulate receipt of response and initialization complete initialize_response = { 'result': { 'capabilities': {} } } completer._HandleInitializeInPollThread( initialize_response ) update.assert_called_with( request_data ) purge.assert_called_with( 'Test.ycmtest' )
def LanguageServerCompleter_ExtraConf_FileEmpty_test( app ): filepath = PathToTestFile( 'extra_confs', 'foo' ) completer = MockCompleter() request_data = RequestWrap( BuildRequest( filepath = filepath, filetype = 'ycmtest', contents = '' ) ) completer.OnFileReadyToParse( request_data ) assert_that( {}, equal_to( completer._settings.get( 'ls', {} ) ) ) # Simulate receipt of response and initialization complete initialize_response = { 'result': { 'capabilities': {} } } completer._HandleInitializeInPollThread( initialize_response ) assert_that( {}, equal_to( completer._settings.get( 'ls', {} ) ) ) # We shouldn't have used the extra_conf path for the project directory, but # that _also_ happens to be the path of the file we opened. assert_that( PathToTestFile( 'extra_confs' ), equal_to( completer._project_directory ) )
def LanguageServerCompleter_ExtraConf_NoExtraConf_test( app ): filepath = PathToTestFile( 'extra_confs', 'foo' ) completer = MockCompleter() request_data = RequestWrap( BuildRequest( filepath = filepath, filetype = 'ycmtest', working_dir = PathToTestFile(), contents = '' ) ) assert_that( {}, equal_to( completer._settings.get( 'ls', {} ) ) ) completer.OnFileReadyToParse( request_data ) assert_that( {}, equal_to( completer._settings.get( 'ls', {} ) ) ) # Simulate receipt of response and initialization complete initialize_response = { 'result': { 'capabilities': {} } } completer._HandleInitializeInPollThread( initialize_response ) assert_that( {}, equal_to( completer._settings.get( 'ls', {} ) ) ) # We use the client working directory assert_that( PathToTestFile(), equal_to( completer._project_directory ) )