Skip to content

feat(lsp): provide hover info for import map resolutions#34854

Merged
littledivy merged 4 commits into
mainfrom
orch/divybot-467
Jun 5, 2026
Merged

feat(lsp): provide hover info for import map resolutions#34854
littledivy merged 4 commits into
mainfrom
orch/divybot-467

Conversation

@divybot

@divybot divybot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

When hovering over a specifier that resolves via an import map, the language server now surfaces the import map resolution in the hover tooltip.

Previously, hovering over an import specifier only showed the resolved Code/Types target. Now, when that specifier was remapped through an import map, an additional line is appended:

**Resolved Dependency**

**Code**: file:///…/lib/foo.ts

**Import Map**: `foo` → `./lib/foo.ts` _(deno.json)_

Implementation

  • cli/lsp/resolver.rs: adds ImportMapHover and LspScopedResolver::import_map_hover(specifier, code, referrer). The responsible entry is found by reverse-lookup on the resolved URL (mirroring import_map::ImportMap::lookup) — an entry matches when its address equals (literal mapping) or is a prefix of (/-suffixed mapping) the resolved specifier. It additionally requires the entry to reconstruct the exact specifier that was written, so a relative import that merely lands inside a mapped directory is not mislabelled as an import map resolution. The displayed key/value are the raw text from the import map file.
  • cli/lsp/language_server.rs: Inner::hover now passes the written specifier text and resolved code URL to import_map_hover and appends the rendered line to the resolved-dependency hover.

Test

tests/integration/lsp_tests.rs::lsp_hover_dependency_import_map covers both a literal mapping (foo./lib/foo.ts) and a prefix mapping (bar/./lib/bar/).

Closes #13622

Closes denoland/divybot#467

littledivy and others added 4 commits June 5, 2026 13:17
When hovering over an import specifier that was remapped through an import
map, the resolved-dependency hover now appends an "Import Map" line showing
the matched key and value, e.g.:

  **Import Map**: `@std/path` → `jsr:@std/path@^1` _(deno.json)_

The matched entry is found by reverse-lookup on the resolved specifier
(mirroring `import_map::ImportMap::lookup`), additionally requiring the entry
to reconstruct the exact specifier that was written so a relative import that
merely lands in a mapped directory is not mislabelled.

Co-Authored-By: Divy Srivastava <[email protected]>
The previous run's 'lint debug' jobs failed because the denoland/setup-deno
'Install Deno' step crashed on the Windows runner (exit 0xC0000409,
STATUS_STACK_BUFFER_OVERRUN) before lint.js/clippy ran; the linux/macos legs
were cancelled by matrix fail-fast. No code change.

Co-Authored-By: Divy Srivastava <[email protected]>
The new "**Import Map**" hover line is appended for any import-map-resolved
dependency, so the existing exact-match hover assertions in
lsp_hover_typescript_types_via_import_map, lsp_deno_json_workspace_import_map
and lsp_deno_json_scopes_import_map now include it.

Co-Authored-By: Divy Srivastava <[email protected]>
In a workspace, member import maps are merged into the workspace-root import
map with values rebased relative to the root deno.json, so the project2 entry
displays as `./project2/foo2.ts` rather than `./foo2.ts`.

Co-Authored-By: Divy Srivastava <[email protected]>
@littledivy
littledivy merged commit 2aa45eb into main Jun 5, 2026
136 checks passed
@littledivy
littledivy deleted the orch/divybot-467 branch June 5, 2026 13:56
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.

lsp: provides hover info for import maps

2 participants