language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Allow esm URL imports

Open Suya1671 opened this issue 2 years ago • 5 comments

Description

I'm working on getting svelte working with deno/vite and I have a fully working demo, and typescript works near perfectly, except for URL imports. Since URL imports are an esm standard and work in the browser already, the LSP should have support for this.

Proposed solution

A deno-lsp-like way of caching and using imports through URLs

Alternatives

Somehow plugging in the deno LSP instead of the typescript LSP into svelte

Additional Information, eg. Screenshots

demo of URL imports working:https://github.com/Suyashtnt/svelte-deno-ssr-demo/

Suya1671 avatar Dec 28 '22 08:12 Suya1671

What exactly is it that you mean by "support"? The error diagnostics ("cannot find module..") going away? This working at runtime? In other words, is this an editor feature request or Svelte feature request?

dummdidumm avatar Dec 28 '22 09:12 dummdidumm

What exactly is it that you mean by "support"? The error diagnostics ("cannot find module..") going away? This working at runtime? In other words, is this an editor feature request or Svelte feature request?

The ability to have types from URL imports and cannot find module to go away

Suya1671 avatar Dec 28 '22 09:12 Suya1671

Is TypeScript able to handle this somehow? Is there some Deno TS plugin that enables support for this? Trying to find out how this works in regular .ts files

dummdidumm avatar Jan 09 '23 11:01 dummdidumm

Hi @dummdidumm, Bartek from the Deno here. AFAIK TypeScript itself doesn't have support for this - we have a custom plugin (https://github.com/denoland/vscode_deno/tree/main/typescript-deno-plugin), but it doesn't seem to handle logic for resolution, from my understanding all requests are sent to Deno's LSP that does the resolution. That said, we have some plugins for eg. ESBuild that implement this logic, so it shouldn't be a hard lift from our side to provide an npm package that provides this resolution. We also have deno_cache which provides the same logic as Deno binary in terms of obtaining and caching of these sources. I'm sure we could provide an npm version for it as well.

bartlomieju avatar Jan 13 '23 21:01 bartlomieju

I'll try having a crack at it, inspired by the work in esbuild_deno_loader, which I've used in a small Deno + Svelte project.

I think the place to look is https://github.com/sveltejs/language-tools/blob/master/packages/language-server/src/plugins/typescript/module-loader.ts

mxdvl avatar Aug 28 '23 08:08 mxdvl