-
Notifications
You must be signed in to change notification settings - Fork 778
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
toml editor #74
Comments
Consider using https://taplo.tamasfe.dev/lib |
Other options:
|
Seems like the library was mostly leveraging this which seems still highly maintained. The rest of the toml parser can be implemented using https://github.com/chevrotain/chevrotain and the parsing rules for TOML & change the API as needed. |
Hello. I am the author of both Some questions:
Cheers. |
Yes to both! |
Graceful automated editingChevrotain could be well suited as an infrastructure for this due to the CST (Concrete Syntax Tree) support.
See: JSON + CST example in the playground TOML Parser / GrammarAs far as I remember, TOML is a very simple language (it has So implementing a parser for it should not be too large of an undertaking and there is already prior work to build on: Full fledged Editor (Semantic Validations / Content Assist / Tool-tips)This is a fair bit more complicated. You would need to implement a Language Server for your wrangler.toml syntax/semantics. I have worked on a similar problem for SAP's UI5 XML webviews. The relevant source code is in these two repos:
Language Server infrastructure to evaluateLangium by Typefox is a new framework that assists in building language servers for DSLs.
@msujew may be able to elaborate more on this option? |
Hey @bd82, thanks for the heads-up! If it's about editor support, I think Langium would be a good choice. Looking at the initial requirements, especially removing deprecated fields should be as simple as writing a validation and executing an associated code action (as in: Executing a quick fix provided by VSCode for unused imports for example). Langium's main use case is to build a language server, so its editing interfaces are tightly coupled to the LSP types. However, everything is also working in CLI/normal app server mode, so once you conform to the LSP types, stuff like executing code actions should also be working fine. Although, we mostly just use the parsing and validation capabilities of Langium when running CLIs. Thinking about it, you probably don't even need to go through the LSP interfaces and can just work on the AST/CST itself, kind of mimicking how editors execute code actions. It might be a bit tricky to get the toml grammar to work correctly in Langium (mostly about lexing, parsing shouldn't be an issue, white space sensitive languages are always a bit difficult to deal with), but definitely possible, since it's using Chevrotain under the hood. However, after that's done, everything else should be straightforward, since semantic validations, content assist, tool-tips, etc. as mentioned by Shahar come out-of-the-box with minimal effort with Langium. |
Closing this, since we're moving Wrangler's config to a JSONC format, and the library we use for that supports editing files (preserving comments). |
There are numerous occasions when we want to be able to 'automatically' edit the
wrangler.toml
file from withiin wrangler. Examples -type
build.upload.main
to something likeentry
(todo)migrations
based on some interactive flow (todo)In rust land, we'd use a format preserving editor like toml-edit, but nothing like it exists in javascript land (that I know of). So this issue tracks the implementation of the thing.
We need to take a toml parser that given a toml string, returns an AST. We then apply edits to the AST directly, and convert it back to a toml string.
Potential code to learn from - https://github.com/ota-meshi/toml-eslint-parser
Sequencing / prioritisation: I think when we should first start simply logging the changes we want people to make directly to the terminal (for backward compat, migrations, whatever.) Once we have that in place, we can start working on this issue to automate the suggestions.
The text was updated successfully, but these errors were encountered: