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
Goto Definition should prioritize symbols in the current file #14
Comments
Taking over suggestion from #341:
|
@FichteFoll y, the current selection doesn't need to be at the top of the list, but being able to just press enter would be good. Essentially, it's about trying to anticipate what you most probably want when you press
I think the default should exclude other scope symbols. You could have an option to enable/disable, but rather than that I think it might be better to have a different command and shortcut for a |
To add on this, when you have the same file open in two views (New View into File), Goto Definition and Goto Symbol in Project will always switch to the first file in a group, as it considers this the best match. It works for Goto Symbol, though. Very annoying when you want to keep two different sections of the same file in focus. |
Same issue encountered in C++. When I'm in a file and I use goto_definition to look up a class or function name, any definition which exists in the current file should appear first in the popup list, not somewhere in the middle. Similarly, it would be nice if definitions from files in the current directory or nearby directories were preferred to those in far-off directories. This is frequently a problem when lookup up common function names like Create() or something; there will be dozens of hits, and the one relevant one is buried somewhere in the middle. |
I just thought I'd chime in here. I had been working on adding symbol support for VHDL in my package and was showing off the capability to a colleague of mine. His first question was "does it go to the local file first?". We tried a few examples and it seems to order the drop down list by alphabetical directory order. It does not prefer the local file nor makes any visible distinction what the local file is in the list. I strongly suggest that if there is a local version of the symbol in the definition list it should be the default selection in some way. Also bold text might be a good thing too but do not know how much formatting (if any) quick panel supports. |
One can patch Patch valid as at build 3150: --- Shipped Packages/Default/symbol.py 2017-10-05 18:43:08
+++ Packages/Default/symbol.py 2017-10-17 10:27:31
@@ -31,10 +31,17 @@
locations.append(l)
for ofl in open_file_locations:
if not file_in_location_list(ofl[0], ofl_ignore):
locations.append(ofl)
+
+ # determine the "key" used in `lookup_symbol_in_open_files` for the active file (the file name if there is one, otherwise the buffer id)
+ active_file_key = window.active_view().file_name() or '<untitled {}>'.format(window.active_view().buffer_id());
+ # sort the locations
+ # - if the location is in the active file, sort by the beginning of the region where the symbol is defined
+ # - otherwise sort by `<z` (to ensure it comes after the active file, regardless of whether the file has been saved or the name starts with a number etc.), followed by the key, followed by the beginning of the region where the symbol is defined
+ locations = list(sorted(locations, key=lambda loc: str(loc[2][0]) if loc[0] == active_file_key else '<z' + loc[0] + str(loc[2][0])))
return locations
def lookup_references(window, symbol): Of course, if you plan to use this patch, don't forget to install https://packagecontrol.io/packages/OverrideAudit to know when your patch is out of date. |
How do you use this patch? Using Sublime Text 3, build 3126, I do not see any Default directory in my Packages directory, and I cannot find symbol.py anywhere. |
@wastedepository until this is merged to ST core, here is how you can use it:
So, to sum it up:
On this file, around line 33, add the snippet above: Couple of extra things:
|
What a breath of fresh air! I've been waiting so long for this problem to be addressed. Here's how to extract the file on OSX, where the file locations are different:
|
The canonical way to do this is not to extract zip files manually, but just to use https://packagecontrol.io/packages/PackageResourceViewer to open the file that you want to override from the relevant package. |
Trying this out today. It definitely is putting the local file first! Also knowing where this happens, maybe we can make it more elaborate with various sorting methods. It currently is looking like it's purely alphabetical, but it might be better to make it project directory hierarchy then alphabetical. I'll have to experiment a little. |
I applied the patch and really like the result! I would love to see this incorporated in a future version. |
@keith-hall I've made a small enhancement to your patch. I moved it into it's own function so it could be used with lookup_references and I've made it sort by descending line number within a file: |
This is fixed in 4092 and probably since 4089. Hooray 🍾 ! |
I do frontend coding mostly. And It happen fairly often for me to have the following structure:
The problem appear when i try to go to a definition inside of
src/foo.js
: a popup will be displayed that give me the choice to pick which file should i go to, with current file being... not first :)I don't mind having multiple files listed there, but i guess the current file should be first, the other to follow.
The text was updated successfully, but these errors were encountered: