deno
3cdc2631 - feat(lsp): autocomplete jsr:/npm:/node: in deno.json(c) imports (#34724)

Commit
94 days ago
feat(lsp): autocomplete jsr:/npm:/node: in deno.json(c) imports (#34724) ## Summary Inside a script, the LSP already completes `jsr:`, `npm:`, and `node:` import specifiers — e.g. typing `import {} from \"jsr:@std/yaml@\"` pops up the available versions. The same completion was missing inside the `imports` (and `scopes`) fields of `deno.json` / `deno.jsonc`, so users had to look up package names and versions by hand and paste them in. This change wires that completion path up for the config file: - A new `get_deno_json_import_completions` in `cli/lsp/completions.rs` parses the open document with `jsonc_parser`, walks the AST to find the innermost string literal whose quoted range contains the cursor, validates that its path is either `imports.<key>` or `scopes.<scope>.<key>`, and then delegates to the existing `get_jsr_completions` / `get_npm_completions` / `get_node_completions` helpers — so jsr packages, jsr exports, npm packages, npm exports, jsr/npm versions, and node builtins all work the same way they do in script imports. - `Inner::completion` in `cli/lsp/language_server.rs` runs this path before the regular flow when the open document is a JSON/JSONC config file. The document is fetched with `Diagnosable::Ignore` (JSON docs aren't diagnosable in the TS sense) and `Enabled::Ignore` (a fresh config file may itself be the only thing that would identify the workspace as enabled). ## Test plan - [x] New integration test `lsp_completions_deno_json_imports` in `tests/integration/lsp_tests.rs` covering jsr version completion in `imports`, node-builtin completion in `imports`, and jsr version completion in `scopes.<scope>.<key>`. - [x] Full LSP completion test suite (`cargo test -p integration_tests --test integration lsp_completion`) — 22/22 pass. - [x] `cargo clippy -p deno --bin deno` clean. - [x] `dprint check` clean. Closes #24927 Closes denoland/divybot#419 Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
Author
Parents
Loading