1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//! # 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:
//!
//! ```bash
//! cargo install logicaffeine-lsp
//! ```
//!
//! Configure your editor to use `logicaffeine-lsp` as the language server for `.logos` files.
//! See the [Editor Integration](#editor-integration) section for specific setup instructions.
//!
//! ## Features
//!
//! The language server provides 14 LSP features organized into four categories:
//!
//! ### Code Intelligence
//!
//! | Feature | Description |
//! |---------|-------------|
//! | **Diagnostics** | Real-time syntax and semantic error detection with actionable error messages |
//! | **Hover** | Type information, documentation, and definition context on hover |
//! | **Semantic Tokens** | Syntax highlighting based on semantic meaning (variables, keywords, types) |
//!
//! ### Navigation
//!
//! | Feature | Description |
//! |---------|-------------|
//! | **Go to Definition** | Jump to where a variable, function, or type is defined |
//! | **Find References** | Find all usages of a symbol across the codebase |
//! | **Document Symbols** | Outline view showing all declarations in the file |
//! | **Code Lens** | Inline reference counts and navigation actions |
//!
//! ### Refactoring
//!
//! | Feature | Description |
//! |---------|-------------|
//! | **Rename** | Safely rename symbols across all references with preview |
//! | **Code Actions** | Quick fixes and refactoring suggestions (e.g., "Extract to function") |
//!
//! ### Editing
//!
//! | Feature | Description |
//! |---------|-------------|
//! | **Completion** | Context-aware autocomplete for keywords, variables, and functions |
//! | **Signature Help** | Parameter hints for function calls |
//! | **Inlay Hints** | Inline type annotations and parameter names |
//!
//! ### Display
//!
//! | Feature | Description |
//! |---------|-------------|
//! | **Folding Ranges** | Collapsible code regions for functions, blocks, and comments |
//! | **Formatting** | Automatic code formatting with consistent style |
//!
//! ## Editor Integration
//!
//! ### VSCode
//!
//! Add to your `settings.json`:
//!
//! ```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`:
//!
//! ```lua
//! 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)
//!
//! ```elisp
//! (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)
//!
//! ```elisp
//! (require 'eglot)
//! (add-to-list 'eglot-server-programs '(logos-mode . ("logicaffeine-lsp")))
//! ```
//!
//! ### Sublime Text
//!
//! Install the LSP package, then add to your LSP settings:
//!
//! ```json
//! {
//! "clients": {
//! "logicaffeine-lsp": {
//! "enabled": true,
//! "command": ["logicaffeine-lsp"],
//! "selector": "source.logos"
//! }
//! }
//! }
//! ```
//!
//! ## Architecture
//!
//! ```text
//! 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
//!
//! - [`diagnostics`] - Error and warning reporting
//! - [`semantic_tokens`] - Semantic syntax highlighting
//! - [`document_symbols`] - Outline and breadcrumb navigation
//! - [`definition`] - Go to definition
//! - [`references`] - Find all references
//! - [`hover`] - Documentation on hover
//! - [`completion`] - Autocomplete
//! - [`signature_help`] - Function parameter hints
//! - [`code_actions`] - Quick fixes and refactorings
//! - [`rename`] - Symbol renaming
//! - [`inlay_hints`] - Inline type hints
//! - [`code_lens`] - Inline actions and reference counts
//! - [`folding`] - Code folding ranges
//! - [`formatting`] - Code formatting
//!
//! ## Testing
//!
//! The crate includes 179 comprehensive tests covering all LSP features:
//!
//! ```bash
//! 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](https://github.com/Brahmastra-Labs/logicaffeine/blob/main/LICENSE.md) for full terms.