Skip to content

Commit

Permalink
fix(lsp): ignore errors on ambient module imports (#27855)
Browse files Browse the repository at this point in the history
This makes it so imports of ambient modules (e.g. `$app/environment` in
svelte, any virtual module in vite, or other module provided by a
bundler) don't error in the LSP.

The way this works is that when we request diagnostics from TSC, we also
respond with the list of ambient modules. Then, in the diagnostics code,
we save diagnostics (produced by deno) that may be invalidated as an
ambient module and wait to publish the diagnostics until we've received
the ambient modules from TSC.

The actual ambient modules you get from TSC can contain globs, e.g.
`*.css`. So when we get new ambient modules, we compile them all into a
regex and check erroring imports against that regex. Ambient modules
should change rarely, so in most cases we should be using a pre-compiled
regex, which executes in linear time (wrt the specifier length).

TODO:
- Ideally we should only publish once, right now we publish with the
filtered specifiers and then the TSC ones
- deno check (#27633)
  • Loading branch information
nathanwhit authored Jan 30, 2025
1 parent 0dd334b commit b7456fe
Show file tree
Hide file tree
Showing 4 changed files with 498 additions and 101 deletions.
Loading

0 comments on commit b7456fe

Please sign in to comment.