def Diagnostics_ZeroBasedLineAndColumn_test(app):
    contents = """
void foo() {
  double baz = "foo";
}
// Padding to 5 lines
// Padding to 5 lines
"""

    filepath = PathToTestFile('foo.cc')
    request = {'contents': contents, 'filepath': filepath, 'filetype': 'cpp'}

    test = {'request': request, 'route': '/receive_messages'}
    results = RunAfterInitialized(app, test)
    assert_that(
        results,
        contains_exactly(
            has_entries({
                'diagnostics':
                contains_exactly(
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'text':
                        contains_string('Cannot initialize'),
                        'ranges':
                        contains_exactly(
                            RangeMatcher(filepath, (3, 10), (3, 13))),
                        'location':
                        LocationMatcher(filepath, 3, 10),
                        'location_extent':
                        RangeMatcher(filepath, (3, 10), (3, 13))
                    }))
            })))
Ejemplo n.º 2
0
def Diagnostics_NoLimitToNumberOfDiagnostics_test( app ):
  filepath = PathToTestFile( 'max_diagnostics.cc' )
  contents = ReadFile( filepath )

  event_data = BuildRequest( contents = contents,
                             event_name = 'FileReadyToParse',
                             filetype = 'cpp',
                             filepath = filepath,
                             compilation_flags = [ '-x', 'c++' ] )

  response = app.post_json( '/event_notification', event_data ).json

  pprint( response )

  assert_that( response, contains(
    has_entries( {
      'kind': equal_to( 'ERROR' ),
      'location': LocationMatcher( filepath, 3, 9 ),
      'location_extent': RangeMatcher( filepath, ( 3, 9 ), ( 3, 13 ) ),
      'ranges': empty(),
      'text': equal_to( "redefinition of 'test'" ),
      'fixit_available': False
    } ),
    has_entries( {
      'kind': equal_to( 'ERROR' ),
      'location': LocationMatcher( filepath, 4, 9 ),
      'location_extent': RangeMatcher( filepath, ( 4, 9 ), ( 4, 13 ) ),
      'ranges': empty(),
      'text': equal_to( "redefinition of 'test'" ),
      'fixit_available': False
    } )
  ) )
Ejemplo n.º 3
0
def FileReadyToParse_Diagnostics_InvalidURI_test( app, uri_to_filepath, *args ):
  StartJavaCompleterServerInDirectory( app,
                                       PathToTestFile( DEFAULT_PROJECT_DIR ) )

  filepath = TestFactory
  contents = ReadFile( filepath )

  # It can take a while for the diagnostics to be ready
  expiration = time.time() + 10
  while True:
    try:
      results = _WaitForDiagnosticsToBeReady( app, filepath, contents )
      print( 'Completer response: {0}'.format(
        json.dumps( results, indent=2 ) ) )

      uri_to_filepath.assert_called()

      assert_that( results, has_item(
        has_entries( {
          'kind': 'WARNING',
          'text': 'The value of the field TestFactory.Bar.testString is not '
                  'used',
          'location': LocationMatcher( '', 15, 19 ),
          'location_extent': RangeMatcher( '', ( 15, 19 ), ( 15, 29 ) ),
          'ranges': contains( RangeMatcher( '', ( 15, 19 ), ( 15, 29 ) ) ),
          'fixit_available': False
        } ),
      ) )

      return
    except AssertionError:
      if time.time() > expiration:
        raise
      time.sleep( 0.25 )
Ejemplo n.º 4
0
def Diagnostics_NoLimitToNumberOfDiagnostics_test( app ):
  filepath = PathToTestFile( 'max_diagnostics.cc' )
  contents = ReadFile( filepath )
  request = { 'contents': contents,
              'filepath': filepath,
              'filetype': 'cpp' }

  test = { 'request': request, 'route': '/receive_messages' }
  response = RunAfterInitialized( app, test )

  pprint( response )

  assert_that( response, contains(
    has_entries( { 'diagnostics': has_items(
      has_entries( {
        'kind': equal_to( 'ERROR' ),
        'location': LocationMatcher( filepath, 3, 9 ),
        'location_extent': RangeMatcher( filepath, ( 3, 9 ), ( 3, 13 ) ),
        'ranges': contains( RangeMatcher( filepath, ( 3, 9 ), ( 3, 13 ) ) ),
        'text': contains_string( "redefinition of 'test'" ),
        'fixit_available': False
      } ),
      has_entries( {
        'kind': equal_to( 'ERROR' ),
        'location': LocationMatcher( filepath, 4, 9 ),
        'location_extent': RangeMatcher( filepath, ( 4, 9 ), ( 4, 13 ) ),
        'ranges': contains( RangeMatcher( filepath, ( 4, 9 ), ( 4, 13 ) ) ),
        'text': contains_string( "redefinition of 'test'" ),
        'fixit_available': False
      } )
    ) } )
  ) )
