@atcute/lex-cli 2.6.1 → 2.8.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/src/lsp-client.ts CHANGED
@@ -112,6 +112,9 @@ export const createLspClient = async (command: string, root: string): Promise<Ls
112
112
  // are handled by the close/error handlers below
113
113
  child.stdin.on('error', () => {});
114
114
 
115
+ // drain stderr so a chatty server doesn't block on a full pipe buffer
116
+ child.stderr.resume();
117
+
115
118
  // #region JSON-RPC framing
116
119
 
117
120
  const pending = new Map<number, PromiseWithResolvers<unknown>>();
@@ -188,7 +191,6 @@ export const createLspClient = async (command: string, root: string): Promise<Ls
188
191
  continue;
189
192
  }
190
193
 
191
- // dispatch responses to pending requests, ignore everything else
192
194
  if (message.id != null) {
193
195
  const entry = pending.get(message.id);
194
196
  if (entry) {
@@ -199,6 +201,13 @@ export const createLspClient = async (command: string, root: string): Promise<Ls
199
201
  } else {
200
202
  entry.resolve(message.result);
201
203
  }
204
+ } else if (message.method != null) {
205
+ // server-initiated request — reply with MethodNotFound so it doesn't hang
206
+ sendMessage({
207
+ jsonrpc: '2.0',
208
+ id: message.id,
209
+ error: { code: -32601, message: `method not found` },
210
+ });
202
211
  }
203
212
  }
204
213
  }
@@ -26,80 +26,81 @@ export const pullGitSource = async (
26
26
  const cloneDir = path.join(tempParent, 'repo');
27
27
 
28
28
  try {
29
- await runGit(
30
- [
31
- 'clone',
32
- '--filter=blob:none',
33
- '--depth',
34
- '1',
35
- '--sparse',
36
- ...(source.ref ? ['--branch', source.ref, '--single-branch'] : []),
37
- source.remote,
38
- cloneDir,
39
- ],
40
- { timeoutMs: 60_000 },
41
- );
42
- } catch (err) {
43
- if (err instanceof GitError) {
44
- console.error(pc.bold(pc.red(`git clone failed for ${source.remote}:`)));
45
- console.error(err.stderr || err.message);
46
- process.exit(1);
29
+ try {
30
+ await runGit(
31
+ [
32
+ 'clone',
33
+ '--filter=blob:none',
34
+ '--depth',
35
+ '1',
36
+ '--sparse',
37
+ ...(source.ref ? ['--branch', source.ref, '--single-branch'] : []),
38
+ source.remote,
39
+ cloneDir,
40
+ ],
41
+ { timeoutMs: 60_000 },
42
+ );
43
+ } catch (err) {
44
+ if (err instanceof GitError) {
45
+ console.error(pc.bold(pc.red(`git clone failed for ${source.remote}:`)));
46
+ console.error(err.stderr || err.message);
47
+ process.exit(1);
48
+ }
49
+
50
+ throw err;
47
51
  }
48
52
 
49
- throw err;
50
- }
51
-
52
- try {
53
- await runGit(['-C', cloneDir, 'sparse-checkout', 'set', '--no-cone', ...source.pattern], {
54
- timeoutMs: 30_000,
55
- });
56
- } catch (err) {
57
- if (err instanceof GitError) {
58
- console.error(pc.bold(pc.red(`git sparse-checkout failed for ${source.remote}:`)));
59
- console.error(err.stderr || err.message);
60
- process.exit(1);
53
+ try {
54
+ await runGit(['-C', cloneDir, 'sparse-checkout', 'set', '--no-cone', ...source.pattern], {
55
+ timeoutMs: 30_000,
56
+ });
57
+ } catch (err) {
58
+ if (err instanceof GitError) {
59
+ console.error(pc.bold(pc.red(`git sparse-checkout failed for ${source.remote}:`)));
60
+ console.error(err.stderr || err.message);
61
+ process.exit(1);
62
+ }
63
+
64
+ throw err;
61
65
  }
62
66
 
63
- throw err;
64
- }
65
-
66
- const pulled = new Map<string, PulledLexicon>();
67
+ const pulled = new Map<string, PulledLexicon>();
67
68
 
68
- for await (const filename of fs.glob(source.pattern, { cwd: cloneDir })) {
69
- const absolute = path.join(cloneDir, filename);
70
- const stat = await fs.stat(absolute);
69
+ for await (const filename of fs.glob(source.pattern, { cwd: cloneDir })) {
70
+ const absolute = path.join(cloneDir, filename);
71
+ const stat = await fs.stat(absolute);
71
72
 
72
- if (!stat.isFile()) {
73
- continue;
74
- }
73
+ if (!stat.isFile()) {
74
+ continue;
75
+ }
75
76
 
76
- const location: SourceLocation = {
77
- absolutePath: absolute,
78
- relativePath: filename,
79
- sourceDescription: source.remote,
80
- };
77
+ const location: SourceLocation = {
78
+ absolutePath: absolute,
79
+ relativePath: filename,
80
+ sourceDescription: source.remote,
81
+ };
81
82
 
82
- const doc = await parseLexiconFile(location);
83
+ const doc = await parseLexiconFile(location);
83
84
 
84
- pulled.set(doc.id, { nsid: doc.id, doc, location });
85
- }
85
+ pulled.set(doc.id, { nsid: doc.id, doc, location });
86
+ }
86
87
 
87
- // get the commit hash
88
- let rev: string;
89
- try {
90
- const result = await runGit(['-C', cloneDir, 'rev-parse', 'HEAD'], { timeoutMs: 10_000 });
91
- rev = result.stdout.trim();
92
- } catch (err) {
93
- if (err instanceof GitError) {
94
- console.error(pc.bold(pc.red(`git rev-parse failed for ${source.remote}:`)));
95
- console.error(err.stderr || err.message);
96
- process.exit(1);
88
+ let rev: string;
89
+ try {
90
+ const result = await runGit(['-C', cloneDir, 'rev-parse', 'HEAD'], { timeoutMs: 10_000 });
91
+ rev = result.stdout.trim();
92
+ } catch (err) {
93
+ if (err instanceof GitError) {
94
+ console.error(pc.bold(pc.red(`git rev-parse failed for ${source.remote}:`)));
95
+ console.error(err.stderr || err.message);
96
+ process.exit(1);
97
+ }
98
+
99
+ throw err;
97
100
  }
98
101
 
99
- throw err;
102
+ return { pulled, rev };
103
+ } finally {
104
+ await fs.rm(tempParent, { recursive: true, force: true });
100
105
  }
101
-
102
- await fs.rm(tempParent, { recursive: true, force: true });
103
-
104
- return { pulled, rev };
105
106
  };