Uh oh!
There was an error while loading. Please reload this page.
Support go-to-definition for imports of arbitrary files - #42539
Conversation
Uh oh!
There was an error while loading. Please reload this page.
DanielRosenwasser
commented
Jan 28, 2021
@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. |
DanielRosenwasser
commented
Jan 28, 2021
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 |
andrewbranch
commented
Jan 28, 2021
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. |
sandersn
commented
Jan 28, 2021
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 |
Uh oh!
There was an error while loading. Please reload this page.
@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 |
sheetalkamat
commented
Feb 1, 2021
@andrewbranch interesting.. till you pointed out, I didn't realize we were doing module resolution as part of |
andrewbranch
commented
Feb 1, 2021
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. |
Uh oh!
There was an error while loading. Please reload this page.
andrewbranch
commented
Feb 16, 2021
New changes:
|
Uh oh!
There was an error while loading. Please reload this page.
…urce file has that path
| end: node.getEnd(), | ||
| fileName: node.text | ||
| }, | ||
| unverified: !!verifiedFileName, |
There was a problem hiding this comment.
@andrewbranch just realised that we are not passing this on in the through server even though we added this property to protocol.
tsserver37220.log
andrewbranch
commented
Aug 27, 2021
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.fileExistscheck 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!