Skip to main content

Crate increparse_lua

Crate increparse_lua 

Source
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 into source — no rebasing traps.
  • Outcomes: a table with an expand array expands the region; "done" accepts it; "failed" or nil marks it failed (later passes retry). A Lua error thrown inside a pass is caught and treated as Failed — 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.
  • diagnostic receives (source, node) with node = { ctx, status, start, end } (status is "failed" or "unparsed"); returning a table with a message publishes a diagnostic at the node’s range (optionally set start/end there).
  • symbols receives 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.