michaelgmcd / vscode-language-babel

VSCode syntax highlighting for today's JavaScript
https://marketplace.visualstudio.com/items?itemName=mgmcdermott.vscode-language-babel
MIT License
130 stars 17 forks source link

rfc: load grammars from babel plugins #61

Open cdaringe opened 4 years ago

cdaringe commented 4 years ago

Describe the issue

what if babel plugins themselves hosted or pointed to vscode injection grammars for syntax support?

the workflow could look like:

now, vscode auto-enhances syntax, rather than having to drop code here to support arbitrary features. that is, i want any babel user to install my custom babel plugin and have syntax supported automatically on-install.

what is not great about this proposal is that babel-plugins would then need to be vscode aware, which seems maybe not the best. it's not the worst either--it's pretty light to add a contributes: field in package.json and host an additional .json file in the npm tarball. however, this could be mitigated by plugins perhaps just referencing an optional dependency (or even just a string mapping in package.json, "vscode-injection-grammar": "some-npm-vscode-injection-grammar") that this pkg would attempt to load.

what do you think?

michaelgmcd commented 4 years ago

This is definitely an interesting idea and I could definitely see this being the future of JS syntax highlighting.

I see two major blockers. VSCode public APIs don't allow this project to update grammars at runtime (see https://github.com/microsoft/vscode/issues/61962). The second would be getting plugin authors to write and maintain their grammars. Most people use something like babel-preset-env these days which contains most of the "newer" syntax.

VSCode uses Textmate grammars, which is a standard across several editors. This means the plugins wouldn't necessarily need to VSCode aware.

We also need to be aware of advances in Node.js. Unlike front-end JS, Node.js (mainly V8) adds native support for newer JS features (like async/await). How would those work?

cdaringe commented 4 years ago

APIs don't allow this project to update grammars at runtime

bummer. thanks for sharing the link! i have subscribed and 👍 'd

getting plugin authors to write and maintain their grammars

agreed. i would hope that if a POC went well enough, the benefit/ROI of the improved UX would drive the community to at least be receptive to it. if babel authors felt uncomfortable about having VSCode-isms in their source because of the low correlation to the actual purpose of the plugin, perhaps some package.json interface could be used that this extension could parse and load--that way adding a grammar into their source would be less invasive, and interested parties could maintain the grammar in a stringly referenced repo from the babel plugin's package.json? i don't know--maybe i'm thinkin too far ahead :)

How would those work?

ya, interesting. one idea would be to synchronize VSCode's internal TM grammar internally here somehow. i bet if one ecosystem advances a feature to stable, vscode would move to support the syntax quickly, and 👏, no further effort? there also may already be a babel-plugin for said hypothetical feature in the users -env plugin stack iff they are using babel, so of course we could sniff there. i think it's less common for node users to babel tho. referring/building back on the package.json interface suggestion, perhaps we could allow users to punch in git urls to grammars to install at runtime for them? 🤔