How kaby76/antlrvsix works
Project type and purpose
• AntlrVSIX is an open‑source language tooling suite built around the Language Server Protocol.
• It delivers grammar‐editing features (tagging, go‑to‑def, hover, find‑refs, rename, formatting), grammar analysis, refactoring, conversion via:
• A .NET LSP server (C#)
• Multiple thin “client” adapters: VS IDE extension, VS Code extension (TypeScript), Emacs Lisp plugin, and a CLI (“Trash”).
File structure
• Top‑level “shared” libraries:
• Logger/ (Log.cs)
• LspHelpers/ (LSP protocol types, helper streams)
• Options/ (per‑client configuration system)
• Core server:
• Server/ (LSPServer.cs, Program.cs, language‐targeting code)
• Clients:
• VsIde/ (C# VSIX extension project, Visual Studio LSP client shim, menus, commands)
• VsCode/ (TS extension.ts, package.json, server launch shim)
• Emacs/ (lsp‑antlr.el, Emacs client readme)
• Command‑line shell:
• Trash under <root>/Trash (invokes parse/transform APIs out of process)
• Transforms:
• transforms/ (scripts implementing individual grammar refactorings)
• Tests:
• test/ (sample grammars, JUnit tests, Java project for integration)
Key README insights
• All clients communicate with the same LSP server process.
• Server internals use Antlr4, Antlr4BuildTasks, XPath2, S‑expressions for parse trees.
• Trash is a CLI shell that serializes parse tree state as JSON, enabling out‑of‑process commands.
• VS IDE uses Microsoft.VisualStudio.LanguageServer.Client; VS Code spawns the server via Node.
a. Main components
• Shared libraries: Logger, LspHelpers, Options
• Core LSP Server (.NET)
• Clients:
• VS IDE extension (C# VSIX)
• VS Code extension (TypeScript + Node)
• Emacs plugin (Elisp)
• Trash CLI (Console app)
• Transform modules (tree refactorings)
• External dependencies: Antlr4 runtime, .NET SDK, Node.js, Visual Studio, VS Code, Emacs
b. Relationships & data flow
• Clients ↔ LSP Server:
• VS IDE uses in‑process NuGet LSP client → named pipes or in‑proc host
• VS Code uses stdio or IPC via Node child_process.spawn
• Emacs uses lsp-mode over stdio
• Trash invokes server APIs directly or via command line serialization
• LSP Server → Core parsing engine → Antlr4 grammar parser → parse tree → XPath/transform modules → analysis/refactor results → back to server → JSON‑RPC responses → clients
c. Architectural patterns & design principles
• Modular “shared‑library” pattern separating cross‑cutting concerns (logging, protocol types, options)
• Language Server Protocol façade isolating client‑specific shims
• Plugin/extension model per‑editor
• Out‑of‑process CLI model with JSON serialization for extensibility
d. Technologies/frameworks
• C#, .NET Core (Server, VS IDE, Logger, LspHelpers, Options, Trash)
• Antlr4 & Antlr4BuildTasks for grammar parsing
• XPath2, S‑expression libraries for tree queries
• Microsoft.VisualStudio.LanguageServer.Client (VS IDE)
• TypeScript, Node.js (VS Code)
• Emacs Lisp (Emacs)