Skip to content
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

Ensure navigation to definitons follows imports and is transparent to decoration #1712

Merged
merged 5 commits into from
Jun 5, 2018

Conversation

PeterJCLaw
Copy link

Fixes #1638

It turns out that there are three mechanisms for getting definitions of a symbol from jedi:

  • goto_definitions: follows all imports and considers the actual value of the target symbol (so returns the wrapped version of a decorated function)
  • goto_assignments: considers the original assignments of a symbol, meaning that it ignores decoration, but doesn't follow import by default
  • goto_assignments(follow_imports=True): behaves like goto_assignments, but doesn't consider an import to be an assignment and so follows to the original assignment

It's the latter behaviour that is what I'd find most useful from an IDE.

This pull request:

  • Has a title summarizes what is changing
  • Includes a news entry file (remember to thank yourself!)
  • Has unit tests & code coverage is not adversely affected (within reason)
  • Works on all actively maintained versions of Python (only tested under Python 2.7, but there's no reason it should be different elsewhere)
  • Works on Windows 10, macOS, and Linux (only tested on Linux, but there's no reason it shouldn't work elsewhere)

This provides a starting point for more interesting tests.
Specifically this covers some basic cases as well as the
reproductions of microsoft#1638 and microsoft#1033 plus the variant of microsoft#1033 which
always worked.
This fixes microsoft#1638 and simplifies the code (to what I believe that
@davidhalter had in mind in
microsoft#1033 (comment)).

This change means that all of the test cases recently added to
'navigation.tests.ts' now pass, meaning that navigtion to the
definition of functions works through imports and goes to the
original function, even when that function is decorated.
@msftclas
Copy link

msftclas commented May 20, 2018

CLA assistant check
All CLA requirements met.

@codecov
Copy link

codecov bot commented May 20, 2018

Codecov Report

Merging #1712 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1712   +/-   ##
=======================================
  Coverage   71.49%   71.49%           
=======================================
  Files         277      277           
  Lines       13014    13014           
  Branches     2344     2344           
=======================================
  Hits         9305     9305           
  Misses       3574     3574           
  Partials      135      135

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e26da1a...7132798. Read the comment docs.

defs = self._get_definitionsx(script.goto_assignments(), request['id'])
except:
pass
defs = self._get_definitionsx(script.goto_assignments(follow_imports=True), request['id'])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally like this. This is way nicer than the code that remains here.

I also want to mention that I think you should read (and subscribe to) davidhalter/jedi-vim#808, because this is a very similar issue. There is going to be an additional option probably that might be helpful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidhalter I opened #1735 to track this.

@DonJayamanne DonJayamanne merged commit 3b2667e into microsoft:master Jun 5, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
@PeterJCLaw PeterJCLaw deleted the fix-1638 branch December 14, 2019 21:13
@PeterJCLaw PeterJCLaw restored the fix-1638 branch December 14, 2019 21:15
@PeterJCLaw PeterJCLaw deleted the fix-1638 branch June 20, 2020 11:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Go To Definition of decorated functions that get wrapped goes to the wrapping function
5 participants