COCOR-LSP.md 2.0 KB

Pascal language services (LSP)

The Theia/VS Code extension starts out/server.js through vscode-languageclient. Two diagnostic sources merge on every edit:

  1. Coco/R dialect validators (external, per-dialect executables).
  2. Local analysis — header/END checks plus a lenient declaration parser driving all navigation features below.

Pascal dialects (.pas / .pp / .p)

Each pilot binary takes the source file as its single argument and writes a .LST listing next to it; the server parses the listing's ***** ^ message lines (positions are caret-relative to the code after the listing prefix, zero-based columns).

"modula2.pascal.dialect": "freepascal",
"modula2.pascal.validators": {
  "p2": "<root>/grammars/P2/build/P2",
  "p4": "<root>/grammars/P4/build/P4",
  "p6": "<root>/grammars/P6/build/P6",
  "pascal": "<root>/grammars/Pascal/build/PStd",
  "turbopascal3": "<root>/grammars/TurboPascal3/build/TP3",
  "freepascal": "<root>/grammars/FreePascal/build/FPC",
  "blaise": "<root>/grammars/Blaise/build/BlaiseV",
  "pascals": "<root>/grammars/PascalS/build/PascalS"
}

Build each binary first with its pilot build.sh (needs CR and gm2 -fiso). With no command configured for the active dialect the server publishes no validator diagnostics. Never point these at the pcom/psc oracle compilers — they can hang on invalid input.

Local intelligence (always on, no compiler needed)

  • Outline (parsePascal: programs, units, routines, params, locals, record fields, enum literals)
  • Completion (.-triggered: unit interface names, record fields, visible declarations, keywords, predefined routines)
  • Hover, go-to-definition, references, rename — incl. Unit.Name resolution through USES (same-directory .pas/.pp/.p) and go-to-unit on USES names; matching is case-insensitive
  • Full + range formatting (modula2.pascal.format.*), semantic tokens, snippets, uppercase-while-typing (modula2.pascal.uppercaseKeywords)