val-town / codemirror-ts

lint, hover, and autocomplete extensions for CodeMirror + TypeScript
https://val-town.github.io/codemirror-ts/
ISC License
105 stars 6 forks source link

Add recipe for remote node modules #27

Open nandorojo opened 3 weeks ago

nandorojo commented 3 weeks ago

A useful feature is to let you use any node modules in the editor. However, this requires 1) parsing the file, 2) querying NPM for their types (potentially@types/package-name) and lastly inserting the types into codemirror-ts. It could be useful to document the ideal way to handle 2 or maybe abstract it into a function

For deno, these would be URLs and/or npm:package-name, but it could be cool to support both

tmcw commented 3 weeks ago

Yep! The answer to this is ata but the long answer is, whew, it's hard and we've poured days into improving type acquisition and it is still really tough. Making TypeScript and Deno get along is extremely hard - TypeScript doesn't support npm: or jsr: prefixes, doesn't support URLs for imports, etc. So you have to do a lot of arbitrary trickery to make the two get along.

I've been planning on refactoring our code and might be able to make it OSS, but can't promise that it'll be all that robust 😭

stevekrouse commented 3 weeks ago

We're also thinking about integrating with Deno LSP run on a server somewhere.

In theory it could also be fun to try getting the Deno LSP server running in wasm on the browser but I am not very hopeful about that.

nandorojo commented 3 weeks ago

would be very cool

nandorojo commented 2 weeks ago

btw @tmcw thanks for sharing ata, not sure how I missed that. I might just try a regex to find-and-replace the npm: and jsr: prefixes. As for the URL imports...well that sounds harder haha.

I'll play with this and share any updates.

nandorojo commented 2 weeks ago

I've been planning on refactoring our code and might be able to make it OSS, but can't promise that it'll be all that robust 😭

Even if it's not...anything helps!

nandorojo commented 2 weeks ago

Just as a note: I managed to get this working with @typescript/ata. However, I haven't yet figured out a way to get the types working with deno. If there's anything you can share about the tricks you used to support these prefixes after fetching the files from ata, would be super appreciated.

nandorojo commented 2 weeks ago

Possibly some relevant notes for Deno here: https://github.com/microsoft/TypeScript-Website/issues/2097

nandorojo commented 2 weeks ago

I managed to get this working for npm: imports. It involves some minor hacks but it's actually quite good and uses internals from @typescript/ata. Let me know if you'd like me to share it here and I can put it together. I think it could be worth adding as an extension to this library.

tmcw commented 2 weeks ago

All right - here's our deno-ata repo: https://github.com/val-town/deno-ata

Pretty unfinished/unpolished, this is derived from a refactor that I've been working on of this code.

nandorojo commented 2 weeks ago

thank you! it’s private though btw

tmcw commented 2 weeks ago

Whoops - it's public now