示例#1
0
def _BuildLocation( request_data, filename, line_num, column_num ):
  contents = utils.SplitLines( GetFileContents( request_data, filename ) )
  line_value = contents[ line_num - 1 ]
  return responses.Location(
      line_num,
      CodepointOffsetToByteOffset( line_value, column_num ),
      filename )
示例#2
0
 def BuildFixItChunk(change):
     filepath = self._ServerPathToAbsolute(change['file'])
     file_contents = utils.SplitLines(
         GetFileContents(request_data, filepath))
     return responses.FixItChunk(
         change['text'],
         BuildRange(file_contents, filepath, change['start'],
                    change['end']))
示例#3
0
 def BuildFixItChunk(change):
     filename = os.path.abspath(change['file'])
     file_contents = utils.SplitLines(
         GetFileContents(request_data, filename))
     return responses.FixItChunk(
         change['text'],
         BuildRange(file_contents, filename, change['start'],
                    change['end']))
示例#4
0
 def BuildRefResponse( ref ):
   filepath = self._ServerPathToAbsolute( ref[ 'file' ] )
   return responses.BuildGoToResponseFromLocation(
     _BuildLocation(
       utils.SplitLines( GetFileContents( request_data, filepath ) ),
       filepath,
       ref[ 'start' ][ 'line' ],
       ref[ 'start' ][ 'ch' ] ) )
示例#5
0
def _BuildFixItChunksForFile( request_data, new_name, file_replacement ):
  """ returns a list of FixItChunk for each replacement range for the
  supplied file"""

  # On windows, tsserver annoyingly returns file path as C:/blah/blah,
  # whereas all other paths in Python are of the C:\\blah\\blah form. We use
  # normpath to have python do the conversion for us.
  file_path = os.path.normpath( file_replacement[ 'file' ] )
  file_contents = utils.SplitLines( GetFileContents( request_data, file_path ) )
  return [ _BuildFixItChunkForRange( new_name, file_contents, file_path, r )
           for r in file_replacement[ 'locs' ] ]
示例#6
0
文件: cs_completer.py 项目: jnhe/ycmd
def _BuildLocation(request_data, filename, line_num, column_num):
    if line_num <= 0:
        return None
    # OmniSharp sometimes incorrectly returns 0 for the column number. Assume the
    # column is 1 in that case.
    if column_num <= 0:
        column_num = 1
    contents = utils.SplitLines(GetFileContents(request_data, filename))
    line_value = contents[line_num - 1]
    return responses.Location(
        line_num, CodepointOffsetToByteOffset(line_value, column_num),
        filename)
示例#7
0
    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(
                utils.SplitLines(GetFileContents(request_data, filepath)),
                filepath, response['start']['line'], response['start']['ch']))
示例#8
0
 def _GetJediScriptForDefinition(self, request_data, definition):
     path = definition.module_path
     source = GetFileContents(request_data, path)
     line = definition.line
     column = definition.column
     environment = self._EnvironmentForRequest(request_data)
     sys_path = self._SysPathForFile(request_data, environment)
     return jedi.Script(source,
                        line,
                        column,
                        path,
                        sys_path=sys_path,
                        environment=environment)
示例#9
0
 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(
                 utils.SplitLines(GetFileContents(request_data,
                                                  ref['file'])),
                 ref['file'], ref['start']['line'], ref['start']['offset']),
             ref['lineText']) for ref in response['refs']
     ]
示例#10
0
    def _GoToReferences(self, request_data):
        query = {
            'type': 'refs',
        }

        response = self._GetResponse(query, request_data['column_codepoint'],
                                     request_data)

        return [
            responses.BuildGoToResponseFromLocation(
                _BuildLocation(
                    utils.SplitLines(GetFileContents(request_data,
                                                     ref['file'])),
                    ref['file'], ref['start']['line'], ref['start']['ch']))
            for ref in response['refs']
        ]
示例#11
0
  def _GoToDefinition( self, request_data ):
    self._Reload( request_data )
    try:
      filespans = self._SendRequest( 'definition', {
        'file':   request_data[ 'filepath' ],
        'line':   request_data[ 'line_num' ],
        'offset': request_data[ 'column_codepoint' ]
      } )

      span = filespans[ 0 ]
      return responses.BuildGoToResponseFromLocation(
        _BuildLocation( utils.SplitLines( GetFileContents( request_data,
                                                           span[ 'file' ] ) ),
                        span[ 'file' ],
                        span[ 'start' ][ 'line' ],
                        span[ 'start' ][ 'offset' ] ) )
    except RuntimeError:
      raise RuntimeError( 'Could not find definition' )