codemirror-ts icon indicating copy to clipboard operation
codemirror-ts copied to clipboard

Add recipe for remote node modules

Open nandorojo opened this issue 1 year ago • 11 comments

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

nandorojo avatar Jun 08 '24 12:06 nandorojo

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 😭

tmcw avatar Jun 08 '24 15:06 tmcw

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.

stevekrouse avatar Jun 08 '24 17:06 stevekrouse

would be very cool

nandorojo avatar Jun 08 '24 17:06 nandorojo

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 avatar Jun 11 '24 13:06 nandorojo

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 avatar Jun 11 '24 13:06 nandorojo

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 avatar Jun 11 '24 20:06 nandorojo

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

nandorojo avatar Jun 11 '24 20:06 nandorojo

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.

nandorojo avatar Jun 12 '24 15:06 nandorojo

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.

tmcw avatar Jun 12 '24 21:06 tmcw

thank you! it’s private though btw

nandorojo avatar Jun 12 '24 21:06 nandorojo

Whoops - it's public now

tmcw avatar Jun 12 '24 21:06 tmcw

Landed #57, which includes an example of ATA hooked into codemirror-ts in the README and in the demo.

tmcw avatar Feb 07 '25 18:02 tmcw

Sweet!

nandorojo avatar Feb 07 '25 18:02 nandorojo