denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.06k stars 5.14k forks source link

LSP errors if both `foo.js` and `foo.d.ts` exist with sloppy imports enabled #23745

Closed nathanwhit closed 1 week ago

nathanwhit commented 1 week ago

If you have sloppy imports enabled, and you have both a .js and .d.ts file, you get an error upon opening the .js file.

For instance:

// deno.json
{
  "unstable": ["sloppy-imports"]
}

// foo.js
export const bar = 3;

// foo.d.ts
export const bar: number;

if you open foo.js, you get

ERROR TSLS = Error: Could not find source file: 'file:///home/lsp-sloppy-imports/foo.js'.
    at getValidSourceFile (ext:deno_tsc/00_typescript.js:144419:24)
    at Object.getSemanticDiagnostics (ext:deno_tsc/00_typescript.js:144681:32)
    at serverRequest (ext:deno_tsc/99_main_compiler.js:1153:34)
Error during TS request "$getDiagnostics":
  Error: Could not find source file: 'file:///home/lsp-sloppy-imports/foo.js'.
    at getValidSourceFile (ext:deno_tsc/00_typescript.js:144419:24)
    at Object.getSemanticDiagnostics (ext:deno_tsc/00_typescript.js:144681:32)
    at serverRequest (ext:deno_tsc/99_main_compiler.js:1153:34)
Error generating TypeScript diagnostics: The response was not received for the request.

This is because the LSP is resolving foo.js to foo.d.ts even though foo.js exists.

dsherret commented 1 week ago

Maybe related: https://github.com/denoland/deno/issues/23197