Skip to content

fix(lsp): preserve URL extensions in typeof import(...) hovers#34565

Merged
littledivy merged 3 commits into
mainfrom
orch/divybot-320
May 30, 2026
Merged

fix(lsp): preserve URL extensions in typeof import(...) hovers#34565
littledivy merged 3 commits into
mainfrom
orch/divybot-320

Conversation

@divybot

@divybot divybot commented May 30, 2026

Copy link
Copy Markdown
Contributor

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 #16058.

Closes denoland/orchid#320

Test plan

  • 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.
  • Outdated comment block in display_parts_to_string that documented the stripped-extension behavior as a tsc limitation has been removed (typeof import(...) strips .ts extension in vscode property tooltip #16058 is fixed).

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]>
@divybot divybot changed the title [denoland/deno#16058] typeof import(...) strips .ts extension in vscode property tooltip fix(lsp): preserve URL extensions in typeof import(...) hovers May 30, 2026
@littledivy
littledivy enabled auto-merge (squash) May 30, 2026 09:16
@littledivy
littledivy merged commit de5c878 into main May 30, 2026
136 checks passed
@littledivy
littledivy deleted the orch/divybot-320 branch May 30, 2026 09:42
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

typeof import(...) strips .ts extension in vscode property tooltip

2 participants