toml editor
See original GitHub issueThere are numerous occasions when we want to be able to ‘automatically’ edit the wrangler.toml
file from withiin wrangler. Examples -
- removing a deprecated field like
type
- renaming a deprecated field like
build.upload.main
to something likeentry
(todo) - adding durable object
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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Hello.
I am the author of both
Chevrotain
and@toml-tools/parser
.Some questions:
Do I understand correctly that you need to make small modifications to an existing toml file, while honoring the existing formatting / style (no full document re-write on change)?
Do you have any future “true editor” requirements in regards to the
wrangler.toml
file? e.g:Cheers. Shahar.
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.