Ejemplo n.º 5
0
    def test_Diagnostics_ZeroBasedLineAndColumn(self, app):
        contents = """
void foo() {
  double baz = "foo";
}
// Padding to 5 lines
// Padding to 5 lines
"""

        event_data = BuildRequest(compilation_flags=['-x', 'c++'],
                                  event_name='FileReadyToParse',
                                  contents=contents,
                                  filepath='foo',
                                  filetype='cpp')

        results = app.post_json('/event_notification', event_data).json
        assert_that(
            results,
            contains_exactly(
                has_entries({
                    'kind':
                    equal_to('ERROR'),
                    'text':
                    contains_string('cannot initialize'),
                    'ranges':
                    contains_exactly(RangeMatcher('foo', (3, 16), (3, 21))),
                    'location':
                    LocationMatcher('foo', 3, 10),
                    'location_extent':
                    RangeMatcher('foo', (3, 10), (3, 13))
                })))
Ejemplo n.º 6
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
      } ) )
    )
Ejemplo n.º 7
0
def FileReadyToParse_Diagnostics_FileNotOnDisk_test( app ):
  StartJavaCompleterServerInDirectory( app,
                                       PathToTestFile( DEFAULT_PROJECT_DIR ) )

  contents = '''
    package com.test;
    class Test {
      public String test
    }
  '''
  filepath = ProjectPath( 'Test.java' )

  event_data = BuildRequest( event_name = 'FileReadyToParse',
                             contents = contents,
                             filepath = filepath,
                             filetype = 'java' )

  results = app.post_json( '/event_notification', event_data ).json

  # This is a new file, so the diagnostics can't possibly be available when the
  # initial parse request is sent. We receive these asynchronously.
  eq_( results, {} )

  diag_matcher = contains( has_entries( {
    'kind': 'ERROR',
    'text': 'Syntax error, insert ";" to complete ClassBodyDeclarations',
    'location': LocationMatcher( filepath, 4, 21 ),
    'location_extent': RangeMatcher( filepath, ( 4, 21 ), ( 4, 25 ) ),
    'ranges': contains( RangeMatcher( filepath, ( 4, 21 ), ( 4, 25 ) ) ),
    'fixit_available': False
  } ) )

  # Poll until we receive the diags
  for message in PollForMessages( app,
                                  { 'filepath': filepath,
                                    'contents': contents,
                                    'filetype': 'java' } ):
    if 'diagnostics' in message and message[ 'filepath' ] == filepath:
      print( 'Message {0}'.format( pformat( message ) ) )
      assert_that( message, has_entries( {
        'diagnostics': diag_matcher,
        'filepath': filepath
      } ) )
      break

  # Now confirm that we _also_ get these from the FileReadyToParse request
  for tries in range( 0, 60 ):
    results = app.post_json( '/event_notification', event_data ).json
    if results:
      break
    time.sleep( 0.5 )

  print( 'completer response: {0}'.format( pformat( results ) ) )

  assert_that( results, diag_matcher )
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()
Ejemplo n.º 9
0
    def test_Diagnostics_MaximumDiagnosticsNumberExceeded(self, app):
        filepath = PathToTestFile('max_diagnostics.cc')
        contents = ReadFile(filepath)
        request = {
            'contents': contents,
            'filepath': filepath,
            'filetype': 'cpp'
        }

        test = {'request': request, 'route': '/receive_messages'}
        response = RunAfterInitialized(app, test)

        pprint(response)

        assert_that(
            response,
            contains_exactly(
                has_entries({
                    'diagnostics':
                    has_items(
                        has_entries({
                            'kind':
                            equal_to('ERROR'),
                            'location':
                            LocationMatcher(filepath, 3, 9),
                            'location_extent':
                            RangeMatcher(filepath, (3, 9), (3, 13)),
                            'ranges':
                            contains_exactly(
                                RangeMatcher(filepath, (3, 9), (3, 13))),
                            'text':
                            contains_string("Redefinition of 'test'"),
                            'fixit_available':
                            False
                        }),
                        has_entries({
                            'kind':
                            equal_to('ERROR'),
                            'location':
                            LocationMatcher(filepath, 1, 1),
                            'location_extent':
                            RangeMatcher(filepath, (1, 1), (1, 1)),
                            'ranges':
                            contains_exactly(
                                RangeMatcher(filepath, (1, 1), (1, 1))),
                            'text':
                            equal_to(
                                'Maximum number of diagnostics exceeded.'),
                            'fixit_available':
                            False
                        }))
                })))
