Nymph Language Server#
A Language Server Protocol (LSP) implementation for the Nymph programming language.
Features#
- Document Management: Track open/close and updates to Nymph source files
- Hover Information: Display type information and symbol details on hover
- Semantic Tokenization: Syntax highlighting with semantic token types
- Keywords, functions, variables, types, interfaces, and more
- Token modifiers for declarations, definitions, builtins, and mutability
- Symbol Navigation: Document symbol provider for outline and go-to-symbol
- Code Completion: Basic keyword and built-in completions
- Parsing Integration: Full integration with the Nymph compiler's parser
Architecture#
Modules#
server.rs- Main LSP server implementation using tower-lspdocument.rs- Document management and parsingworkspace.rs- Workspace state managementanalyzer.rs- Semantic analysis for symbol resolutionsemantic_tokens.rs- Semantic tokenization for highlightingsymbols.rs- Symbol information types
How It Works#
- Document Lifecycle: When a document is opened/changed, it's stored in the workspace and parsed using the Nymph compiler
- Analysis: The semantic analyzer extracts symbols and type information from the parsed AST
- Tokenization: Semantic tokens are generated for syntax highlighting
- LSP Responses: The server responds to client requests with type hints, symbols, completions, etc.
Building#
cargo build --release --package nymph-lsp
The binary will be at target/release/nymph-lsp
Running#
./target/release/nymph-lsp
The server communicates via stdin/stdout using the LSP protocol.
Supported LSP Features#
Server Capabilities#
- ✅ Text Document Synchronization (full document sync)
- ✅ Hover Provider
- ✅ Semantic Tokens (legend + full document)
- ✅ Document Symbol Provider
- ✅ Completion Provider
- ✅ Definition Provider (stub)
In Progress#
- Symbol resolution and hover type information
- Improved semantic tokenization with AST integration
- Incremental text document sync
- Go-to-definition functionality
- Workspace symbol search
Extension Integration#
VS Code#
To use with VS Code, create a .vscode/extensions/nymph-lsp/ directory and configure the extension client:
{
"language": "nymph",
"scheme": "file",
"initializationOptions": {},
"documentSelector": [{ "language": "nymph", "scheme": "file" }]
}
Configure the server path in your LSP client extension.
Neovim#
For Neovim with nvim-lspconfig:
require('lspconfig').nymph.setup {
cmd = {"/path/to/nymph-lsp"},
filetypes = {"nymph"},
root_dir = require('lspconfig.util').root_pattern(".git", "Cargo.toml"),
}
Testing#
Run the test suite:
cargo test --package nymph-lsp
Dependencies#
tower-lsp- LSP protocol frameworksmol- Async runtimeserde/serde_json- JSON serializationnymph-compiler- Nymph language compilerecow- Efficient copy-on-write stringsurl- URL parsing for file URIs
Future Enhancements#
- Full semantic analysis with type checking
- Format provider
- Rename provider
- References provider
- Call hierarchy
- Signature help
- Document/workspace diagnostics
- Incremental text sync
- Multi-file workspace support
- Macro expansion support