Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language support for VSCode? #690

Open
manterfield opened this issue Jul 26, 2024 · 5 comments
Open

Language support for VSCode? #690

manterfield opened this issue Jul 26, 2024 · 5 comments

Comments

@manterfield
Copy link

Thanks for the awesome project!

I'm considering using expr embedded within a product, however I'd want to ensure my end users get syntax highlighting within their editor (VSCode support as a minimum). Without this end users aren't going to have the best possible experience.

I can't really expect them to use the standalone expr editor given that by its nature this is embedded within other syntaxes and contexts (so users pulling out the expression to work on in another editor is too much friction).

I can see on the docs site you've got expr blocks highlighted and you're using prism, but I couldn't track down how that was being implemented.

Do you already have a TextMate grammar, language server or VSCode extension? If not, can something along these lines be added?

@antonmedv
Copy link
Member

VSCode extention for Expr is in the works. 😉

But difficult comes with providing Env completions and embedding in other languages. For now it will be more like a separate highlighter for separate files.

How do you use Expr? How do you think highlighter should work?

@manterfield
Copy link
Author

For us, expressions will appear within a yaml block which is in turn within markdown frontmatter.

Completions etc would be lovely, but the main things are highlighting (followed by diagnostics).

For highlighting - if there's a TextMate language/grammar spec created for your VSCode extension, then that can also be embedded in other language extensions created by users adding expr to their tools. Language only extensions are pretty straightforward to create - HCL is one example here.

For diagnostics - there's a few ways to skin this cat, but as long as we can run validation of an expression without choking on the absence of runtime variables then users can create their own diagnostics and a lightweight language server.

Of the two, diagnostics is likely the easier to solve as a user of expr, but the highlighting really isn't something I'd want to be implementing from the outside without any formal spec for the language.

Would you be able to share/open source whatever code you have that enables highlighting of expr on the docs site? I imagine that would massively speed up any attempts to create embedded highlighting.

@antonmedv
Copy link
Member

Sure. Will try to shape it into some sort of a package.

But how you will embed one grammar into YAML?
This is actually possible with Expr Editor, btw.

@manterfield
Copy link
Author

Perhaps I've misunderstood Expr Editor, but I thought it was a standalone tool.

If that's the case, then I couldn't really make use of it in the context Expr is used. My end users will be editing my config syntax within their own IDEs, with Expr being one part of that wider syntax. It'd be a big ask to have them change their local dev flow and tooling in order to make best use of the expression syntax I've chosen.

You can embed languages by matching the key and defining it as using a specific grammar. GitHub Actions do this with the GitHub Actions VSCode extension (also on their expressions). If you check that out, you'll notice that whilst it's YAML, the if statements still highlight correctly rather than as strings with that extension installed.

There's a few ways to support embedded languages though, this VSCode doc goes into more detail.

@antonmedv
Copy link
Member

Cool. Will definitely check this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants