From 9cf566bd8fc203685a448c190ffc0c22568cbd90 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Fri, 21 Mar 2014 11:34:00 -0700 Subject: [PATCH] Renamed GoToDefinitionElseDeclaration to GoTo The old name still works for the sake of backwards compatibility. --- README.md | 11 ++++++----- python/ycm/client/command_request.py | 9 +++++++-- python/ycm/completers/cpp/clang_completer.py | 8 ++++---- python/ycm/completers/cs/cs_completer.py | 2 +- python/ycm/completers/python/jedi_completer.py | 8 ++++---- python/ycm/server/tests/subcommands_test.py | 4 ++-- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index f1efb824..af80cf30 100644 --- a/README.md +++ b/README.md @@ -594,7 +594,7 @@ Python one and on the Clang completer if the currently active file is a C/C++/Objective-C one. You may also want to map the subcommands to something less verbose; for -instance, `nnoremap jd :YcmCompleter GoToDefinitionElseDeclaration` +instance, `nnoremap jd :YcmCompleter GoTo` maps the `jd` sequence to the longer subcommand invocation. The various `GoTo*` subcommands add entries to Vim's `jumplist` so you can use @@ -618,11 +618,12 @@ with `#include` directives (directly or indirectly) in that file. Supported in filetypes: `c, cpp, objc, objcpp, python, cs` -### The `GoToDefinitionElseDeclaration` subcommand +### The `GoTo` subcommand -Looks up the symbol under the cursor and jumps to its definition if possible; if -the definition is not accessible from the current translation unit, jumps to the -symbol's declaration. +This command tries to perform the "most sensible" GoTo operation it can. +Currently, this means that it tries to look up the symbol under the cursor and +jumps to its definition if possible; if the definition is not accessible from +the current translation unit, jumps to the symbol's declaration. Supported in filetypes: `c, cpp, objc, objcpp, python, cs` diff --git a/python/ycm/client/command_request.py b/python/ycm/client/command_request.py index 7e5073c2..effc5a5c 100644 --- a/python/ycm/client/command_request.py +++ b/python/ycm/client/command_request.py @@ -22,15 +22,20 @@ from ycm.client.base_request import BaseRequest, BuildRequestData, ServerError from ycm import vimsupport from ycm.utils import ToUtf8IfNeeded +def _EnsureBackwardsCompatibility( arguments ): + if arguments and arguments[ 0 ] == 'GoToDefinitionElseDeclaration': + arguments[ 0 ] = 'GoTo' + return arguments + class CommandRequest( BaseRequest ): def __init__( self, arguments, completer_target = None ): super( CommandRequest, self ).__init__() - self._arguments = arguments + self._arguments = _EnsureBackwardsCompatibility( arguments ) self._completer_target = ( completer_target if completer_target else 'filetype_default' ) self._is_goto_command = ( - arguments and arguments[ 0 ].startswith( 'GoTo' ) ) + self._arguments and self._arguments[ 0 ].startswith( 'GoTo' ) ) self._response = None diff --git a/python/ycm/completers/cpp/clang_completer.py b/python/ycm/completers/cpp/clang_completer.py index b8372e86..eafcc23d 100644 --- a/python/ycm/completers/cpp/clang_completer.py +++ b/python/ycm/completers/cpp/clang_completer.py @@ -103,7 +103,7 @@ class ClangCompleter( Completer ): def DefinedSubcommands( self ): return [ 'GoToDefinition', 'GoToDeclaration', - 'GoToDefinitionElseDeclaration', + 'GoTo', 'ClearCompilationFlagCache'] @@ -116,8 +116,8 @@ class ClangCompleter( Completer ): return self._GoToDefinition( request_data ) elif command == 'GoToDeclaration': return self._GoToDeclaration( request_data ) - elif command == 'GoToDefinitionElseDeclaration': - return self._GoToDefinitionElseDeclaration( request_data ) + elif command == 'GoTo': + return self._GoTo( request_data ) elif command == 'ClearCompilationFlagCache': return self._ClearCompilationFlagCache() raise ValueError( self.UserCommandsHelpMessage() ) @@ -163,7 +163,7 @@ class ClangCompleter( Completer ): location.column_number_ - 1) - def _GoToDefinitionElseDeclaration( self, request_data ): + def _GoTo( self, request_data ): location = self._LocationForGoTo( 'GetDefinitionLocation', request_data ) if not location or not location.IsValid(): location = self._LocationForGoTo( 'GetDeclarationLocation', request_data ) diff --git a/python/ycm/completers/cs/cs_completer.py b/python/ycm/completers/cs/cs_completer.py index 6fe6644b..285c9a13 100755 --- a/python/ycm/completers/cs/cs_completer.py +++ b/python/ycm/completers/cs/cs_completer.py @@ -48,7 +48,7 @@ class CsharpCompleter( Completer ): 'ServerReady': (lambda self, request_data: self._ServerIsReady()), 'GoToDefinition': (lambda self, request_data: self._GoToDefinition( request_data )), 'GoToDeclaration': (lambda self, request_data: self._GoToDefinition( request_data )), - 'GoToDefinitionElseDeclaration': (lambda self, request_data: self._GoToDefinition( request_data )) + 'GoTo': (lambda self, request_data: self._GoToDefinition( request_data )) } def __init__( self, user_options ): diff --git a/python/ycm/completers/python/jedi_completer.py b/python/ycm/completers/python/jedi_completer.py index 421dc009..b7f61a61 100644 --- a/python/ycm/completers/python/jedi_completer.py +++ b/python/ycm/completers/python/jedi_completer.py @@ -66,7 +66,7 @@ class JediCompleter( Completer ): def DefinedSubcommands( self ): return [ 'GoToDefinition', 'GoToDeclaration', - 'GoToDefinitionElseDeclaration' ] + 'GoTo' ] def OnUserCommand( self, arguments, request_data ): @@ -78,8 +78,8 @@ class JediCompleter( Completer ): return self._GoToDefinition( request_data ) elif command == 'GoToDeclaration': return self._GoToDeclaration( request_data ) - elif command == 'GoToDefinitionElseDeclaration': - return self._GoToDefinitionElseDeclaration( request_data ) + elif command == 'GoTo': + return self._GoTo( request_data ) raise ValueError( self.UserCommandsHelpMessage() ) @@ -99,7 +99,7 @@ class JediCompleter( Completer ): raise RuntimeError( 'Can\'t jump to declaration.' ) - def _GoToDefinitionElseDeclaration( self, request_data ): + def _GoTo( self, request_data ): definitions = ( self._GetDefinitionsList( request_data ) or self._GetDefinitionsList( request_data, declaration = True ) ) if definitions: diff --git a/python/ycm/server/tests/subcommands_test.py b/python/ycm/server/tests/subcommands_test.py index 45ba2797..9da31b0b 100644 --- a/python/ycm/server/tests/subcommands_test.py +++ b/python/ycm/server/tests/subcommands_test.py @@ -95,7 +95,7 @@ def DefinedSubcommands_Works_test(): eq_( [ 'GoToDefinition', 'GoToDeclaration', - 'GoToDefinitionElseDeclaration' ], + 'GoTo' ], app.post_json( '/defined_subcommands', subcommands_data ).json ) @@ -106,6 +106,6 @@ def DefinedSubcommands_WorksWhenNoExplicitCompleterTargetSpecified_test(): eq_( [ 'GoToDefinition', 'GoToDeclaration', - 'GoToDefinitionElseDeclaration' ], + 'GoTo' ], app.post_json( '/defined_subcommands', subcommands_data ).json )