Skip to content

Commit

Permalink
Auto merge of ycm-core#458 - icholy:master, r=vheon
Browse files Browse the repository at this point in the history
TypeScript: Add GoToType command

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/458)
<!-- Reviewable:end -->
  • Loading branch information
homu committed Apr 14, 2016
2 parents 92083b2 + 31feae6 commit 8cd2a03
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ycmd/completers/typescript/typescript_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ def GetSubcommandsMap( self ):
self._GoToDefinition( request_data ) ),
'GoToReferences' : ( lambda self, request_data, args:
self._GoToReferences( request_data ) ),
'GoToType' : ( lambda self, request_data, args:
self._GoToType( request_data ) ),
'GetType' : ( lambda self, request_data, args:
self._GetType( request_data ) ),
'GetDoc' : ( lambda self, request_data, args:
Expand Down Expand Up @@ -358,6 +360,25 @@ def _GoToReferences( self, request_data ):
) for ref in response[ 'refs' ] ]


def _GoToType( self, request_data ):
self._Reload( request_data )
try:
filespans = self._SendRequest( 'typeDefinition', {
'file': request_data[ 'filepath' ],
'line': request_data[ 'line_num' ],
'offset': request_data[ 'column_num' ]
} )

span = filespans[ 0 ]
return responses.BuildGoToResponse(
filepath = span[ 'file' ],
line_num = span[ 'start' ][ 'line' ],
column_num = span[ 'start' ][ 'offset' ]
)
except RuntimeError:
raise RuntimeError( 'Could not find type definition' )


def _GetType( self, request_data ):
self._Reload( request_data )
info = self._SendRequest( 'quickinfo', {
Expand Down
56 changes: 56 additions & 0 deletions ycmd/tests/typescript/subcommands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,62 @@ def Subcommands_GoTo_Fail_test( app ):
ErrorMatcher( RuntimeError, 'Could not find definition' ) )


@SharedYcmd
def Subcommands_GoToType_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 )

goto_data = BuildRequest( completer_target = 'filetype_default',
command_arguments = [ 'GoToType' ],
line_num = 14,
column_num = 6,
contents = contents,
filetype = 'typescript',
filepath = filepath )

response = app.post_json( '/run_completer_command', goto_data ).json
assert_that( response,
has_entries( {
'filepath': filepath,
'line_num': 2,
'column_num': 1,
} ) )


@SharedYcmd
def Subcommands_GoToType_fail_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 )

goto_data = BuildRequest( completer_target = 'filetype_default',
command_arguments = [ 'GoToType' ],
line_num = 39,
column_num = 8,
contents = contents,
filetype = 'typescript',
filepath = filepath )

response = app.post_json( '/run_completer_command',
goto_data,
expect_errors = True ).json
assert_that( response,
ErrorMatcher( RuntimeError, 'Could not find type definition' ) )


@SharedYcmd
def Subcommands_RefactorRename_Missing_test( app ):
filepath = PathToTestFile( 'test.ts' )
Expand Down

0 comments on commit 8cd2a03

Please sign in to comment.