-
-
Notifications
You must be signed in to change notification settings - Fork 369
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
Fix other file goto definition #3725
Fix other file goto definition #3725
Conversation
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.
Nice catch, LGTM!
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.
Great investigation!
I wonder if we have this problem anywhere else? I could imagine that e.g. |
Wait, it would have to be workspace symbols, or maybe call hierarchy. |
e.g.
@wz1000 I'm guessing that these hiedb operations will return the positions in the file from some past point in time? Or will it do the right thing if the target file is open in the editor and has been altered by the user? |
we index files asynchronously whenever they are changed, so if that is completed it will do the right thing (as long as the file compiles). |
d561562
to
3b64fbb
Compare
Thanks all! Anything else that needs to happen before it gets the mergeme label? |
And if it isn't it won't! It seems like in principle we probably ought to be computing position mappings for things from hiedb also, tbh. |
yes, but then we would need to know which version of the file was indexed in hiedb. Even if we kept track of file versions (source hashes?) in hiedb, this would still not be complete and potentially add a lot of latency to these requests. If you open and edit a file, but the initial load hasn't completed, we will still have a location from the
2 seems not quite worth it and it would also be susceptible to race conditions. |
In my work on gotoDefinition for dependencies I found a bug that predates my code. In the first few seconds of startup for big projects, gotoDefinition uses the persistent rule for GetHieAst and gets its PositionMapping from that. This PositionMapping gets used on any location a definition is found, even if that definition is in a different file. This doesn't usually cause a problem, except when the definition in the other file is found on a line that is greater than the number of lines in the file we are coming from. In this case, the PositionMapping will end up nullifying the result returned by AtPoint.gotoDefinition.
If you want to see this bug in action, try opening ghcide/src/Development/IDE/LSP/Outline.hs and try to immediately do gotoDefinition on
extract_cons
on line 115.This code adds some tests for gotoDefinition and fixes the problem by checking if the file where the definition is found is the same as the file we are calling gotoDefinition from. If not, we get the PositionMapping for the file we are going to and use that instead.