8000 Can start the LS without an Output channel. · arduino/vscode-arduino-tools@a35aa11 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a35aa11

Browse files
author
Akos Kitta
committed
Can start the LS without an Output channel.
Ref: arduino/arduino-ide#714 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 714fffc commit a35aa11

File tree

2 files changed

+53
-35
lines changed

2 files changed

+53
-35
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vscode-arduino-tools",
33
"private": true,
4-
"version": "0.0.2-beta.4",
4+
"version": "0.0.2-beta.5",
55
"publisher": "arduino",
66
"license": "Apache-2.0",
77
"author": "Arduino SA",

src/extension.ts

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import deepEqual from 'deep-equal';
55
import WebRequest from 'web-request';
66
import deepmerge from 'deepmerge';
77
import { Mutex } from 'async-mutex';
8-
import vscode, { ExtensionContext } from 'vscode';
9-
import { LanguageClient, CloseAction, ErrorAction, InitializeError, Message, RevealOutputChannelOn } from 'vscode-languageclient';
8+
import vscode, { ExtensionContext, OutputChannel } from 'vscode';
9+
import { LanguageClient, CloseAction, ErrorAction, InitializeError, Message, RevealOutputChannelOn, LanguageClientOptions } from 'vscode-languageclient';
1010
import { DidCompleteBuildNotification, DidCompleteBuildParams } from './protocol';
1111

1212
interface LanguageServerConfig {
@@ -28,6 +28,7 @@ interface LanguageServerConfig {
2828
readonly env?: any;
2929
readonly flags?: string[];
3030
readonly realTimeDiagnostics?: boolean;
31+
readonly silentOutput?: boolean;
3132
}
3233

3334
interface DebugConfig {
@@ -224,43 +225,48 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
224225
args.push('-logpath', logPath);
225226
}
226227
}
227-
return new LanguageClient(
228-
'ino',
229-
'Arduino Language Server',
230-
{
231-
command,
232-
args,
233-
options: { env },
228+
const clientOptions = {
229+
initializationOptions: {},
230+
documentSelector: ['ino', 'c', 'cpp', 'h', 'hpp', 'pde'],
231+
uriConverters: {
232+
code2Protocol: (uri: vscode.Uri): string => (uri.scheme ? uri : uri.with({ scheme: 'file' })).toString(),
233+
protocol2Code: (uri: string) => vscode.Uri.parse(uri)
234234
},
235-
{
236-
initializationOptions: {},
237-
documentSelector: ['ino', 'c', 'cpp', 'h', 'hpp', 'pde'],
238-
uriConverters: {
239-
code2Protocol: (uri: vscode.Uri): string => (uri.scheme ? uri : uri.with({ scheme: 'file' })).toString(),
240-
protocol2Code: (uri: string) => vscode.Uri.parse(uri)
241-
},
242-
revealOutputChannelOn: RevealOutputChannelOn.Never,
243-
initializationFailedHandler: (error: WebRequest.ResponseError<InitializeError>): boolean => {
244-
vscode.window.showErrorMessage(`The language server is not able to serve any features. Initialization failed: ${error}.`);
245-
return false;
235+
revealOutputChannelOn: RevealOutputChannelOn.Never,
236+
initializationFailedHandler: (error: WebRequest.ResponseError<InitializeError>): boolean => {
237+
vscode.window.showErrorMessage(`The language server is not able to serve any features. Initialization failed: ${error}.`);
238+
return false;
239+
},
240+
errorHandler: {
241+
error: (error: Error, message: Message, count: number): ErrorAction => {
242+
vscode.window.showErrorMessage(`Error communicating with the language server: ${error}: ${message}.`);
243+
if (count < 5) {
244+
return ErrorAction.Continue;
245+
}
246+
return ErrorAction.Shutdown;
246247
},
247-
errorHandler: {
248-
error: (error: Error, message: Message, count: number): ErrorAction => {
249-
vscode.window.showErrorMessage(`Error communicating with the language server: ${error}: ${message}.`);
250-
if (count < 5) {
251-
return ErrorAction.Continue;
252-
}
253-
return ErrorAction.Shutdown;
254-
},
255-
closed: (): CloseAction => {
256-
crashCount++;
257-
if (crashCount < 5) {
258-
return CloseAction.Restart;
259-
}
260-
return CloseAction.DoNotRestart;
248+
closed: (): CloseAction => {
249+
crashCount++;
250+
if (crashCount < 5) {
251+
return CloseAction.Restart;
261252
}
253+
return CloseAction.DoNotRestart;
262254
}
263255
}
256+
} as LanguageClientOptions;
257+
if (!!config.silentOutput) {
258+
clientOptions.outputChannel = noopOutputChannel('Arduino Language Server');
259+
}
260+
const serverOptions = {
261+
command,
262+
args,
263+
options: { env },
264+
};
265+
return new LanguageClient(
266+
'ino',
267+
'Arduino Language Server',
268+
serverOptions,
269+
clientOptions
264270
);
265271
}
266272

@@ -282,3 +288,15 @@ async function updateLaunchConfig(debugConfig: DebugConfig, launchConfig: object
282288
await configuration.update('launch', launchConfig, false);
283289
}
284290
}
291+
292+
function noopOutputChannel(name: string): OutputChannel {
293+
return {
294+
append: () => {},
295+
appendLine: () => {},
296+
clear: () => {},
297+
dispose: () => {},
298+
hide: () => {},
299+
show: () => {},
300+
name
301+
};
302+
}

0 commit comments

Comments
 (0)
0