Skip to content

Commit f284ece

Browse files
authored
feat: add statusBar of rslint (#253)
1 parent 07dfe7a commit f284ece

File tree

5 files changed

+114
-9
lines changed

5 files changed

+114
-9
lines changed

internal/lsp/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package lsp
22

33
import (
44
"context"
5-
"encoding/json"
65
"errors"
76
"fmt"
87
"io"
@@ -12,6 +11,7 @@ import (
1211
"strings"
1312
"sync"
1413

14+
"github.com/go-json-experiment/json"
1515
"github.com/microsoft/typescript-go/shim/ast"
1616
"github.com/microsoft/typescript-go/shim/bundled"
1717
"github.com/microsoft/typescript-go/shim/core"
@@ -266,10 +266,9 @@ func (s *LSPServer) handleCodeAction(ctx context.Context, req *jsonrpc2.Request)
266266
if err := json.Unmarshal(*req.Params, &params); err != nil {
267267
return nil, &jsonrpc2.Error{
268268
Code: jsonrpc2.CodeParseError,
269-
Message: "Failed to parse code action params",
269+
Message: fmt.Sprintf("Failed to parse code action params %v", err),
270270
}
271271
}
272-
273272
uri := params.TextDocument.Uri
274273

275274
// Get stored diagnostics for this document

packages/vscode-extension/src/Extension.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import {
44
workspace,
55
WorkspaceFolder,
66
ExtensionMode,
7+
OutputChannel,
8+
window,
79
} from 'vscode';
810
import { State } from 'vscode-languageclient/node';
911
import { LogLevel, Logger } from './logger';
1012
import { Rslint } from './Rslint';
13+
import { setupStatusBar } from './statusBar';
14+
import { RegisterCommands } from './commands';
1115

1216
export class Extension implements Disposable {
1317
private rslintInstances: Map<string, Rslint> = new Map();
@@ -25,12 +29,26 @@ export class Extension implements Disposable {
2529
this.logger.info('Rslint extension activating...');
2630

2731
const folders = workspace.workspaceFolders ?? [];
32+
const outputChannel = window.createOutputChannel(
33+
'Rslint Language Server',
34+
'log',
35+
);
36+
const lspOutputChannel = window.createOutputChannel(
37+
'Rslint Language Server(LSP)',
38+
);
39+
2840
for (const folder of folders) {
29-
const workspaceRslint = this.createRslintInstance(folder.name, folder);
41+
const workspaceRslint = this.createRslintInstance(
42+
folder.name,
43+
folder,
44+
outputChannel,
45+
lspOutputChannel,
46+
);
3047
await workspaceRslint.start();
3148
this.setupStateChangeMonitoring(workspaceRslint, folder.name);
3249
}
33-
50+
setupStatusBar(this.context);
51+
RegisterCommands(this.context, outputChannel, lspOutputChannel);
3452
this.logger.info('Rslint extension activated successfully');
3553
}
3654

@@ -55,14 +73,21 @@ export class Extension implements Disposable {
5573
public createRslintInstance(
5674
id: string,
5775
workspaceFolder: WorkspaceFolder,
76+
outputChannel: OutputChannel,
77+
lspOutputChannel: OutputChannel,
5878
): Rslint {
5979
if (this.rslintInstances.has(id)) {
6080
this.logger.warn(`Rslint instance with id '${id}' already exists`);
6181
return this.rslintInstances.get(id)!;
6282
}
6383

6484
// TODO: single file mode
65-
const rslint = new Rslint(this, workspaceFolder);
85+
const rslint = new Rslint(
86+
this,
87+
workspaceFolder,
88+
outputChannel,
89+
lspOutputChannel,
90+
);
6691
this.rslintInstances.set(id, rslint);
6792
this.logger.debug(`Created Rslint instance with id: ${id}`);
6893
return rslint;

packages/vscode-extension/src/Rslint.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ export class Rslint implements Disposable {
2525
private readonly extension: Extension;
2626
private readonly workspaceFolder: WorkspaceFolder;
2727
private lspOutputChannel: OutputChannel | undefined;
28-
29-
constructor(extension: Extension, workspaceFolder: WorkspaceFolder) {
28+
private outputChannel: OutputChannel | undefined;
29+
30+
constructor(
31+
extension: Extension,
32+
workspaceFolder: WorkspaceFolder,
33+
outputChannel: OutputChannel,
34+
lspOutputChannel: OutputChannel,
35+
) {
3036
this.extension = extension;
3137
this.workspaceFolder = workspaceFolder;
3238
this.logger = new Logger('Rslint (workspace)').useDefaultLogLevel();
39+
this.lspOutputChannel = lspOutputChannel;
40+
this.outputChannel = outputChannel;
3341
}
3442

3543
public async start(): Promise<void> {
@@ -69,10 +77,10 @@ export class Rslint implements Disposable {
6977
'**/{rslint.{json,jsonc},package-lock.json,pnpm-lock.yaml,yarn.lock}',
7078
),
7179
},
80+
outputChannel: this.outputChannel,
7281
};
7382

7483
if (traceEnabled) {
75-
this.lspOutputChannel = window.createOutputChannel('Rslint LSP trace');
7684
clientOptions.traceOutputChannel = this.lspOutputChannel;
7785
this.logger.info(
7886
'LSP tracing enabled, output will be logged to "Rslint LSP trace" channel',
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as vscode from 'vscode';
2+
export function RegisterCommands(
3+
context: vscode.ExtensionContext,
4+
outputChannel: vscode.OutputChannel,
5+
traceOutputChannel: vscode.OutputChannel,
6+
) {
7+
context.subscriptions.push(
8+
vscode.commands.registerCommand('rslint.showMenu', showCommands),
9+
);
10+
// context.subscriptions.push(vscode.commands.registerCommand('rslint.restart', async () => {
11+
// await vscode.commands.executeCommand('rslint.restart');
12+
// }));
13+
context.subscriptions.push(
14+
vscode.commands.registerCommand('rslint.output.focus', () => {
15+
outputChannel.show();
16+
}),
17+
);
18+
context.subscriptions.push(
19+
vscode.commands.registerCommand('rslint.lsp-trace.focus', () => {
20+
traceOutputChannel.show();
21+
}),
22+
);
23+
}
24+
25+
async function showCommands(): Promise<void> {
26+
const commands: readonly {
27+
label: string;
28+
description: string;
29+
command: string;
30+
}[] = [
31+
// {
32+
// label: "$(refresh) RestartRslint Server",
33+
// description: "Restart the Rslint language server",
34+
// command: "rslint.restart",
35+
// },
36+
{
37+
label: '$(output) Show Rslint Server Log',
38+
description: 'Show the Rslint server log',
39+
command: 'rslint.output.focus',
40+
},
41+
{
42+
label: '$(debug-console) Show Rslint LSP Messages',
43+
description: 'Show the LSP communication trace',
44+
command: 'rslint.lsp-trace.focus',
45+
},
46+
];
47+
48+
// eslint-disable-next-line @typescript-eslint/await-thenable
49+
const selected = await vscode.window.showQuickPick(commands, {
50+
placeHolder: 'Rslint Commands',
51+
});
52+
53+
if (selected) {
54+
// eslint-disable-next-line
55+
await vscode.commands.executeCommand(selected.command);
56+
}
57+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as vscode from 'vscode';
2+
export function setupStatusBar(context: vscode.ExtensionContext) {
3+
const statusBar = vscode.window.createStatusBarItem(
4+
vscode.StatusBarAlignment.Right,
5+
100,
6+
);
7+
statusBar.text = '$(beaker) rslint';
8+
statusBar.tooltip = 'Rslint Language Server';
9+
statusBar.command = 'rslint.showMenu';
10+
statusBar.backgroundColor = new vscode.ThemeColor(
11+
'statusBarItem.warningBackground',
12+
);
13+
statusBar.show();
14+
15+
context.subscriptions.push(statusBar);
16+
}

0 commit comments

Comments
 (0)