Repository navigation
feat: multiline array support to the toml parser - #176
paval-shlyk wants to merge 4 commits into
Conversation
|
Hey, thanks for this PR! I'll try to take a closer look and try this out this weekend. I've noticed a few things right away. I don't think the case where inline-array items come after the multiline features array is handled. The type declaration of Somewhat related, with TOML 1.1 support landing in cargo, there is now also the possibility of multiline inline-tables. I'm not sure if that changes anything about this PR, just came to mind :) |
|
I believed that everything would be much simpler) Honestly, I didn't even know that multiline inline-tables had been added. |
🫂
Even if this PR "only" adds support for multi-line features, that would still be an improvement worth while :) |
1fce917 to
c194451
Compare
|
@saecki. sorry for the delay (honestly, I completely forgot about this PR since I was using my branch). I pushed some changes recently because I wanted to make the PR feature complete. Sorry for the tremendous amount of changes (1k LoC is really huge for human beings 😢 ), but they are mostly tests. Also updated the PR description. The proposal and changes are mostly machine-generated (since I don't want to invest too much time in Lua). But the code, at least, looks good to me 😉 |
|
No worries, I'll try to find time this weekend to review this :) |
Situation:
I'm using the crates.nvim Neovim plugin (tbh, my use case is very limited; I only use it for feature toggling and quick crate inspection). I'm also using the taplo LSP for formatting.
If a crate has many features, taplo will typically format them as a multi-line array (TOML v1.0 spec).
crates.nvim does not support multi-line arrays.
Target:
Proposal:
Parser (
lua/crates/toml.lua)features = [and accumulate lines until]. Same path for table crates ([dependencies.foo]) and inline tables (foo = { ... }).feat.end_line/feat.end_colat]. For a single-line array they equalfeat.line/feat.col.e.]on the closing line (], version = "1.2.3" }).features(extra-features = [).]in the single-line array patterns (it was optional).name = {with no complete inline table still starts a crate, so a multi-linefeaturesarray on later lines can attach.refresh_crate(buf, crate)re-parses the buffer and returns the crate with the same cache key.Spans
TomlFeature.col/decl_colare absolute columns onTomlFeature.line, not offsets intofeat.text.decl_colis clamped to that line when leading/trailing whitespace sits on a neighbor.feat.line+ absolute columns.toml.feat_contains_linecovers the full array range.Edit (
lua/crates/edit.lua)insert_posreturns(line, col, before)so inserts ofversion/default-features/featureswork when the inline table already spans lines.col_to_insertremains as a column-only wrapper.], indented like the last item.Popup / completion / diagnostics
refresh_crateinstead of patching spans from the edited line.Tests
extra-featuresfalse positive, diesel-style taplo output.default-featuresafter a features-first array, remove array without a stray comma, extract into table, two features on one inner line.Out of Scope
foo = {\n version = "1",\n}). This branch only covers newlines inside thefeaturesarray (valid in TOML 1.0, and what taplo emits).