Ejemplo n.º 10
0
    def test_Diagnostics_Unity(self, app):
        app.post_json('/load_extra_conf_file',
                      {'filepath': PathToTestFile('.ycm_extra_conf.py')})

        for filename in ['unity.cc', 'unity.h', 'unitya.cc']:
            contents = ReadFile(PathToTestFile(filename))

            event_data = BuildRequest(filepath=PathToTestFile(filename),
                                      contents=contents,
                                      event_name='FileReadyToParse',
                                      filetype='cpp')

            response = app.post_json('/event_notification', event_data).json

            pprint(response)

            assert_that(
                response,
                contains_inanyorder(
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(PathToTestFile('unity.h'), 4, 3),
                        'location_extent':
                        RangeMatcher(PathToTestFile('unity.h'), (4, 3),
                                     (4, 14)),
                        'ranges':
                        empty(),
                        'text':
                        equal_to("use of undeclared identifier 'fake_method'"),
                        'fixit_available':
                        False
                    }),
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'location':
                        LocationMatcher(PathToTestFile('unitya.cc'), 11, 18),
                        'location_extent':
                        RangeMatcher(PathToTestFile('unitya.cc'), (11, 18),
                                     (11, 18)),
                        'ranges':
                        empty(),
                        'text':
                        equal_to("expected ';' after expression"),
                        'fixit_available':
                        True
                    }),
                ))
Ejemplo n.º 11
0
def Subcommands_RefactorRename_MultiFile_test( app ):
  continuous_test = PathToTestFile( 'testy', 'ContinuousTest.cs' )
  fixit_test = PathToTestFile( 'testy', 'FixItTestCase.cs' )
  get_type_test = PathToTestFile( 'testy', 'GetTypeTestCase.cs' )
  goto_test = PathToTestFile( 'testy', 'GotoTestCase.cs' )
  import_test = PathToTestFile( 'testy', 'ImportTest.cs' )
  program = PathToTestFile( 'testy', 'Program.cs' )
  get_doc_test = PathToTestFile( 'testy', 'GetDocTestCase.cs' )
  unicode_test = PathToTestFile( 'testy', 'Unicode.cs' )
  with WrapOmniSharpServer( app, continuous_test ):
    contents = ReadFile( continuous_test )

    request = BuildRequest( completer_target = 'filetype_default',
                            command_arguments = [ 'RefactorRename', 'x' ],
                            line_num = 3,
                            column_num = 11,
                            contents = contents,
                            filetype = 'cs',
                            filepath = continuous_test )

    response = app.post_json( '/run_completer_command', request ).json
    print( 'response = ', response )
    assert_that( response, has_entries( {
      'fixits': contains_exactly( has_entries( {
        'location': LocationMatcher( continuous_test, 3, 11 ),
        'chunks': contains_exactly(
          has_entries( {
            'replacement_text': 'x',
            'range': RangeMatcher( continuous_test, ( 3, 11 ), ( 3, 16 ) )
          } ),
          has_entries( {
            'replacement_text': 'x',
            'range': RangeMatcher( fixit_test, ( 1, 11 ), ( 1, 16 ) )
          } ),
          has_entries( {
            'replacement_text': 'x',
            'range': RangeMatcher( get_doc_test, ( 4, 11 ), ( 4, 16 ) )
          } ),
          has_entries( {
            'replacement_text': 'x',
            'range': RangeMatcher( get_type_test, ( 2, 11 ), ( 2, 16 ) )
          } ),
          has_entries( {
            'replacement_text': 'x',
            'range': RangeMatcher( goto_test, ( 4, 11 ), ( 4, 16 ) )
          } ),
          has_entries( {
            'replacement_text': 'x',
            'range': RangeMatcher( import_test, ( 3, 11 ), ( 3, 16 ) )
          } ),
          has_entries( {
            'replacement_text': 'x',
            'range': RangeMatcher( program, ( 3, 11 ), ( 3, 16 ) )
          } ),
          has_entries( {
            'replacement_text': 'x',
            'range': RangeMatcher( unicode_test, ( 4, 11 ), ( 4, 16 ) )
          } ),
        ) } ) ) } ) )
