Skip to main content
ThunderLang™
Draft documentation. Syntax and behavior are illustrative and will change before v1.

Editor Support (Language Server)

ThunderLang ships a Language Server, so any editor that speaks the Language Server Protocol (VS Code, Neovim, Helix, Sublime LSP, Emacs eglot, ...) gets live ThunderLang intelligence: diagnostics as you type, go to definition, find references, rename, keyword and type completions, and hover docs for semantic types and note lenses. It wraps the same deterministic compiler the CLI uses, no AI, no network.

Start it#

Text
thunder lsp

That runs the server over stdio (LSP Content-Length-framed JSON-RPC on stdin/stdout). You do not run it directly; your editor launches it and talks to it.

What it provides#

  • Diagnostics (textDocument/publishDiagnostics) on open and on every change. A Thunder Core program gets the Core compiler's problems (TC… codes) at their own lines, with the hint; in a project, a test file is checked against src/, as thunder test does. A mission gets the full semantic pass (missing goals, unverified guarantees, undefined lifecycle states, purpose-limitation gaps, and the rest of the IL-* catalog), each anchored to the relevant line and carrying its code and the "why".
  • Go to definition (textDocument/definition) and find references (textDocument/references). In a Thunder Core program: functions, data types, alternatives, kept and stored values, values set at the top of a file, and a function's inputs and the values it sets (only inside that function). Names can be several words ("decide refund"); spacing and a capital letter don't matter. In a project (a folder with thunder.toml), every .thunder file is read, with unsaved editor text in place of what is on disk, so a function's references include the tests that call it. In a mission: decisions, rules, the fields under input, output, and data, and the other named blocks; prose, case titles, comments, and text are not uses.
  • Rename (textDocument/prepareRename, textDocument/rename): every use, across the project's files, keeping each one's capital letter ("Approved:" and "an approved Refund") and plural ("list of Refunds"). Thunder refuses a rename, and says why, when the new name is not a valid name, is a Thunder word, is already used, or would give any file a problem it does not have now (each Core file is compiled again to check). It also refuses to rename an endpoint's input, because callers send that name.
  • Not yet: fields of records (a field is written without its data type, as in with amount $5, so a safe rename needs the checker's types), and endpoints, which are named by their route.
  • Completion (textDocument/completion): block keywords and semantic types, with snippet insert text.
  • Hover (textDocument/hover): markdown docs for semantic types and ThunderLens notes.

Wire it up#

Neovim (built-in LSP)#

Lua
vim.api.nvim_create_autocmd("FileType", {
  pattern = "intent",
  callback = function()
    vim.lsp.start({
      name = "thunderlang",
      cmd = { "intent", "lsp" },
      root_dir = vim.fs.dirname(vim.fs.find({ ".git" }, { upward = true })[1]),
    })
  end,
})
-- map the .thunder extension to the `intent` filetype
vim.filetype.add({ extension = { intent = "intent" } })

VS Code#

A ready-to-build extension lives in the repo at editors/vscode/. It contributes the intent language + the grammar and starts the language server:

Terminal
cd editors/vscode
npm install
npm run compile              # syncs the grammar, type-checks, emits out/extension.js
npx @vscode/vsce package     # -> thunderlang-vscode-<version>.vsix, install via "Install from VSIX"

The extension runs thunder lsp (configurable via thunderlang.serverCommand), so install the CLI too (npm install -g @skillstech/thunderlang).

Any LSP client#

Point it at the command thunder lsp (stdio transport) for documents with the .thunder extension. The server advertises its capabilities in the initialize response.

Syntax highlighting#

The Language Server provides semantics (diagnostics, definitions, references, rename, completion, hover). For coloring, the package ships a TextMate grammar at syntaxes/thunder.tmLanguage.json (scope source.thunder, the same grammar the VS Code extension uses, covering missions and Thunder Core), the format VS Code, GitHub Linguist, and most editors use. It colors comments, strings, block keywords, typed fields (name: Type), semantic/entity types, expression operators, and numbers.

Point your editor's grammar registration at that file for .thunder files. In a VS Code extension, reference it in package.json:

JSON
"contributes": {
  "languages": [{ "id": "thunder", "extensions": [".thunder", ".tl"] }],
  "grammars": [{
    "language": "thunder",
    "scopeName": "source.thunder",
    "path": "./syntaxes/thunder.tmLanguage.json"
  }]
}

The older syntaxes/intent.tmLanguage.json (scope source.intent, missions only) still ships so existing setups keep working; new setups should use thunder.tmLanguage.json.

The library#

startLspServer({ readable, writable }) is exported from @skillstech/thunderlang if you want to embed the server (for example over a different transport or in a test). It is the same server the thunder lsp command runs.

The names behind go to definition, references, and rename are a browser-safe library call too, from @skillstech/thunderlang/program: give it the files ([{ path, source }]) and a position (1-based line and column):

JavaScript
import { definitionsAt, referencesAt, renameAt, applyRename } from "@skillstech/thunderlang/program";

referencesAt(files, "src/desk.thunder", { line: 32, col: 5 });
// the To line, its call on line 87, and the three tests that call it:
// [{ path: "src/desk.thunder", line: 32, col: 4, length: 13 }, { path: "src/desk.thunder", line: 87, col: 19, length: 13 },
//  { path: "tests/desk-tests.thunder", line: 5, col: 10, length: 13 }, …]
const r = renameAt(files, "src/desk.thunder", { line: 32, col: 5 }, "judge refund");
if (r.ok) files = applyRename(files, r.edits); else console.log(r.problem);