Skip to content

Commit 1f2d71c

Browse files
committed
feat: tree-sitter parse-error diagnostics alongside compiler diagnostics
Surface tree-sitter ERROR/MISSING nodes as diagnostics for the languages with a parser, published alongside (not replacing) the compiler diagnostics via a per-source store keyed by NormalizedUri. Gated by a new `bgforge.diagnostics` setting (default on), independent of `bgforge.validate` since the parse is in-memory and instant. Register MSG and TRA tree-sitter parsers (parser-only, no LSP provider) so their parse errors surface too. Tighten the MSG grammar to require marked comments (`#`, `//`, `/* */`): markerless out-of-band text is now a parse error rather than a silently-accepted comment, with matching TextMate and tree-sitter highlighting.
1 parent 188c8ec commit 1f2d71c

31 files changed

Lines changed: 654 additions & 63 deletions

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ client/ # VSCode extension client (LSP client, webviews, binary
5656
server/ # LSP server (providers, symbol system, compilation, dialog bridges)
5757
data/ # YAML engine definitions (functions, actions, triggers)
5858
shared/ # Shared pure TypeScript helpers used by runtime and build-time code
59-
grammars/ # Tree-sitter grammars (6 dirs: 4 LSP + 2 highlight-only)
59+
grammars/ # Tree-sitter grammars (6 dirs: 4 LSP + 2 parsed for diagnostics/highlighting only: msg, tra)
6060
binary/ # @bgforge/binary package: library + fgbin CLI (Fallout PRO/MAP, Infinity Engine ITM/SPL/EFF/CRE parser)
6161
binary-editor/ # @bgforge/binary-editor package: declarative layout layer (parsed records -> editor blocks), consumed by the client webview
6262
format/ # @bgforge/format package: library + fgfmt CLI (Fallout/WeiDU formatters)

docs/settings.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ All settings are under the `bgforge` namespace.
66

77
## General
88

9-
| Setting | Default | Description |
10-
| ----------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11-
| `bgforge.validate` | `saveAndType` | When validation runs: `manual` = only when invoked explicitly, `save` = on save, `type` = while editing, `saveAndType` = on both save and edit. `type`/`saveAndType` are disk-intensive and debounced at 300ms. |
12-
| `bgforge.binaryEditor.autoDumpJson` | `false` | Whether saving a file in the binary editor should also write a JSON snapshot next to it. |
13-
| `bgforge.debug` | `false` | Enable debug logging in the Output panel (BGforge MLS channel) |
9+
| Setting | Default | Description |
10+
| ----------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11+
| `bgforge.validate` | `saveAndType` | When validation runs: `manual` = only when invoked explicitly, `save` = on save, `type` = while editing, `saveAndType` = on both save and edit. `type`/`saveAndType` are disk-intensive and debounced at 300ms. |
12+
| `bgforge.diagnostics` | `true` | Report tree-sitter parse errors as diagnostics, alongside compiler diagnostics, for languages with a parser (Fallout SSL/MSG, WeiDU BAF/D/TP2/TRA). In-memory and instant, so it runs independently of `bgforge.validate`; set to `false` to silence the syntax source without disabling compiler validation. |
13+
| `bgforge.binaryEditor.autoDumpJson` | `false` | Whether saving a file in the binary editor should also write a JSON snapshot next to it. |
14+
| `bgforge.debug` | `false` | Enable debug logging in the Output panel (BGforge MLS channel) |
1415

1516
## Fallout SSL
1617

grammars/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
See also: [CONTRIBUTING.md](../CONTRIBUTING.md) | [docs/architecture.md](../docs/architecture.md) | [scripts/README.md](../scripts/README.md)
44

5-
Six tree-sitter grammars for the supported languages. Four are used by the LSP server for parsing (formatting, symbols, etc.), two are highlight-only for external editors.
5+
Six tree-sitter grammars for the supported languages. Four back full LSP providers (formatting, symbols, etc.); the other two (MSG, TRA) have no provider but are parsed by the server to surface parse errors as diagnostics, and provide highlighting for external editors.
66

7-
| Grammar | Language | Used By |
8-
| ------------- | ------------------------------- | -------------------------------------------------------- |
9-
| `fallout-ssl` | Fallout SSL (.ssl, .h) | LSP provider (format, symbols, definition, rename, etc.) |
10-
| `weidu-baf` | WeiDU BAF (.baf) | LSP provider (format, folding) |
11-
| `weidu-d` | WeiDU D (.d) | LSP provider (format, symbols, definition, folding) |
12-
| `weidu-tp2` | WeiDU TP2 (.tp2/.tpa/.tph/.tpp) | LSP provider (format, symbols, definition, rename, etc.) |
13-
| `fallout-msg` | Fallout MSG (.msg) | Highlighting only (Neovim, Helix, Zed, Emacs) |
14-
| `weidu-tra` | WeiDU TRA (.tra) | Highlighting only (Neovim, Helix, Zed, Emacs) |
7+
| Grammar | Language | Used By |
8+
| ------------- | ------------------------------- | ------------------------------------------------------------------------ |
9+
| `fallout-ssl` | Fallout SSL (.ssl, .h) | LSP provider (format, symbols, definition, rename, etc.) |
10+
| `weidu-baf` | WeiDU BAF (.baf) | LSP provider (format, folding) |
11+
| `weidu-d` | WeiDU D (.d) | LSP provider (format, symbols, definition, folding) |
12+
| `weidu-tp2` | WeiDU TP2 (.tp2/.tpa/.tph/.tpp) | LSP provider (format, symbols, definition, rename, etc.) |
13+
| `fallout-msg` | Fallout MSG (.msg) | Server parse-error diagnostics; highlighting (Neovim, Helix, Zed, Emacs) |
14+
| `weidu-tra` | WeiDU TRA (.tra) | Server parse-error diagnostics; highlighting (Neovim, Helix, Zed, Emacs) |
1515

