fix(ext): v0.5.5 wrong-LS 자동 복구 — fixLSConnection export + 'input not registered' 감지 시 LS 재연결 + 1회 retry
This commit is contained in:
@@ -210,18 +210,18 @@ async function initSDK(context: vscode.ExtensionContext): Promise<boolean> {
|
||||
* lowercased (desktop_variet_agent) → no match → falls back to first LS
|
||||
* found (wrong workspace).
|
||||
*/
|
||||
async function fixLSConnection(): Promise<void> {
|
||||
if (!sdk?.ls) return;
|
||||
export async function fixLSConnection(): Promise<boolean> {
|
||||
if (!sdk?.ls) { logToFile('[LS-FIX] skipped: sdk.ls not available'); return false; }
|
||||
try {
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
if (!folders || folders.length === 0) return;
|
||||
if (!folders || folders.length === 0) { logToFile('[LS-FIX] skipped: no workspace folders'); return false; }
|
||||
|
||||
// Generate the workspace hint the same way SDK does, but we'll match case-insensitively
|
||||
const folder = folders[0].uri.fsPath;
|
||||
const parts = folder.replace(/\\/g, '/').split('/');
|
||||
const hint = parts.slice(-2).join('_').replace(/[-.\s]/g, '_').toLowerCase();
|
||||
|
||||
if (!hint) return;
|
||||
if (!hint) { logToFile('[LS-FIX] skipped: empty hint'); return false; }
|
||||
|
||||
// Find all language_server processes with csrf_token
|
||||
const { exec } = cp;
|
||||
@@ -237,12 +237,16 @@ async function fixLSConnection(): Promise<void> {
|
||||
{ encoding: 'utf8', timeout: 15000, windowsHide: true }
|
||||
);
|
||||
output = result.stdout;
|
||||
} catch {
|
||||
return; // Can't discover processes — leave SDK's choice
|
||||
} catch (psErr: any) {
|
||||
logToFile(`[LS-FIX] skipped: PowerShell failed — ${psErr.message?.substring(0, 100)}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const lines = output.split('\n').filter((l: string) => l.trim().length > 0);
|
||||
if (lines.length <= 1) return; // Only one LS — no ambiguity
|
||||
if (lines.length === 0) { logToFile('[LS-FIX] skipped: no LS processes found'); return false; }
|
||||
// NOTE: Do NOT skip on single LS — SDK may have fallen back to wrong LS
|
||||
// due to case-sensitive hint mismatch, even when only one process exists.
|
||||
logToFile(`[LS-FIX] found ${lines.length} LS process(es), hint="${hint}"`);
|
||||
|
||||
// Find the line whose workspace_id matches our workspace (case-insensitive)
|
||||
let matchedLine: string | null = null;
|
||||
@@ -261,7 +265,7 @@ async function fixLSConnection(): Promise<void> {
|
||||
|
||||
if (!matchedLine) {
|
||||
logToFile(`[LS-FIX] No LS process matched hint="${hint}" (${lines.length} processes)`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Extract port and csrf_token from matched line
|
||||
@@ -271,7 +275,7 @@ async function fixLSConnection(): Promise<void> {
|
||||
|
||||
if (!csrfMatch || !extPortMatch) {
|
||||
logToFile(`[LS-FIX] Matched LS but missing csrf/port args`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
const csrfToken = csrfMatch[1];
|
||||
@@ -281,7 +285,7 @@ async function fixLSConnection(): Promise<void> {
|
||||
// Check if SDK already connected to this LS
|
||||
if (sdk.ls.port === extPort) {
|
||||
logToFile(`[LS-FIX] SDK already on correct LS port=${extPort}`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find ConnectRPC port via netstat (same as SDK logic)
|
||||
@@ -297,7 +301,7 @@ async function fixLSConnection(): Promise<void> {
|
||||
logToFile(`[LS-FIX] netstat failed, using ext_port=${extPort} for PID=${pid}`);
|
||||
sdk.ls.setConnection(extPort, csrfToken, false);
|
||||
logToFile(`[LS-FIX] ✅ Reconnected to correct LS: port=${extPort} hint="${hint}" PID=${pid}`);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
const portMatches = netstatOutput.matchAll(/127\.0\.0\.1:(\d+)/g);
|
||||
@@ -338,7 +342,7 @@ async function fixLSConnection(): Promise<void> {
|
||||
if (ok) {
|
||||
sdk.ls.setConnection(port, csrfToken, useTls);
|
||||
logToFile(`[LS-FIX] ✅ Reconnected to correct LS: port=${port} ${proto} hint="${hint}" PID=${pid}`);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
} catch { /* try next */ }
|
||||
}
|
||||
@@ -347,8 +351,10 @@ async function fixLSConnection(): Promise<void> {
|
||||
// Last resort: use extension_server_port
|
||||
sdk.ls.setConnection(extPort, csrfToken, false);
|
||||
logToFile(`[LS-FIX] ✅ Reconnected via ext_port=${extPort} hint="${hint}" PID=${pid}`);
|
||||
return true;
|
||||
} catch (err: any) {
|
||||
logToFile(`[LS-FIX] error: ${err.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,6 +516,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
recentDiscordSentTexts,
|
||||
writeChatSnapshot,
|
||||
writeChatSnapshotWithFiles,
|
||||
fixLSConnection,
|
||||
} as BridgeContext);
|
||||
// Start HTTP bridge with live step-probe state (prevents stale primitive bug)
|
||||
const httpBridgeCtx: HttpBridgeContext = {
|
||||
|
||||
Reference in New Issue
Block a user