fix(lsp): preserve URL extensions in typeof import(...) hovers#34565
Merged
Conversation
When hovering over a value typed by a remote module namespace, vscode
displayed `typeof import('https://.../mod')` instead of the URL the user
wrote (`typeof import('https://.../mod.ts')`). The cause was that the
LSP's custom document registry built source files with
`createLanguageServiceSourceFile` but never set `sourceFile.moduleName`,
so tsc's `getSpecifierForModuleSymbol` fell through to
`getModuleSpecifiers`, which strips `.ts` from URL specifiers.
Mirror the `cli/tsc/97_ts_host.js` behavior by assigning `moduleName` on
acquire/update for non-`file:` specifiers. We skip `file:` so that
relative paths and the internal `/$node_modules/` rewrite don't leak
into hovers for local files and npm packages.
Closes denoland/orchid#320
Co-Authored-By: Divy Srivastava <[email protected]>
typeof import(...) strips .ts extension in vscode property tooltiptypeof import(...) hovers
littledivy
approved these changes
May 30, 2026
littledivy
enabled auto-merge (squash)
May 30, 2026 09:16
littledivy
added a commit
to crowlKats/deno
that referenced
this pull request
Jun 10, 2026
…oland#34565) ## Summary When hovering over a value whose type is a remote module namespace, vscode displayed `typeof import('https://.../mod')` instead of the URL the user actually wrote (`typeof import('https://.../mod.ts')`). The cause was that the LSP's custom document registry (`cli/tsc/98_lsp.js`) built source files via `ts.createLanguageServiceSourceFile` but never set `sourceFile.moduleName`. Without `moduleName`, tsc's `getSpecifierForModuleSymbol` falls through to `getModuleSpecifiers`, which strips `.ts` from URL specifiers. The CLI path (`cli/tsc/97_ts_host.js`) already sets `moduleName = specifier` after creating a source file, so this only affects the LSP. Mirror that behavior on the LSP side by assigning `moduleName` in both `acquireDocumentWithKey` and `updateDocumentWithKey`, but only for non-`file:` specifiers. Skipping `file:` keeps tsc's relative-path computation for local files and prevents the internal `/$node_modules/` rewrite from leaking into hovers for npm packages. Fixes denoland#16058. Closes denoland/orchid#320 ## Test plan - [x] `cargo test -p deno --lib lsp::tsc::tests` — the existing `test_modify_sources` already exercises this exact code path through a `Property X does not exist on type 'typeof import("URL")'` diagnostic; its expected message is updated to keep `.ts`. - [x] Outdated comment block in `display_parts_to_string` that documented the stripped-extension behavior as a tsc limitation has been removed (denoland#16058 is fixed). Co-authored-by: divybot <[email protected]> Co-authored-by: Divy Srivastava <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When hovering over a value whose type is a remote module namespace, vscode displayed
typeof import('https://.../mod')instead of the URL the user actually wrote (typeof import('https://.../mod.ts')).The cause was that the LSP's custom document registry (
cli/tsc/98_lsp.js) built source files viats.createLanguageServiceSourceFilebut never setsourceFile.moduleName. WithoutmoduleName, tsc'sgetSpecifierForModuleSymbolfalls through togetModuleSpecifiers, which strips.tsfrom URL specifiers.The CLI path (
cli/tsc/97_ts_host.js) already setsmoduleName = specifierafter creating a source file, so this only affects the LSP.Mirror that behavior on the LSP side by assigning
moduleNamein bothacquireDocumentWithKeyandupdateDocumentWithKey, but only for non-file:specifiers. Skippingfile:keeps tsc's relative-path computation for local files and prevents the internal/$node_modules/rewrite from leaking into hovers for npm packages.Fixes #16058.
Closes denoland/orchid#320
Test plan
cargo test -p deno --lib lsp::tsc::tests— the existingtest_modify_sourcesalready exercises this exact code path through aProperty X does not exist on type 'typeof import("URL")'diagnostic; its expected message is updated to keep.ts.display_parts_to_stringthat documented the stripped-extension behavior as a tsc limitation has been removed (typeof import(...)strips.tsextension in vscode property tooltip #16058 is fixed).