Skip to content

Commit 6a8c69e

Browse files
committed
feat(scan): add more log about child process
1 parent 0a6f107 commit 6a8c69e

File tree

4 files changed

+48
-12
lines changed

4 files changed

+48
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vim-language-server",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "vim language server",
55
"keywords": [
66
"viml",

src/server/buffer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export class Buffer {
225225
try {
226226
this.resolveCompletionItems([node]);
227227
} catch (error) {
228-
log.error(error.stack);
228+
log.warn(`updateBufferByNode: ${error.stack}`);
229229
}
230230
}
231231

src/server/builtin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class Builtin {
322322
try {
323323
colorschemes = await fg(glob, { onlyFiles: false, deep: 0 });
324324
} catch (error) {
325-
log.error(
325+
log.warn(
326326
[
327327
`Index Colorschemes Error: ${JSON.stringify(glob)}`,
328328
`Error => ${error.stack || error.message || error}`,

src/server/parser.ts

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { join } from "path";
33
import { from, Subject, timer } from "rxjs";
44
import { waitMap } from "rxjs-operators/lib/waitMap";
55
import { filter, map, switchMap } from "rxjs/operators";
6-
import { TextDocument } from "vscode-languageserver";
6+
import { TextDocument } from "vscode-languageserver-textdocument";
77
import { URI } from "vscode-uri";
88

99
import logger from "../common/logger";
@@ -24,6 +24,26 @@ const origin$: Subject<TextDocument> = new Subject<TextDocument>();
2424
let scanProcess: ChildProcess;
2525
let isScanRuntimepath: boolean = false;
2626

27+
function send(params: any) {
28+
if (!scanProcess) {
29+
log.log('scan process do not exists')
30+
return
31+
}
32+
if ((scanProcess as any).signalCode) {
33+
log.log(`scan process signal code: ${(scanProcess as any).signalCode}`)
34+
return
35+
}
36+
if (scanProcess.killed) {
37+
log.log('scan process was killed')
38+
return
39+
}
40+
scanProcess.send(params, (err) => {
41+
if (err) {
42+
log.warn(`Send error: ${err.stack || err.message || err.name}`)
43+
}
44+
})
45+
}
46+
2747
function startIndex() {
2848
if (scanProcess) {
2949
return;
@@ -47,16 +67,32 @@ function startIndex() {
4767
});
4868

4969
scanProcess.on("error", (err: Error) => {
50-
log.error(`${err.stack || err.message || err}`);
70+
log.warn(`${err.stack || err.message || err}`);
5171
});
5272

53-
scanProcess.send({
73+
scanProcess.on('exit', (code, signal) => {
74+
log.log(`exit: ${code}, signal: ${signal}`);
75+
});
76+
77+
scanProcess.on('close', (code, signal) => {
78+
log.log(`close: ${code}, signal: ${signal}`);
79+
});
80+
81+
scanProcess.on('uncaughtException', (err) => {
82+
log.log(`Uncaught exception: ${err.stack || err.message || err.name || err}`);
83+
})
84+
85+
scanProcess.on('disconnect', () => {
86+
log.log(`disconnect`);
87+
})
88+
89+
send({
5490
config: {
5591
gap: config.indexes.gap,
5692
count: config.indexes.count,
5793
projectRootPatterns: config.indexes.projectRootPatterns,
5894
},
59-
});
95+
})
6096
}
6197

6298
export function next(
@@ -85,17 +121,17 @@ export function next(
85121
// scan project
86122
if (!indexes[uri]) {
87123
indexes[uri] = true;
88-
scanProcess.send({
124+
send({
89125
uri,
90-
});
126+
})
91127
if (!isScanRuntimepath) {
92128
isScanRuntimepath = true;
93129
scan([config.vimruntime].concat(config.runtimepath));
94130
}
95131
}
96132
},
97133
(err: Error) => {
98-
log.error(`${err.stack || err.message || err}`);
134+
log.warn(`${err.stack || err.message || err}`);
99135
},
100136
);
101137
}
@@ -128,9 +164,9 @@ export function scan(paths: string | string[]) {
128164
if (!p || p === "/") {
129165
continue;
130166
}
131-
scanProcess.send({
167+
send({
132168
uri: URI.file(join(p, "f")).toString(),
133-
});
169+
})
134170
}
135171
}
136172
}

0 commit comments

Comments
 (0)