From a49457829d10631a2444d08b5de94615a3f2b646 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Thu, 14 Apr 2016 12:11:47 -0400 Subject: [PATCH 1/4] Add GoToType command --- .../typescript/typescript_completer.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ycmd/completers/typescript/typescript_completer.py b/ycmd/completers/typescript/typescript_completer.py index e9dcd1c809..fe99564a14 100755 --- a/ycmd/completers/typescript/typescript_completer.py +++ b/ycmd/completers/typescript/typescript_completer.py @@ -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: @@ -357,6 +359,24 @@ def _GoToReferences( self, request_data ): description = ref[ 'lineText' ] ) 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 ) From 432f47332aaa9f239cf92dc5e3937d2452a306d6 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Thu, 14 Apr 2016 12:12:09 -0400 Subject: [PATCH 2/4] whitespace --- ycmd/completers/typescript/typescript_completer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ycmd/completers/typescript/typescript_completer.py b/ycmd/completers/typescript/typescript_completer.py index fe99564a14..eb41323233 100755 --- a/ycmd/completers/typescript/typescript_completer.py +++ b/ycmd/completers/typescript/typescript_completer.py @@ -359,6 +359,7 @@ def _GoToReferences( self, request_data ): description = ref[ 'lineText' ] ) for ref in response[ 'refs' ] ] + def _GoToType( self, request_data ): self._Reload( request_data ) try: From 5f2a819ba12ea2d26fde697bcf059fdd9e1bc4bd Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Thu, 14 Apr 2016 12:23:21 -0400 Subject: [PATCH 3/4] Add test for GoToType command --- ycmd/tests/typescript/subcommands_test.py | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ycmd/tests/typescript/subcommands_test.py b/ycmd/tests/typescript/subcommands_test.py index a5e501927b..01056ed89d 100644 --- a/ycmd/tests/typescript/subcommands_test.py +++ b/ycmd/tests/typescript/subcommands_test.py @@ -233,6 +233,35 @@ 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_RefactorRename_Missing_test( app ): filepath = PathToTestFile( 'test.ts' ) From 31feae61f0eca6c1108b02b097e6a059aa5a51e3 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Thu, 14 Apr 2016 15:14:47 -0400 Subject: [PATCH 4/4] Add a another test for GoToType command --- ycmd/tests/typescript/subcommands_test.py | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ycmd/tests/typescript/subcommands_test.py b/ycmd/tests/typescript/subcommands_test.py index 01056ed89d..da1fd1f33a 100644 --- a/ycmd/tests/typescript/subcommands_test.py +++ b/ycmd/tests/typescript/subcommands_test.py @@ -262,6 +262,33 @@ def Subcommands_GoToType_test( app ): } ) ) +@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' )