Skip to content

ComlineProject/language-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comline Language Server

A Language Server Protocol (LSP) implementation for Comline, providing intelligent code editing features for .ids schema files.

Features

✅ Fully Implemented

  • Diagnostics - Real-time syntax error detection and reporting
  • Document Symbols - Hierarchical outline view of structs, enums, protocols, and constants
  • Hover Information - Rich tooltips showing full type definitions and signatures
  • Go to Definition - Jump from type references to their declarations
  • Find References - Locate all usages of a symbol (with include/exclude declaration option)
  • Auto-Completion - Context-aware code suggestions:
    • Keywords with snippets (struct, enum, protocol, const, use, import)
    • Primitive types (i8-i64, u8-u64, f32/f64, string, bool)
    • User-defined types (all structs, enums, protocols from current file)
    • Context detection (type position, top-level, struct body)

🚧 Planned

  • Find References - Locate all usages of a symbol
  • Auto-Completion - Context-aware code completion
  • Rename Symbol - Safe refactoring across files
  • Code Formatting - Automatic code formatting
  • Semantic Tokens - Enhanced syntax highlighting

Installation

Building from Source

cd language-server
cargo build --release

The LSP server binary will be available at target/release/comline-lsp.

Editor Integration

Visual Studio Code

  1. Install a generic LSP client extension (e.g., vscode-languageclient)
  2. Configure the server in your settings:
{
  "comline.server": {
    "command": "/path/to/comline-lsp",
    "args": [],
    "transport": "stdio"
  }
}

Neovim

Using nvim-lspconfig:

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

-- Define Comline LSP
if not configs.comline_ls then
  configs.comline_ls = {
    default_config = {
      cmd = {'/path/to/comline-lsp'},
      filetypes = {'comline'},
      root_dir = lspconfig.util.root_pattern('.git', 'config.idp'),
      settings = {},
    },
  }
end

-- Setup Comline LSP
lspconfig.comline_ls.setup{}

-- Associate .ids files with comline filetype
vim.filetype.add({
  extension = {
    ids = 'comline',
  },
})

Helix

Add to your languages.toml:

[[language]]
name = "comline"
scope = "source.comline"
file-types = ["ids"]
roots = ["config.idp", ".git"]
language-servers = ["comline-ls"]

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

Emacs (lsp-mode)

(add-to-list 'lsp-language-id-configuration '(comline-mode . "comline"))

(lsp-register-client
 (make-lsp-client
  :new-connection (lsp-stdio-connection "/path/to/comline-lsp")
  :major-modes '(comline-mode)
  :server-id 'comline-ls))

Usage

Once integrated with your editor, the LSP server provides:

Real-time Diagnostics

Syntax errors are highlighted as you type:

struct User {
    name string  // ← Error: Missing colon
    age: i32
}

Outline View

Navigate your schema using the document symbols panel:

📦 User (3 fields)
  ├─ 📄 name
  ├─ 📄 age
  └─ 📄 email
🔌 UserService (2 functions)
  ├─ ⚡ getUser
  └─ ⚡ createUser

Hover Information

Hover over any symbol to see its definition:

struct User {
  name: string
  age: i32
  optional email: string
}

3 fields

Go to Definition

Ctrl/Cmd + Click on any type reference to jump to its definition:

struct User { ... }

struct Request {
    user: User  // ← Click jumps to User definition
}

Development

Project Structure

src/
├── main.rs              # Entry point
├── backend.rs           # LSP protocol implementation
├── document.rs          # Document management
├── parser.rs            # Comline parser integration
├── util.rs              # Utility functions
├── analysis/            # Semantic analysis
│   ├── diagnostics.rs   # Error reporting
│   ├── symbols.rs       # Symbol extraction
│   ├── types.rs         # Type resolution
│   └── imports.rs       # Import resolution
└── handlers/            # LSP feature handlers
    ├── completion.rs
    ├── definition.rs
    ├── formatting.rs
    ├── hover.rs
    ├── references.rs
    ├── rename.rs
    └── symbols.rs

Running Tests

cargo test

All tests should pass:

  • Parser tests
  • Diagnostic tests
  • Symbol extraction tests
  • Handler tests
  • Integration tests

Logging

Set the RUST_LOG environment variable for debugging:

RUST_LOG=debug /path/to/comline-lsp

Logs are written to stderr and won't interfere with the LSP protocol communication over stdio.

Technical Details

LSP Capabilities

The server advertises the following capabilities:

  • Text Document Sync - Full document synchronization
  • Hover Provider - Type information on hover
  • Completion Provider - Trigger characters: ., :
  • Definition Provider - Go to definition support
  • References Provider - Find all references (planned)
  • Document Symbol Provider - Outline view
  • Workspace Symbol Provider - Global symbol search (planned)
  • Document Formatting - Auto-formatting (planned)
  • Rename Provider - Symbol renaming (planned)
  • Semantic Tokens - Enhanced highlighting (planned)

Dependencies

  • tower-lsp - LSP protocol framework
  • comline-core - Comline parser and AST
  • rust-sitter - Parser infrastructure
  • tokio - Async runtime
  • dashmap - Concurrent hashmap for document storage
  • tracing - Structured logging

Contributing

Contributions are welcome! Areas for improvement:

  1. Find References - Implement reference finding across files
  2. Auto-Completion - Add intelligent completion suggestions
  3. Import Resolution - Cross-file type resolution
  4. Code Actions - Quick fixes and refactorings
  5. Formatting - Implement Comline code formatter

License

See the main Comline project for licensing information.

Acknowledgments

Built using:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages