-
Notifications
You must be signed in to change notification settings - Fork 774
[RFC] Remap GoTo commands in Python completer #1200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Map GoTo, GoToDefinition, and GoToDeclaration to Jedi goto_assignments. Add GoToType command and map it to Jedi goto_definitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 2 LGTMs obtained (waiting on @micbou)
ycmd/completers/python/python_completer.py, line 290 at r1 (raw file):
# set to True. Unfortunately, we can't use that option because it also # jumps to the original name of aliases which is unexpected as an alias is # a kind of definition. So, we need to traverse definitions by repeatedly
Hmmmmmmm.
I have personally become quite used to the behaviour of jumping to the import statement.
In fact, I rely on it. Often I will be looking at some code with the goal of, let's say, "re-appropriating" it for something. I see a type or something that I need to use, and do my GoTo mapping on it to get the import statement that I also need.
If I happen to actually want the real def, I just hit the mapping 2x.
So changing this is tricky in the sense that there's a real use case for the current behaviour, and probably why it's an option in Jedi's API.
I realise it is perhaps somewhat arbitrary, but maybe GoToDefinition
jumps through imports, but GoToDeclaration
jumps to imports ? Not sure.
Thoughts?
Codecov Report
@@ Coverage Diff @@
## master #1200 +/- ##
==========================================
- Coverage 97.28% 97.09% -0.19%
==========================================
Files 95 95
Lines 7109 7128 +19
==========================================
+ Hits 6916 6921 +5
- Misses 193 207 +14 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 12 of 12 files at r1.
Reviewable status: 0 of 2 LGTMs obtained (waiting on @puremourning)
ycmd/completers/python/python_completer.py, line 290 at r1 (raw file):
Previously, puremourning (Ben Jackson) wrote…
Hmmmmmmm.
I have personally become quite used to the behaviour of jumping to the import statement.
In fact, I rely on it. Often I will be looking at some code with the goal of, let's say, "re-appropriating" it for something. I see a type or something that I need to use, and do my GoTo mapping on it to get the import statement that I also need.
If I happen to actually want the real def, I just hit the mapping 2x.
So changing this is tricky in the sense that there's a real use case for the current behaviour, and probably why it's an option in Jedi's API.
I realise it is perhaps somewhat arbitrary, but maybe
GoToDefinition
jumps through imports, butGoToDeclaration
jumps to imports ? Not sure.Thoughts?
Sorry for taking a month to respond to this one... I completely forgot about it after our brief talk in gitter.
I'm not sure what @puremourning is referring to as "re-appropriating", but I too have had a need to see from where was something imported. Though I mostly used *
followed by gg
in vim. Much more often, my intention for :YcmCompleter GoTo
was to jump through the imports and to the actual definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 12 of 12 files at r1.
Reviewable status: 0 of 2 LGTMs obtained (waiting on @puremourning)
ycmd/completers/python/python_completer.py, line 290 at r1 (raw file):
Previously, bstaletic (Boris Staletic) wrote…
Sorry for taking a month to respond to this one... I completely forgot about it after our brief talk in gitter.
I'm not sure what @puremourning is referring to as "re-appropriating", but I too have had a need to see from where was something imported. Though I mostly used
*
followed bygg
in vim. Much more often, my intention for:YcmCompleter GoTo
was to jump through the imports and to the actual definition.
Using GoTo
to find how a symbol is imported doesn't seem right to me. What about displaying that information with the GetType
command? Jedi returns the fully qualified name in the full_name
field. For instance, instead of returning the following info on GetType
for the ExpandVariablesInPath
function imported in that file:
def ExpandVariablesInPath(path)
we could return
def ycmd.utils.ExpandVariablesInPath(path)
which is enough to know how to import this symbol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 2 LGTMs obtained (waiting on @puremourning)
ycmd/completers/python/python_completer.py, line 290 at r1 (raw file):
Previously, micbou wrote…
Using
GoTo
to find how a symbol is imported doesn't seem right to me. What about displaying that information with theGetType
command? Jedi returns the fully qualified name in thefull_name
field. For instance, instead of returning the following info onGetType
for theExpandVariablesInPath
function imported in that file:def ExpandVariablesInPath(path)we could return
def ycmd.utils.ExpandVariablesInPath(path)which is enough to know how to import this symbol.
That sounds good to me.
Submitted #1275 |
The
GoToDefinition
,GoToDeclaration
, andGoTo
commands in the Python completer are currently mapped to Jedi methods as follows:GoToDefinition
togoto_definitions
;GoToDeclaration
togoto_assignments
;GoTo
togoto_definitions
thengoto_assignments
ifgoto_definitions
failed.These mappings don't really make sense since there is no distinction between a definition and a declaration in Python. All these
GoTo
commands should be identical. Said that, we need to decide to which function these commands should be mapped:goto_definitions
orgoto_assignments
? My understanding is thatgoto_definitions
doesn't jump to the definition but the type definition whilegoto_assignments
actually jumps to the definition with the caveat that it doesn't follow imports by default. This is confirmed by looking at some examples (these examples are used in the tests):With the cursor on the second
my_variable
:goto_definitions
returns theint
builtin. This is clearly not the definition ofmy_variable
but its type;goto_assignments
returns the firstmy_variable
which is wheremy_variable
is defined.With the cursor on the second
my_instance
:goto_definitions
returns the firstMyClass
. Again, not the definition ofmy_instance
but its type;goto_assignments
returns the firstmy_instance
.This PR thus proposes to remap the three
GoTo
commands togoto_assignments
(with some additional work to follow imports and to deal with aliases) and to introduce a new commandGoToType
which is mapped togoto_definitions
.This change is