Expand description
Define an increparse language server in pure Lua.
A language is a single Lua file returning a table:
-- minilang.lua
return {
name = "minilang",
root_ctx = { File = true },
-- round r of a run calls passes[r]
passes = {
function(source, span, ctx)
-- span = { start = , end = , rev = }
-- return { expand = { { start = , end = , ctx = ... }, ... } }
-- or "done" / "failed" / nil
return "done"
end,
},
-- optional: how a failing region becomes a diagnostic
diagnostic = function(source, node) return { message = "oops" } end,
-- optional: outline symbols from a snapshot of the tree
symbols = function(nodes) return {} end,
}Hand the file to the bundled binary and point any LSP client at it:
increparse-lua-server ~/.config/minilang/lang.lua§Semantics
- Passes receive
(source, span, ctx)where child ranges in the outcome are absolute byte ranges intosource— no rebasing traps. - Outcomes: a table with an
expandarray expands the region;"done"accepts it;"failed"ornilmarks it failed (later passes retry). A Lua error thrown inside a pass is caught and treated asFailed— a broken pass never takes the server down. - Contexts are arbitrary Lua values. Region reuse after an edit matches contexts by deep equality (tables compared recursively), so edits re-parse only the touched chain — the same incremental behaviour the Rust side gets.
diagnosticreceives(source, node)withnode = { ctx, status, start, end }(statusis"failed"or"unparsed"); returning a table with amessagepublishes a diagnostic at the node’s range (optionally setstart/endthere).symbolsreceives an array of{ start, end, status, ctx }snapshots and returns{ { name = , detail = , start = , end = } }; ranges are byte ranges, converted to editor positions by the skeleton.
Structs§
- LuaCtx
- A context value from Lua: any
Value, compared by deep equality. - LuaLanguage
- A language defined by a Lua configuration file.