1616
## Building
1717

@@ -47,8 +47,10 @@ WASM files are copied to `server/out/` by `scripts/build-base-server.sh` during
4747
- `tree-sitter-baf.wasm` -- WeiDU BAF grammar
4848
- `tree-sitter-weidu_d.wasm` -- WeiDU D grammar
4949
- `tree-sitter-weidu_tp2.wasm` -- WeiDU TP2 grammar
50+
- `tree-sitter-fallout_msg.wasm` -- Fallout MSG grammar (parse-error diagnostics)
51+
- `tree-sitter-weidu_tra.wasm` -- WeiDU TRA grammar (parse-error diagnostics)
5052

51-
The MSG and TRA grammars are not bundled (no LSP provider uses them). They are built for external editors that install tree-sitter grammars natively.
53+
The MSG and TRA grammars ship to `server/out/` for parse-error diagnostics, but are not copied to the `@bgforge/format` CLI bundle (`format/out/`) since their formatters are string-based, not tree-sitter. They are also built for external editors that install tree-sitter grammars natively.
5254

5355
## Highlight Queries
5456

grammars/fallout-msg/grammar.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* @license MIT
55
*
66
* Format: {number}{audio}{text} entries, where audio is optional (but braces required).
7-
* Text can span multiple lines. Anything outside entries is a comment.
7+
* Text can span multiple lines. Outside entries, only marked comments are allowed
8+
* (# and // line comments, or block comments); markerless free text is a parse error.
89
*/
910

1011
/// <reference types="tree-sitter-cli/dsl" />
@@ -16,7 +17,7 @@ export default grammar({
1617
extras: ($) => [/\s/],
1718

1819
rules: {
19-
source_file: ($) => repeat(choice($.entry, $.comment)),
20+
source_file: ($) => repeat(choice($.entry, $.comment, $.block_comment)),
2021

2122
// {number}{audio}{text}
2223
// Text can span multiple lines - closing } terminates.
@@ -41,8 +42,12 @@ export default grammar({
4142
// Message text - may contain newlines, terminated by }
4243
text: () => /[^}]+/,
4344

44-
// Anything outside {n}{a}{t} entries is a comment.
45-
// Matches one or more characters that don't start an entry.
46-
comment: () => /[^{\s][^{]*/,
45+
// Comments must be explicitly marked. '#' and '//' are line comments;
46+
// markerless free text outside an entry is left unparsed (an ERROR node)
47+
// so it surfaces as a diagnostic rather than being silently accepted.
48+
comment: () => token(choice(seq("#", /[^\n]*/), seq("//", /[^\n]*/))),
49+
50+
// '/* ... */' block comment (may span multiple lines).
51+
block_comment: () => token(seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, "/")),
4752
},
4853
});

grammars/fallout-msg/queries/highlights.scm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
; entity.name.function.sound.fallout-msg -> @string.special (audio filename)
77
; string.quoted.fallout-msg -> @string (message text)
88
; keyword.control.fallout-msg -> @punctuation.bracket (braces)
9-
; comment.block.fallout-msg -> @comment
9+
; comment.line/comment.block.fallout-msg -> @comment
1010

1111
; ----- Comments -----
1212

1313
(comment) @comment
14+
(block_comment) @comment
1415

1516
; ----- Entry fields -----
1617

grammars/fallout-msg/test/corpus/entries.txt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Entry with audio
2929
Comment between entries
3030
================
3131

32-
This is a comment
32+
# This is a comment
3333
{100}{}{Text.}
3434

3535
---
@@ -40,6 +40,39 @@ This is a comment
4040
(number)
4141
(text)))
4242

43+
================
44+
Line comment styles
45+
================
46+
47+
# hash comment
48+
// slash comment
49+
{100}{}{Text.}
50+
51+
---
52+
53+
(source_file
54+
(comment)
55+
(comment)
56+
(entry
57+
(number)
58+
(text)))
59+
60+
================
61+
Block comment
62+
================
63+
64+
/* block
65+
comment */
66+
{100}{}{Text.}
67+
68+
---
69+
70+
(source_file
71+
(block_comment)
72+
(entry
73+
(number)
74+
(text)))
75+
4376
================
4477
Multiple entries
4578
================
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
This is a comment
1+
# This is a comment
22
// <- comment
33
{100}{sound_file}{Hello world.}
44
// <- punctuation.bracket
55
// ^ number
66
// ^ string.special
7-
// ^ string
7+
// ^ string
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is a comment
1+
# This is a comment
22
{100}{}{First entry.}
3-
Another comment here
3+
# Another comment here
44
{200}{}{Second entry.}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is a comment
1+
# This is a comment
22
{100}{}{First entry.}
3-
Another comment here
3+
# Another comment here
44
{200}{}{Second entry.}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is a comment
1+
# This is a comment
22
{100}{}{First entry.}
3-
Another comment here
3+
# Another comment here
44
{200}{}{Second entry.}

0 commit comments

Comments
 (0)