From 011e80f3d2a891f04bf42b72f2aed9f0f84931f1 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 20 Mar 2017 14:32:57 -0700 Subject: [PATCH 1/5] Add settings to disable automatic loading of extension and console This change adds two new settings to control the automatic loading of the PowerShell extension and integrated console: - `powershell.startAutomatically` - `powershell.integratedConsole.showOnStartup` Both of which default to `true`. Resolves #580. --- package.json | 10 ++++++++++ src/logging.ts | 15 ++++++++++----- src/main.ts | 6 +++++- src/session.ts | 9 ++++++--- src/settings.ts | 14 +++++++++++++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 065ff87eaf..bf0b68d064 100644 --- a/package.json +++ b/package.json @@ -305,6 +305,11 @@ "type": "object", "title": "PowerShell Configuration", "properties": { + "powershell.startAutomatically": { + "type": "boolean", + "default": true, + "description": "If true, causes PowerShell extension features to start automatically when a PowerShell file is opened. If false, the user must initiate startup using the 'PowerShell: Restart Current Session' command. IntelliSense, code navigation, integrated console, code formatting, and other features will not be enabled until the extension has been started." + }, "powershell.useX86Host": { "type": "boolean", "default": false, @@ -393,6 +398,11 @@ "type": "boolean", "default": true, "description": "Ignore blocks of code on one line. For example, if true, the braces in \"if (...) {...} else {...}\", will not be formatted." + }, + "powershell.integratedConsole.showOnStartup": { + "type": "boolean", + "default": true, + "description": "If true, causes the integrated console to be shown automatically when the PowerShell extension is initialized." } } } diff --git a/src/logging.ts b/src/logging.ts index fe79c3268a..02806cc4e7 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -49,13 +49,10 @@ export class Logger { public writeAtLevel(logLevel: LogLevel, message: string, ...additionalMessages: string[]) { if (logLevel >= this.MinimumLogLevel) { - // TODO: Add timestamp - this.logChannel.appendLine(message); - fs.appendFile(this.logFilePath, message + os.EOL); + this.writeLine(message) additionalMessages.forEach((line) => { - this.logChannel.appendLine(line); - fs.appendFile(this.logFilePath, line + os.EOL); + this.writeLine(message); }); } } @@ -138,6 +135,14 @@ export class Logger { true); } } + + private writeLine(message: string) { + // TODO: Add timestamp + this.logChannel.appendLine(message); + if (this.logFilePath) { + fs.appendFile(this.logFilePath, message + os.EOL); + } + } } export class LanguageClientLogger implements ILogger { diff --git a/src/main.ts b/src/main.ts index 564dd9c448..46f45cc30d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import vscode = require('vscode'); import utils = require('./utils'); +import Settings = require('./settings'); import { Logger, LogLevel } from './logging'; import { IFeature } from './feature'; import { SessionManager } from './session'; @@ -118,7 +119,10 @@ export function activate(context: vscode.ExtensionContext): void { logger, extensionFeatures); - sessionManager.start(); + var extensionSettings = Settings.load(utils.PowerShellLanguageId); + if (extensionSettings.startAutomatically) { + sessionManager.start(); + } } export function deactivate(): void { diff --git a/src/session.ts b/src/session.ts index f7808914e8..2d55ad9ded 100644 --- a/src/session.ts +++ b/src/session.ts @@ -99,13 +99,14 @@ export class SessionManager { this.hostVersion = this.hostVersion.split('-')[0]; this.registerCommands(); - this.createStatusBarItem(); } public start(sessionConfig: SessionConfiguration = { type: SessionType.UseDefault }) { this.sessionSettings = Settings.load(utils.PowerShellLanguageId); this.log.startNewLog(this.sessionSettings.developer.editorServicesLogLevel); + this.createStatusBarItem(); + this.sessionConfiguration = this.resolveSessionConfiguration(sessionConfig); if (this.sessionConfiguration.type === SessionType.UsePath || @@ -317,7 +318,9 @@ export class SessionManager { powerShellExePath, powerShellArgs); - this.consoleTerminal.show(); + if (this.sessionSettings.integratedConsole.showOnStartup) { + this.consoleTerminal.show(true); + } // Start the language client utils.waitForSessionFile( @@ -490,7 +493,7 @@ export class SessionManager { } private createStatusBarItem() { - if (this.statusBarItem == undefined) { + if (this.statusBarItem === undefined) { // Create the status bar item and place it right next // to the language indicator this.statusBarItem = diff --git a/src/settings.ts b/src/settings.ts index c18e60af22..f395fe159c 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -32,11 +32,17 @@ export interface IDeveloperSettings { } export interface ISettings { + startAutomatically?: boolean; useX86Host?: boolean; enableProfileLoading?: boolean; scriptAnalysis?: IScriptAnalysisSettings; developer?: IDeveloperSettings; codeFormatting?: ICodeFormattingSettings; + integratedConsole?: IIntegratedConsoleSettings; +} + +export interface IIntegratedConsoleSettings { + showOnStartup?: boolean; } export function load(myPluginId: string): ISettings { @@ -67,11 +73,17 @@ export function load(myPluginId: string): ISettings { ignoreOneLineBlock: true }; + let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = { + showOnStartup: true, + }; + return { + startAutomatically: configuration.get("startAutomatically", true), useX86Host: configuration.get("useX86Host", false), enableProfileLoading: configuration.get("enableProfileLoading", false), scriptAnalysis: configuration.get("scriptAnalysis", defaultScriptAnalysisSettings), developer: configuration.get("developer", defaultDeveloperSettings), - codeFormatting: configuration.get("codeFormatting", defaultCodeFormattingSettings) + codeFormatting: configuration.get("codeFormatting", defaultCodeFormattingSettings), + integratedConsole: configuration.get("integratedConsole", defaultIntegratedConsoleSettings) }; } From f8a1694114df10921df7082a7d4c648814a9ce90 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 20 Mar 2017 15:24:21 -0700 Subject: [PATCH 2/5] Add setting to determine console focus behavior on script execution This change adds a new setting that controls whether focus changes to the integrated console when scripts are executed or debugged: - `powershell.integratedConsole.focusConsoleOnExecute` When true, it causes the focus to get set to the console on any script execution. It is set to true by default to ensure that screen readers pick up the execution output once it starts. Resolves #588. --- package.json | 5 +++++ src/features/Console.ts | 2 +- src/features/DebugSession.ts | 2 +- src/session.ts | 12 +++++++++--- src/settings.ts | 2 ++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index bf0b68d064..095b10e670 100644 --- a/package.json +++ b/package.json @@ -403,6 +403,11 @@ "type": "boolean", "default": true, "description": "If true, causes the integrated console to be shown automatically when the PowerShell extension is initialized." + }, + "powershell.integratedConsole.focusConsoleOnExecute": { + "type": "boolean", + "default": true, + "description": "If true, causes the integrated console to be focused when a script selection is run or a script file is debugged." } } } diff --git a/src/features/Console.ts b/src/features/Console.ts index b8472b39c6..31f2298901 100644 --- a/src/features/Console.ts +++ b/src/features/Console.ts @@ -217,7 +217,7 @@ export class ConsoleFeature implements IFeature { }); // Show the integrated console if it isn't already visible - vscode.commands.executeCommand("PowerShell.ShowSessionConsole"); + vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true); }) ]; } diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 25ff001a38..5dd183a254 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -63,7 +63,7 @@ export class DebugSessionFeature implements IFeature { // Create or show the interactive console // TODO #367: Check if "newSession" mode is configured - vscode.commands.executeCommand('PowerShell.ShowSessionConsole'); + vscode.commands.executeCommand('PowerShell.ShowSessionConsole', true); vscode.commands.executeCommand('vscode.startDebug', config); } diff --git a/src/session.ts b/src/session.ts index 2d55ad9ded..b1be15fc09 100644 --- a/src/session.ts +++ b/src/session.ts @@ -64,6 +64,7 @@ export class SessionManager { private hostVersion: string; private isWindowsOS: boolean; private sessionStatus: SessionStatus; + private focusConsoleOnExecute: boolean; private statusBarItem: vscode.StatusBarItem; private sessionConfiguration: SessionConfiguration; private versionDetails: PowerShellVersionDetails; @@ -105,6 +106,8 @@ export class SessionManager { this.sessionSettings = Settings.load(utils.PowerShellLanguageId); this.log.startNewLog(this.sessionSettings.developer.editorServicesLogLevel); + this.focusConsoleOnExecute = this.sessionSettings.integratedConsole.focusConsoleOnExecute; + this.createStatusBarItem(); this.sessionConfiguration = this.resolveSessionConfiguration(sessionConfig); @@ -206,6 +209,8 @@ export class SessionManager { private onConfigurationUpdated() { var settings = Settings.load(utils.PowerShellLanguageId); + this.focusConsoleOnExecute = settings.integratedConsole.focusConsoleOnExecute; + // Detect any setting changes that would affect the session if (settings.useX86Host !== this.sessionSettings.useX86Host || settings.developer.powerShellExePath.toLowerCase() !== this.sessionSettings.developer.powerShellExePath.toLowerCase() || @@ -245,7 +250,7 @@ export class SessionManager { vscode.commands.registerCommand('PowerShell.RestartSession', () => { this.restartSession(); }), vscode.commands.registerCommand(this.ShowSessionMenuCommandName, () => { this.showSessionMenu(); }), vscode.workspace.onDidChangeConfiguration(() => this.onConfigurationUpdated()), - vscode.commands.registerCommand('PowerShell.ShowSessionConsole', () => { this.showSessionConsole(); }) + vscode.commands.registerCommand('PowerShell.ShowSessionConsole', (isExecute?: boolean) => { this.showSessionConsole(isExecute); }) ] } @@ -629,9 +634,10 @@ export class SessionManager { return resolvedPath; } - private showSessionConsole() { + private showSessionConsole(isExecute?: boolean) { if (this.consoleTerminal) { - this.consoleTerminal.show(true); + this.consoleTerminal.show( + isExecute && !this.focusConsoleOnExecute); } } diff --git a/src/settings.ts b/src/settings.ts index f395fe159c..68501c5317 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -43,6 +43,7 @@ export interface ISettings { export interface IIntegratedConsoleSettings { showOnStartup?: boolean; + focusConsoleOnExecute?: boolean; } export function load(myPluginId: string): ISettings { @@ -75,6 +76,7 @@ export function load(myPluginId: string): ISettings { let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = { showOnStartup: true, + focusConsoleOnExecute: true }; return { From 9a61d1a9d25a766e5299d47f01e5c76b63baf3d7 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 20 Mar 2017 15:29:45 -0700 Subject: [PATCH 3/5] Rename show console command to 'Show Integrated Console' --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 095b10e670..196c7f583c 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ }, { "command": "PowerShell.ShowSessionConsole", - "title": "Show Session Interactive Console", + "title": "Show Integrated Console", "category": "PowerShell" }, { From a4d1e43194b318f0f19da29739fbde9b0af73cce Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 20 Mar 2017 15:36:26 -0700 Subject: [PATCH 4/5] Add .NET CLI configuration to appveyor.yml This change adds a couple of environment variables to the appveyor.yml to speed up builds of PowerShell Editor Services by disabling package caching and telemetry. --- appveyor.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 59944faefe..5fc9f45686 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,6 +8,10 @@ branches: - master - develop +environment: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Don't download unneeded packages + DOTNET_CLI_TELEMETRY_OPTOUT: true # Don't send telemetry + install: - git clone https://github.com/PowerShell/PowerShellEditorServices.git ../PowerShellEditorServices - ps: Install-Product node '6.9.2' From 91c5e2fcd22435ca1a081a8102a37e002b458bb5 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 20 Mar 2017 15:38:28 -0700 Subject: [PATCH 5/5] Update appveyor.yml to Visual Studio 2017 image --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 5fc9f45686..7ae3974ee0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ version: '0.10.1-insiders-{build}' -image: Visual Studio 2017 RC +image: Visual Studio 2017 clone_depth: 10 skip_tags: true