Esempio n. 1
0
    def OrganizeImports(self, request_data):
        workspace_edit = self.GetCommandResponse(
            request_data, 'java.edit.organizeImports',
            [lsp.FilePathToUri(request_data['filepath'])])

        fixit = language_server_completer.WorkspaceEditToFixIt(
            request_data, workspace_edit)
        return responses.BuildFixItResponse([fixit])
Esempio n. 2
0
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
      } ) )
    )
Esempio n. 3
0
 def OrganizeImports(self, request_data):
     fixit = {
         'resolve': True,
         'command': {
             'title': 'Organize Imports',
             'command': 'java.edit.organizeImports',
             'arguments': [lsp.FilePathToUri(request_data['filepath'])]
         }
     }
     return self._ResolveFixit(request_data, fixit)
def LanguageServerCompleter_OnFileReadyToParse_InvalidURI_test():
    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, 'ServerIsReady', return_value=True):
        completer.SendInitialize(
            request_data, completer._GetSettingsFromExtraConf(request_data))
        # Simulate receipt of response and initialization complete
        initialize_response = {'result': {'capabilities': {}}}
        completer._HandleInitializeInPollThread(initialize_response)

        diagnostics = contains(
            has_entries({
                'kind': equal_to('ERROR'),
                'location': LocationMatcher('', 4, 11),
                'location_extent': RangeMatcher('', (4, 11), (4, 12)),
                'ranges': contains(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()
Esempio n. 5
0
    def GetDetailedDiagnostic(self, request_data):
        self._UpdateServerWithFileContents(request_data)

        current_line_lsp = request_data['line_num'] - 1
        current_file = request_data['filepath']

        if not self._latest_diagnostics:
            return responses.BuildDisplayMessageResponse(
                'Diagnostics are not ready yet.')

        with self._server_info_mutex:
            diagnostics = list(
                self._latest_diagnostics[lsp.FilePathToUri(current_file)])

        if not diagnostics:
            return responses.BuildDisplayMessageResponse(
                'No diagnostics for current file.')

        current_column = lsp.CodepointsToUTF16CodeUnits(
            GetFileLines(request_data, current_file)[current_line_lsp],
            request_data['column_codepoint'])
        minimum_distance = None

        message = 'No diagnostics for current line.'
        for diagnostic in diagnostics:
            start = diagnostic['range']['start']
            end = diagnostic['range']['end']
            if current_line_lsp < start['line'] or end[
                    'line'] < current_line_lsp:
                continue
            point = {'line': current_line_lsp, 'character': current_column}
            distance = DistanceOfPointToRange(point, diagnostic['range'])
            if minimum_distance is None or distance < minimum_distance:
                message = diagnostic['message']
                if distance == 0:
                    break
                minimum_distance = distance

        return responses.BuildDisplayMessageResponse(message)
 def test_FilePathToUri_Windows( self ):
   assert_that( lsp.FilePathToUri( 'C:\\usr\\local\\test\\test.test' ),
                equal_to( 'file:///C:/usr/local/test/test.test' ) )
 def test_FilePathToUri_Unix( self ):
   assert_that( lsp.FilePathToUri( '/usr/local/test/test.test' ),
                equal_to( 'file:///usr/local/test/test.test' ) )
def FilePathToUri_Unix_test():
    assert_that(lsp.FilePathToUri('/usr/local/test/test.test'),
                equal_to('file:///usr/local/test/test.test'))
def LanguageServerCompleter_Diagnostics_NoLimitToNumberOfDiagnostics_test():
    completer = MockCompleter({'max_diagnostics_to_display': 0})
    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'
            }, {
                'range': {
                    'start': {
                        'line': 4,
                        'character': 7
                    },
                    'end': {
                        'line': 4,
                        'character': 13
                    }
                },
                'severity': 1,
                'message': 'Second error'
            }]
        }
    }
    completer.GetConnection()._notifications.put(notification)
    completer.HandleNotificationInPollThread(notification)

    with patch.object(completer, 'ServerIsReady', return_value=True):
        completer.SendInitialize(request_data)
        # Simulate recept of response and initialization complete
        initialize_response = {'result': {'capabilities': {}}}
        completer._HandleInitializeInPollThread(initialize_response)

        diagnostics = contains(
            has_entries({
                'kind':
                equal_to('ERROR'),
                'location':
                LocationMatcher(filepath, 4, 11),
                'location_extent':
                RangeMatcher(filepath, (4, 11), (4, 12)),
                'ranges':
                contains(RangeMatcher(filepath, (4, 11), (4, 12))),
                'text':
                equal_to('First error'),
                'fixit_available':
                False
            }),
            has_entries({
                'kind':
                equal_to('ERROR'),
                'location':
                LocationMatcher(filepath, 5, 8),
                'location_extent':
                RangeMatcher(filepath, (5, 8), (5, 14)),
                'ranges':
                contains(RangeMatcher(filepath, (5, 8), (5, 14))),
                'text':
                equal_to('Second error'),
                'fixit_available':
                False
            }))

        assert_that(completer.OnFileReadyToParse(request_data), diagnostics)

        assert_that(
            completer.PollForMessages(request_data),
            contains(
                has_entries({
                    'diagnostics': diagnostics,
                    'filepath': filepath
                })))