Skip to content

1NickPappas/compact-lsp

compact-lsp

License: MIT CI Rust

⚠️ 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).

Features

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

Cross-Project Support

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

Missing Things

Feature Status
Code Actions TODO

Requirements

  • Rust toolchain (for building)
  • compactc compiler (for diagnostics)
  • format-compact (optional, for formatting)

Building

cargo build --release

Binary: target/release/compact-lsp

Compiler Location

The LSP auto-detects compactc.bin:

  1. COMPACT_COMPILER environment variable
  2. ~/compactc/compactc.bin
  3. compactc.bin in PATH

Related Projects

Neovim Setup

1. Create LSP config

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" },
}

2. Register filetype and enable LSP

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,
})

3. Verify

Open a .compact file and run:

:LspInfo

Optional: Enable semantic highlighting

Add 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,
})

License

MIT

About

Language Server Protocol (LSP) implementation for Compact smart contract language (Midnight network) – diagnostics, completion, hover, go-to-definition, references, rename, and more

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages