@hmharness/lsp 0.23.39 → 0.23.41
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/package.json +23 -23
- package/src/__tests__/deveco.test.ts +60 -60
- package/src/__tests__/fixtures/fake-server.cjs +89 -89
- package/src/__tests__/lsp.test.ts +131 -131
- package/src/__tests__/trust.test.ts +68 -68
- package/src/client.ts +137 -137
- package/src/index.ts +15 -15
- package/src/process-manager.ts +118 -118
- package/src/protocol.ts +113 -113
- package/src/registry.ts +130 -130
- package/src/tools.ts +229 -229
- package/src/trust.ts +108 -108
- package/tsconfig.build.json +18 -18
- package/verify-clangd.mts +40 -40
- package/verify-live.mts +27 -27
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtemp, rm, writeFile, readFile } from 'node:fs/promises';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { checkTrust, trustServer, untrustServer, listTrust, serverHash, trustPath } from '../trust.ts';
|
|
7
|
-
|
|
8
|
-
async function tmpHome(): Promise<string> {
|
|
9
|
-
return mkdtemp(join(tmpdir(), 'lsp-trust-'));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
test('trust: PATH server needs explicit trust; trust pins the hash; round-trip verifies', async () => {
|
|
13
|
-
const home = await tmpHome();
|
|
14
|
-
const bin = join(home, 'fake-server.bin');
|
|
15
|
-
await writeFile(bin, Buffer.from('fake server binary v1'));
|
|
16
|
-
const server = { id: 'fakepath', command: bin, origin: 'PATH' };
|
|
17
|
-
// untrusted initially
|
|
18
|
-
const v0 = await checkTrust(home, server);
|
|
19
|
-
assert.equal(v0.trusted, false);
|
|
20
|
-
assert.match(v0.reason, /hmh lsp trust fakepath/);
|
|
21
|
-
// trust pins the current hash
|
|
22
|
-
const t = await trustServer(home, server);
|
|
23
|
-
assert.equal(t.ok, true);
|
|
24
|
-
assert.equal(t.sha256, await serverHash(bin));
|
|
25
|
-
// now trusted, hash matches
|
|
26
|
-
const v1 = await checkTrust(home, server);
|
|
27
|
-
assert.equal(v1.trusted, true);
|
|
28
|
-
assert.match(v1.reason, /hash matches/);
|
|
29
|
-
// binary CHANGES -> tamper refusal with both hashes shown
|
|
30
|
-
await writeFile(bin, Buffer.from('tampered binary'));
|
|
31
|
-
const v2 = await checkTrust(home, server);
|
|
32
|
-
assert.equal(v2.trusted, false);
|
|
33
|
-
assert.match(v2.reason, /CHANGED/);
|
|
34
|
-
assert.equal(v2.tampered?.pinned, t.sha256);
|
|
35
|
-
assert.equal(v2.tampered?.actual, await serverHash(bin));
|
|
36
|
-
// untrust works and returns to untrusted
|
|
37
|
-
assert.equal(await untrustServer(home, 'fakepath'), true);
|
|
38
|
-
assert.equal((await checkTrust(home, server)).trusted, false);
|
|
39
|
-
assert.equal(await untrustServer(home, 'fakepath'), false);
|
|
40
|
-
await rm(home, { recursive: true, force: true });
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('trust: DevEco-local servers auto-trust ONCE with pinning', async () => {
|
|
44
|
-
const home = await tmpHome();
|
|
45
|
-
const bin = join(home, 'clangd.exe');
|
|
46
|
-
await writeFile(bin, Buffer.from('official clangd bytes'));
|
|
47
|
-
const server = { id: 'clangd', command: bin, origin: 'DevEco-local' };
|
|
48
|
-
const v1 = await checkTrust(home, server);
|
|
49
|
-
assert.equal(v1.trusted, true);
|
|
50
|
-
assert.match(v1.reason, /auto-trusted/);
|
|
51
|
-
// the pin landed in the store (user-inspectable JSON)
|
|
52
|
-
const store = JSON.parse(await readFile(trustPath(home), 'utf8'));
|
|
53
|
-
assert.equal(store.entries.clangd.autoTrusted, true);
|
|
54
|
-
assert.equal(store.entries.clangd.sha256, await serverHash(bin));
|
|
55
|
-
// second check: now a normal trusted entry, still hash-matched
|
|
56
|
-
const v2 = await checkTrust(home, server);
|
|
57
|
-
assert.equal(v2.trusted, true);
|
|
58
|
-
// tamper detection applies to auto-trusted servers equally
|
|
59
|
-
await writeFile(bin, Buffer.from('evil'));
|
|
60
|
-
const v3 = await checkTrust(home, server);
|
|
61
|
-
assert.equal(v3.trusted, false);
|
|
62
|
-
assert.match(v3.reason, /CHANGED/);
|
|
63
|
-
// listTrust exposes the audit view
|
|
64
|
-
const entries = await listTrust(home);
|
|
65
|
-
assert.equal(entries.length, 1);
|
|
66
|
-
assert.equal(entries[0]!.id, 'clangd');
|
|
67
|
-
await rm(home, { recursive: true, force: true });
|
|
68
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { mkdtemp, rm, writeFile, readFile } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { checkTrust, trustServer, untrustServer, listTrust, serverHash, trustPath } from '../trust.ts';
|
|
7
|
+
|
|
8
|
+
async function tmpHome(): Promise<string> {
|
|
9
|
+
return mkdtemp(join(tmpdir(), 'lsp-trust-'));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
test('trust: PATH server needs explicit trust; trust pins the hash; round-trip verifies', async () => {
|
|
13
|
+
const home = await tmpHome();
|
|
14
|
+
const bin = join(home, 'fake-server.bin');
|
|
15
|
+
await writeFile(bin, Buffer.from('fake server binary v1'));
|
|
16
|
+
const server = { id: 'fakepath', command: bin, origin: 'PATH' };
|
|
17
|
+
// untrusted initially
|
|
18
|
+
const v0 = await checkTrust(home, server);
|
|
19
|
+
assert.equal(v0.trusted, false);
|
|
20
|
+
assert.match(v0.reason, /hmh lsp trust fakepath/);
|
|
21
|
+
// trust pins the current hash
|
|
22
|
+
const t = await trustServer(home, server);
|
|
23
|
+
assert.equal(t.ok, true);
|
|
24
|
+
assert.equal(t.sha256, await serverHash(bin));
|
|
25
|
+
// now trusted, hash matches
|
|
26
|
+
const v1 = await checkTrust(home, server);
|
|
27
|
+
assert.equal(v1.trusted, true);
|
|
28
|
+
assert.match(v1.reason, /hash matches/);
|
|
29
|
+
// binary CHANGES -> tamper refusal with both hashes shown
|
|
30
|
+
await writeFile(bin, Buffer.from('tampered binary'));
|
|
31
|
+
const v2 = await checkTrust(home, server);
|
|
32
|
+
assert.equal(v2.trusted, false);
|
|
33
|
+
assert.match(v2.reason, /CHANGED/);
|
|
34
|
+
assert.equal(v2.tampered?.pinned, t.sha256);
|
|
35
|
+
assert.equal(v2.tampered?.actual, await serverHash(bin));
|
|
36
|
+
// untrust works and returns to untrusted
|
|
37
|
+
assert.equal(await untrustServer(home, 'fakepath'), true);
|
|
38
|
+
assert.equal((await checkTrust(home, server)).trusted, false);
|
|
39
|
+
assert.equal(await untrustServer(home, 'fakepath'), false);
|
|
40
|
+
await rm(home, { recursive: true, force: true });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('trust: DevEco-local servers auto-trust ONCE with pinning', async () => {
|
|
44
|
+
const home = await tmpHome();
|
|
45
|
+
const bin = join(home, 'clangd.exe');
|
|
46
|
+
await writeFile(bin, Buffer.from('official clangd bytes'));
|
|
47
|
+
const server = { id: 'clangd', command: bin, origin: 'DevEco-local' };
|
|
48
|
+
const v1 = await checkTrust(home, server);
|
|
49
|
+
assert.equal(v1.trusted, true);
|
|
50
|
+
assert.match(v1.reason, /auto-trusted/);
|
|
51
|
+
// the pin landed in the store (user-inspectable JSON)
|
|
52
|
+
const store = JSON.parse(await readFile(trustPath(home), 'utf8'));
|
|
53
|
+
assert.equal(store.entries.clangd.autoTrusted, true);
|
|
54
|
+
assert.equal(store.entries.clangd.sha256, await serverHash(bin));
|
|
55
|
+
// second check: now a normal trusted entry, still hash-matched
|
|
56
|
+
const v2 = await checkTrust(home, server);
|
|
57
|
+
assert.equal(v2.trusted, true);
|
|
58
|
+
// tamper detection applies to auto-trusted servers equally
|
|
59
|
+
await writeFile(bin, Buffer.from('evil'));
|
|
60
|
+
const v3 = await checkTrust(home, server);
|
|
61
|
+
assert.equal(v3.trusted, false);
|
|
62
|
+
assert.match(v3.reason, /CHANGED/);
|
|
63
|
+
// listTrust exposes the audit view
|
|
64
|
+
const entries = await listTrust(home);
|
|
65
|
+
assert.equal(entries.length, 1);
|
|
66
|
+
assert.equal(entries[0]!.id, 'clangd');
|
|
67
|
+
await rm(home, { recursive: true, force: true });
|
|
68
|
+
});
|
package/src/client.ts
CHANGED
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @hmharness/lsp - LSP client over stdio
|
|
3
|
-
*
|
|
4
|
-
* Speaks the base protocol to ONE managed language-server process:
|
|
5
|
-
* initialize handshake -> requests (hover/definition/references/symbols)
|
|
6
|
-
* -> document sync notifications -> shutdown/exit. Diagnostics arrive as
|
|
7
|
-
* push notifications and land in the caller's callback (diagnostics-store
|
|
8
|
-
* behavior is the caller's; here we just route).
|
|
9
|
-
*/
|
|
10
|
-
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
11
|
-
import {
|
|
12
|
-
encodeMessage, MessageDecoder,
|
|
13
|
-
type InitializeParams, type InitializeResult, type JsonRpcResponse,
|
|
14
|
-
type Diagnostic, type DidOpenParams, type Hover, type Location, type DocumentSymbol, type ReferenceParams, type Position, type TextDocumentIdentifier,
|
|
15
|
-
} from './protocol.ts';
|
|
16
|
-
|
|
17
|
-
export interface LspClientOptions {
|
|
18
|
-
requestTimeoutMs?: number;
|
|
19
|
-
onDiagnostics?: (uri: string, diagnostics: Diagnostic[]) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class LspClient {
|
|
23
|
-
private seq = 0;
|
|
24
|
-
private pending = new Map<number, { resolve: (v: unknown) => void; reject: (e: Error) => void; timer: NodeJS.Timeout }>();
|
|
25
|
-
private decoder = new MessageDecoder();
|
|
26
|
-
private serverInfo: InitializeResult | null = null;
|
|
27
|
-
|
|
28
|
-
constructor(private proc: ChildProcessWithoutNullStreams, private opts: LspClientOptions = {}) {
|
|
29
|
-
proc.stdout.on('data', (chunk: Buffer) => {
|
|
30
|
-
for (const msg of this.decoder.push(chunk)) this.handle(msg as Record<string, unknown>);
|
|
31
|
-
});
|
|
32
|
-
proc.on('exit', () => {
|
|
33
|
-
for (const [, p] of this.pending) { clearTimeout(p.timer); p.reject(new Error('server exited')); }
|
|
34
|
-
this.pending.clear();
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private handle(msg: Record<string, unknown>): void {
|
|
39
|
-
if (msg.method === 'textDocument/publishDiagnostics') {
|
|
40
|
-
const p = msg.params as { uri: string; diagnostics: Diagnostic[] };
|
|
41
|
-
this.opts.onDiagnostics?.(p.uri, p.diagnostics ?? []);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (typeof msg.id === 'number' && ('result' in msg || 'error' in msg)) {
|
|
45
|
-
const p = this.pending.get(msg.id);
|
|
46
|
-
if (!p) return;
|
|
47
|
-
this.pending.delete(msg.id);
|
|
48
|
-
clearTimeout(p.timer);
|
|
49
|
-
const resp = msg as unknown as JsonRpcResponse;
|
|
50
|
-
if (resp.error) p.reject(new Error(`LSP ${resp.error.code}: ${resp.error.message}`));
|
|
51
|
-
else p.resolve(resp.result);
|
|
52
|
-
}
|
|
53
|
-
// window/logMessage etc: intentionally ignored (noise for the agent)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
request<T>(method: string, params?: unknown): Promise<T> {
|
|
57
|
-
const id = ++this.seq;
|
|
58
|
-
return new Promise<T>((resolve, reject) => {
|
|
59
|
-
const timer = setTimeout(() => {
|
|
60
|
-
this.pending.delete(id);
|
|
61
|
-
reject(new Error(`LSP request ${method} timed out`));
|
|
62
|
-
}, this.opts.requestTimeoutMs ?? 20_000);
|
|
63
|
-
this.pending.set(id, { resolve: resolve as (v: unknown) => void, reject, timer });
|
|
64
|
-
this.proc.stdin.write(encodeMessage({ jsonrpc: '2.0', id, method, params }));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
notify(method: string, params?: unknown): void {
|
|
69
|
-
this.proc.stdin.write(encodeMessage({ jsonrpc: '2.0', method, params }));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async initialize(rootUri: string): Promise<InitializeResult> {
|
|
73
|
-
const params: InitializeParams = {
|
|
74
|
-
processId: process.pid,
|
|
75
|
-
rootUri,
|
|
76
|
-
workspaceFolders: [{ name: 'workspace', uri: rootUri }],
|
|
77
|
-
capabilities: { textDocument: { hover: {}, definition: {}, references: {}, documentSymbol: {}, publishDiagnostics: {} } },
|
|
78
|
-
};
|
|
79
|
-
const result = await this.request<InitializeResult>('initialize', params);
|
|
80
|
-
this.serverInfo = result;
|
|
81
|
-
this.notify('initialized', {});
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get info(): InitializeResult | null {
|
|
86
|
-
return this.serverInfo;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/* ---------------- document sync (minimal: open + full change) ---------------- */
|
|
90
|
-
|
|
91
|
-
openDoc(uri: string, languageId: string, text: string): void {
|
|
92
|
-
const params: DidOpenParams = { textDocument: { uri, languageId, version: 1, text } };
|
|
93
|
-
this.notify('textDocument/didOpen', params);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/* ---------------- Tier-0 requests ---------------- */
|
|
97
|
-
|
|
98
|
-
hover(textDocument: TextDocumentIdentifier, position: Position): Promise<Hover | null> {
|
|
99
|
-
return this.request<Hover | null>('textDocument/hover', { textDocument, position });
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
definition(textDocument: TextDocumentIdentifier, position: Position): Promise<Location | Location[] | null> {
|
|
103
|
-
return this.request<Location | Location[] | null>('textDocument/definition', { textDocument, position });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
references(textDocument: TextDocumentIdentifier, position: Position, includeDeclaration = false): Promise<Location[]> {
|
|
107
|
-
const params: ReferenceParams = { textDocument, position, context: { includeDeclaration } };
|
|
108
|
-
return this.request<Location[]>('textDocument/references', params);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
documentSymbols(textDocument: TextDocumentIdentifier): Promise<DocumentSymbol[]> {
|
|
112
|
-
return this.request<DocumentSymbol[]>('textDocument/documentSymbol', { textDocument });
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/* ---------------- Tier-1 requests ---------------- */
|
|
116
|
-
|
|
117
|
-
implementation(textDocument: TextDocumentIdentifier, position: Position): Promise<Location | Location[] | null> {
|
|
118
|
-
return this.request<Location | Location[] | null>('textDocument/implementation', { textDocument, position });
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** call hierarchy: prepare the item at a position, then incoming/outgoing */
|
|
122
|
-
async prepareCallHierarchy(textDocument: TextDocumentIdentifier, position: Position): Promise<unknown> {
|
|
123
|
-
return this.request<unknown>('textDocument/prepareCallHierarchy', { textDocument, position });
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
callHierarchyIncoming(item: unknown): Promise<Array<{ from: unknown; fromRanges: Location['range'][] }>> {
|
|
127
|
-
return this.request('callHierarchy/incomingCalls', { item });
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
callHierarchyOutgoing(item: unknown): Promise<Array<{ to: unknown; toRanges: Location['range'][] }>> {
|
|
131
|
-
return this.request('callHierarchy/outgoingCalls', { item });
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async shutdown(): Promise<void> {
|
|
135
|
-
try { await this.request('shutdown'); this.notify('exit'); } catch { /* best effort */ }
|
|
136
|
-
}
|
|
137
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/lsp - LSP client over stdio
|
|
3
|
+
*
|
|
4
|
+
* Speaks the base protocol to ONE managed language-server process:
|
|
5
|
+
* initialize handshake -> requests (hover/definition/references/symbols)
|
|
6
|
+
* -> document sync notifications -> shutdown/exit. Diagnostics arrive as
|
|
7
|
+
* push notifications and land in the caller's callback (diagnostics-store
|
|
8
|
+
* behavior is the caller's; here we just route).
|
|
9
|
+
*/
|
|
10
|
+
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
11
|
+
import {
|
|
12
|
+
encodeMessage, MessageDecoder,
|
|
13
|
+
type InitializeParams, type InitializeResult, type JsonRpcResponse,
|
|
14
|
+
type Diagnostic, type DidOpenParams, type Hover, type Location, type DocumentSymbol, type ReferenceParams, type Position, type TextDocumentIdentifier,
|
|
15
|
+
} from './protocol.ts';
|
|
16
|
+
|
|
17
|
+
export interface LspClientOptions {
|
|
18
|
+
requestTimeoutMs?: number;
|
|
19
|
+
onDiagnostics?: (uri: string, diagnostics: Diagnostic[]) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class LspClient {
|
|
23
|
+
private seq = 0;
|
|
24
|
+
private pending = new Map<number, { resolve: (v: unknown) => void; reject: (e: Error) => void; timer: NodeJS.Timeout }>();
|
|
25
|
+
private decoder = new MessageDecoder();
|
|
26
|
+
private serverInfo: InitializeResult | null = null;
|
|
27
|
+
|
|
28
|
+
constructor(private proc: ChildProcessWithoutNullStreams, private opts: LspClientOptions = {}) {
|
|
29
|
+
proc.stdout.on('data', (chunk: Buffer) => {
|
|
30
|
+
for (const msg of this.decoder.push(chunk)) this.handle(msg as Record<string, unknown>);
|
|
31
|
+
});
|
|
32
|
+
proc.on('exit', () => {
|
|
33
|
+
for (const [, p] of this.pending) { clearTimeout(p.timer); p.reject(new Error('server exited')); }
|
|
34
|
+
this.pending.clear();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private handle(msg: Record<string, unknown>): void {
|
|
39
|
+
if (msg.method === 'textDocument/publishDiagnostics') {
|
|
40
|
+
const p = msg.params as { uri: string; diagnostics: Diagnostic[] };
|
|
41
|
+
this.opts.onDiagnostics?.(p.uri, p.diagnostics ?? []);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (typeof msg.id === 'number' && ('result' in msg || 'error' in msg)) {
|
|
45
|
+
const p = this.pending.get(msg.id);
|
|
46
|
+
if (!p) return;
|
|
47
|
+
this.pending.delete(msg.id);
|
|
48
|
+
clearTimeout(p.timer);
|
|
49
|
+
const resp = msg as unknown as JsonRpcResponse;
|
|
50
|
+
if (resp.error) p.reject(new Error(`LSP ${resp.error.code}: ${resp.error.message}`));
|
|
51
|
+
else p.resolve(resp.result);
|
|
52
|
+
}
|
|
53
|
+
// window/logMessage etc: intentionally ignored (noise for the agent)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
request<T>(method: string, params?: unknown): Promise<T> {
|
|
57
|
+
const id = ++this.seq;
|
|
58
|
+
return new Promise<T>((resolve, reject) => {
|
|
59
|
+
const timer = setTimeout(() => {
|
|
60
|
+
this.pending.delete(id);
|
|
61
|
+
reject(new Error(`LSP request ${method} timed out`));
|
|
62
|
+
}, this.opts.requestTimeoutMs ?? 20_000);
|
|
63
|
+
this.pending.set(id, { resolve: resolve as (v: unknown) => void, reject, timer });
|
|
64
|
+
this.proc.stdin.write(encodeMessage({ jsonrpc: '2.0', id, method, params }));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
notify(method: string, params?: unknown): void {
|
|
69
|
+
this.proc.stdin.write(encodeMessage({ jsonrpc: '2.0', method, params }));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async initialize(rootUri: string): Promise<InitializeResult> {
|
|
73
|
+
const params: InitializeParams = {
|
|
74
|
+
processId: process.pid,
|
|
75
|
+
rootUri,
|
|
76
|
+
workspaceFolders: [{ name: 'workspace', uri: rootUri }],
|
|
77
|
+
capabilities: { textDocument: { hover: {}, definition: {}, references: {}, documentSymbol: {}, publishDiagnostics: {} } },
|
|
78
|
+
};
|
|
79
|
+
const result = await this.request<InitializeResult>('initialize', params);
|
|
80
|
+
this.serverInfo = result;
|
|
81
|
+
this.notify('initialized', {});
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get info(): InitializeResult | null {
|
|
86
|
+
return this.serverInfo;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* ---------------- document sync (minimal: open + full change) ---------------- */
|
|
90
|
+
|
|
91
|
+
openDoc(uri: string, languageId: string, text: string): void {
|
|
92
|
+
const params: DidOpenParams = { textDocument: { uri, languageId, version: 1, text } };
|
|
93
|
+
this.notify('textDocument/didOpen', params);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* ---------------- Tier-0 requests ---------------- */
|
|
97
|
+
|
|
98
|
+
hover(textDocument: TextDocumentIdentifier, position: Position): Promise<Hover | null> {
|
|
99
|
+
return this.request<Hover | null>('textDocument/hover', { textDocument, position });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
definition(textDocument: TextDocumentIdentifier, position: Position): Promise<Location | Location[] | null> {
|
|
103
|
+
return this.request<Location | Location[] | null>('textDocument/definition', { textDocument, position });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
references(textDocument: TextDocumentIdentifier, position: Position, includeDeclaration = false): Promise<Location[]> {
|
|
107
|
+
const params: ReferenceParams = { textDocument, position, context: { includeDeclaration } };
|
|
108
|
+
return this.request<Location[]>('textDocument/references', params);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
documentSymbols(textDocument: TextDocumentIdentifier): Promise<DocumentSymbol[]> {
|
|
112
|
+
return this.request<DocumentSymbol[]>('textDocument/documentSymbol', { textDocument });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* ---------------- Tier-1 requests ---------------- */
|
|
116
|
+
|
|
117
|
+
implementation(textDocument: TextDocumentIdentifier, position: Position): Promise<Location | Location[] | null> {
|
|
118
|
+
return this.request<Location | Location[] | null>('textDocument/implementation', { textDocument, position });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** call hierarchy: prepare the item at a position, then incoming/outgoing */
|
|
122
|
+
async prepareCallHierarchy(textDocument: TextDocumentIdentifier, position: Position): Promise<unknown> {
|
|
123
|
+
return this.request<unknown>('textDocument/prepareCallHierarchy', { textDocument, position });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
callHierarchyIncoming(item: unknown): Promise<Array<{ from: unknown; fromRanges: Location['range'][] }>> {
|
|
127
|
+
return this.request('callHierarchy/incomingCalls', { item });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
callHierarchyOutgoing(item: unknown): Promise<Array<{ to: unknown; toRanges: Location['range'][] }>> {
|
|
131
|
+
return this.request('callHierarchy/outgoingCalls', { item });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async shutdown(): Promise<void> {
|
|
135
|
+
try { await this.request('shutdown'); this.notify('exit'); } catch { /* best effort */ }
|
|
136
|
+
}
|
|
137
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @hmharness/lsp - LSP Client/Manager for agent code intelligence
|
|
3
|
-
*
|
|
4
|
-
* Client ONLY (master prompt rule): we drive external language servers
|
|
5
|
-
* over stdio (LSP 3.18 subset), never implement one. Security walls live
|
|
6
|
-
* in process-manager (workspace-bound cwd, scrubbed env, restart caps,
|
|
7
|
-
* timeouts). Tier-0 read-only tools in tools.ts; guarded rename/code
|
|
8
|
-
* actions are Tier-3 and NOT implemented here.
|
|
9
|
-
*/
|
|
10
|
-
export * from './protocol.ts';
|
|
11
|
-
export { ProcessManager, scrubEnv, fromPath, type ServerSpec, type ManagedServerOptions } from './process-manager.ts';
|
|
12
|
-
export { LspClient, type LspClientOptions } from './client.ts';
|
|
13
|
-
export { discoverServers, serverForFile, fileToUri, type DiscoveredServer } from './registry.ts';
|
|
14
|
-
export { lspTools, shutdownLsp, diagnosticsSummary, type LspToolContext } from './tools.ts';
|
|
15
|
-
export { checkTrust, trustServer, untrustServer, listTrust, serverHash, trustPath, type TrustEntry, type TrustStore, type TrustVerdict } from './trust.ts';
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/lsp - LSP Client/Manager for agent code intelligence
|
|
3
|
+
*
|
|
4
|
+
* Client ONLY (master prompt rule): we drive external language servers
|
|
5
|
+
* over stdio (LSP 3.18 subset), never implement one. Security walls live
|
|
6
|
+
* in process-manager (workspace-bound cwd, scrubbed env, restart caps,
|
|
7
|
+
* timeouts). Tier-0 read-only tools in tools.ts; guarded rename/code
|
|
8
|
+
* actions are Tier-3 and NOT implemented here.
|
|
9
|
+
*/
|
|
10
|
+
export * from './protocol.ts';
|
|
11
|
+
export { ProcessManager, scrubEnv, fromPath, type ServerSpec, type ManagedServerOptions } from './process-manager.ts';
|
|
12
|
+
export { LspClient, type LspClientOptions } from './client.ts';
|
|
13
|
+
export { discoverServers, serverForFile, fileToUri, type DiscoveredServer } from './registry.ts';
|
|
14
|
+
export { lspTools, shutdownLsp, diagnosticsSummary, type LspToolContext } from './tools.ts';
|
|
15
|
+
export { checkTrust, trustServer, untrustServer, listTrust, serverHash, trustPath, type TrustEntry, type TrustStore, type TrustVerdict } from './trust.ts';
|