Skip to content

Commit f7b0b79

Browse files
fix: implement LSP server restart mechanism for Justfile changes (#4)
- Add automatic LSP client restart when Justfile is modified/created/deleted - Enhance error handling with user notifications and restart after 3+ errors - Add diagnostic monitoring to ensure problems appear in VS Code Problems panel - Fix issue where syntax errors persist after Justfile fixes Closes #3 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent a1165d5 commit f7b0b79

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/client.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,18 @@ export async function createLanguageClient(context: vscode.ExtensionContext): Pr
8585
errorHandler: {
8686
error: (error, message, count) => {
8787
console.error(`[justlang-lsp] LSP Error (${count}):`, error, message);
88+
vscode.window.showErrorMessage(`Just LSP Error: ${error?.message || error}`);
89+
90+
// After 3 errors, try to restart
91+
if (count !== undefined && count >= 3) {
92+
console.warn('[justlang-lsp] Too many errors, attempting restart');
93+
return { action: ErrorAction.Shutdown };
94+
}
8895
return { action: ErrorAction.Continue };
8996
},
9097
closed: () => {
91-
console.warn('[justlang-lsp] LSP connection closed');
98+
console.warn('[justlang-lsp] LSP connection closed unexpectedly');
99+
vscode.window.showWarningMessage('Just Language Server connection closed, attempting restart...');
92100
return { action: CloseAction.Restart };
93101
}
94102
}
@@ -122,6 +130,15 @@ export async function createLanguageClient(context: vscode.ExtensionContext): Pr
122130
console.log(`[justlang-lsp] Server message: ${params.message}`);
123131
});
124132

133+
// Monitor diagnostics to ensure they're being published
134+
client.onNotification('textDocument/publishDiagnostics', (params) => {
135+
console.log(`[justlang-lsp] Publishing diagnostics for ${params.uri}: ${params.diagnostics.length} issues`);
136+
if (params.diagnostics.length > 0) {
137+
// Show Problems panel when diagnostics are published
138+
vscode.commands.executeCommand('workbench.action.problems.focus');
139+
}
140+
});
141+
125142
// Handle server-to-client commands
126143
client.onRequest('workspace/executeCommand', async (params) => {
127144
console.log(`[justlang-lsp] Execute command request: ${params.command}`, params.arguments);

src/extension.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ export function activate(context: vscode.ExtensionContext) {
9595

9696
if (enableLsp) {
9797
startLsp();
98+
99+
// Watch for Justfile changes and restart LSP if needed
100+
const justfileWatcher = vscode.workspace.createFileSystemWatcher('**/*.{just,justfile,Justfile}');
101+
102+
const restartLspOnFileChange = async () => {
103+
if (client) {
104+
logger.info('Justfile changed, restarting LSP client', 'Extension');
105+
await stopLsp();
106+
await startLsp();
107+
}
108+
};
109+
110+
justfileWatcher.onDidChange(restartLspOnFileChange);
111+
justfileWatcher.onDidCreate(restartLspOnFileChange);
112+
justfileWatcher.onDidDelete(restartLspOnFileChange);
113+
114+
context.subscriptions.push(justfileWatcher);
98115
} else {
99116
logger.info('LSP subsystem disabled by configuration', 'Extension');
100117
}

0 commit comments

Comments
 (0)