Skip to content

Commit fe28456

Browse files
committed
refactor(vscode): move lsp server notification handling to helper function
1 parent a219acc commit fe28456

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

editors/vscode/client/linter.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@ import {
1313
workspace,
1414
} from 'vscode';
1515

16-
import {
17-
ConfigurationParams,
18-
ExecuteCommandRequest,
19-
MessageType,
20-
ShowMessageNotification,
21-
} from 'vscode-languageclient';
16+
import { ConfigurationParams, ExecuteCommandRequest, ShowMessageNotification } from 'vscode-languageclient';
2217

2318
import { Executable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
2419

2520
import { join } from 'node:path';
2621
import { ConfigService } from './ConfigService';
2722
import { VSCodeConfig } from './VSCodeConfig';
2823
import { OxcCommands } from './commands';
29-
import { runExecutable } from './lsp_helper';
24+
import { onClientNotification, runExecutable } from './lsp_helper';
3025

3126
const languageClientName = 'oxc';
3227

@@ -149,25 +144,7 @@ export async function activate(
149144
client = new LanguageClient(languageClientName, serverOptions, clientOptions);
150145

151146
const onNotificationDispose = client.onNotification(ShowMessageNotification.type, (params) => {
152-
switch (params.type) {
153-
case MessageType.Debug:
154-
outputChannel.debug(params.message);
155-
break;
156-
case MessageType.Log:
157-
outputChannel.info(params.message);
158-
break;
159-
case MessageType.Info:
160-
window.showInformationMessage(params.message);
161-
break;
162-
case MessageType.Warning:
163-
window.showWarningMessage(params.message);
164-
break;
165-
case MessageType.Error:
166-
window.showErrorMessage(params.message);
167-
break;
168-
default:
169-
outputChannel.info(params.message);
170-
}
147+
onClientNotification(params, outputChannel);
171148
});
172149

173150
context.subscriptions.push(onNotificationDispose);

editors/vscode/client/lsp_helper.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Executable } from 'vscode-languageclient/node';
1+
import { LogOutputChannel, window } from 'vscode';
2+
import { Executable, MessageType, ShowMessageParams } from 'vscode-languageclient/node';
23

34
export function runExecutable(path: string, nodePath?: string): Executable {
45
const serverEnv: Record<string, string> = {
@@ -32,3 +33,25 @@ export function runExecutable(path: string, nodePath?: string): Executable {
3233
},
3334
};
3435
}
36+
37+
export function onClientNotification(params: ShowMessageParams, outputChannel: LogOutputChannel) {
38+
switch (params.type) {
39+
case MessageType.Debug:
40+
outputChannel.debug(params.message);
41+
break;
42+
case MessageType.Log:
43+
outputChannel.info(params.message);
44+
break;
45+
case MessageType.Info:
46+
window.showInformationMessage(params.message);
47+
break;
48+
case MessageType.Warning:
49+
window.showWarningMessage(params.message);
50+
break;
51+
case MessageType.Error:
52+
window.showErrorMessage(params.message);
53+
break;
54+
default:
55+
outputChannel.info(params.message);
56+
}
57+
}

0 commit comments

Comments
 (0)