Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/vscode-extension/__tests__/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import path from 'node:path';
suite('rslint extension', function () {
this.timeout(50000);

test('restart command is registered', async () => {
// Check that the restart command is available
const commands = await vscode.commands.getCommands(true);
assert.ok(
commands.includes('rslint.restart'),
'rslint.restart command should be registered',
);
});

// Helper function to wait for diagnostics
async function waitForDiagnostics(
doc: vscode.TextDocument,
Expand Down
7 changes: 7 additions & 0 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
"onLanguage:javascriptreact"
],
"contributes": {
"commands": [
{
"command": "rslint.restart",
"title": "Restart Rslint Server",
"category": "Rslint"
}
],
"configuration": {
"type": "object",
"title": "Rslint",
Expand Down
26 changes: 25 additions & 1 deletion packages/vscode-extension/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Extension implements Disposable {
this.setupStateChangeMonitoring(workspaceRslint, folder.name);
}
setupStatusBar(this.context);
RegisterCommands(this.context, outputChannel, lspOutputChannel);
RegisterCommands(this.context, outputChannel, lspOutputChannel, this);
this.logger.info('Rslint extension activated successfully');
}

Expand Down Expand Up @@ -115,6 +115,30 @@ export class Extension implements Disposable {
return new Map(this.rslintInstances);
}

public async restartAllInstances(): Promise<void> {
this.logger.info('Restarting all Rslint instances...');

const restartPromises = Array.from(this.rslintInstances.values()).map(
async instance => {
try {
await instance.stop();
await instance.start();
} catch (err: unknown) {
this.logger.error('Error restarting Rslint instance', err);
throw err;
}
},
);

try {
await Promise.all(restartPromises);
this.logger.info('All Rslint instances restarted successfully');
} catch (err: unknown) {
this.logger.error('Error restarting some Rslint instances', err);
throw err;
}
}

public dispose(): void {
this.rslintInstances.forEach(instance => {
instance.dispose();
Expand Down
31 changes: 23 additions & 8 deletions packages/vscode-extension/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import * as vscode from 'vscode';
import type { Extension } from './Extension';

export function RegisterCommands(
context: vscode.ExtensionContext,
outputChannel: vscode.OutputChannel,
traceOutputChannel: vscode.OutputChannel,
extension: Extension,
) {
context.subscriptions.push(
vscode.commands.registerCommand('rslint.showMenu', showCommands),
);
// context.subscriptions.push(vscode.commands.registerCommand('rslint.restart', async () => {
// await vscode.commands.executeCommand('rslint.restart');
// }));
context.subscriptions.push(
vscode.commands.registerCommand('rslint.restart', async () => {
try {
await extension.restartAllInstances();
vscode.window.showInformationMessage(
'Rslint server restarted successfully',
);
} catch (err: unknown) {
const message = err instanceof Error ? err.message : 'Unknown error';
vscode.window.showErrorMessage(
`Failed to restart Rslint server: ${message}`,
);
}
}),
);
context.subscriptions.push(
vscode.commands.registerCommand('rslint.output.focus', () => {
outputChannel.show();
Expand All @@ -28,11 +43,11 @@ async function showCommands(): Promise<void> {
description: string;
command: string;
}[] = [
// {
// label: "$(refresh) RestartRslint Server",
// description: "Restart the Rslint language server",
// command: "rslint.restart",
// },
{
label: '$(refresh) Restart Rslint Server',
description: 'Restart the Rslint language server',
command: 'rslint.restart',
},
{
label: '$(output) Show Rslint Server Log',
description: 'Show the Rslint server log',
Expand Down
Loading