How tencent/luahelper works
Project Type and Purpose
• LuaHelper is a two-part tooling ecosystem:
a. A Visual Studio Code extension (luahelper-vscode) written in TypeScript that provides editor UI, language client, and debug adapter.
b. A standalone Language Server Protocol (LSP) server (luahelper-lsp) written in Go that performs parsing, semantic analysis, formatting, and diagnostics.
• It implements Microsoft’s Language Server Protocol for Lua editing features (completion, go-to-definition, hover, references) and integrates a Debug Adapter Protocol (DAP) debug adapter based on LuaPanda.
File-Structure Analysis
• Top level: docs, images, README, CI configs.
• luahelper-lsp: Go module containing:
• main.go — entry point for the LSP server
• langserver/ — LSP protocol handlers (initialize, textDocument, workspace, common utilities, file management)
• langserver/check/ — code analysis packages (lexer, parser, AST annotation, semantic checks, caches)
• langserver/diagnostics_manager.go — orchestrates error reporting
• testdata/ — sample Lua projects for unit tests
• luahelper-vscode: VSCode extension containing:
• src/ — TypeScript code for language client, debug adapter, and extension activation
• debug/ — DAP adapter implementation (debugAdapter.ts, luaDebugRuntime.ts)
• client/ and server/ — shipped binaries (lualsp.exe, luaformat, luasocket plugins) for different OSes
• build/ — packaging scripts
Key README Insights
• Emphasizes cross-platform support, coroutine-based real-time analysis, large-project scalability, and integration of external libs:
• luago-book for AST
• LuaFormatter (C++)
• LuaPanda for debugging
a. Main Components
• VSCode Editor & Extension Host (Frontend UI)
• Language Client (TS)
• Debug Adapter (TS)
• LSP Server Process (Go)
• Lua Analysis Engine (lexer/parser/AST/semantic modules)
• External Libraries (luago AST generator, LuaFormatter, LuaPanda debug runtime)
• Workspace File System & Configuration (jsonconfig, user settings)
b. Relationships & Data Flows
1. User edits Lua → VSCode UI → Language Client sends JSON-RPC LSP requests (over stdio or TCP) → LSP Server
2. LSP Server parses files, runs checks, formatting via external libs, returns diagnostics/responses → Language Client → UI
3. On debug start → VSCode UI triggers Debug Adapter → spawns Lua process with LuaPanda.lua injected → communicates via DAP → VSCode UI
c. Architectural Patterns
• Client-Server (LSP over JSON-RPC)
• Adapter (Debug Adapter Protocol)
• Modular Go packages (analysis, annotation, common utilities)
• VSCode extension activation events & command registration
d. Core Technologies
• Go (LSP server)
• TypeScript (VSCode extension)
• JSON-RPC, LSP & DAP protocols
• C++ LuaFormatter
• LuaPanda (Lua debug runtime)
Detailed Capture
• Testdata as supporting unit-test artifact.
• Build scripts packaging VSCode extension and compiled LSP binaries for each OS.