Skip to main content

Crate logicaffeine_lsp

Crate logicaffeine_lsp 

Source
Expand description

§logicaffeine-lsp

Language Server Protocol implementation providing IDE integration for LogicAffeine.

This crate implements a complete LSP server that enables rich code intelligence in any LSP-compatible editor, including diagnostics, completion, hover documentation, refactoring, and more.

§Quick Start

Install the language server binary:

cargo install logicaffeine-lsp

Configure your editor to use logicaffeine-lsp as the language server for .logos files. See the Editor Integration section for specific setup instructions.

§Features

The language server provides 14 LSP features organized into four categories:

§Code Intelligence

FeatureDescription
DiagnosticsReal-time syntax and semantic error detection with actionable error messages
HoverType information, documentation, and definition context on hover
Semantic TokensSyntax highlighting based on semantic meaning (variables, keywords, types)
FeatureDescription
Go to DefinitionJump to where a variable, function, or type is defined
Find ReferencesFind all usages of a symbol across the codebase
Document SymbolsOutline view showing all declarations in the file
Code LensInline reference counts and navigation actions

§Refactoring

FeatureDescription
RenameSafely rename symbols across all references with preview
Code ActionsQuick fixes and refactoring suggestions (e.g., “Extract to function”)

§Editing

FeatureDescription
CompletionContext-aware autocomplete for keywords, variables, and functions
Signature HelpParameter hints for function calls
Inlay HintsInline type annotations and parameter names

§Display

FeatureDescription
Folding RangesCollapsible code regions for functions, blocks, and comments
FormattingAutomatic code formatting with consistent style

§Editor Integration

§VSCode

Add to your settings.json:

{
  "logicaffeine.lsp.serverPath": "/path/to/logicaffeine-lsp",
  "logicaffeine.lsp.trace.server": "verbose"
}

The official VSCode extension is available at editors/vscode/logicaffeine/.

§Neovim

Using nvim-lspconfig:

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

if not configs.logicaffeine_lsp then
  configs.logicaffeine_lsp = {
    default_config = {
      cmd = { 'logicaffeine-lsp' },
      filetypes = { 'logos' },
      root_dir = lspconfig.util.root_pattern('.git', 'Project.toml'),
      settings = {},
    },
  }
end

lspconfig.logicaffeine_lsp.setup{}

§Emacs (lsp-mode)

(require 'lsp-mode)
(add-to-list 'lsp-language-id-configuration '(logos-mode . "logos"))
(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection "logicaffeine-lsp")
                  :major-modes '(logos-mode)
                  :server-id 'logicaffeine-lsp))

§Emacs (eglot)

(require 'eglot)
(add-to-list 'eglot-server-programs '(logos-mode . ("logicaffeine-lsp")))

§Sublime Text

Install the LSP package, then add to your LSP settings:

{
  "clients": {
    "logicaffeine-lsp": {
      "enabled": true,
      "command": ["logicaffeine-lsp"],
      "selector": "source.logos"
    }
  }
}

§Architecture

LSP Client (Editor)
     │
     ▼
┌─────────────────────────────────────────┐
│     Language Server (tower-lsp)         │
│  ┌─────────────────────────────────┐   │
│  │   Document State Management      │   │
│  │   (incremental sync, indexing)   │   │
│  └─────────────────────────────────┘   │
└──────────────┬──────────────────────────┘
               │
               ▼
┌─────────────────────────────────────────┐
│     LogicAffeine Pipeline               │
│  ┌──────┐  ┌────────┐  ┌──────────┐   │
│  │Lexer │→ │ Parser │→ │ Analysis │   │
│  └──────┘  └────────┘  └──────────┘   │
└─────────────────────────────────────────┘
               │
               ▼
┌─────────────────────────────────────────┐
│          LSP Features                    │
│  Diagnostics, Hover, Completion, etc.   │
└─────────────────────────────────────────┘

The server integrates LogicAffeine’s compilation pipeline with the LSP protocol:

  1. server - Tower-LSP server handling client communication
  2. state - Document state management with incremental updates
  3. pipeline - Compilation pipeline integration (lexer, parser, analysis)
  4. index - Symbol indexing for cross-file references
  5. Feature modules - Individual LSP capabilities (diagnostics, hover, completion, etc.)

§Modules

  • server - Main LSP server implementation using tower-lsp
  • state - Document state and workspace management
  • document - Individual document handling with incremental sync
  • pipeline - Integration with LogicAffeine compilation pipeline
  • index - Symbol indexing and cross-reference tracking
  • line_index - Line/column to byte offset conversion

§Feature Modules

§Testing

The crate includes 179 comprehensive tests covering all LSP features:

cargo test -p logicaffeine-lsp --lib

§Performance

  • Incremental sync: Only re-analyzes changed documents
  • Parallel analysis: Uses DashMap for concurrent document processing
  • Lazy indexing: Symbol index built on-demand
  • Optimized for REPL: Workspace state persists across document changes

§License

Business Source License 1.1 (BUSL-1.1)

  • Free for individuals and organizations with <25 employees
  • Commercial license required for organizations with 25+ employees offering Logic Services
  • Converts to MIT on December 24, 2029

See LICENSE for full terms.

Modules§

code_actions
code_lens
completion
definition
diagnostics
document
document_symbols
folding
formatting
hover
index
inlay_hints
line_index
pipeline
references
rename
semantic_tokens
server
signature_help
state