@spences10/pi-lsp 0.0.1
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/LICENSE +21 -0
- package/README.md +93 -0
- package/dist/client.d.ts +92 -0
- package/dist/client.js +366 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +679 -0
- package/dist/index.js.map +1 -0
- package/dist/servers.d.ts +12 -0
- package/dist/servers.js +162 -0
- package/dist/servers.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Scott Spence
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @spences10/pi-lsp
|
|
2
|
+
|
|
3
|
+
[](https://viteplus.dev)
|
|
4
|
+
[](https://vitest.dev)
|
|
5
|
+
|
|
6
|
+
Pi extension that exposes Language Server Protocol diagnostics and
|
|
7
|
+
symbol tools to the model.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pi install npm:@spences10/pi-lsp
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Local development from this monorepo:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm --filter @spences10/pi-lsp run build
|
|
19
|
+
pi install ./packages/pi-lsp
|
|
20
|
+
# or for one run only
|
|
21
|
+
pi -e ./packages/pi-lsp
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Required language servers
|
|
25
|
+
|
|
26
|
+
This package talks to language-server binaries installed in your
|
|
27
|
+
project or on `PATH`. For TypeScript, JavaScript, and Svelte projects:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add -D typescript typescript-language-server svelte-language-server
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Supported server discovery includes:
|
|
34
|
+
|
|
35
|
+
- TypeScript / JavaScript via `typescript-language-server`
|
|
36
|
+
- Svelte via `svelteserver`
|
|
37
|
+
- Python via `python-lsp-server`
|
|
38
|
+
- Go via `gopls`
|
|
39
|
+
- Rust via `rust-analyzer`
|
|
40
|
+
- Ruby via `solargraph`
|
|
41
|
+
- Java via `jdtls`
|
|
42
|
+
- Lua via `lua-language-server`
|
|
43
|
+
|
|
44
|
+
Project-local binaries in `node_modules/.bin` are preferred over
|
|
45
|
+
global binaries.
|
|
46
|
+
|
|
47
|
+
## Tools
|
|
48
|
+
|
|
49
|
+
The extension registers LSP-backed Pi tools for:
|
|
50
|
+
|
|
51
|
+
- diagnostics
|
|
52
|
+
- hover
|
|
53
|
+
- definitions
|
|
54
|
+
- references
|
|
55
|
+
- document symbols
|
|
56
|
+
|
|
57
|
+
These tools let the model inspect types, find usages, and catch
|
|
58
|
+
diagnostics without guessing from text search alone.
|
|
59
|
+
|
|
60
|
+
## Commands
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
/lsp status
|
|
64
|
+
/lsp list
|
|
65
|
+
/lsp restart all
|
|
66
|
+
/lsp restart <language>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Use `/lsp status` to inspect active clients and `/lsp restart` after
|
|
70
|
+
dependency installs or language-server crashes.
|
|
71
|
+
|
|
72
|
+
## Using from a custom harness
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import lsp from '@spences10/pi-lsp';
|
|
76
|
+
|
|
77
|
+
// pass `lsp` as an ExtensionFactory to your Pi runtime
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`my-pi` imports this package directly and enables it as the built-in
|
|
81
|
+
LSP extension.
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pnpm --filter @spences10/pi-lsp run check
|
|
87
|
+
pnpm --filter @spences10/pi-lsp run test
|
|
88
|
+
pnpm --filter @spences10/pi-lsp run build
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
export interface LspPosition {
|
|
3
|
+
line: number;
|
|
4
|
+
character: number;
|
|
5
|
+
}
|
|
6
|
+
export interface LspRange {
|
|
7
|
+
start: LspPosition;
|
|
8
|
+
end: LspPosition;
|
|
9
|
+
}
|
|
10
|
+
export interface LspLocation {
|
|
11
|
+
uri: string;
|
|
12
|
+
range: LspRange;
|
|
13
|
+
}
|
|
14
|
+
export interface LspLocationLink {
|
|
15
|
+
targetUri: string;
|
|
16
|
+
targetRange: LspRange;
|
|
17
|
+
targetSelectionRange?: LspRange;
|
|
18
|
+
originSelectionRange?: LspRange;
|
|
19
|
+
}
|
|
20
|
+
export interface LspDocumentSymbol {
|
|
21
|
+
name: string;
|
|
22
|
+
kind: number;
|
|
23
|
+
detail?: string;
|
|
24
|
+
range: LspRange;
|
|
25
|
+
selectionRange: LspRange;
|
|
26
|
+
children?: LspDocumentSymbol[];
|
|
27
|
+
uri?: string;
|
|
28
|
+
containerName?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface LspDiagnostic {
|
|
31
|
+
range: LspRange;
|
|
32
|
+
severity?: 1 | 2 | 3 | 4;
|
|
33
|
+
code?: string | number;
|
|
34
|
+
source?: string;
|
|
35
|
+
message: string;
|
|
36
|
+
}
|
|
37
|
+
export interface LspHover {
|
|
38
|
+
contents: string | {
|
|
39
|
+
language?: string;
|
|
40
|
+
value: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: string;
|
|
43
|
+
value: string;
|
|
44
|
+
} | Array<string | {
|
|
45
|
+
language?: string;
|
|
46
|
+
value: string;
|
|
47
|
+
} | {
|
|
48
|
+
kind: string;
|
|
49
|
+
value: string;
|
|
50
|
+
}>;
|
|
51
|
+
range?: LspRange;
|
|
52
|
+
}
|
|
53
|
+
export interface LspClientOptions {
|
|
54
|
+
command: string;
|
|
55
|
+
args: string[];
|
|
56
|
+
root_uri: string;
|
|
57
|
+
language_id_for_uri: (uri: string) => string | undefined;
|
|
58
|
+
request_timeout_ms?: number;
|
|
59
|
+
}
|
|
60
|
+
export declare class LspClientStartError extends Error {
|
|
61
|
+
command: string;
|
|
62
|
+
args: string[];
|
|
63
|
+
code?: string;
|
|
64
|
+
constructor(message: string, options: {
|
|
65
|
+
command: string;
|
|
66
|
+
args: string[];
|
|
67
|
+
cause?: unknown;
|
|
68
|
+
code?: string;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export declare class LspClient extends EventEmitter {
|
|
72
|
+
#private;
|
|
73
|
+
constructor(options: LspClientOptions);
|
|
74
|
+
start(): Promise<void>;
|
|
75
|
+
is_ready(): boolean;
|
|
76
|
+
ensure_document_open(uri: string, text: string): Promise<void>;
|
|
77
|
+
hover(uri: string, position: LspPosition): Promise<LspHover | null>;
|
|
78
|
+
definition(uri: string, position: LspPosition): Promise<LspLocation[]>;
|
|
79
|
+
references(uri: string, position: LspPosition, include_declaration: boolean): Promise<LspLocation[]>;
|
|
80
|
+
document_symbols(uri: string): Promise<LspDocumentSymbol[]>;
|
|
81
|
+
get_diagnostics(uri: string): LspDiagnostic[];
|
|
82
|
+
wait_for_diagnostics(uri: string, timeout_ms?: number): Promise<LspDiagnostic[]>;
|
|
83
|
+
stop(): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
export declare function normalize_location_result(result: LspLocation | LspLocation[] | LspLocationLink | LspLocationLink[] | null): LspLocation[];
|
|
86
|
+
export declare function normalize_document_symbol_result(result: LspDocumentSymbol[] | Array<{
|
|
87
|
+
name: string;
|
|
88
|
+
kind: number;
|
|
89
|
+
location: LspLocation;
|
|
90
|
+
containerName?: string;
|
|
91
|
+
}> | null): LspDocumentSymbol[];
|
|
92
|
+
export declare function file_path_to_uri(file_path: string): string;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
export class LspClientStartError extends Error {
|
|
5
|
+
command;
|
|
6
|
+
args;
|
|
7
|
+
code;
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
super(message, options.cause ? { cause: options.cause } : undefined);
|
|
10
|
+
this.name = 'LspClientStartError';
|
|
11
|
+
this.command = options.command;
|
|
12
|
+
this.args = options.args;
|
|
13
|
+
this.code = options.code;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class LspClient extends EventEmitter {
|
|
17
|
+
#proc = null;
|
|
18
|
+
#options;
|
|
19
|
+
#next_id = 1;
|
|
20
|
+
#pending = new Map();
|
|
21
|
+
#buffer = Buffer.alloc(0);
|
|
22
|
+
#initialized = false;
|
|
23
|
+
#open_docs = new Map();
|
|
24
|
+
#diagnostics_by_uri = new Map();
|
|
25
|
+
#diagnostic_waiters = new Set();
|
|
26
|
+
constructor(options) {
|
|
27
|
+
super();
|
|
28
|
+
this.#options = options;
|
|
29
|
+
}
|
|
30
|
+
async start() {
|
|
31
|
+
this.#proc = spawn(this.#options.command, this.#options.args, {
|
|
32
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
33
|
+
env: process.env,
|
|
34
|
+
});
|
|
35
|
+
let start_reject = null;
|
|
36
|
+
const start_failure = new Promise((_, reject) => {
|
|
37
|
+
start_reject = reject;
|
|
38
|
+
});
|
|
39
|
+
const reject_start = (error) => {
|
|
40
|
+
if (!start_reject)
|
|
41
|
+
return false;
|
|
42
|
+
const reject = start_reject;
|
|
43
|
+
start_reject = null;
|
|
44
|
+
reject(error);
|
|
45
|
+
return true;
|
|
46
|
+
};
|
|
47
|
+
const start_error = (message, cause, code) => new LspClientStartError(message, {
|
|
48
|
+
command: this.#options.command,
|
|
49
|
+
args: this.#options.args,
|
|
50
|
+
cause,
|
|
51
|
+
code,
|
|
52
|
+
});
|
|
53
|
+
this.#proc.on('error', (err) => {
|
|
54
|
+
const wrapped = start_error(`Failed to spawn ${this.#options.command}`, err, error_code(err));
|
|
55
|
+
if (!reject_start(wrapped)) {
|
|
56
|
+
this.#emit_error(wrapped);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
this.#proc.on('close', () => {
|
|
60
|
+
if (!this.#initialized) {
|
|
61
|
+
reject_start(start_error(`LSP server ${this.#options.command} closed before initialization`));
|
|
62
|
+
}
|
|
63
|
+
for (const pending of this.#pending.values()) {
|
|
64
|
+
clearTimeout(pending.timer);
|
|
65
|
+
pending.reject(new Error('LSP server closed'));
|
|
66
|
+
}
|
|
67
|
+
this.#pending.clear();
|
|
68
|
+
this.#initialized = false;
|
|
69
|
+
this.#proc = null;
|
|
70
|
+
});
|
|
71
|
+
this.#proc.stderr?.on('data', () => {
|
|
72
|
+
// Discard stderr; many servers are chatty.
|
|
73
|
+
});
|
|
74
|
+
this.#proc.stdout.on('data', (chunk) => {
|
|
75
|
+
this.#buffer = Buffer.concat([this.#buffer, chunk]);
|
|
76
|
+
this.#drain_buffer();
|
|
77
|
+
});
|
|
78
|
+
try {
|
|
79
|
+
await Promise.race([
|
|
80
|
+
this.#request('initialize', {
|
|
81
|
+
processId: process.pid,
|
|
82
|
+
rootUri: this.#options.root_uri,
|
|
83
|
+
capabilities: {
|
|
84
|
+
textDocument: {
|
|
85
|
+
publishDiagnostics: {
|
|
86
|
+
relatedInformation: true,
|
|
87
|
+
},
|
|
88
|
+
hover: {
|
|
89
|
+
contentFormat: ['markdown', 'plaintext'],
|
|
90
|
+
},
|
|
91
|
+
definition: { linkSupport: false },
|
|
92
|
+
references: {},
|
|
93
|
+
documentSymbol: {
|
|
94
|
+
hierarchicalDocumentSymbolSupport: true,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
workspace: {
|
|
98
|
+
workspaceFolders: true,
|
|
99
|
+
symbol: {},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
workspaceFolders: [
|
|
103
|
+
{ uri: this.#options.root_uri, name: 'workspace' },
|
|
104
|
+
],
|
|
105
|
+
}),
|
|
106
|
+
start_failure,
|
|
107
|
+
]);
|
|
108
|
+
this.#notify('initialized', {});
|
|
109
|
+
this.#initialized = true;
|
|
110
|
+
start_reject = null;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
await this.stop();
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
is_ready() {
|
|
118
|
+
return this.#initialized;
|
|
119
|
+
}
|
|
120
|
+
async ensure_document_open(uri, text) {
|
|
121
|
+
const existing = this.#open_docs.get(uri);
|
|
122
|
+
if (existing) {
|
|
123
|
+
if (existing.text === text)
|
|
124
|
+
return;
|
|
125
|
+
const next_version = existing.version + 1;
|
|
126
|
+
this.#open_docs.set(uri, { version: next_version, text });
|
|
127
|
+
this.#notify('textDocument/didChange', {
|
|
128
|
+
textDocument: { uri, version: next_version },
|
|
129
|
+
contentChanges: [{ text }],
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const language_id = this.#options.language_id_for_uri(uri) ?? 'plaintext';
|
|
134
|
+
this.#open_docs.set(uri, { version: 1, text });
|
|
135
|
+
this.#notify('textDocument/didOpen', {
|
|
136
|
+
textDocument: {
|
|
137
|
+
uri,
|
|
138
|
+
languageId: language_id,
|
|
139
|
+
version: 1,
|
|
140
|
+
text,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
async hover(uri, position) {
|
|
145
|
+
const result = (await this.#request('textDocument/hover', {
|
|
146
|
+
textDocument: { uri },
|
|
147
|
+
position,
|
|
148
|
+
}));
|
|
149
|
+
return result ?? null;
|
|
150
|
+
}
|
|
151
|
+
async definition(uri, position) {
|
|
152
|
+
const result = (await this.#request('textDocument/definition', {
|
|
153
|
+
textDocument: { uri },
|
|
154
|
+
position,
|
|
155
|
+
}));
|
|
156
|
+
return normalize_location_result(result);
|
|
157
|
+
}
|
|
158
|
+
async references(uri, position, include_declaration) {
|
|
159
|
+
const result = (await this.#request('textDocument/references', {
|
|
160
|
+
textDocument: { uri },
|
|
161
|
+
position,
|
|
162
|
+
context: { includeDeclaration: include_declaration },
|
|
163
|
+
}));
|
|
164
|
+
return result ?? [];
|
|
165
|
+
}
|
|
166
|
+
async document_symbols(uri) {
|
|
167
|
+
const result = (await this.#request('textDocument/documentSymbol', {
|
|
168
|
+
textDocument: { uri },
|
|
169
|
+
}));
|
|
170
|
+
return normalize_document_symbol_result(result);
|
|
171
|
+
}
|
|
172
|
+
get_diagnostics(uri) {
|
|
173
|
+
return this.#diagnostics_by_uri.get(uri) ?? [];
|
|
174
|
+
}
|
|
175
|
+
async wait_for_diagnostics(uri, timeout_ms = 1500) {
|
|
176
|
+
if (this.#diagnostics_by_uri.has(uri)) {
|
|
177
|
+
return this.get_diagnostics(uri);
|
|
178
|
+
}
|
|
179
|
+
return new Promise((resolve) => {
|
|
180
|
+
let active = true;
|
|
181
|
+
const cleanup = () => {
|
|
182
|
+
if (!active)
|
|
183
|
+
return;
|
|
184
|
+
active = false;
|
|
185
|
+
this.off('diagnostics', handler);
|
|
186
|
+
clearTimeout(timer);
|
|
187
|
+
this.#diagnostic_waiters.delete(cleanup);
|
|
188
|
+
resolve(this.get_diagnostics(uri));
|
|
189
|
+
};
|
|
190
|
+
const handler = (event_uri) => {
|
|
191
|
+
if (event_uri !== uri)
|
|
192
|
+
return;
|
|
193
|
+
cleanup();
|
|
194
|
+
};
|
|
195
|
+
const timer = setTimeout(cleanup, timeout_ms);
|
|
196
|
+
this.on('diagnostics', handler);
|
|
197
|
+
this.#diagnostic_waiters.add(cleanup);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
async stop() {
|
|
201
|
+
if (this.#initialized) {
|
|
202
|
+
try {
|
|
203
|
+
await this.#request('shutdown', null, 1000);
|
|
204
|
+
this.#notify('exit', null);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
// Server may already be dead; proceed.
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
for (const pending of this.#pending.values()) {
|
|
211
|
+
clearTimeout(pending.timer);
|
|
212
|
+
pending.reject(new Error('LSP client stopped'));
|
|
213
|
+
}
|
|
214
|
+
this.#pending.clear();
|
|
215
|
+
for (const cleanup of Array.from(this.#diagnostic_waiters)) {
|
|
216
|
+
cleanup();
|
|
217
|
+
}
|
|
218
|
+
if (this.#proc) {
|
|
219
|
+
this.#proc.kill();
|
|
220
|
+
this.#proc = null;
|
|
221
|
+
}
|
|
222
|
+
this.#initialized = false;
|
|
223
|
+
}
|
|
224
|
+
#request(method, params, timeout_override) {
|
|
225
|
+
return new Promise((resolve, reject) => {
|
|
226
|
+
const id = this.#next_id++;
|
|
227
|
+
const timeout_ms = timeout_override ??
|
|
228
|
+
this.#options.request_timeout_ms ??
|
|
229
|
+
30_000;
|
|
230
|
+
const timer = setTimeout(() => {
|
|
231
|
+
if (this.#pending.has(id)) {
|
|
232
|
+
this.#pending.delete(id);
|
|
233
|
+
reject(new Error(`LSP request ${method} timed out`));
|
|
234
|
+
}
|
|
235
|
+
}, timeout_ms);
|
|
236
|
+
this.#pending.set(id, { resolve, reject, timer });
|
|
237
|
+
try {
|
|
238
|
+
this.#send({ jsonrpc: '2.0', id, method, params });
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
clearTimeout(timer);
|
|
242
|
+
this.#pending.delete(id);
|
|
243
|
+
reject(error);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
#notify(method, params) {
|
|
248
|
+
this.#send({ jsonrpc: '2.0', method, params });
|
|
249
|
+
}
|
|
250
|
+
#send(message) {
|
|
251
|
+
if (!this.#proc?.stdin?.writable) {
|
|
252
|
+
throw new Error('LSP server not connected');
|
|
253
|
+
}
|
|
254
|
+
const body = Buffer.from(JSON.stringify(message), 'utf8');
|
|
255
|
+
const header = Buffer.from(`Content-Length: ${body.length}\r\n\r\n`, 'ascii');
|
|
256
|
+
this.#proc.stdin.write(Buffer.concat([header, body]));
|
|
257
|
+
}
|
|
258
|
+
#emit_error(error) {
|
|
259
|
+
if (this.listenerCount('error') > 0) {
|
|
260
|
+
this.emit('error', error);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
#drain_buffer() {
|
|
264
|
+
while (true) {
|
|
265
|
+
const header_end = this.#buffer.indexOf('\r\n\r\n');
|
|
266
|
+
if (header_end === -1)
|
|
267
|
+
return;
|
|
268
|
+
const header = this.#buffer
|
|
269
|
+
.subarray(0, header_end)
|
|
270
|
+
.toString('ascii');
|
|
271
|
+
const match = header.match(/Content-Length:\s*(\d+)/i);
|
|
272
|
+
if (!match) {
|
|
273
|
+
this.#buffer = this.#buffer.subarray(header_end + 4);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const length = Number(match[1]);
|
|
277
|
+
const body_start = header_end + 4;
|
|
278
|
+
if (this.#buffer.length < body_start + length)
|
|
279
|
+
return;
|
|
280
|
+
const body = this.#buffer.subarray(body_start, body_start + length);
|
|
281
|
+
this.#buffer = this.#buffer.subarray(body_start + length);
|
|
282
|
+
try {
|
|
283
|
+
this.#handle_message(JSON.parse(body.toString('utf8')));
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
this.#emit_error(error);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
#handle_message(message) {
|
|
291
|
+
const numeric_id = typeof message.id === 'number'
|
|
292
|
+
? message.id
|
|
293
|
+
: typeof message.id === 'string' && /^-?\d+$/.test(message.id)
|
|
294
|
+
? Number(message.id)
|
|
295
|
+
: null;
|
|
296
|
+
if (numeric_id != null && this.#pending.has(numeric_id)) {
|
|
297
|
+
const pending = this.#pending.get(numeric_id);
|
|
298
|
+
this.#pending.delete(numeric_id);
|
|
299
|
+
clearTimeout(pending.timer);
|
|
300
|
+
if (message.error) {
|
|
301
|
+
pending.reject(new Error(`LSP error ${message.error.code}: ${message.error.message}`));
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
pending.resolve(message.result);
|
|
305
|
+
}
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (message.method === 'textDocument/publishDiagnostics' &&
|
|
309
|
+
message.params) {
|
|
310
|
+
const params = message.params;
|
|
311
|
+
this.#diagnostics_by_uri.set(params.uri, params.diagnostics);
|
|
312
|
+
this.emit('diagnostics', params.uri);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (message.method && message.id != null) {
|
|
316
|
+
// Respond to server-to-client requests we don't implement so it doesn't block.
|
|
317
|
+
this.#send({
|
|
318
|
+
jsonrpc: '2.0',
|
|
319
|
+
id: message.id,
|
|
320
|
+
result: null,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
export function normalize_location_result(result) {
|
|
326
|
+
if (!result)
|
|
327
|
+
return [];
|
|
328
|
+
const entries = Array.isArray(result) ? result : [result];
|
|
329
|
+
return entries.map((entry) => {
|
|
330
|
+
if ('uri' in entry)
|
|
331
|
+
return entry;
|
|
332
|
+
return {
|
|
333
|
+
uri: entry.targetUri,
|
|
334
|
+
range: entry.targetSelectionRange ?? entry.targetRange,
|
|
335
|
+
};
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
export function normalize_document_symbol_result(result) {
|
|
339
|
+
if (!result)
|
|
340
|
+
return [];
|
|
341
|
+
if (result.length === 0 ||
|
|
342
|
+
('range' in result[0] && 'selectionRange' in result[0])) {
|
|
343
|
+
return result;
|
|
344
|
+
}
|
|
345
|
+
const symbol_info = result;
|
|
346
|
+
return symbol_info.map((entry) => ({
|
|
347
|
+
name: entry.name,
|
|
348
|
+
kind: entry.kind,
|
|
349
|
+
range: entry.location.range,
|
|
350
|
+
selectionRange: entry.location.range,
|
|
351
|
+
containerName: entry.containerName,
|
|
352
|
+
uri: entry.location.uri,
|
|
353
|
+
}));
|
|
354
|
+
}
|
|
355
|
+
export function file_path_to_uri(file_path) {
|
|
356
|
+
return pathToFileURL(file_path).href;
|
|
357
|
+
}
|
|
358
|
+
function error_code(error) {
|
|
359
|
+
return typeof error === 'object' &&
|
|
360
|
+
error !== null &&
|
|
361
|
+
'code' in error &&
|
|
362
|
+
typeof error.code === 'string'
|
|
363
|
+
? error.code
|
|
364
|
+
: undefined;
|
|
365
|
+
}
|
|
366
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,E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AM,CAAC,CAAC,CAAC,CAAC,EACtD,CAAC;QACF,OAAO,MAA6B,CAAC;IACtC,CAAC;IACD,MAAM,WAAW,GAAG,MAKlB,CAAC;IACH,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK;QAC3B,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK;QACpC,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG;KACvB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IACjD,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;AACtC,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ;QAC/B,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ;QACtD,CAAC,CAAE,KAA0B,CAAC,IAAI;QAClC,CAAC,CAAC,SAAS,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ExtensionAPI } from '@mariozechner/pi-coding-agent';
|
|
2
|
+
import { type LspClientOptions, type LspDiagnostic, type LspDocumentSymbol, type LspHover, type LspLocation, type LspPosition } from './client.js';
|
|
3
|
+
export interface LspClientLike {
|
|
4
|
+
start(): Promise<void>;
|
|
5
|
+
stop(): Promise<void>;
|
|
6
|
+
is_ready(): boolean;
|
|
7
|
+
ensure_document_open(uri: string, text: string): Promise<void>;
|
|
8
|
+
hover(uri: string, position: LspPosition): Promise<LspHover | null>;
|
|
9
|
+
definition(uri: string, position: LspPosition): Promise<LspLocation[]>;
|
|
10
|
+
references(uri: string, position: LspPosition, include_declaration: boolean): Promise<LspLocation[]>;
|
|
11
|
+
document_symbols(uri: string): Promise<LspDocumentSymbol[]>;
|
|
12
|
+
wait_for_diagnostics(uri: string, timeout_ms?: number): Promise<LspDiagnostic[]>;
|
|
13
|
+
}
|
|
14
|
+
export interface CreateLspExtensionOptions {
|
|
15
|
+
create_client?: (options: LspClientOptions) => LspClientLike;
|
|
16
|
+
read_file?: (path: string) => Promise<string>;
|
|
17
|
+
cwd?: () => string;
|
|
18
|
+
}
|
|
19
|
+
export declare function create_lsp_extension(options?: CreateLspExtensionOptions): (pi: ExtensionAPI) => Promise<void>;
|
|
20
|
+
declare const _default: (pi: ExtensionAPI) => Promise<void>;
|
|
21
|
+
export default _default;
|