Ejemplo n.º 12
0
    def test_Diagnostics_SimpleLocationExtent(self, app):
        contents = """
void foo() {
  baz = 5;
}
// Padding to 5 lines
// Padding to 5 lines
"""

        filepath = PathToTestFile('foo.cc')
        request = {
            'contents': contents,
            'filepath': filepath,
            'filetype': 'cpp'
        }
        test = {'request': request, 'route': '/receive_messages'}
        results = RunAfterInitialized(app, test)
        assert_that(
            results,
            contains_exactly(
                has_entries({
                    'diagnostics':
                    contains_exactly(
                        has_entries({
                            'location_extent':
                            RangeMatcher(filepath, (3, 3), (3, 6))
                        }))
                })))
Ejemplo n.º 13
0
def Diagnostics_HandleZeroColumnDiagnostic_test(app):
    filepath = PathToTestFile('testy', 'ZeroColumnDiagnostic.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        for _ in (0, 1):  # First call always returns blank for some reason
            event_data = BuildRequest(filepath=filepath,
                                      event_name='FileReadyToParse',
                                      filetype='cs',
                                      contents=contents)

            results = app.post_json('/event_notification', event_data).json

        assert_that(
            results,
            contains(
                has_entries({
                    'kind':
                    equal_to('ERROR'),
                    'text':
                    contains_string("Unexpected symbol `}'', "
                                    "expecting `;'', `{'', or `where''"),
                    'location':
                    LocationMatcher(filepath, 3, 1),
                    'location_extent':
                    RangeMatcher(filepath, (3, 1), (3, 1))
                })))
Ejemplo n.º 14
0
def Diagnostics_ZeroBasedLineAndColumn_test(app):
    filepath = PathToTestFile('testy', 'Program.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        for _ in (0, 1):  # First call always returns blank for some reason
            event_data = BuildRequest(filepath=filepath,
                                      event_name='FileReadyToParse',
                                      filetype='cs',
                                      contents=contents)

            results = app.post_json('/event_notification', event_data).json

        assert_that(
            results,
            contains(
                has_entries({
                    'kind':
                    equal_to('ERROR'),
                    'text':
                    contains_string(
                        "Unexpected symbol `}'', expecting identifier"),
                    'location':
                    LocationMatcher(filepath, 11, 2),
                    'location_extent':
                    RangeMatcher(filepath, (11, 2), (11, 2)),
                })))
Ejemplo n.º 15
0
def Diagnostics_MultipleSolution_test(app):
    filepaths = [
        PathToTestFile('testy', 'Program.cs'),
        PathToTestFile('testy-multiple-solutions',
                       'solution-named-like-folder', 'testy', 'Program.cs')
    ]
    lines = [11, 10]
    for filepath, line in zip(filepaths, lines):
        with WrapOmniSharpServer(app, filepath):
            contents = ReadFile(filepath)

            for _ in (0, 1):  # First call always returns blank for some reason
                event_data = BuildRequest(filepath=filepath,
                                          event_name='FileReadyToParse',
                                          filetype='cs',
                                          contents=contents)

                results = app.post_json('/event_notification', event_data).json

            assert_that(
                results,
                contains(
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'text':
                        contains_string("Unexpected symbol `}'', "
                                        "expecting identifier"),
                        'location':
                        LocationMatcher(filepath, line, 2),
                        'location_extent':
                        RangeMatcher(filepath, (line, 2), (line, 2))
                    })))
