From 16031863ed9cdd5547e2741836ed132d4c21662d Mon Sep 17 00:00:00 2001 From: Alexey Date: Sun, 26 Feb 2017 09:54:34 +0300 Subject: [PATCH] Added `revealOutputChannelOn`. (#113) --- doc/rls_mode/main.md | 12 +++++ package.json | 22 ++++++++- .../configuration/configuration_manager.ts | 49 +++++++++++++++++-- src/components/language_client/creator.ts | 7 +-- src/components/language_client/manager.ts | 9 ++-- src/extension.ts | 9 ++-- 6 files changed, 91 insertions(+), 17 deletions(-) diff --git a/doc/rls_mode/main.md b/doc/rls_mode/main.md index ffb9977..79e1bd6 100644 --- a/doc/rls_mode/main.md +++ b/doc/rls_mode/main.md @@ -11,9 +11,21 @@ The type of the parameter is an object with the following fields: * `"executable"` - a string. The path to an executable to execute * `"args"` - an array of strings. Arguments to pass to the executable * `"env"` - an environment to append to the current environment to execute the executable +* `"revealOutputChannelOn"` - a string. Specifies the condition when the output channel should be revealed By default, it is `null`. +### The revealOutputChannelOn configuration parameter + +This determines when the Output channel is revealed. + +The possible values are: + +* `"info"` - revealed on each info line +* `"warn"` - revealed on each warn line +* `"error"` - revealed on each error line (default) +* `"never"` - the output channel never reveals automatically + ## Setting up First of all, you have to download the [RLS](https://github.com/rust-lang-nursery/rls) sources: diff --git a/package.json b/package.json index fd4c34e..e0fe861 100644 --- a/package.json +++ b/package.json @@ -434,11 +434,29 @@ "items": { "type": "string" }, - "type": "array" + "type": [ + "array", + "null" + ] }, "env": { "default": null, - "description": "An environment to run the executable in" + "description": "An environment to run the executable in", + "type": [ + "object", + "null" + ] + }, + "revealOutputChannelOn": { + "default": "error", + "description": "Specifies when the output channel should be revealed", + "enum": [ + "info", + "warn", + "error", + "never" + ], + "type": "string" } } } diff --git a/src/components/configuration/configuration_manager.ts b/src/components/configuration/configuration_manager.ts index 591c6bf..e083981 100644 --- a/src/components/configuration/configuration_manager.ts +++ b/src/components/configuration/configuration_manager.ts @@ -6,6 +6,8 @@ import { join } from 'path'; import { WorkspaceConfiguration, workspace } from 'vscode'; +import { RevealOutputChannelOn } from 'vscode-languageclient'; + import expandTilde = require('expand-tilde'); export interface RlsConfiguration { @@ -14,6 +16,8 @@ export interface RlsConfiguration { args?: string[]; env?: any; + + revealOutputChannelOn: RevealOutputChannelOn; } export enum ActionOnStartingCommandIfThereIsRunningCommand { @@ -35,17 +39,54 @@ export class ConfigurationManager { return new ConfigurationManager(rustcSysRoot, rustSourcePath); } - public getRlsConfiguration(): RlsConfiguration | null { + public getRlsConfiguration(): RlsConfiguration | undefined { const configuration = ConfigurationManager.getConfiguration(); - const rlsConfiguration: RlsConfiguration | null = configuration['rls']; + const rlsConfiguration: any | null = configuration['rls']; + + if (rlsConfiguration === null) { + return undefined; + } + + const executable: string = rlsConfiguration.executable; + const args: string[] | null = rlsConfiguration.args; + const env: any | null = rlsConfiguration.env; + const revealOutputChannelOn: string = rlsConfiguration.revealOutputChannelOn; + + let revealOutputChannelOnEnum: RevealOutputChannelOn; + + switch (revealOutputChannelOn) { + case 'info': + revealOutputChannelOnEnum = RevealOutputChannelOn.Info; + break; + + case 'warn': + revealOutputChannelOnEnum = RevealOutputChannelOn.Warn; + break; + + case 'error': + revealOutputChannelOnEnum = RevealOutputChannelOn.Error; + break; + + case 'never': + revealOutputChannelOnEnum = RevealOutputChannelOn.Never; + break; + + default: + revealOutputChannelOnEnum = RevealOutputChannelOn.Error; + } - return rlsConfiguration; + return { + executable, + args: args !== null ? args : undefined, + env: env !== null ? env : undefined, + revealOutputChannelOn: revealOutputChannelOnEnum + }; } public shouldExecuteCargoCommandInTerminal(): boolean { // When RLS is used any cargo command is executed in an integrated terminal. - if (this.getRlsConfiguration()) { + if (this.getRlsConfiguration() !== undefined) { return true; } diff --git a/src/components/language_client/creator.ts b/src/components/language_client/creator.ts index 72277e5..0286c5b 100644 --- a/src/components/language_client/creator.ts +++ b/src/components/language_client/creator.ts @@ -1,13 +1,14 @@ -import { LanguageClient, LanguageClientOptions as ClientOptions, ServerOptions } from 'vscode-languageclient'; +import { LanguageClient, LanguageClientOptions as ClientOptions, RevealOutputChannelOn, ServerOptions } from 'vscode-languageclient'; export class Creator { private clientOptions: ClientOptions; private serverOptions: ServerOptions; - public constructor(executable: string, args?: string[], env?: any) { + public constructor(executable: string, args: string[] | undefined, env: any | undefined, revealOutputChannelOn: RevealOutputChannelOn) { this.clientOptions = { documentSelector: ['rust'], + revealOutputChannelOn, synchronize: { configurationSection: 'languageServerExample' } @@ -15,7 +16,7 @@ export class Creator { this.serverOptions = { command: executable, - args: args, + args, options: { env: Object.assign({}, process.env, env ? env : {}) } diff --git a/src/components/language_client/manager.ts b/src/components/language_client/manager.ts index a8102d4..82897c8 100644 --- a/src/components/language_client/manager.ts +++ b/src/components/language_client/manager.ts @@ -1,6 +1,6 @@ import { ExtensionContext } from 'vscode'; -import { LanguageClient, State } from 'vscode-languageclient'; +import { LanguageClient, RevealOutputChannelOn, State } from 'vscode-languageclient'; import ChildLogger from '../logging/child_logger'; @@ -23,10 +23,11 @@ export class Manager { context: ExtensionContext, logger: ChildLogger, executable: string, - args?: string[], - env?: any + args: string[] | undefined, + env: any | undefined, + revealOutputChannelOn: RevealOutputChannelOn ) { - this.languageClientCreator = new LanguageClientCreator(executable, args, env); + this.languageClientCreator = new LanguageClientCreator(executable, args, env, revealOutputChannelOn); this.context = context; diff --git a/src/extension.ts b/src/extension.ts index 15cfab8..0ff2dfc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -23,7 +23,7 @@ export async function activate(ctx: ExtensionContext): Promise { const currentWorkingDirectoryManager = new CurrentWorkingDirectoryManager(); - const rlsConfiguration: RlsConfiguration | null = configurationManager.getRlsConfiguration(); + const rlsConfiguration: RlsConfiguration | undefined = configurationManager.getRlsConfiguration(); const cargoManager = new CargoManager( ctx, @@ -32,8 +32,8 @@ export async function activate(ctx: ExtensionContext): Promise { logger.createChildLogger('Cargo Manager: ') ); - if (rlsConfiguration) { - let { executable, args, env } = rlsConfiguration; + if (rlsConfiguration !== undefined) { + let { executable, args, env, revealOutputChannelOn } = rlsConfiguration; if (!env) { env = {}; @@ -48,7 +48,8 @@ export async function activate(ctx: ExtensionContext): Promise { logger.createChildLogger('Language Client Manager: '), executable, args, - env + env, + revealOutputChannelOn ); languageClientManager.start();