Baboon provides a Language Server Protocol (LSP) implementation for editor integration. The LSP server provides real-time diagnostics, hover information, go-to-definition, completion, and document symbols for .baboon files.
Standard mode for editor integration:
baboon --model-dir ./src/models :lspThe server communicates via stdin/stdout using the LSP JSON-RPC protocol.
For debugging or testing with external tools:
baboon --model-dir ./src/models :lsp --port 5000The server listens on the specified port and accepts a single client connection. Output appears on stderr:
Baboon LSP server listening on port 5000
Client connected
The simplest way to verify the compiler and model loading works is to use explorer mode, which shares the same compilation pipeline:
# Build native executable
mdl :build
# Test with the built-in test models
baboon --model-dir baboon-compiler/src/test/resources/baboon :exploreIf explorer mode successfully loads and displays types, the LSP server will work with the same models.
-
Start the server:
baboon --model-dir baboon-compiler/src/test/resources/baboon :lsp --port 5000
-
Connect with netcat or a similar tool:
nc localhost 5000
-
Send an LSP initialize request (JSON-RPC format):
Content-Length: 123 {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{}}}
The server should respond with its capabilities.
The server publishes diagnostics on document open, change, and save. Diagnostics include:
- Parse errors (syntax issues)
- Type errors (undefined types, type mismatches)
- Validation errors (evolution issues, missing roots)
Hover over type references to see:
- Type definition summary
- Source location
- Field structure for data types
Jump to the definition of:
- Type references in field declarations
- Parent types in
+/-/^operations - Types in collection parameters (
lst[T],opt[T], etc.)
Auto-completion is triggered by:
.- for namespace-qualified types:- for annotations (:derived[...])[- for collection type parameters
Completions include:
- Type names from current domain
- Built-in types (
str,uid,i32, etc.) - Keywords and annotations
Shows outline of the current document:
- Namespaces
- Data types
- ADTs and their branches
- Enums
- Contracts
- Foreign types
Install the Baboon VS Code extension.
The extension can be configured via standard VS Code settings (settings.json):
{
"baboon.serverPath": "baboon",
"baboon.modelDirs": ["${workspaceFolder}/models"],
"baboon.serverOptions": ["--debug"]
}baboon.serverPath: Path to thebaboonexecutable. Defaults tobaboon(assumes it's in your PATH).baboon.modelDirs: List of directories containing.baboonfiles. If empty, the workspace root is used.baboon.serverOptions: Extra arguments to pass to the compiler before the:lspcommand.baboon.serverArgsOverride: Replace all arguments passed to the server. If this is set,baboon.modelDirsandbaboon.serverOptionsare ignored.
For development, you can point baboon.serverPath to your local build:
"baboon.serverPath": "${workspaceFolder}/baboon-compiler/.jvm/target/graalvm-native-image/baboon"
Add to your LSP configuration:
local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')
if not configs.baboon then
configs.baboon = {
default_config = {
cmd = { 'baboon', '--model-dir', '.', ':lsp' },
filetypes = { 'baboon' },
root_dir = lspconfig.util.root_pattern('.git', 'model'),
},
}
end
lspconfig.baboon.setup({})(with-eval-after-load 'lsp-mode
(add-to-list 'lsp-language-id-configuration '(baboon-mode . "baboon"))
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection '("baboon" "--model-dir" "." ":lsp"))
:major-modes '(baboon-mode)
:server-id 'baboon-lsp)))The LSP server uses workspace folders to discover .baboon files. When initialized, it:
- Scans all workspace folders for
.baboonfiles - Compiles the domain model
- Publishes initial diagnostics
On document changes, it recompiles and updates diagnostics incrementally.
- Verify the native executable is built:
mdl :build - Check that
baboonis in your PATH or use an absolute path - Test with explorer mode first to verify model loading works
- Ensure the file has
.baboonextension - Check that
--model-dirincludes the file's directory - Verify the file is in an open workspace folder
- Check no firewall blocks the port
- Ensure no other process uses the same port
- The server accepts only one client; restart for new connections
The LSP server uses the following components:
BaboonLanguageServer- Main LSP protocol handlerBaboonTextDocumentService- Handles document operations (open, change, save)BaboonWorkspaceService- Handles workspace operationsWorkspaceState- Maintains compilation state and model cacheDocumentState- Tracks open document contents
Feature providers:
DiagnosticsProvider- Converts compilation issues to LSP diagnosticsHoverProvider- Generates hover informationDefinitionProvider- Resolves go-to-definition locationsCompletionProvider- Generates completion itemsDocumentSymbolProvider- Extracts document outline