Ejemplo n.º 16
0
def Subcommands_RefactorRename_Unicode_test(app):
    unicode_test = PathToTestFile('testy', 'Unicode.cs')
    with WrapOmniSharpServer(app, unicode_test, wait_for_diags=False):
        contents = ReadFile(unicode_test)

        request = BuildRequest(completer_target='filetype_default',
                               command_arguments=['RefactorRename', 'x'],
                               line_num=30,
                               column_num=31,
                               contents=contents,
                               filetype='cs',
                               filepath=unicode_test)
        response = app.post_json('/run_completer_command', request).json
        assert_that(
            response,
            has_entries({
                'fixits':
                contains_exactly(
                    has_entries({
                        'location':
                        LocationMatcher(unicode_test, 30, 31),
                        'chunks':
                        contains_exactly(
                            has_entries({
                                'replacement_text':
                                'x',
                                'range':
                                RangeMatcher(unicode_test, (30, 29), (30, 35))
                            }))
                    }))
            }))
Ejemplo n.º 17
0
def Subcommands_FixIt_Single_test(app):
    fixit_test = PathToTestFile('testy', 'FixItTestCase.cs')
    with WrapOmniSharpServer(app, fixit_test, wait_for_diags=False):
        contents = ReadFile(fixit_test)

        request = BuildRequest(completer_target='filetype_default',
                               command_arguments=['FixIt'],
                               line_num=4,
                               column_num=17,
                               contents=contents,
                               filetype='cs',
                               filepath=fixit_test)
        response = app.post_json('/run_completer_command', request).json
        LOGGER.debug('r = %s', response)
        assert_that(
            response,
            has_entries({
                'fixits':
                contains_exactly(
                    has_entries({
                        'location':
                        LocationMatcher(fixit_test, 4, 17),
                        'chunks':
                        contains_exactly(
                            has_entries({
                                'replacement_text':
                                'var',
                                'range':
                                RangeMatcher(fixit_test, (4, 13), (4, 16))
                            }))
                    }))
            }))
