Skip to content

Can start the LS without an Output channel. #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2022
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-arduino-tools",
"private": true,
"version": "0.0.2-beta.4",
"version": "0.0.2-beta.5",
"publisher": "arduino",
"license": "Apache-2.0",
"author": "Arduino SA",
Expand Down
86 changes: 52 additions & 34 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import deepEqual from 'deep-equal';
import WebRequest from 'web-request';
import deepmerge from 'deepmerge';
import { Mutex } from 'async-mutex';
import vscode, { ExtensionContext } from 'vscode';
import { LanguageClient, CloseAction, ErrorAction, InitializeError, Message, RevealOutputChannelOn } from 'vscode-languageclient';
import vscode, { ExtensionContext, OutputChannel } from 'vscode';
import { LanguageClient, CloseAction, ErrorAction, InitializeError, Message, RevealOutputChannelOn, LanguageClientOptions } from 'vscode-languageclient';
import { DidCompleteBuildNotification, DidCompleteBuildParams } from './protocol';

interface LanguageServerConfig {
Expand All @@ -28,6 +28,7 @@ interface LanguageServerConfig {
readonly env?: any;
readonly flags?: string[];
readonly realTimeDiagnostics?: boolean;
readonly silentOutput?: boolean;
}

interface DebugConfig {
Expand Down Expand Up @@ -224,43 +225,48 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
args.push('-logpath', logPath);
}
}
return new LanguageClient(
'ino',
'Arduino Language Server',
{
command,
args,
options: { env },
const clientOptions = {
initializationOptions: {},
documentSelector: ['ino', 'c', 'cpp', 'h', 'hpp', 'pde'],
uriConverters: {
code2Protocol: (uri: vscode.Uri): string => (uri.scheme ? uri : uri.with({ scheme: 'file' })).toString(),
protocol2Code: (uri: string) => vscode.Uri.parse(uri)
},
{
initializationOptions: {},
documentSelector: ['ino', 'c', 'cpp', 'h', 'hpp', 'pde'],
uriConverters: {
code2Protocol: (uri: vscode.Uri): string => (uri.scheme ? uri : uri.with({ scheme: 'file' })).toString(),
protocol2Code: (uri: string) => vscode.Uri.parse(uri)
},
revealOutputChannelOn: RevealOutputChannelOn.Never,
initializationFailedHandler: (error: WebRequest.ResponseError<InitializeError>): boolean => {
vscode.window.showErrorMessage(`The language server is not able to serve any features. Initialization failed: ${error}.`);
return false;
revealOutputChannelOn: RevealOutputChannelOn.Never,
initializationFailedHandler: (error: WebRequest.ResponseError<InitializeError>): boolean => {
vscode.window.showErrorMessage(`The language server is not able to serve any features. Initialization failed: ${error}.`);
return false;
},
errorHandler: {
error: (error: Error, message: Message, count: number): ErrorAction => {
vscode.window.showErrorMessage(`Error communicating with the language server: ${error}: ${message}.`);
if (count < 5) {
return ErrorAction.Continue;
}
return ErrorAction.Shutdown;
},
errorHandler: {
error: (error: Error, message: Message, count: number): ErrorAction => {
vscode.window.showErrorMessage(`Error communicating with the language server: ${error}: ${message}.`);
if (count < 5) {
return ErrorAction.Continue;
}
return ErrorAction.Shutdown;
},
closed: (): CloseAction => {
crashCount++;
if (crashCount < 5) {
return CloseAction.Restart;
}
return CloseAction.DoNotRestart;
closed: (): CloseAction => {
crashCount++;
if (crashCount < 5) {
return CloseAction.Restart;
}
return CloseAction.DoNotRestart;
}
}
} as LanguageClientOptions;
if (!!config.silentOutput) {
clientOptions.outputChannel = noopOutputChannel('Arduino Language Server');
}
const serverOptions = {
command,
args,
options: { env },
};
return new LanguageClient(
'ino',
'Arduino Language Server',
serverOptions,
clientOptions
);
}

Expand All @@ -282,3 +288,15 @@ async function updateLaunchConfig(debugConfig: DebugConfig, launchConfig: object
await configuration.update('launch', launchConfig, false);
}
}

function noopOutputChannel(name: string): OutputChannel {
return {
append: () => {},
appendLine: () => {},
clear: () => {},
dispose: () => {},
hide: () => {},
show: () => {},
name
};
}