-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Support go-to-definition for imports of arbitrary files #42539
Conversation
@typescript-bot pack this |
Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 5f256f1. You can monitor the build here. |
Heads up @mjbvz and @minestarks. |
How does this work with partial semantic mode (including in the browser)? What will happen if we try go-to-definition on import { thing } from "./vandelay.js"/*1*/;
thing/*2*/(); |
Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
Whatever the current behavior for go-to-definition on the identifier reference, that will be unchanged.
Don’t we already resolve one level of direct imports from your current source file? That should be unchanged as well. If we don’t, we would return a response saying the definition is at position 0 of |
I mostly ask because #39037 is a related issue I've been interested in unlocking as well, but I get why this doesn't automatically unlock that. |
Answering a question that nobody has asked, I tested this with emacs. This gives a picture of how a simply written language plugin will behave and is usually similar to how VS works too. Everything works fine. For the non-existent file, the editor raises an error inside |
@sheetalkamat I’m looking at adding a case in partialSemanticServer.ts now (just pushed a new commit), and it seems imports are resolved... the source file’s If we hadn’t resolved them, this case would be a problem, because the module specifier is extensionless. Without doing at least some basic module resolution, we wouldn’t know that the target file has a |
@andrewbranch interesting.. till you pointed out, I didn't realize we were doing module resolution as part of |
In that case, this feature currently works exactly the same for partial semantic mode as full semantic mode, and the new test will ensure that we don’t break it if we change partial semantic mode later. |
2c49160
to
f6d3b18
Compare
New changes:
|
…urce file has that path
end: node.getEnd(), | ||
fileName: node.text | ||
}, | ||
unverified: !!verifiedFileName, |
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.
@andrewbranch just realised that we are not passing this on in the through server even though we added this property to protocol.
tsserver37220.log
That's correct, it was shipped in 4.3 |
Fixes #41861
The first commit adds support for jumping to arbitrary files from import/require module specifiers, whether those are scripts or non-source files like CSS (thanks @DanielRosenwasser for the idea that this should work).
The second commit goes further by allowing us to return a successful response for files that don’t exist. I was curious what would happen, so I removed the
host.fileExists
check and made sure we don’t try to read a file’s text to convert{ position: 0 }
to{ line: 0, column: 0 }
. The result in VS Code was this:Having the quick option to create the file seemed like a win to me; better than doing nothing. But I’m open to debate on whether we want that.
Also, if anyone knows how this will work in Visual Studio or has a quick way to test it, that would be appreciated!