Ejemplo n.º 18
0
def Diagnostics_WithRange_test(app):
    filepath = PathToTestFile('testy', 'DiagnosticRange.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        for _ in (0, 1):  # First call always returns blank for some reason
            event_data = BuildRequest(filepath=filepath,
                                      event_name='FileReadyToParse',
                                      filetype='cs',
                                      contents=contents)

            results = app.post_json('/event_notification', event_data).json

        assert_that(
            results,
            contains(
                has_entries({
                    'kind':
                    equal_to('WARNING'),
                    'text':
                    contains_string("Name should have prefix '_'"),
                    'location':
                    LocationMatcher(filepath, 3, 16),
                    'location_extent':
                    RangeMatcher(filepath, (3, 16), (3, 25))
                })))
Ejemplo n.º 19
0
def Diagnostics_MultipleSolution_test(app):
    filepaths = [
        PathToTestFile('testy', 'Program.cs'),
        PathToTestFile('testy-multiple-solutions',
                       'solution-named-like-folder', 'testy', 'Program.cs')
    ]
    for filepath in filepaths:
        with WrapOmniSharpServer(app, filepath):
            contents = ReadFile(filepath)

            event_data = BuildRequest(filepath=filepath,
                                      event_name='FileReadyToParse',
                                      filetype='cs',
                                      contents=contents)

            results = app.post_json('/event_notification', event_data).json

            assert_that(
                results,
                has_items(
                    has_entries({
                        'kind':
                        equal_to('ERROR'),
                        'text':
                        contains_string("Identifier expected"),
                        'location':
                        LocationMatcher(filepath, 10, 12),
                        'location_extent':
                        RangeMatcher(filepath, (10, 12), (10, 12))
                    })))
Ejemplo n.º 20
0
def Diagnostics_WithRange_test(app):
    filepath = PathToTestFile('testy', 'DiagnosticRange.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        event_data = BuildRequest(filepath=filepath,
                                  event_name='FileReadyToParse',
                                  filetype='cs',
                                  contents=contents)

        results = app.post_json('/event_notification', event_data).json

        assert_that(
            results,
            has_items(
                has_entries({
                    'kind':
                    equal_to('ERROR'),
                    'text':
                    contains_string(
                        "A namespace cannot directly "
                        "contain members such as fields or methods"),
                    'location':
                    LocationMatcher(filepath, 1, 1),
                    'location_extent':
                    RangeMatcher(filepath, (1, 1), (1, 6))
                })))
Ejemplo n.º 21
0
def Subcommands_RefactorRename_Basic_test(app):
    continuous_test = PathToTestFile('testy', 'ContinuousTest.cs')
    with WrapOmniSharpServer(app, continuous_test):
        contents = ReadFile(continuous_test)

        request = BuildRequest(completer_target='filetype_default',
                               command_arguments=['RefactorRename', 'x'],
                               line_num=5,
                               column_num=15,
                               contents=contents,
                               filetype='cs',
                               filepath=continuous_test)
        response = app.post_json('/run_completer_command', request).json
        assert_that(
            response,
            has_entries({
                'fixits':
                contains(
                    has_entries({
                        'location':
                        LocationMatcher(continuous_test, 5, 15),
                        'chunks':
                        contains(
                            has_entries({
                                'replacement_text':
                                'x',
                                'range':
                                RangeMatcher(continuous_test, (5, 15), (5, 29))
                            }))
                    }))
            }))
Ejemplo n.º 22
0
def Subcommands_FixIt_Single_test(app):
    fixit_test = PathToTestFile('testy', 'FixItTestCase.cs')
    with WrapOmniSharpServer(app, fixit_test):
        contents = ReadFile(fixit_test)

        request = BuildRequest(completer_target='filetype_default',
                               command_arguments=['FixIt'],
                               line_num=4,
                               column_num=23,
                               contents=contents,
                               filetype='cs',
                               filepath=fixit_test)
        response = app.post_json('/run_completer_command', request).json
        LOGGER.debug('r = %s', response)
        assert_that(
            response,
            has_entries({
                'fixits':
                contains(
                    has_entries({
                        'location':
                        LocationMatcher(fixit_test, 4, 23),
                        'chunks':
                        contains(
                            has_entries({
                                'replacement_text':
                                '\n        {\n            NewMethod();\n        }\n\n'
                                '        private static void NewMethod()\n        {\r\n',
                                'range':
                                RangeMatcher(fixit_test, (3, 31), (4, 1))
                            }))
                    }))
            }))
Ejemplo n.º 23
0
def GenericLSPCompleter_Diagnostics_test(app):
    request = BuildRequest(filepath=TEST_FILE,
                           filetype='foo',
                           line_num=1,
                           column_num=1,
                           contents=TEST_FILE_CONTENT,
                           event_name='FileReadyToParse')

    app.post_json('/event_notification', request)
    WaitUntilCompleterServerReady(app, 'foo')
    request.pop('event_name')
    response = app.post_json('/receive_messages', request)
    assert_that(
        response.json,
        has_items(
            has_entries({
                'diagnostics':
                has_items(
                    has_entries({
                        'kind':
                        equal_to('WARNING'),
                        'location':
                        LocationMatcher(TEST_FILE, 2, 1),
                        'location_extent':
                        RangeMatcher(TEST_FILE, (2, 1), (2, 4)),
                        'text':
                        equal_to('FOO is all uppercase.'),
                        'fixit_available':
                        False
                    }))
            })))
Ejemplo n.º 24
0
def Diagnostics_WithRange_test(app):
    filepath = PathToTestFile('testy', 'DiagnosticRange.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        event_data = BuildRequest(filepath=filepath,
                                  event_name='FileReadyToParse',
                                  filetype='cs',
                                  contents=contents)

        results = app.post_json('/event_notification', event_data).json

        assert_that(
            results,
            contains(
                has_entries({
                    'kind':
                    equal_to('WARNING'),
                    'text':
                    contains_string(
                        "The variable '\u4e5d' is assigned but its value is never used"
                    ),
                    'location':
                    LocationMatcher(filepath, 6, 13),
                    'location_extent':
                    RangeMatcher(filepath, (6, 13), (6, 16))
                })))
Ejemplo n.º 25
0
def Diagnostics_ZeroBasedLineAndColumn_test(app):
    filepath = PathToTestFile('testy', 'Program.cs')
    with WrapOmniSharpServer(app, filepath):
        contents = ReadFile(filepath)

        event_data = BuildRequest(filepath=filepath,
                                  event_name='FileReadyToParse',
                                  filetype='cs',
                                  contents=contents)

        results = app.post_json('/event_notification', event_data).json

        assert_that(
            results,
            has_items(
                has_entries({
                    'kind':
                    equal_to('ERROR'),
                    'text':
                    contains_string("Identifier expected"),
                    'location':
                    LocationMatcher(filepath, 10, 12),
                    'location_extent':
                    RangeMatcher(filepath, (10, 12), (10, 12)),
                })))
Ejemplo n.º 26
0
def Diagnostics_MaximumDiagnosticsNumberExceeded_test(app):
    filepath = PathToTestFile('testy', 'MaxDiagnostics.cs')
    contents = ReadFile(filepath)

    event_data = BuildRequest(filepath=filepath,
                              event_name='FileReadyToParse',
                              filetype='cs',
                              contents=contents)

    app.post_json('/event_notification', event_data).json
    WaitUntilCsCompleterIsReady(app, filepath, False)

    event_data = BuildRequest(filepath=filepath,
                              event_name='FileReadyToParse',
                              filetype='cs',
                              contents=contents)

    results = app.post_json('/event_notification', event_data).json

    assert_that(
        results,
        contains_exactly(
            has_entries({
                'kind':
                equal_to('ERROR'),
                'text':
                contains_string("A namespace cannot directly "
                                "contain members such as fields or methods"),
                'location':
                LocationMatcher(filepath, 1, 1),
                'location_extent':
                RangeMatcher(filepath, (1, 1), (1, 6))
            }),
            has_entries({
                'kind':
                equal_to('ERROR'),
                'text':
                contains_string('Maximum number of diagnostics exceeded.'),
                'location':
                LocationMatcher(filepath, 1, 1),
                'location_extent':
                RangeMatcher(filepath, (1, 1), (1, 1)),
                'ranges':
                contains_exactly(RangeMatcher(filepath, (1, 1), (1, 1)))
            })))

    StopCompleterServer(app, 'cs', filepath)
Ejemplo n.º 27
0
def Diagnostics_MaximumDiagnosticsNumberExceeded_test(app):
    filepath = PathToTestFile('test.ts')
    contents = ReadFile(filepath)

    event_data = BuildRequest(filepath=filepath,
                              filetype='typescript',
                              contents=contents,
                              event_name='BufferVisit')
    app.post_json('/event_notification', event_data)

    event_data = BuildRequest(filepath=filepath,
                              filetype='typescript',
                              contents=contents,
                              event_name='FileReadyToParse')

    assert_that(
        app.post_json('/event_notification', event_data).json,
        contains_inanyorder(
            has_entries({
                'kind':
                'ERROR',
                'text':
                "Property 'mA' does not exist on type 'Foo'.",
                'location':
                LocationMatcher(filepath, 17, 5),
                'location_extent':
                RangeMatcher(filepath, (17, 5), (17, 7)),
                'ranges':
                contains(RangeMatcher(filepath, (17, 5), (17, 7))),
                'fixit_available':
                True
            }),
            has_entries({
                'kind':
                'ERROR',
                'text':
                'Maximum number of diagnostics exceeded.',
                'location':
                LocationMatcher(filepath, 1, 1),
                'location_extent':
                RangeMatcher(filepath, (1, 1), (1, 1)),
                'ranges':
                contains(RangeMatcher(filepath, (1, 1), (1, 1))),
                'fixit_available':
                False
            }),
        ))
Ejemplo n.º 28
0
def Diagnostics_MaximumDiagnosticsNumberExceeded_test(app):
    filepath = PathToTestFile('testy', 'MaxDiagnostics.cs')
    contents = ReadFile(filepath)

    event_data = BuildRequest(filepath=filepath,
                              event_name='FileReadyToParse',
                              filetype='cs',
                              contents=contents)

    app.post_json('/event_notification', event_data).json
    WaitUntilCsCompleterIsReady(app, filepath)

    event_data = BuildRequest(filepath=filepath,
                              event_name='FileReadyToParse',
                              filetype='cs',
                              contents=contents)

    results = app.post_json('/event_notification', event_data).json

    assert_that(
        results,
        contains(
            has_entries({
                'kind':
                equal_to('ERROR'),
                'text':
                contains_string("The type 'MaxDiagnostics' already contains "
                                "a definition for 'test'"),
                'location':
                LocationMatcher(filepath, 4, 16),
                'location_extent':
                RangeMatcher(filepath, (4, 16), (4, 20))
            }),
            has_entries({
                'kind':
                equal_to('ERROR'),
                'text':
                contains_string('Maximum number of diagnostics exceeded.'),
                'location':
                LocationMatcher(filepath, 1, 1),
                'location_extent':
                RangeMatcher(filepath, (1, 1), (1, 1)),
                'ranges':
                contains(RangeMatcher(filepath, (1, 1), (1, 1)))
            })))

    StopCompleterServer(app, 'cs', filepath)
Ejemplo n.º 29
0
 def test_multiple(self, app):
     RunTest(
         app, {
             'request': {
                 'filetype': 'cpp',
                 'filepath': PathToTestFile('tokens.manual.cpp'),
                 'contents':
                 '#define MACRO( x, y ) ( x );\n\nnamespace Test {}'
             },
             'expect': {
                 'response':
                 requests.codes.ok,
                 'data':
                 has_entries({
                     'errors':
                     empty(),
                     'semantic_tokens':
                     has_entries({
                         'tokens':
                         contains(
                             has_entries({
                                 'range':
                                 RangeMatcher(
                                     PathToTestFile('tokens.manual.cpp'),
                                     (1, 9), (1, 14)),
                                 'type':
                                 'macro',
                                 'modifiers':
                                 contains('declaration', 'globalScope')
                             }),
                             has_entries({
                                 'range':
                                 RangeMatcher(
                                     PathToTestFile('tokens.manual.cpp'),
                                     (3, 11), (3, 15)),
                                 'type':
                                 'namespace',
                                 'modifiers':
                                 contains('declaration', 'globalScope')
                             }))
                     }),
                 })
             },
         })
Ejemplo n.º 30
0
def Diagnostics_LocationExtent_MissingSemicolon_test( app ):
  filepath = PathToTestFile( 'location_extent.cc' )

  event_data = BuildRequest( contents = ReadFile( filepath ),
                             event_name = 'FileReadyToParse',
                             filepath = filepath,
                             filetype = 'cpp',
                             compilation_flags = [ '-x', 'c++' ] )

  response = app.post_json( '/event_notification', event_data ).json

  pprint( response )

  assert_that( response, contains(
    has_entries( {
      'kind': equal_to( 'ERROR' ),
      'location': LocationMatcher( filepath, 2, 9 ),
      'location_extent': RangeMatcher( filepath, ( 2, 9 ), ( 2, 9 ) ),
      'ranges': empty(),
      'text': equal_to( "expected ';' at end of declaration list" ),
      'fixit_available': True
    } ),
    has_entries( {
      'kind': equal_to( 'ERROR' ),
      'location': LocationMatcher( filepath, 5, 1 ),
      'location_extent': RangeMatcher( filepath, ( 5, 1 ), ( 6, 11 ) ),
      'ranges': empty(),
      'text': equal_to( "unknown type name 'multiline_identifier'" ),
      'fixit_available': False
    } ),
    has_entries( {
      'kind': equal_to( 'ERROR' ),
      'location': LocationMatcher( filepath, 8, 7 ),
      'location_extent': RangeMatcher( filepath, ( 8, 7 ), ( 8, 11 ) ),
      'ranges': contains(
        # FIXME: empty ranges from libclang should be ignored.
        RangeMatcher( '', ( 0, 0 ), ( 0, 0 ) ),
        RangeMatcher( filepath, ( 8, 7 ), ( 8, 11 ) )
      ),
      'text': equal_to( 'constructor cannot have a return type' ),
      'fixit_available': False
    } )
  ) )