⚠️ Note: This is an experimental project developed in my personal free time for educational purposes — primarily to learn how Language Server Protocol implementations work. While functional, it is not officially supported. Feedback and contributions are welcome!
Language Server Protocol implementation for the Compact smart contract language (Midnight network).
| Feature | Description |
|---|---|
| Diagnostics | Real-time syntax errors + compiler errors on save |
| Semantic Tokens | Rich syntax highlighting (functions, types, parameters, etc.) |
| Completion | Keywords, types, snippets, local and imported symbols |
| Hover | Documentation for keywords, types, and symbols |
| Go to Definition | Jump to symbol definitions (local and imported) |
| Find References | Find all usages of a symbol (local and cross-file) |
| Rename | Rename symbols across the workspace |
| Signature Help | Parameter hints while typing function calls |
| Document Symbols | Outline view (circuits, structs, enums, modules) |
| Formatting | Code formatting via format-compact |
| Folding Ranges | Code folding for blocks and functions |
| Cross-file Errors | Errors propagate to dependent files on save |
Works with Compact's import system:
import "./Utils" prefix Utils_;
Utils_add(5, 5); // Completion, hover, go-to-def, find refs, rename, signature help all work
| Feature | Status |
|---|---|
| Code Actions | TODO |
- Rust toolchain (for building)
compactccompiler (for diagnostics)format-compact(optional, for formatting)
cargo build --releaseBinary: target/release/compact-lsp
The LSP auto-detects compactc.bin:
COMPACT_COMPILERenvironment variable~/compactc/compactc.bincompactc.binin PATH
- compact.vim - Vim/Neovim syntax highlighting
- compact-tree-sitter - Tree-sitter grammar
Create ~/.config/nvim/lua/lsp/compact.lua:
return {
cmd = { vim.fn.expand("~/path/to/compact-lsp/target/release/compact-lsp") },
filetypes = { "compact" },
root_markers = { ".git", "compact.toml", "package.json" },
}Add to your Neovim config:
-- Register .compact filetype
vim.filetype.add({
extension = { compact = "compact" },
})
-- Load and register compact LSP
local compact_config = require("lsp.compact")
vim.lsp.config("compact_lsp", compact_config)
-- Auto-enable for .compact files
vim.api.nvim_create_autocmd("FileType", {
pattern = "compact",
callback = function()
vim.lsp.enable("compact_lsp")
end,
})Open a .compact file and run:
:LspInfoAdd to your config to use LSP semantic tokens for highlighting:
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client and client.server_capabilities.semanticTokensProvider then
vim.lsp.semantic_tokens.start(args.buf, args.data.client_id)
end
end,
})MIT