Skip to content

Commit 011e80f

Browse files
committed
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.
1 parent c594ccd commit 011e80f

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -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,11 @@
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."
396406
}
397407
}
398408
}

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ export class SessionManager {
9999
this.hostVersion = this.hostVersion.split('-')[0];
100100

101101
this.registerCommands();
102-
this.createStatusBarItem();
103102
}
104103

105104
public start(sessionConfig: SessionConfiguration = { type: SessionType.UseDefault }) {
106105
this.sessionSettings = Settings.load(utils.PowerShellLanguageId);
107106
this.log.startNewLog(this.sessionSettings.developer.editorServicesLogLevel);
108107

108+
this.createStatusBarItem();
109+
109110
this.sessionConfiguration = this.resolveSessionConfiguration(sessionConfig);
110111

111112
if (this.sessionConfiguration.type === SessionType.UsePath ||
@@ -317,7 +318,9 @@ export class SessionManager {
317318
powerShellExePath,
318319
powerShellArgs);
319320

320-
this.consoleTerminal.show();
321+
if (this.sessionSettings.integratedConsole.showOnStartup) {
322+
this.consoleTerminal.show(true);
323+
}
321324

322325
// Start the language client
323326
utils.waitForSessionFile(
@@ -490,7 +493,7 @@ export class SessionManager {
490493
}
491494

492495
private createStatusBarItem() {
493-
if (this.statusBarItem == undefined) {
496+
if (this.statusBarItem === undefined) {
494497
// Create the status bar item and place it right next
495498
// to the language indicator
496499
this.statusBarItem =

src/settings.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ 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;
4046
}
4147

4248
export function load(myPluginId: string): ISettings {
@@ -67,11 +73,17 @@ export function load(myPluginId: string): ISettings {
6773
ignoreOneLineBlock: true
6874
};
6975

76+
let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = {
77+
showOnStartup: true,
78+
};
79+
7080
return {
81+
startAutomatically: configuration.get<boolean>("startAutomatically", true),
7182
useX86Host: configuration.get<boolean>("useX86Host", false),
7283
enableProfileLoading: configuration.get<boolean>("enableProfileLoading", false),
7384
scriptAnalysis: configuration.get<IScriptAnalysisSettings>("scriptAnalysis", defaultScriptAnalysisSettings),
7485
developer: configuration.get<IDeveloperSettings>("developer", defaultDeveloperSettings),
75-
codeFormatting: configuration.get<ICodeFormattingSettings>("codeFormatting", defaultCodeFormattingSettings)
86+
codeFormatting: configuration.get<ICodeFormattingSettings>("codeFormatting", defaultCodeFormattingSettings),
87+
integratedConsole: configuration.get<IIntegratedConsoleSettings>("integratedConsole", defaultIntegratedConsoleSettings)
7688
};
7789
}

0 commit comments

Comments
 (0)