Skip to content
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

Add new integrated console settings #590

Merged
merged 5 commits into from
Mar 20, 2017
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
6 changes: 5 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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'
Expand Down
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
},
{
"command": "PowerShell.ShowSessionConsole",
"title": "Show Session Interactive Console",
"title": "Show Integrated Console",
"category": "PowerShell"
},
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -393,6 +398,16 @@
"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."
},
"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."
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 10 additions & 5 deletions src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 15 additions & 6 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,13 +100,16 @@ 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.focusConsoleOnExecute = this.sessionSettings.integratedConsole.focusConsoleOnExecute;

this.createStatusBarItem();

this.sessionConfiguration = this.resolveSessionConfiguration(sessionConfig);

if (this.sessionConfiguration.type === SessionType.UsePath ||
Expand Down Expand Up @@ -205,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() ||
Expand Down Expand Up @@ -244,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); })
]
}

Expand Down Expand Up @@ -317,7 +323,9 @@ export class SessionManager {
powerShellExePath,
powerShellArgs);

this.consoleTerminal.show();
if (this.sessionSettings.integratedConsole.showOnStartup) {
this.consoleTerminal.show(true);
}

// Start the language client
utils.waitForSessionFile(
Expand Down Expand Up @@ -490,7 +498,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 =
Expand Down Expand Up @@ -626,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);
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ 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;
focusConsoleOnExecute?: boolean;
}

export function load(myPluginId: string): ISettings {
Expand Down Expand Up @@ -67,11 +74,18 @@ export function load(myPluginId: string): ISettings {
ignoreOneLineBlock: true
};

let defaultIntegratedConsoleSettings: IIntegratedConsoleSettings = {
showOnStartup: true,
focusConsoleOnExecute: true
};

return {
startAutomatically: configuration.get<boolean>("startAutomatically", true),
useX86Host: configuration.get<boolean>("useX86Host", false),
enableProfileLoading: configuration.get<boolean>("enableProfileLoading", false),
scriptAnalysis: configuration.get<IScriptAnalysisSettings>("scriptAnalysis", defaultScriptAnalysisSettings),
developer: configuration.get<IDeveloperSettings>("developer", defaultDeveloperSettings),
codeFormatting: configuration.get<ICodeFormattingSettings>("codeFormatting", defaultCodeFormattingSettings)
codeFormatting: configuration.get<ICodeFormattingSettings>("codeFormatting", defaultCodeFormattingSettings),
integratedConsole: configuration.get<IIntegratedConsoleSettings>("integratedConsole", defaultIntegratedConsoleSettings)
};
}