-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsconfig.json
More file actions
83 lines (73 loc) · 2.78 KB
/
Copy pathtsconfig.json
File metadata and controls
83 lines (73 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import * as vscode from 'vscode';
let output: vscode.OutputChannel;
export function activate(context: vscode.ExtensionContext) {
output = vscode.window.createOutputChannel("Language Server Watchdog");
output.appendLine("🐍 Watchdog started.");
const interval = setInterval(async () => {
const editor = vscode.window.activeTextEditor;
if (!editor || editor.document.languageId !== 'python') {
output.appendLine("📄 No active Python document – skipping check.");
return;
}
try {
const ok = await checkLanguageServerHealth(editor.document.uri);
if (!ok) {
output.appendLine("⚠️ Health check failed – attempting passive restart...");
await passiveRecovery(editor.document);
} else {
output.appendLine("✅ Language Server is responsive.");
}
} catch (err) {
output.appendLine(`❌ Unexpected error: ${err}`);
}
}, 30000); // alle 30 Sekunden
context.subscriptions.push({
dispose() {
clearInterval(interval);
output.appendLine("🛑 Watchdog stopped.");
}
});
}
export function deactivate() {
output?.appendLine("🛑 Watchdog deactivated.");
output?.dispose();
}
async function checkLanguageServerHealth(uri: vscode.Uri): Promise<boolean> {
try {
const result = await withTimeout(
vscode.commands.executeCommand<vscode.DocumentSymbol[]>('vscode.executeDocumentSymbolProvider', uri),
3000
);
return !!(result && result.length >= 0);
} catch (e) {
output.appendLine(`⏱ Timeout or error during health check: ${e}`);
return false;
}
}
async function passiveRecovery(doc: vscode.TextDocument) {
try {
const dummyChange = new vscode.WorkspaceEdit();
const pos = new vscode.Position(0, 0);
dummyChange.insert(doc.uri, pos, "");
await vscode.workspace.applyEdit(dummyChange);
await delay(500);
output.appendLine("🔄 Triggered passive restart via empty insert.");
} catch (err) {
output.appendLine(`❌ Passive restart failed: ${err}`);
}
}
function delay(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
function withTimeout<T>(promise: Thenable<T>, timeoutMs: number): Promise<T> {
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => reject(new Error("Timeout")), timeoutMs);
promise.then(result => {
clearTimeout(timeout);
resolve(result);
}, err => {
clearTimeout(timeout);
reject(err);
});
});
}