Skip to content

Commit 10395d7

Browse files
authored
Merge pull request PowerShell#590 from daviwil/console-settings
Add new integrated console settings
2 parents c594ccd + 91c5e2f commit 10395d7

File tree

8 files changed

+68
-17
lines changed

8 files changed

+68
-17
lines changed

appveyor.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version: '0.10.1-insiders-{build}'
2-
image: Visual Studio 2017 RC
2+
image: Visual Studio 2017
33
clone_depth: 10
44
skip_tags: true
55

@@ -8,6 +8,10 @@ branches:
88
- master
99
- develop
1010

11+
environment:
12+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Don't download unneeded packages
13+
DOTNET_CLI_TELEMETRY_OPTOUT: true # Don't send telemetry
14+
1115
install:
1216
- git clone https://github.com/PowerShell/PowerShellEditorServices.git ../PowerShellEditorServices
1317
- ps: Install-Product node '6.9.2'

package.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
},
136136
{
137137
"command": "PowerShell.ShowSessionConsole",
138-
"title": "Show Session Interactive Console",
138+
"title": "Show Integrated Console",
139139
"category": "PowerShell"
140140
},
141141
{
@@ -305,6 +305,11 @@
305305
"type": "object",
306306
"title": "PowerShell Configuration",
307307
"properties": {
308+
"powershell.startAutomatically": {
309+
"type": "boolean",
310+
"default": true,
311+
"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."
312+
},
308313
"powershell.useX86Host": {
309314
"type": "boolean",
310315
"default": false,
@@ -393,6 +398,16 @@
393398
"type": "boolean",
394399
"default": true,
395400
"description": "Ignore blocks of code on one line. For example, if true, the braces in \"if (...) {...} else {...}\", will not be formatted."
401+
},
402+
"powershell.integratedConsole.showOnStartup": {
403+
"type": "boolean",
404+
"default": true,
405+
"description": "If true, causes the integrated console to be shown automatically when the PowerShell extension is initialized."
406+
},
407+
"powershell.integratedConsole.focusConsoleOnExecute": {
408+
"type": "boolean",
409+
"default": true,
410+
"description": "If true, causes the integrated console to be focused when a script selection is run or a script file is debugged."
396411
}
397412
}
398413
}

src/features/Console.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class ConsoleFeature implements IFeature {
217217
});
218218

219219
// Show the integrated console if it isn't already visible
220-
vscode.commands.executeCommand("PowerShell.ShowSessionConsole");
220+
vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
221221
})
222222
];
223223
}

src/features/DebugSession.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class DebugSessionFeature implements IFeature {
6363

6464
// Create or show the interactive console
6565
// TODO #367: Check if "newSession" mode is configured
66-
vscode.commands.executeCommand('PowerShell.ShowSessionConsole');
66+
vscode.commands.executeCommand('PowerShell.ShowSessionConsole', true);
6767

6868
vscode.commands.executeCommand('vscode.startDebug', config);
6969
}

src/logging.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,10 @@ export class Logger {
4949

5050
public writeAtLevel(logLevel: LogLevel, message: string, ...additionalMessages: string[]) {
5151
if (logLevel >= this.MinimumLogLevel) {
52-
// TODO: Add timestamp
53-
this.logChannel.appendLine(message);
54-
fs.appendFile(this.logFilePath, message + os.EOL);
52+
this.writeLine(message)
5553

5654
additionalMessages.forEach((line) => {
57-
this.logChannel.appendLine(line);
58-
fs.appendFile(this.logFilePath, line + os.EOL);
55+
this.writeLine(message);
5956
});
6057
}
6158
}
@@ -138,6 +135,14 @@ export class Logger {
138135
true);
139136
}
140137
}
138+
139+
private writeLine(message: string) {
140+
// TODO: Add timestamp
141+
this.logChannel.appendLine(message);
142+
if (this.logFilePath) {
143+
fs.appendFile(this.logFilePath, message + os.EOL);
144+
}
145+
}
141146
}
142147

143148
export class LanguageClientLogger implements ILogger {

src/main.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import vscode = require('vscode');
88
import utils = require('./utils');
9+
import Settings = require('./settings');
910
import { Logger, LogLevel } from './logging';
1011
import { IFeature } from './feature';
1112
import { SessionManager } from './session';
@@ -118,7 +119,10 @@ export function activate(context: vscode.ExtensionContext): void {
118119
logger,
119120
extensionFeatures);
120121

121-
sessionManager.start();
122+
var extensionSettings = Settings.load(utils.PowerShellLanguageId);
123+
if (extensionSettings.startAutomatically) {
124+
sessionManager.start();
125+
}
122126
}
123127

