logicaffeine_lsp/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! # logicaffeine-lsp
4//!
5//! Language Server Protocol implementation providing IDE integration for LogicAffeine.
6//!
7//! This crate implements a complete LSP server that enables rich code intelligence in any LSP-compatible editor,
8//! including diagnostics, completion, hover documentation, refactoring, and more.
9//!
10//! ## Quick Start
11//!
12//! Install the language server binary:
13//!
14//! ```bash
15//! cargo install logicaffeine-lsp
16//! ```
17//!
18//! Configure your editor to use `logicaffeine-lsp` as the language server for `.logos` files.
19//! See the [Editor Integration](#editor-integration) section for specific setup instructions.
20//!
21//! ## Features
22//!
23//! The language server provides 14 LSP features organized into four categories:
24//!
25//! ### Code Intelligence
26//!
27//! | Feature | Description |
28//! |---------|-------------|
29//! | **Diagnostics** | Real-time syntax and semantic error detection with actionable error messages |
30//! | **Hover** | Type information, documentation, and definition context on hover |
31//! | **Semantic Tokens** | Syntax highlighting based on semantic meaning (variables, keywords, types) |
32//!
33//! ### Navigation
34//!
35//! | Feature | Description |
36//! |---------|-------------|
37//! | **Go to Definition** | Jump to where a variable, function, or type is defined |
38//! | **Find References** | Find all usages of a symbol across the codebase |
39//! | **Document Symbols** | Outline view showing all declarations in the file |
40//! | **Code Lens** | Inline reference counts and navigation actions |
41//!
42//! ### Refactoring
43//!
44//! | Feature | Description |
45//! |---------|-------------|
46//! | **Rename** | Safely rename symbols across all references with preview |
47//! | **Code Actions** | Quick fixes and refactoring suggestions (e.g., "Extract to function") |
48//!
49//! ### Editing
50//!
51//! | Feature | Description |
52//! |---------|-------------|
53//! | **Completion** | Context-aware autocomplete for keywords, variables, and functions |
54//! | **Signature Help** | Parameter hints for function calls |
55//! | **Inlay Hints** | Inline type annotations and parameter names |
56//!
57//! ### Display
58//!
59//! | Feature | Description |
60//! |---------|-------------|
61//! | **Folding Ranges** | Collapsible code regions for functions, blocks, and comments |
62//! | **Formatting** | Automatic code formatting with consistent style |
63//!
64//! ## Editor Integration
65//!
66//! ### VSCode
67//!
68//! Add to your `settings.json`:
69//!
70//! ```json
71//! {
72//! "logicaffeine.lsp.serverPath": "/path/to/logicaffeine-lsp",
73//! "logicaffeine.lsp.trace.server": "verbose"
74//! }
75//! ```
76//!
77//! The official VSCode extension is available at `editors/vscode/logicaffeine/`.
78//!
79//! ### Neovim
80//!
81//! Using `nvim-lspconfig`:
82//!
83//! ```lua
84//! local lspconfig = require('lspconfig')
85//! local configs = require('lspconfig.configs')
86//!
87//! if not configs.logicaffeine_lsp then
88//! configs.logicaffeine_lsp = {
89//! default_config = {
90//! cmd = { 'logicaffeine-lsp' },
91//! filetypes = { 'logos' },
92//! root_dir = lspconfig.util.root_pattern('.git', 'Project.toml'),
93//! settings = {},
94//! },
95//! }
96//! end
97//!
98//! lspconfig.logicaffeine_lsp.setup{}
99//! ```
100//!
101//! ### Emacs (lsp-mode)
102//!
103//! ```elisp
104//! (require 'lsp-mode)
105//! (add-to-list 'lsp-language-id-configuration '(logos-mode . "logos"))
106//! (lsp-register-client
107//! (make-lsp-client :new-connection (lsp-stdio-connection "logicaffeine-lsp")
108//! :major-modes '(logos-mode)
109//! :server-id 'logicaffeine-lsp))
110//! ```
111//!
112//! ### Emacs (eglot)
113//!
114//! ```elisp
115//! (require 'eglot)
116//! (add-to-list 'eglot-server-programs '(logos-mode . ("logicaffeine-lsp")))
117//! ```
118//!
119//! ### Sublime Text
120//!
121//! Install the LSP package, then add to your LSP settings:
122//!
123//! ```json
124//! {
125//! "clients": {
126//! "logicaffeine-lsp": {
127//! "enabled": true,
128//! "command": ["logicaffeine-lsp"],
129//! "selector": "source.logos"
130//! }
131//! }
132//! }
133//! ```
134//!
135//! ## Architecture
136//!
137//! ```text
138//! LSP Client (Editor)
139//! │
140//! ▼
141//! ┌─────────────────────────────────────────┐
142//! │ Language Server (tower-lsp) │
143//! │ ┌─────────────────────────────────┐ │
144//! │ │ Document State Management │ │
145//! │ │ (incremental sync, indexing) │ │
146//! │ └─────────────────────────────────┘ │
147//! └──────────────┬──────────────────────────┘
148//! │
149//! ▼
150//! ┌─────────────────────────────────────────┐
151//! │ LogicAffeine Pipeline │
152//! │ ┌──────┐ ┌────────┐ ┌──────────┐ │
153//! │ │Lexer │→ │ Parser │→ │ Analysis │ │
154//! │ └──────┘ └────────┘ └──────────┘ │
155//! └─────────────────────────────────────────┘
156//! │
157//! ▼
158//! ┌─────────────────────────────────────────┐
159//! │ LSP Features │
160//! │ Diagnostics, Hover, Completion, etc. │
161//! └─────────────────────────────────────────┘
162//! ```
163//!
164//! The server integrates LogicAffeine's compilation pipeline with the LSP protocol:
165//!
166//! 1. **[`server`]** - Tower-LSP server handling client communication
167//! 2. **[`state`]** - Document state management with incremental updates
168//! 3. **[`pipeline`]** - Compilation pipeline integration (lexer, parser, analysis)
169//! 4. **[`index`]** - Symbol indexing for cross-file references
170//! 5. **Feature modules** - Individual LSP capabilities ([`diagnostics`], [`hover`], [`completion`], etc.)
171//!
172//! ## Modules
173//!
174//! - [`server`] - Main LSP server implementation using tower-lsp
175//! - [`state`] - Document state and workspace management
176//! - [`document`] - Individual document handling with incremental sync
177//! - [`pipeline`] - Integration with LogicAffeine compilation pipeline
178//! - [`index`] - Symbol indexing and cross-reference tracking
179//! - [`line_index`] - Line/column to byte offset conversion
180//!
181//! ### Feature Modules
182//!
183//! - [`diagnostics`] - Error and warning reporting
184//! - [`semantic_tokens`] - Semantic syntax highlighting
185//! - [`document_symbols`] - Outline and breadcrumb navigation
186//! - [`definition`] - Go to definition
187//! - [`references`] - Find all references
188//! - [`hover`] - Documentation on hover
189//! - [`completion`] - Autocomplete
190//! - [`signature_help`] - Function parameter hints
191//! - [`code_actions`] - Quick fixes and refactorings
192//! - [`rename`] - Symbol renaming
193//! - [`inlay_hints`] - Inline type hints
194//! - [`code_lens`] - Inline actions and reference counts
195//! - [`folding`] - Code folding ranges
196//! - [`formatting`] - Code formatting
197//!
198//! ## Testing
199//!
200//! The crate includes 179 comprehensive tests covering all LSP features:
201//!
202//! ```bash
203//! cargo test -p logicaffeine-lsp --lib
204//! ```
205//!
206//! ## Performance
207//!
208//! - **Incremental sync**: Only re-analyzes changed documents
209//! - **Parallel analysis**: Uses `DashMap` for concurrent document processing
210//! - **Lazy indexing**: Symbol index built on-demand
211//! - **Optimized for REPL**: Workspace state persists across document changes
212//!
213//! ## License
214//!
215//! Business Source License 1.1 (BUSL-1.1)
216//!
217//! - **Free** for individuals and organizations with <25 employees
218//! - **Commercial license** required for organizations with 25+ employees offering Logic Services
219//! - **Converts to MIT** on December 24, 2029
220//!
221//! See [LICENSE](https://github.com/Brahmastra-Labs/logicaffeine/blob/main/LICENSE.md) for full terms.
222
223pub mod line_index;
224pub mod state;
225pub mod document;
226pub mod pipeline;
227pub mod diagnostics;
228pub mod semantic_tokens;
229pub mod document_symbols;
230pub mod index;
231pub mod definition;
232pub mod hover;
233pub mod completion;
234pub mod references;
235pub mod signature_help;
236pub mod code_actions;
237pub mod rename;
238pub mod folding;
239pub mod inlay_hints;
240pub mod code_lens;
241pub mod formatting;
242pub mod server;