deno
85cb7aea - fix(lsp): spurious diagnostics in Jupyter notebook cells (#34734)

Commit
122 days ago
fix(lsp): spurious diagnostics in Jupyter notebook cells (#34734) Fixes two sources of spurious diagnostics in Jupyter notebook cells when using the Deno kernel (denoland/deno#22628). ## 1. Unsaved notebooks weren't resolved against the workspace This is the one that matches @littledivy's note that **the problem goes away when the notebook is saved**. Unsaved (untitled) notebooks have no path on disk. Their notebook/cell URIs use the `untitled:` / `vscode-notebook-cell:` schemes, which `uri_to_url` converts to a `file:` URL at the *filesystem root* (e.g. `file:///Untitled-1.ipynb`). That URL matches no workspace scope, so the cells were analyzed unscoped — without the workspace's `deno.json` and its import map. Imports like `import { x } from "exports"` (mapped in `deno.json`) were therefore flagged as missing dependencies. Saving the notebook into the workspace gives it a real path under the workspace folder, the scope resolves, and the errors disappear. Fix: associate in-memory documents (untitled files and unsaved notebook cells) with the workspace root scope when they don't otherwise resolve to one, so they behave the same whether or not the notebook has been saved. ## 2. Top-level declarations shadowing default-library globals Notebook cells are analyzed as classic scripts so that top-level declarations are shared between cells. As a side effect, declaring a top-level binding whose name matches an ambient global from the default libraries (e.g. `const name = "..."` shadowing `declare var name` in `lib.deno.window.d.ts`) was reported as a redeclaration error (`2451 Cannot redeclare block-scoped variable`), even though it's valid in a notebook. Fix: filter out redeclaration diagnostics (`2300`/`2403`/`2451`) for classic scripts (notebook cells) when the conflicting declaration lives in a default library. Cross-cell redeclarations still error (their related declaration is in another cell, not in an asset library), and regular files are unaffected because Deno's default compiler options set `moduleDetection: "force"`, so only notebook cells are classic scripts in the LSP. Both fixes have integration test coverage in `tests/integration/lsp_tests.rs` (`lsp_jupyter_untitled_notebook_workspace_scope` and `lsp_jupyter_import_map_and_diagnostics`), and the existing notebook/untitled tests still pass. Refs #22628 Closes denoland/divybot#433 --------- Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
Author
Parents
Loading