@lokascript/language-server 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +312 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +1578 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
# @lokascript/language-server
|
|
2
|
+
|
|
3
|
+
Language Server Protocol (LSP) implementation supporting both **original \_hyperscript** and **LokaScript** (a 100% compatible superset with extensions).
|
|
4
|
+
|
|
5
|
+
## Multi-Mode Support
|
|
6
|
+
|
|
7
|
+
The language server supports four operating modes:
|
|
8
|
+
|
|
9
|
+
| Mode | Commands | Multilingual | Use Case |
|
|
10
|
+
| -------------------- | ------------------ | ------------ | ------------------------------------------ |
|
|
11
|
+
| **hyperscript** | \_hyperscript only | English only | Original \_hyperscript users |
|
|
12
|
+
| **hyperscript-i18n** | \_hyperscript only | 24 languages | Users of `@lokascript/hyperscript-adapter` |
|
|
13
|
+
| **lokascript** | All (extended) | 24 languages | Full LokaScript development |
|
|
14
|
+
| **auto** | (detected) | (detected) | Most users - just works |
|
|
15
|
+
|
|
16
|
+
### Mode Selection
|
|
17
|
+
|
|
18
|
+
- **auto** (default): If `@lokascript/semantic` is available, uses `lokascript` mode; otherwise uses `hyperscript` mode
|
|
19
|
+
- **hyperscript**: Enforces \_hyperscript-compatible syntax, English keywords only
|
|
20
|
+
- **hyperscript-i18n**: Enforces \_hyperscript-compatible syntax with multilingual keyword support. Use this if you have original \_hyperscript with `@lokascript/hyperscript-adapter` for writing in non-English languages
|
|
21
|
+
- **lokascript**: Enables all features including LokaScript extensions and multilingual support
|
|
22
|
+
|
|
23
|
+
### LokaScript Extensions (flagged in hyperscript mode)
|
|
24
|
+
|
|
25
|
+
When in `hyperscript` mode, the following LokaScript-only features are flagged as errors:
|
|
26
|
+
|
|
27
|
+
| Feature | Example | Alternative for \_hyperscript |
|
|
28
|
+
| ------------------------- | ---------------------------------- | ----------------------------- |
|
|
29
|
+
| Dot notation | `my.textContent` | `my textContent` |
|
|
30
|
+
| Extended commands | `morph`, `settle`, `persist` | N/A |
|
|
31
|
+
| Extended `as` conversions | `as Int`, `as JSON` | N/A |
|
|
32
|
+
| Temporal modifiers | `.debounce(300)`, `.throttle(100)` | N/A |
|
|
33
|
+
|
|
34
|
+
This allows LokaScript users to maintain \_hyperscript compatibility by using `hyperscript` mode as a lint.
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
### Core LSP Features
|
|
39
|
+
|
|
40
|
+
| Feature | Description | Status |
|
|
41
|
+
| ----------------------- | ------------------------------------------------------------- | ------ |
|
|
42
|
+
| **Diagnostics** | Real-time error detection and warnings | ✅ |
|
|
43
|
+
| **Completions** | Context-aware keyword and selector suggestions | ✅ |
|
|
44
|
+
| **Hover** | Documentation on hover for commands and keywords | ✅ |
|
|
45
|
+
| **Document Symbols** | Outline view showing event handlers, behaviors, and functions | ✅ |
|
|
46
|
+
| **Code Actions** | Quick fixes for common issues | ✅ |
|
|
47
|
+
| **Go to Definition** | Jump to behavior and function definitions | ✅ |
|
|
48
|
+
| **Find References** | Find all usages of a symbol | ✅ |
|
|
49
|
+
| **Document Formatting** | Format hyperscript code with consistent indentation | ✅ |
|
|
50
|
+
|
|
51
|
+
### Multilingual Support
|
|
52
|
+
|
|
53
|
+
Works with hyperscript written in any of 21 supported languages:
|
|
54
|
+
|
|
55
|
+
en (English), es (Spanish), pt (Portuguese), fr (French), de (German), it (Italian), ru (Russian), pl (Polish), uk (Ukrainian), ja (Japanese), ko (Korean), zh (Chinese), ar (Arabic), he (Hebrew), tr (Turkish), id (Indonesian), ms (Malay), th (Thai), vi (Vietnamese), tl (Tagalog), sw (Swahili)
|
|
56
|
+
|
|
57
|
+
### HTML Support
|
|
58
|
+
|
|
59
|
+
The language server understands hyperscript embedded in HTML files:
|
|
60
|
+
|
|
61
|
+
- `_="..."` attributes (double and single quotes)
|
|
62
|
+
- `<script type="text/hyperscript">` tags
|
|
63
|
+
- Correct position mapping for diagnostics and navigation
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm install @lokascript/language-server
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
### As a standalone server
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Start with stdio transport (default)
|
|
77
|
+
npx lokascript-language-server --stdio
|
|
78
|
+
|
|
79
|
+
# Or run directly
|
|
80
|
+
node dist/server.js --stdio
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### With VS Code
|
|
84
|
+
|
|
85
|
+
Use the companion extension `lokascript-vscode` which automatically starts this server.
|
|
86
|
+
|
|
87
|
+
### With other editors
|
|
88
|
+
|
|
89
|
+
Configure your editor's LSP client to start the language server with stdio transport.
|
|
90
|
+
|
|
91
|
+
#### Neovim (nvim-lspconfig)
|
|
92
|
+
|
|
93
|
+
```lua
|
|
94
|
+
require('lspconfig.configs').lokascript = {
|
|
95
|
+
default_config = {
|
|
96
|
+
cmd = { 'npx', 'lokascript-language-server', '--stdio' },
|
|
97
|
+
filetypes = { 'html', 'hyperscript' },
|
|
98
|
+
root_dir = function() return vim.loop.cwd() end,
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
require('lspconfig').lokascript.setup{}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Emacs (lsp-mode)
|
|
105
|
+
|
|
106
|
+
```elisp
|
|
107
|
+
(lsp-register-client
|
|
108
|
+
(make-lsp-client
|
|
109
|
+
:new-connection (lsp-stdio-connection '("npx" "lokascript-language-server" "--stdio"))
|
|
110
|
+
:activation-fn (lsp-activate-on "html" "hyperscript")
|
|
111
|
+
:server-id 'lokascript))
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Configuration
|
|
115
|
+
|
|
116
|
+
The server accepts configuration via the LSP `workspace/configuration` mechanism:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"lokascript": {
|
|
121
|
+
"mode": "auto",
|
|
122
|
+
"language": "en",
|
|
123
|
+
"maxDiagnostics": 100
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
| Setting | Default | Description |
|
|
129
|
+
| ---------------- | -------- | -------------------------------------------------------------------------------------- |
|
|
130
|
+
| `mode` | `"auto"` | Operating mode: `"auto"`, `"hyperscript"`, `"hyperscript-i18n"`, or `"lokascript"` |
|
|
131
|
+
| `language` | `"en"` | Primary language for keyword suggestions (used in `lokascript` and `hyperscript-i18n`) |
|
|
132
|
+
| `maxDiagnostics` | `100` | Maximum diagnostics per file |
|
|
133
|
+
|
|
134
|
+
The server also accepts configuration under the `hyperscript` namespace for users of original \_hyperscript:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"hyperscript": {
|
|
139
|
+
"mode": "hyperscript",
|
|
140
|
+
"maxDiagnostics": 100
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## VS Code Extension Settings Schema
|
|
146
|
+
|
|
147
|
+
When building a VS Code extension that uses this language server, add the following to your extension's `package.json`:
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"contributes": {
|
|
152
|
+
"configuration": {
|
|
153
|
+
"title": "Hyperscript / LokaScript",
|
|
154
|
+
"properties": {
|
|
155
|
+
"lokascript.mode": {
|
|
156
|
+
"type": "string",
|
|
157
|
+
"enum": ["auto", "hyperscript", "hyperscript-i18n", "lokascript"],
|
|
158
|
+
"enumDescriptions": [
|
|
159
|
+
"Detect based on available packages",
|
|
160
|
+
"Restrict to _hyperscript-compatible syntax, English only",
|
|
161
|
+
"Restrict to _hyperscript-compatible syntax with multilingual support (for hyperscript-adapter users)",
|
|
162
|
+
"Allow all LokaScript features including extensions"
|
|
163
|
+
],
|
|
164
|
+
"default": "auto",
|
|
165
|
+
"description": "Operating mode for syntax validation."
|
|
166
|
+
},
|
|
167
|
+
"lokascript.language": {
|
|
168
|
+
"type": "string",
|
|
169
|
+
"default": "en",
|
|
170
|
+
"description": "Primary language for multilingual keyword support (lokascript mode only)."
|
|
171
|
+
},
|
|
172
|
+
"lokascript.maxDiagnostics": {
|
|
173
|
+
"type": "number",
|
|
174
|
+
"default": 100,
|
|
175
|
+
"description": "Maximum number of diagnostics per file."
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
For users who prefer the `hyperscript` namespace:
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
{
|
|
187
|
+
"contributes": {
|
|
188
|
+
"configuration": {
|
|
189
|
+
"title": "Hyperscript",
|
|
190
|
+
"properties": {
|
|
191
|
+
"hyperscript.mode": {
|
|
192
|
+
"type": "string",
|
|
193
|
+
"enum": ["auto", "hyperscript", "hyperscript-i18n", "lokascript"],
|
|
194
|
+
"enumDescriptions": [
|
|
195
|
+
"Detect based on available packages",
|
|
196
|
+
"Restrict to _hyperscript-compatible syntax, English only",
|
|
197
|
+
"Restrict to _hyperscript-compatible syntax with multilingual support",
|
|
198
|
+
"Allow all LokaScript features"
|
|
199
|
+
],
|
|
200
|
+
"default": "hyperscript",
|
|
201
|
+
"description": "Operating mode for syntax validation."
|
|
202
|
+
},
|
|
203
|
+
"hyperscript.language": {
|
|
204
|
+
"type": "string",
|
|
205
|
+
"default": "en",
|
|
206
|
+
"description": "Primary language for multilingual keyword support (hyperscript-i18n mode)."
|
|
207
|
+
},
|
|
208
|
+
"hyperscript.maxDiagnostics": {
|
|
209
|
+
"type": "number",
|
|
210
|
+
"default": 100,
|
|
211
|
+
"description": "Maximum number of diagnostics per file."
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Dependencies
|
|
220
|
+
|
|
221
|
+
The language server works best with these optional peer dependencies installed:
|
|
222
|
+
|
|
223
|
+
- `@lokascript/semantic` - Enables 21-language support and semantic analysis
|
|
224
|
+
- `@lokascript/ast-toolkit` - Enables AST-based analysis and complexity metrics
|
|
225
|
+
- `@lokascript/core` - Enables full hyperscript parsing and AST-based formatting
|
|
226
|
+
|
|
227
|
+
Without these dependencies, the server falls back to pattern-based analysis (English only).
|
|
228
|
+
|
|
229
|
+
## Development
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Build
|
|
233
|
+
npm run build
|
|
234
|
+
|
|
235
|
+
# Run in development
|
|
236
|
+
npm run dev
|
|
237
|
+
|
|
238
|
+
# Type check
|
|
239
|
+
npm run typecheck
|
|
240
|
+
|
|
241
|
+
# Test
|
|
242
|
+
npm test
|
|
243
|
+
|
|
244
|
+
# Test with coverage
|
|
245
|
+
npm test -- --coverage
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Architecture
|
|
249
|
+
|
|
250
|
+
The language server is implemented as a single `server.ts` file that:
|
|
251
|
+
|
|
252
|
+
1. **Extracts** hyperscript regions from HTML documents
|
|
253
|
+
2. **Analyzes** code using semantic parsing (multilingual) or pattern-based fallback
|
|
254
|
+
3. **Provides** LSP features through the standard protocol
|
|
255
|
+
|
|
256
|
+
### HTML Extraction
|
|
257
|
+
|
|
258
|
+
The server handles three types of hyperscript in HTML:
|
|
259
|
+
|
|
260
|
+
```html
|
|
261
|
+
<!-- Double-quoted attribute -->
|
|
262
|
+
<button _="on click toggle .active">Click me</button>
|
|
263
|
+
|
|
264
|
+
<!-- Single-quoted attribute -->
|
|
265
|
+
<button _="on click toggle .active">Click me</button>
|
|
266
|
+
|
|
267
|
+
<!-- Script tag -->
|
|
268
|
+
<script type="text/hyperscript">
|
|
269
|
+
behavior Modal
|
|
270
|
+
on open show me
|
|
271
|
+
on close hide me
|
|
272
|
+
end
|
|
273
|
+
</script>
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Position Mapping
|
|
277
|
+
|
|
278
|
+
All diagnostics, hover, and navigation features correctly map positions between:
|
|
279
|
+
|
|
280
|
+
- HTML document coordinates (line/character in the full file)
|
|
281
|
+
- Hyperscript region coordinates (line/character within the `_="..."` value)
|
|
282
|
+
|
|
283
|
+
This ensures that clicking on an error jumps to the correct position, even in multiline attributes.
|
|
284
|
+
|
|
285
|
+
## Testing
|
|
286
|
+
|
|
287
|
+
The server has comprehensive test coverage:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
# Run all tests
|
|
291
|
+
npm test
|
|
292
|
+
|
|
293
|
+
# Run with coverage report
|
|
294
|
+
npm test -- --coverage
|
|
295
|
+
|
|
296
|
+
# Run specific test file
|
|
297
|
+
npm test -- --run src/server.test.ts
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Test categories:
|
|
301
|
+
|
|
302
|
+
- HTML document detection
|
|
303
|
+
- Hyperscript region extraction
|
|
304
|
+
- Position mapping (offset to line/character)
|
|
305
|
+
- Go to Definition
|
|
306
|
+
- Find References
|
|
307
|
+
- Code Formatting
|
|
308
|
+
- LSP integration tests
|
|
309
|
+
|
|
310
|
+
## License
|
|
311
|
+
|
|
312
|
+
MIT
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|