H-5839, FE-488: Petrinaut: LSP-like interface for Diagnostics and Code Editor#8300
H-5839, FE-488: Petrinaut: LSP-like interface for Diagnostics and Code Editor#8300
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
ef002c8 to
18ec8e9
Compare
18ec8e9 to
90fb012
Compare
213628d to
5cb42ad
Compare
7c811a0 to
16b35f4
Compare
…o editors Wire TypeScript LanguageService features through the checker WebWorker to Monaco editors via JSON-RPC. The LanguageServiceHost is now mutable (per-file version tracking) so completions reflect current editor state. - Completions: registerCompletionItemProvider with ScriptElementKind mapping - Hover: registerHoverProvider backed by getQuickInfoAtPosition - Signature help: registerSignatureHelpProvider backed by getSignatureHelpItems - All three adjust offsets to account for injected declaration prefixes - Add tests for completions and updateFileContent in the language service Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…DCPN changes Convert the checker communication layer from ad-hoc method names and types to an LSP-inspired protocol (initialize, sdcpn/didChange, textDocument/didChange, textDocument/completion, textDocument/hover, textDocument/signatureHelp), with push-based diagnostics via textDocument/publishDiagnostics notifications. Replace the factory function with a persistent SDCPNLanguageServer class that creates ts.createLanguageService() once and incrementally syncs virtual files (add/remove/update) when the SDCPN structure changes, instead of recreating from scratch on every mutation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ypes Replace hand-rolled Diagnostic, CompletionItem, Hover, and SignatureHelp types with official LSP types from vscode-languageserver-types. Protocol now uses LSP Position (line/character) instead of raw offsets, with offset<->position conversion utilities bridging the TS LanguageService (offset-based) and LSP (Position-based) worlds. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use React 19 Context shorthand, derive totalDiagnosticsCount directly instead of useMemo, and extract pure helper functions for building the diagnostics map. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix import sorting, remove unused imports, simplify unnecessary type assertions and conditions, avoid array index keys, and fix no-return-assign in provider singleton. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
….worker Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ntent The worker was converting Monaco positions against the full file content (prefix + user code), but Monaco positions are relative to the visible user code only. This caused double-counting of the prefix offset since SDCPNLanguageServer methods already add prefixLength internally. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add key={petriNetId} so the language client remounts with fresh state
when switching between Petri nets.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Monaco providers now call notifyDocumentChanged before each completion/hover/signatureHelp request so the worker always has up-to-date content when converting positions. Without this, typing a trigger character (e.g. ".") could race the SDCPN state sync, causing the worker to compute offsets against stale text. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
bc34ac2 to
fdc56a8
Compare
PR SummaryMedium Risk Overview Replaces the previous on-main-thread checker/Monaco typings setup with Cleans up and adjusts packaging/security: removes CDN-related CSP allowances, drops the frontend webpack browser fallbacks previously used for Written by Cursor Bugbot for commit d86a788. This will update automatically on new commits. Configure here. |
libs/@hashintel/petrinaut/src/views/Editor/panels/PropertiesPanel/place-properties.tsx
Show resolved
Hide resolved
🤖 Augment PR SummarySummary: This PR introduces an LSP-inspired TypeScript Language Service layer for Petrinaut’s Monaco editors, moving diagnostics and IntelliSense work off the main thread into a WebWorker. Changes:
Technical Notes: Monaco’s built-in TypeScript worker features are disabled and replaced by worker-backed providers; diagnostics are pushed from the worker and mirrored into Monaco markers. 🤖 Was this summary useful? React with 👍 or 👎 |
| } else { | ||
| client.notifySDCPNChanged(petriNetDefinition); | ||
| } | ||
| }, [petriNetDefinition, client]); |
There was a problem hiding this comment.
useLanguageClient() returns a fresh object each render, so including client in these effect deps can retrigger initialize/notifySDCPNChanged even when petriNetDefinition didn’t change (e.g., after diagnostics state updates). Consider stabilizing client (memoizing the returned API) or depending on specific stable callbacks instead.
Severity: medium
Other Locations
libs/@hashintel/petrinaut/src/lsp/provider.tsx:54
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
Same as above — React Compiler handles this automatically.
| /> | ||
| </div> | ||
| <CodeEditor | ||
| path={`inmemory://sdcpn/places/${place.id}/visualizer.tsx`} |
There was a problem hiding this comment.
This editor uses an inmemory://sdcpn/places/... URI, but the worker URI mapping currently only recognizes transitions + differential equations; with Monaco’s built-in TS features disabled, this model will likely have no completions/hover/diagnostics. Is the visualizer intentionally excluded, or should it be added to the URI mapping/worker support?
Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
Intentional — see above.
| i++; | ||
| } | ||
|
|
||
| return i + position.character; |
There was a problem hiding this comment.
positionToOffset can return an offset beyond text.length when position.line/position.character is out of range, which could propagate into TS LanguageService queries. Consider clamping to the text length (similar to offsetToPosition’s clamping) for defensive safety.
Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
Valid — adding a clamp for symmetry with offsetToPosition.
…offsetToPosition` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

🌟 What is the purpose of this PR?
Add a TypeScript Language Service layer for Petrinaut's Monaco editors, providing real-time diagnostics, completions, hover info, and signature help — all running off the main thread in a WebWorker, communicating via an LSP-inspired JSON-RPC 2.0 protocol with standard
vscode-languageserver-types.graph TD subgraph Main Thread SDCPN["SDCPNContext"] --updates--> LC["LanguageClientContext"] LC --> Sync["Sync Components"] Monaco["MonacoContext"] --> Sync CodeEditor --uses--> Monaco end subgraph WebWorker Worker["language-server.worker"] --> LS["SDCPNLanguageServer"] end LC -- "notifications" --> Worker Worker -. "diagnostics" .-> LC Sync -- "requests" --> Worker Worker -. "responses" .-> SyncProtocol messages (JSON-RPC 2.0)
initialize,sdcpn/didChange,textDocument/didChangetextDocument/publishDiagnosticsDiagnostic[]per URItextDocument/completionPosition→CompletionListtextDocument/hoverPosition→HovertextDocument/signatureHelpPosition→SignatureHelp🔗 Related links
🔍 What does this change?
Architecture
monaco/provider.tsx) with a module-level lazy singleton to prevent re-initializationlsp/)lsp/worker/language-server.worker.ts) with a JSON-RPC 2.0 protocolLSP-inspired protocol (
lsp/worker/protocol.ts)vscode-languageserver-types(Diagnostic,CompletionItem,CompletionList,Hover,SignatureHelp,Position,Range)initialize,sdcpn/didChange,textDocument/didChangetextDocument/completion,textDocument/hover,textDocument/signatureHelptextDocument/publishDiagnostics(per-URI diagnostic notifications)Position { line, character }with offset↔position conversion utilities bridging the TS LanguageServicePersistent LanguageService (
lsp/lib/create-sdcpn-language-service.ts)SDCPNLanguageServerclass creatests.createLanguageService()once and reuses it across SDCPN changessyncFiles(sdcpn)diffs virtual files incrementally (add/remove/update) rather than recreating everythingupdateDocumentContent()for single-file typing updatesgetFileContent()for offset↔position conversionShared modules
lsp/lib/document-uris.ts: Single source of truth for URI ↔ file path ↔ item type mapping, consumed by both the worker and Monaco componentslsp/lib/ts-to-lsp.ts: Pure TS → LSP type conversion functions (toLspSeverity,toCompletionItemKind,serializeDiagnostic), extracted from the worker for testabilitylsp/lib/position-utils.ts: Offset ↔ LSP Position conversion utilitiesLanguage features (Monaco sync components)
DiagnosticsSyncmaps LSPDiagnosticranges to Monaco markers (diagnostics-sync.tsx)CompletionSyncwith LSPCompletionItemKind→ Monaco kind mapping (completion-sync.tsx)HoverSyncrendering LSPMarkupContent(hover-sync.tsx)SignatureHelpSyncwith LSPSignatureHelp→ Monaco mapping (signature-help-sync.tsx)Cleanup
@dnd-kitdependency and feature flagsrollup-plugin-visualizerdependencyPre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
🛡 What tests cover this?
checker.test.ts: 20 tests covering SDCPN validation with theSDCPNLanguageServercreate-sdcpn-language-service.test.ts: 11 tests covering dot completions, top-level completions,updateDocumentContentmutability,syncFilesstructural updates, and differential equation completionsposition-utils.test.ts: 12 tests coveringoffsetToPosition,positionToOffset, and roundtrip identitydocument-uris.test.ts: 22 tests covering URI construction, parsing, file path conversion, and roundtrip identity for all item typests-to-lsp.test.ts: 38 tests covering TS diagnostic severity → LSP severity mapping, all TSScriptElementKind→ LSPCompletionItemKindmappings, and fullserializeDiagnosticconversion (multi-line ranges, chained messages, defaults)🐾 Next steps
vscode-languageserver/vscode-languageclient) to replace custom JSON-RPC mapping and reduce protocol boilerplate.