@hmharness/lsp 0.23.16 → 0.23.17
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/dist/client.d.ts +11 -0
- package/dist/client.js +14 -0
- package/dist/registry.d.ts +7 -1
- package/dist/registry.js +46 -11
- package/dist/tools.js +35 -0
- package/package.json +23 -23
- package/src/__tests__/deveco.test.ts +60 -0
- package/src/__tests__/fixtures/fake-server.cjs +89 -73
- package/src/__tests__/lsp.test.ts +119 -108
- package/src/client.ts +137 -118
- package/src/index.ts +14 -14
- package/src/process-manager.ts +118 -118
- package/src/protocol.ts +113 -113
- package/src/registry.ts +130 -92
- package/src/tools.ts +193 -160
- package/tsconfig.build.json +18 -18
- package/verify-clangd.mts +40 -0
- package/verify-live.mts +27 -27
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// REAL-server full-chain verification against DevEco's bundled clangd
|
|
2
|
+
// (the previously NOT VERIFIED item: no healthy language server existed)
|
|
3
|
+
import { ProcessManager, LspClient, discoverServers, fileToUri } from './src/index.ts';
|
|
4
|
+
|
|
5
|
+
const clangd = discoverServers(true).find((s) => s.id === 'clangd' && s.origin === 'DevEco-local');
|
|
6
|
+
if (!clangd || !clangd.healthy) {
|
|
7
|
+
console.log('DevEco clangd not discovered/healthy:', clangd?.unhealthyReason ?? 'absent');
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
10
|
+
console.log('server:', clangd.command, '| origin:', clangd.origin, '| official:', clangd.official);
|
|
11
|
+
|
|
12
|
+
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
const ws = mkdtempSync(join(tmpdir(), 'clangd-ws-'));
|
|
16
|
+
// a C file with a REAL syntax error (missing semicolon)
|
|
17
|
+
writeFileSync(join(ws, 'probe.c'), 'int main(void) {\n int x = 1\n return x;\n}\n');
|
|
18
|
+
|
|
19
|
+
const mgr = new ProcessManager(clangd, ws);
|
|
20
|
+
const diags: Array<{ uri: string; n: number; msgs: string[] }> = [];
|
|
21
|
+
const client = new LspClient(mgr.start(), {
|
|
22
|
+
requestTimeoutMs: 30_000,
|
|
23
|
+
onDiagnostics: (uri, d) => diags.push({ uri, n: d.length, msgs: d.map((x) => x.message.slice(0, 60)) }),
|
|
24
|
+
});
|
|
25
|
+
const init = await client.initialize(fileToUri(ws));
|
|
26
|
+
console.log('initialize OK:', JSON.stringify(init.serverInfo), '| hoverProvider:', Boolean((init.capabilities as Record<string, unknown>).hoverProvider));
|
|
27
|
+
const uri = fileToUri(join(ws, 'probe.c'));
|
|
28
|
+
client.openDoc(uri, 'c', 'int main(void) {\n int x = 1\n return x;\n}\n');
|
|
29
|
+
// clangd needs a moment to parse and publish
|
|
30
|
+
await new Promise((r) => setTimeout(r, 4_000));
|
|
31
|
+
const got = diags.filter((d) => d.uri === uri);
|
|
32
|
+
console.log('diagnostics pushes:', got.length, '| total diags:', got.reduce((s, d) => s + d.n, 0));
|
|
33
|
+
if (got.length > 0 && got[0]!.n > 0) console.log('first diag:', got[0]!.msgs[0]);
|
|
34
|
+
const hover = await client.hover({ uri }, { line: 0, character: 5 }).catch((e: Error) => ({ error: e.message }));
|
|
35
|
+
console.log('hover:', hover && 'contents' in (hover as object) ? 'returned' : JSON.stringify(hover).slice(0, 120));
|
|
36
|
+
await client.shutdown();
|
|
37
|
+
await mgr.stop();
|
|
38
|
+
console.log('stopped cleanly:', mgr.running === false);
|
|
39
|
+
rmSync(ws, { recursive: true, force: true });
|
|
40
|
+
console.log('REAL-SERVER (DevEco clangd) FULL CHAIN:', diags.length > 0 ? 'VERIFIED' : 'handshake verified, no diagnostics pushed');
|
package/verify-live.mts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
// Real-machine LSP verification against the fake server via the public surface
|
|
2
|
-
import { shutdownLsp, discoverServers, ProcessManager, LspClient, fileToUri } from './src/index.ts';
|
|
3
|
-
import { writeFileSync, mkdirSync, rmSync } from 'node:fs';
|
|
4
|
-
|
|
5
|
-
const ws = 'G:/hmharness/.tmp-lsp-ws';
|
|
6
|
-
rmSync(ws, { recursive: true, force: true });
|
|
7
|
-
mkdirSync(ws, { recursive: true });
|
|
8
|
-
writeFileSync(ws + '/demo.ts', 'const x: number = 1;\nconsole.log(x);\n');
|
|
9
|
-
|
|
10
|
-
console.log('discovered real servers:', discoverServers().map((s) => s.id).join(', ') || '(none)');
|
|
11
|
-
|
|
12
|
-
const mgr = new ProcessManager({ id: 'fake', command: process.execPath, args: ['src/__tests__/fixtures/fake-server.cjs'], source: 'explicit' }, process.cwd());
|
|
13
|
-
const client = new LspClient(mgr.start(), { requestTimeoutMs: 10_000 });
|
|
14
|
-
const info = await client.initialize(fileToUri(ws));
|
|
15
|
-
console.log('initialized:', info.serverInfo?.name, info.serverInfo?.version);
|
|
16
|
-
const uri = fileToUri(ws + '/demo.ts');
|
|
17
|
-
client.openDoc(uri, 'typescript', 'const y = DELBERATE_ERROR_MARKER;\n');
|
|
18
|
-
await new Promise((r) => setTimeout(r, 400));
|
|
19
|
-
const hover = await client.hover({ uri }, { line: 0, character: 6 });
|
|
20
|
-
console.log('hover:', JSON.stringify(hover?.contents).slice(0, 80));
|
|
21
|
-
const def = await client.definition({ uri }, { line: 0, character: 6 });
|
|
22
|
-
console.log('definition:', Array.isArray(def) ? def[0]?.uri : def?.uri);
|
|
23
|
-
await client.shutdown();
|
|
24
|
-
await mgr.stop();
|
|
25
|
-
console.log('stopped:', mgr.running === false);
|
|
26
|
-
await shutdownLsp();
|
|
27
|
-
console.log('REAL-MACHINE (fake-server) LIFECYCLE OK — real typescript-language-server: NOT ON PATH (NOT VERIFIED against a real server this round)');
|
|
1
|
+
// Real-machine LSP verification against the fake server via the public surface
|
|
2
|
+
import { shutdownLsp, discoverServers, ProcessManager, LspClient, fileToUri } from './src/index.ts';
|
|
3
|
+
import { writeFileSync, mkdirSync, rmSync } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
const ws = 'G:/hmharness/.tmp-lsp-ws';
|
|
6
|
+
rmSync(ws, { recursive: true, force: true });
|
|
7
|
+
mkdirSync(ws, { recursive: true });
|
|
8
|
+
writeFileSync(ws + '/demo.ts', 'const x: number = 1;\nconsole.log(x);\n');
|
|
9
|
+
|
|
10
|
+
console.log('discovered real servers:', discoverServers().map((s) => s.id).join(', ') || '(none)');
|
|
11
|
+
|
|
12
|
+
const mgr = new ProcessManager({ id: 'fake', command: process.execPath, args: ['src/__tests__/fixtures/fake-server.cjs'], source: 'explicit' }, process.cwd());
|
|
13
|
+
const client = new LspClient(mgr.start(), { requestTimeoutMs: 10_000 });
|
|
14
|
+
const info = await client.initialize(fileToUri(ws));
|
|
15
|
+
console.log('initialized:', info.serverInfo?.name, info.serverInfo?.version);
|
|
16
|
+
const uri = fileToUri(ws + '/demo.ts');
|
|
17
|
+
client.openDoc(uri, 'typescript', 'const y = DELBERATE_ERROR_MARKER;\n');
|
|
18
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
19
|
+
const hover = await client.hover({ uri }, { line: 0, character: 6 });
|
|
20
|
+
console.log('hover:', JSON.stringify(hover?.contents).slice(0, 80));
|
|
21
|
+
const def = await client.definition({ uri }, { line: 0, character: 6 });
|
|
22
|
+
console.log('definition:', Array.isArray(def) ? def[0]?.uri : def?.uri);
|
|
23
|
+
await client.shutdown();
|
|
24
|
+
await mgr.stop();
|
|
25
|
+
console.log('stopped:', mgr.running === false);
|
|
26
|
+
await shutdownLsp();
|
|
27
|
+
console.log('REAL-MACHINE (fake-server) LIFECYCLE OK — real typescript-language-server: NOT ON PATH (NOT VERIFIED against a real server this round)');
|