124128
export function deactivate(): void {

src/session.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export class SessionManager {
6464
private hostVersion: string;
6565
private isWindowsOS: boolean;
6666
private sessionStatus: SessionStatus;
67+
private focusConsoleOnExecute: boolean;
6768
private statusBarItem: vscode.StatusBarItem;
6869
private sessionConfiguration: SessionConfiguration;
6970
private versionDetails: PowerShellVersionDetails;
@@ -99,13 +100,16 @@ export class SessionManager {
99100
this.hostVersion = this.hostVersion.split('-')[0];
100101

101102
this.registerCommands();
102-
this.createStatusBarItem();
103103
}
104104

105105
public start(sessionConfig: SessionConfiguration = { type: SessionType.UseDefault }) {
106106
this.sessionSettings = Settings.load(utils.PowerShellLanguageId);
107107
this.log.startNewLog(this.sessionSettings.developer.editorServicesLogLevel);
108108

109+
this.focusConsoleOnExecute = this.sessionSettings.integratedConsole.focusConsoleOnExecute;
110+
111+
this.createStatusBarItem();
112+
109113
this.sessionConfiguration = this.resolveSessionConfiguration(sessionConfig);
110114

111115
if (this.sessionConfiguration.type === SessionType.UsePath ||
@@ -205,6 +209,8 @@ export class SessionManager {
205209
private onConfigurationUpdated() {
206210
var settings = Settings.load(utils.PowerShellLanguageId);
207211

212+
this.focusConsoleOnExecute = settings.integratedConsole.focusConsoleOnExecute;
213+
208214
// Detect any setting changes that would affect the session
209215
if (settings.useX86Host !== this.sessionSettings.useX86Host ||
210216
settings.developer.powerShellExePath.toLowerCase() !== this.sessionSettings.developer.powerShellExePath.toLowerCase() ||
@@ -244,7 +250,7 @@ export class SessionManager {
244250
vscode.commands.registerCommand('PowerShell.RestartSession', () => { this.restartSession(); }),
245251
vscode.commands.registerCommand(this.ShowSessionMenuCommandName, () => { this.showSessionMenu(); }),
246252
vscode.workspace.onDidChangeConfiguration(() => this.onConfigurationUpdated()),
247-
vscode.commands.registerCommand('PowerShell.ShowSessionConsole', () => { this.showSessionConsole(); })
253+
vscode.commands.registerCommand('PowerShell.ShowSessionConsole', (isExecute?: boolean) => { this.showSessionConsole(isExecute); })
248254
]
249255
}
250256

@@ -317,7 +323,9 @@ export class SessionManager {
317323
powerShellExePath,
318324
powerShellArgs);
319325

320-
this.consoleTerminal.show();
326+
if (this.sessionSettings.integratedConsole.showOnStartup) {
327+
this.consoleTerminal.show(true);
328+
}
321329

322330
// Start the language client
323331
utils.waitForSessionFile(
@@ -490,7 +498,7 @@ export class SessionManager {
490498
}
491499

492500
private createStatusBarItem() {
493-
if (this.statusBarItem == undefined) {
501+
if (this.statusBarItem === undefined) {
494502
// Create the status bar item and place it right next
495503
// to the language indicator
496504
this.statusBarItem =
@@ -626,9 +634,10 @@ export class SessionManager {
626634
return resolvedPath;
627635
}
628636

629-
private showSessionConsole() {
637+
private showSessionConsole(isExecute?: boolean) {
630638
if (this.consoleTerminal) {
631-
this.consoleTerminal.show(true);
639+
this.consoleTerminal.show(
640+
isExecute && !this.focusConsoleOnExecute);
632641
}
633642
}
634643

src/settings.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ export interface IDeveloperSettings {
3232
}
3333

3434
export interface ISettings {
35+
startAutomatically?: boolean;
3536
useX86Host?: boolean;
3637
enableProfileLoading?: boolean;
3738
scriptAnalysis?: IScriptAnalysisSettings;
3839
developer?: IDeveloperSettings;
3940
codeFormatting?: ICodeFormattingSettings;
41+
integratedConsole?: IIntegratedConsoleSettings;
42+
}
43+
44+
export interface IIntegratedConsoleSettings {
45+
showOnStartup?: boolean;
46+
focusConsoleOnExecute?: boolean;
4047
}
4148

4249
export function load(myPluginId: string): ISettings {
@@ -67,11 +74,18 @@ export function load(myPluginId: string): ISettings {
6774
ignoreOneLineBlock: true
6875
};
6976

77+
let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = {
78+
showOnStartup: true,
79+
focusConsoleOnExecute: true
80+
};
81+
7082
return {
83+
startAutomatically: configuration.get<boolean>("startAutomatically", true),
7184
useX86Host: configuration.get<boolean>("useX86Host", false),
7285
enableProfileLoading: configuration.get<boolean>("enableProfileLoading", false),
7386
scriptAnalysis: configuration.get<IScriptAnalysisSettings>("scriptAnalysis", defaultScriptAnalysisSettings),
7487
developer: configuration.get<IDeveloperSettings>("developer", defaultDeveloperSettings),
75-
codeFormatting: configuration.get<ICodeFormattingSettings>("codeFormatting", defaultCodeFormattingSettings)
88+
codeFormatting: configuration.get<ICodeFormattingSettings>("codeFormatting", defaultCodeFormattingSettings),
89+
integratedConsole: configuration.get<IIntegratedConsoleSettings>("integratedConsole", defaultIntegratedConsoleSettings)
7690
};
7791
}

0 commit comments

Comments
 (0)