A human-friendly DSL for ATProto Lexicons
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

README.md

mlf-lsp#

Language Server Protocol (LSP) implementation for Matt's Lexicon Format (MLF).

Features#

Currently Implemented#

  • Diagnostics: Real-time syntax error reporting as you type
  • Document Synchronization: Tracks open/changed/closed MLF files
  • Hover Information: Shows type information, documentation comments, and field details on hover
  • Completion: Auto-complete for keywords, primitive types, defined types, and constraint names
  • Go to Definition: Jump to type definitions across files using workspace resolution
  • Workspace Support: Automatically builds a workspace from open files with cross-file type resolution
  • Logging: Server activity logging for debugging

Planned Features#

  • Formatting: Auto-format MLF code from AST
  • Rename: Rename symbols across files
  • Find References: Find all usages of a symbol
  • Code Actions: Quick fixes and refactoring
  • Signature Help: Parameter hints for queries/procedures
  • Semantic Tokens: Enhanced syntax highlighting
  • Document Symbols: Outline view of definitions
  • Workspace Validation: Multi-file validation with workspace support

Usage#

Running the Server#

cargo build --release -p mlf-lsp
./target/release/mlf-lsp

The server communicates over stdin/stdout using the LSP protocol.

Editor Integration#

VS Code#

Create a VS Code extension that launches the LSP server:

{
  "languageServer": {
    "module": "/path/to/mlf-lsp",
    "args": [],
    "filetypes": ["mlf"]
  }
}

Neovim#

Configure with nvim-lspconfig:

local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')

configs.mlf = {
  default_config = {
    cmd = { '/path/to/mlf-lsp' },
    filetypes = { 'mlf' },
    root_dir = lspconfig.util.root_pattern('mlf.toml', '.git'),
  },
}

lspconfig.mlf.setup{}

Helix#

Add to your languages.toml:

[[language]]
name = "mlf"
scope = "source.mlf"
file-types = ["mlf"]
language-servers = ["mlf-lsp"]

[language-server.mlf-lsp]
command = "/path/to/mlf-lsp"

Development#

The LSP server is built using:

  • tower-lsp: High-level LSP framework
  • tokio: Async runtime
  • mlf-lang: MLF parser and AST
  • mlf-diagnostics: Error reporting

Architecture#

mlf-lsp/
├── src/
│   ├── lib.rs           # Library exports
│   ├── main.rs          # Binary entry point
│   └── server.rs        # LSP server implementation
└── Cargo.toml

Adding Features#

  1. Hover: Implement position-based type lookup in the AST
  2. Completion: Build a context-aware symbol table from the workspace
  3. Go to Definition: Track symbol definitions and references
  4. Formatting: Generate MLF source from the AST with consistent formatting

Testing#

# Run tests
cargo test -p mlf-lsp

# Test with LSP inspector
npm install -g @vscode/language-server-inspector
lsp-inspector --command "/path/to/mlf-lsp"

Logging#

Set the RUST_LOG environment variable to control logging:

RUST_LOG=debug mlf-lsp
RUST_LOG=mlf_lsp=trace mlf-lsp

Logs are written to stderr.

Contributing#

The LSP server is in early development. Contributions are welcome!

Priority features:

  1. Hover information with type details
  2. Completion for types and keywords
  3. Go to definition for imports and references
  4. Formatting using mlf-lang AST