def _GoToImplementation( self, request_data, fallback_to_declaration ): """ Jump to implementation of identifier under cursor """ implementation = self._GetResponse( '/findimplementations', self._DefaultParameters( request_data ) ) if implementation[ 'QuickFixes' ]: if len( implementation[ 'QuickFixes' ] ) == 1: return responses.BuildGoToResponseFromLocation( _BuildLocation( request_data, implementation[ 'QuickFixes' ][ 0 ][ 'FileName' ], implementation[ 'QuickFixes' ][ 0 ][ 'Line' ], implementation[ 'QuickFixes' ][ 0 ][ 'Column' ] ) ) else: return [ responses.BuildGoToResponseFromLocation( _BuildLocation( request_data, x[ 'FileName' ], x[ 'Line' ], x[ 'Column' ] ) ) for x in implementation[ 'QuickFixes' ] ] else: if ( fallback_to_declaration ): return self._GoToDefinition( request_data ) elif implementation[ 'QuickFixes' ] is None: raise RuntimeError( 'Can\'t jump to implementation' ) else: raise RuntimeError( 'No implementations found' )
def _GoToReferences(self, request_data): """ Jump to references of identifier under cursor """ # _GetResponse can throw. Original code by @mispencer # wrapped it in a try/except and set `reference` to `{ 'QuickFixes': None }` # After being unable to hit that case with tests, # that code path was thrown away. reference = self._GetResponse('/findusages', self._DefaultParameters(request_data)) if reference['QuickFixes']: if len(reference['QuickFixes']) == 1: return responses.BuildGoToResponseFromLocation( _BuildLocation(request_data, reference['QuickFixes'][0]['FileName'], reference['QuickFixes'][0]['Line'], reference['QuickFixes'][0]['Column'])) else: return [ responses.BuildGoToResponseFromLocation( _BuildLocation(request_data, ref['FileName'], ref['Line'], ref['Column'])) for ref in reference['QuickFixes'] ] else: raise RuntimeError('No references found')
def _GoToSymbol(self, request_data, args): request = self._DefaultParameters(request_data) request.update({'Language': 'C#', 'Filter': args[0]}) response = self._GetResponse('/findsymbols', request) quickfixes = response['QuickFixes'] if quickfixes: if len(quickfixes) == 1: ref = quickfixes[0] ref_file = ref['FileName'] ref_line = ref['Line'] lines = GetFileLines(request_data, ref_file) line = lines[min(len(lines), ref_line - 1)] return responses.BuildGoToResponseFromLocation( _BuildLocation(request_data, ref_file, ref_line, ref['Column']), line) else: goto_locations = [] for ref in quickfixes: ref_file = ref['FileName'] ref_line = ref['Line'] lines = GetFileLines(request_data, ref_file) line = lines[min(len(lines), ref_line - 1)] goto_locations.append( responses.BuildGoToResponseFromLocation( _BuildLocation(request_data, ref_file, ref_line, ref['Column']), line)) return goto_locations else: raise RuntimeError('No symbols found')
def _GoToImplementation(self, request_data, fallback_to_declaration): """ Jump to implementation of identifier under cursor """ try: implementation = self._GetResponse( '/findimplementations', self._DefaultParameters(request_data)) except ValueError: implementation = {'QuickFixes': None} quickfixes = implementation['QuickFixes'] if quickfixes: if len(quickfixes) == 1: impl = quickfixes[0] return responses.BuildGoToResponseFromLocation( _BuildLocation(request_data, impl['FileName'], impl['Line'], impl['Column'])) else: return [ responses.BuildGoToResponseFromLocation( _BuildLocation(request_data, x['FileName'], x['Line'], x['Column'])) for x in quickfixes ] else: if (fallback_to_declaration): return self._GoToDefinition(request_data) elif quickfixes is None: raise RuntimeError('Can\'t jump to implementation') else: raise RuntimeError('No implementations found')
def _GoToSymbol( self, request_data, args ): if len( args ) < 1: raise RuntimeError( 'Must specify something to search for' ) query = args[ 0 ] self._Reload( request_data ) filespans = self._SendRequest( 'navto', { 'searchValue': query, 'file': request_data[ 'filepath' ] } ) if not filespans: raise RuntimeError( 'Symbol not found' ) results = [ responses.BuildGoToResponseFromLocation( _BuildLocation( GetFileLines( request_data, fs[ 'file' ] ), fs[ 'file' ], fs[ 'start' ][ 'line' ], fs[ 'start' ][ 'offset' ] ), fs[ 'name' ] ) for fs in filespans ] if len( results ) == 1: return results[ 0 ] return results
def BuildRefResponse( ref ): filepath = self._ServerPathToAbsolute( ref[ 'file' ] ) return responses.BuildGoToResponseFromLocation( _BuildLocation( GetFileLines( request_data, filepath ), filepath, ref[ 'start' ][ 'line' ], ref[ 'start' ][ 'ch' ] ) )
def _GoToDefinition(self, request_data): """ Jump to definition of identifier under cursor """ definition = self._GetResponse('/gotodefinition', self._DefaultParameters(request_data)) if definition['FileName'] is not None: return responses.BuildGoToResponseFromLocation( _BuildLocation(request_data, definition['FileName'], definition['Line'], definition['Column'])) else: raise RuntimeError('Can\'t jump to definition')
def _GoToDefinition(self, request_data): query = { 'type': 'definition', } response = self._GetResponse(query, request_data['column_codepoint'], request_data) filepath = self._ServerPathToAbsolute(response['file']) return responses.BuildGoToResponseFromLocation( _BuildLocation(GetFileLines(request_data, filepath), filepath, response['start']['line'], response['start']['ch']))
def _GoToDefinition(self, request_data): query = { 'type': 'definition', } response = self._GetResponse(query, request_data['column_codepoint'], request_data) return responses.BuildGoToResponseFromLocation( _BuildLocation( utils.SplitLines( GetFileContents(request_data, response['file'])), response['file'], response['start']['line'], response['start']['ch']))
def _GoToReferences(self, request_data): self._Reload(request_data) response = self._SendRequest( 'references', { 'file': request_data['filepath'], 'line': request_data['line_num'], 'offset': request_data['column_codepoint'] }) return [ responses.BuildGoToResponseFromLocation( _BuildLocation(GetFileLines(request_data, ref['file']), ref['file'], ref['start']['line'], ref['start']['offset']), ref['lineText']) for ref in response['refs'] ]
def _GoToDefinition(self, request_data): self._Reload(request_data) filespans = self._SendRequest( 'definition', { 'file': request_data['filepath'], 'line': request_data['line_num'], 'offset': request_data['column_codepoint'] }) if not filespans: raise RuntimeError('Could not find definition.') span = filespans[0] return responses.BuildGoToResponseFromLocation( _BuildLocation(GetFileLines(request_data, span['file']), span['file'], span['start']['line'], span['start']['offset']))
def _GoToImplementation( self, request_data ): self._Reload( request_data ) try: filespans = self._SendRequest( 'implementation', { 'file': request_data[ 'filepath' ], 'line': request_data[ 'line_num' ], 'offset': request_data[ 'column_codepoint' ] } ) except RuntimeError: raise RuntimeError( 'No implementation found.' ) results = [] for span in filespans: filename = span[ 'file' ] start = span[ 'start' ] lines = GetFileLines( request_data, span[ 'file' ] ) line_num = start[ 'line' ] results.append( responses.BuildGoToResponseFromLocation( _BuildLocation( lines, filename, line_num, start[ 'offset' ] ), lines[ line_num - 1 ] ) ) return results