COCOR-LSP.md 2.0 KB

Coco/R diagnostics through LSP

Version 0.1.7 adds the first real Language Server connection. The Theia/VS Code extension starts out/server.js through vscode-languageclient; the server invokes a configured executable containing the generated Coco/R parser/validator.

Coco/R itself is a compiler-compiler: it generates a scanner/parser from an .atg grammar. It is therefore not run for every keystroke. The editor runs the generated validator instead.

Configuration

"modula2.cocoR.validatorCommand": "/path/to/generated-modula2-validator",
"modula2.cocoR.validatorArguments": ["{file}"]

{file} is replaced by a temporary copy of the current .mod or .def document. The validator is run with the original document directory as its working directory.

The server understands the editor-oriented Coco/R output used by the CRQ frame:

source.mod (12,7) message

Line numbers are converted from one-based to LSP zero-based positions.

When validatorCommand is empty, the LSP publishes no Coco/R diagnostics; the existing lightweight diagnostics remain available.

Tested validator (GNU-grammar)

GNU-grammar/bin/GM2 is a validator built from the tested gm2-gcc-0.2 grammar. Besides the .LST listing file, it prints one editor-oriented diagnostic per error to standard output:

/tmp/.../multi.mod (3,0) 'MODULE' expected
/tmp/.../multi.mod (5,15) invalid SetOrDesignatorOrFunction

Line numbers are one-based, columns are zero-based, matching the file (line,column) message pattern above. A clean file prints only Parsing / Parsed correctly (no diagnostic lines).

Example configuration:

"modula2.cocoR.validatorCommand": "/home/eric/Projets/Projets-Modula2/MyWork/Theia/GNU-grammar/bin/GM2",
"modula2.cocoR.validatorArguments": ["{file}"]

The reference grammar lives at grammars/Modula2.atg (copy of the tested gm2-gcc-0.2.atg); parser regression tests live in grammars/tests/ and are checked with <GNU-grammar>/bin/GM2 <test>.mod (expect 0 errors).