sysml-v2-lsp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.1.0]
6
+
7
+ ### Added
8
+
9
+ - Initial LSP server with ANTLR4-based SysML v2 parser
10
+ - Diagnostics: syntax error reporting
11
+ - Document symbols: outline panel integration
12
+ - Hover: element kind, type, and documentation
13
+ - Go to definition: navigate to declarations
14
+ - Find references: locate all usages
15
+ - Code completion: keywords, snippets, symbol suggestions
16
+ - Semantic tokens: rich syntax highlighting
17
+ - Folding ranges: collapsible blocks and comments
18
+ - Rename: symbol rename with reference updates
19
+ - VS Code Language Client extension
20
+ - vitest unit tests
21
+ - GitHub Actions CI/CD
22
+ - Dev Container support
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jamie Dalton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,254 @@
1
+ # SysML v2 Language Server
2
+
3
+ A [Language Server Protocol (LSP)](https://microsoft.github.io/language-server-protocol/) implementation for [SysML v2](https://www.omgsysml.org/SysML-2.htm), powered by the ANTLR4 grammar from [daltskin/sysml-v2-grammar](https://github.com/daltskin/sysml-v2-grammar).
4
+
5
+ ## Features
6
+
7
+ ### Editing & Navigation
8
+
9
+ | Feature | Shortcut | Description |
10
+ |---------|----------|-------------|
11
+ | **Diagnostics** | — | Syntax errors, unknown identifiers, keyword typos with red/yellow squiggles |
12
+ | **Code Completion** | `Ctrl+Space` | Keywords, snippets, and symbol suggestions with documentation |
13
+ | **Signature Help** | auto on `(` | Parameter tooltips when invoking `action def` / `calc def` |
14
+ | **Hover** | mouse hover | Element kind, type, qualified name, and documentation |
15
+ | **Go to Definition** | `Ctrl+Click` / `F12` | Jump to a symbol's declaration |
16
+ | **Find References** | `Shift+F12` | Find all usages of a symbol across the document |
17
+ | **Rename Symbol** | `F2` | Rename a symbol and update all references |
18
+ | **Linked Editing** | auto | Edit a name and all same-scope occurrences update simultaneously |
19
+ | **Document Links** | `Ctrl+Click` | Clickable `import` paths — jump to the imported namespace |
20
+
21
+ ### Code Intelligence
22
+
23
+ | Feature | Shortcut | Description |
24
+ |---------|----------|-------------|
25
+ | **CodeLens** | — | "N references" shown above each definition, clickable |
26
+ | **Inlay Hints** | — | Ghost text showing inferred types (`: Type`) and supertypes (`:> Super`) |
27
+ | **Type Hierarchy** | `Shift+Alt+H` | Navigate specialization chains — supertypes and subtypes |
28
+ | **Call Hierarchy** | `Shift+Alt+H` | Navigate `perform`/`include` chains between actions |
29
+ | **Workspace Symbols** | `Ctrl+T` | Fuzzy search for any definition across all open files |
30
+
31
+ ### Presentation
32
+
33
+ | Feature | Shortcut | Description |
34
+ |---------|----------|-------------|
35
+ | **Semantic Tokens** | — | Rich, context-aware syntax highlighting (definitions, usages, keywords, types) |
36
+ | **Document Symbols** | `Ctrl+Shift+O` | Outline panel + breadcrumbs showing SysML model structure |
37
+ | **Folding Ranges** | — | Collapsible `{ }` blocks and comment regions |
38
+ | **Selection Ranges** | `Shift+Alt+Right/Left` | Smart expand/shrink selection (word → line → block → enclosing block) |
39
+
40
+ ### Productivity
41
+
42
+ | Feature | Shortcut | Description |
43
+ |---------|----------|-------------|
44
+ | **Quick Fix** | `Ctrl+.` | Fix keyword typos (e.g., `paart` → `part`) |
45
+ | **Formatting** | `Shift+Alt+F` | Auto-indent, normalize braces, trim trailing whitespace |
46
+ | **Snippets** | type prefix + `Tab` | 30 SysML snippets — `partdef`, `actiondef`, `reqdef`, `statedef`, etc. |
47
+
48
+ ## Quick Start
49
+
50
+ ### Dev Container (recommended)
51
+
52
+ Open in GitHub Codespaces or VS Code Dev Containers — everything is pre-installed.
53
+
54
+ ### Manual Setup
55
+
56
+ ```bash
57
+ # Install dependencies
58
+ npm install
59
+
60
+ # Generate TypeScript parser from ANTLR4 grammar
61
+ npm run generate
62
+
63
+ # Build
64
+ npm run build
65
+
66
+ # Run tests
67
+ npm test
68
+ ```
69
+
70
+ ### Development
71
+
72
+ ```bash
73
+ # Watch mode — recompiles on file changes
74
+ npm run watch
75
+
76
+ # Then press F5 in VS Code to launch the extension + server
77
+ ```
78
+
79
+ Use the **"Client + Server"** compound debug configuration to debug both sides simultaneously.
80
+
81
+ ## Architecture
82
+
83
+ ```
84
+ ┌──────────────────────┐ IPC ┌──────────────────────────┐
85
+ │ VS Code Extension │ ◄─────────► │ Language Server │
86
+ │ (Language Client) │ │ (Separate Process) │
87
+ ├──────────────────────┤ ├──────────────────────────────┤
88
+ │ • Starts server │ │ • ANTLR4 parser (worker thread)│
89
+ │ • Registers language │ │ • Diagnostics + keyword typos │
90
+ │ │ │ • Completions / signature help│
91
+ │ │ │ • Hover / go-to-def / refs │
92
+ │ │ │ • Semantic tokens / CodeLens │
93
+ │ │ │ • Rename / linked editing │
94
+ │ │ │ • Inlay hints / document links│
95
+ │ │ │ • Type & call hierarchy │
96
+ │ │ │ • Formatting / folding / sel. │
97
+ │ │ │ • Workspace symbols │
98
+ └──────────────────────┘ └──────────────────────────┘
99
+
100
+ ┌──────────────────────┐ stdio ┌──────────────────────────┐
101
+ │ AI Assistant │ ◄─────────► │ MCP Server │
102
+ │ (Claude, Copilot) │ │ (Standalone Process) │
103
+ ├──────────────────────┤ ├──────────────────────────────┤
104
+ │ • Sends tool calls │ │ • Parse / validate SysML │
105
+ │ • Reads resources │ │ • Symbol table queries │
106
+ │ • Uses prompts │ │ • Hierarchy / references │
107
+ │ │ │ • Grammar reference resources │
108
+ │ │ │ • Review / generate prompts │
109
+ └──────────────────────┘ └──────────────────────────┘
110
+ ```
111
+
112
+ ### Project Structure
113
+
114
+ ```
115
+ sysml-v2-lsp/
116
+ ├── client/ # VS Code Language Client extension
117
+ │ └── src/extension.ts # Starts LanguageClient, connects to server
118
+ ├── server/ # Language Server (runs in separate process)
119
+ │ └── src/
120
+ │ ├── server.ts # LSP connection, capability registration
121
+ │ ├── mcpServer.ts # MCP server (standalone, stdio transport)
122
+ │ ├── documentManager.ts # Parse cache, document lifecycle
123
+ │ ├── parser/ # ANTLR4 parse pipeline
124
+ │ ├── symbols/ # Symbol table, scopes, element types
125
+ │ └── providers/ # LSP feature implementations
126
+ ├── grammar/ # ANTLR4 grammar files (.g4)
127
+ ├── test/ # Unit tests (vitest) + E2E tests
128
+ └── package.json # Extension manifest + monorepo scripts
129
+ ```
130
+
131
+ ## Grammar Updates
132
+
133
+ The grammar files in `grammar/` are sourced from [daltskin/sysml-v2-grammar](https://github.com/daltskin/sysml-v2-grammar). To pull the latest version:
134
+
135
+ ```bash
136
+ npm run update-grammar
137
+ npm run generate
138
+ ```
139
+
140
+ ## Available Commands
141
+
142
+ ```bash
143
+ make install # Install all dependencies
144
+ make generate # Generate TypeScript parser from grammar
145
+ make build # Compile + bundle
146
+ make watch # Watch mode
147
+ make test # Run unit tests
148
+ make lint # ESLint
149
+ make package # Build .vsix
150
+ make update-grammar # Pull latest grammar from upstream
151
+ make ci # Full CI pipeline
152
+ ```
153
+
154
+ ## MCP Server (AI Integration)
155
+
156
+ The project includes a [Model Context Protocol](https://modelcontextprotocol.io/) server that lets AI assistants parse, validate, and query SysML v2 models.
157
+
158
+ ### VS Code
159
+
160
+ The workspace includes `.vscode/mcp.json` — the MCP server is automatically available to GitHub Copilot. Build first:
161
+
162
+ ```bash
163
+ npm run build
164
+ ```
165
+
166
+ ### Claude Desktop
167
+
168
+ Add to `claude_desktop_config.json`:
169
+
170
+ ```json
171
+ {
172
+ "mcpServers": {
173
+ "sysml-v2": {
174
+ "command": "node",
175
+ "args": ["/path/to/sysml-v2-lsp/dist/server/mcpServer.mjs"]
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ ### Available Tools
182
+
183
+ | Tool | Description |
184
+ |------|-------------|
185
+ | `parse` | Parse SysML source, build symbol table, return summary |
186
+ | `validate` | Check syntax and return errors |
187
+ | `getSymbols` | List symbols (filter by kind, URI, definitions/usages) |
188
+ | `getDefinition` | Look up a symbol by name or qualified name |
189
+ | `getReferences` | Find all references to a symbol |
190
+ | `getHierarchy` | Get parent–child containment structure |
191
+ | `getModelSummary` | Counts, kinds, and loaded documents |
192
+
193
+ ### Available Resources
194
+
195
+ | URI | Description |
196
+ |-----|-------------|
197
+ | `sysml://element-kinds` | All recognised element kinds |
198
+ | `sysml://keywords` | Complete keyword list |
199
+ | `sysml://grammar-overview` | Language structure reference |
200
+
201
+ ### Available Prompts
202
+
203
+ | Prompt | Description |
204
+ |--------|-------------|
205
+ | `review-sysml` | Review a SysML model for correctness |
206
+ | `explain-element` | Explain a SysML element kind |
207
+ | `generate-sysml` | Generate SysML from a description |
208
+
209
+ ### Quick Test Examples
210
+
211
+ Once the MCP server is running (green dot in **MCP: List Servers**), try these prompts in Copilot Chat:
212
+
213
+ **Parse a model:**
214
+ > `@sysml-v2` parse this: `package Demo { part def Vehicle { attribute speed : Real; } part car : Vehicle; }`
215
+
216
+ **Validate with errors:**
217
+ > `@sysml-v2` validate this: `part def Broken { attribute x :`
218
+
219
+ **List symbols after parsing:**
220
+ > `@sysml-v2` what symbols are in the model?
221
+
222
+ **Look up a definition:**
223
+ > `@sysml-v2` find the definition of Vehicle
224
+
225
+ **Get the hierarchy:**
226
+ > `@sysml-v2` show the hierarchy of car
227
+
228
+ **Get a model summary:**
229
+ > `@sysml-v2` summarise the loaded model
230
+
231
+ > **Tip:** Click the **tools icon** (wrench) at the bottom of the Chat input to see all available `sysml-v2` tools.
232
+
233
+ ## Technology Stack
234
+
235
+ | Component | Technology |
236
+ |-----------|-----------|
237
+ | Language | TypeScript (strict mode) |
238
+ | Runtime | Node.js ≥ 18 |
239
+ | Parser | ANTLR4 via [antlr4ng](https://github.com/mike-lischke/antlr4ng) |
240
+ | Generator | [antlr-ng](https://github.com/nicklockwood/antlr-ng) |
241
+ | LSP | [vscode-languageserver](https://github.com/microsoft/vscode-languageserver-node) |
242
+ | MCP | [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/typescript-sdk) |
243
+ | Bundler | esbuild |
244
+ | Tests | vitest |
245
+
246
+ ## Related Projects
247
+
248
+ - [daltskin/sysml-v2-grammar](https://github.com/daltskin/sysml-v2-grammar) — ANTLR4 grammar for SysML v2
249
+ - [daltskin/VSCode_SysML_Extension](https://github.com/daltskin/VSCode_SysML_Extension) — VS Code extension with visualization
250
+ - [OMG SysML v2 Specification](https://github.com/Systems-Modeling/SysML-v2-Release)
251
+
252
+ ## License
253
+
254
+ MIT