Skip to content

Improve PowerShell session management, status reporting, and logging #350

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

Merged
merged 4 commits into from
Dec 1, 2016
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ out/
node_modules/
logs/
modules/*
sessions/*
!modules/README.md
vscode-powershell.zip
vscps-preview.zip
*.vsix
*.vsix
npm-debug.log
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"editor.insertSpaces": true,

// When enabled, will trim trailing whitespace when you save a file.
"files.trimTrailingWhitespace": true
"files.trimTrailingWhitespace": true,

// Lock the TypeScript SDK path to the version we use
"typescript.tsdk": "./node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ bin/EditorServices.log
bin/DebugAdapter.log
bin/*.vshost.*
logs/**

sessions/**
2 changes: 1 addition & 1 deletion examples/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"cwd": "${file}"
}
]
}
}
33 changes: 27 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"publisher": "ms-vscode",
"description": "Develop PowerShell scripts in Visual Studio Code!",
"engines": {
"vscode": "1.x.x"
"vscode": "^1.7.0"
},
"license": "SEE LICENSE IN LICENSE.txt",
"homepage": "https://github.com/PowerShell/vscode-powershell/blob/master/README.md",
Expand All @@ -32,16 +32,17 @@
"vscode-languageclient": "1.3.1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it missing "vscode-jsonrpc" ? I cannot compile it without adding "vscode-jsonrpc" as a dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that shouldn't be the case, I'll come by your office later to take a look.

},
"devDependencies": {
"vscode": "^0.11.12",
"typescript": "^1.8.0"
"vscode": "^1.0.0",
"typescript": "^2.0.3",
"@types/node": "^6.0.40"
},
"extensionDependencies": [
"vscode.powershell"
],
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -p ./",
"compile-watch": "node ./node_modules/vscode/bin/compile -watch -p ./",
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -p ./",
"compile-watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"contributes": {
Expand Down Expand Up @@ -88,6 +89,21 @@
"title": "Run selection",
"category": "PowerShell"
},
{
"command": "PowerShell.RestartSession",
"title": "Restart Current Session",
"category": "PowerShell"
},
{
"command": "PowerShell.ShowLogs",
"title": "Show PowerShell Extension Logs",
"category": "PowerShell"
},
{
"command": "PowerShell.OpenLogFolder",
"title": "Open PowerShell Extension Logs Folder",
"category": "PowerShell"
},
{
"command": "PowerShell.OpenInISE",
"title": "Open current file in PowerShell ISE",
Expand All @@ -102,6 +118,11 @@
"command": "PowerShell.ShowAdditionalCommands",
"title": "Show additional commands from PowerShell modules",
"category": "PowerShell"
},
{
"command": "PowerShell.ShowSessionMenu",
"title": "Show Session Menu",
"category": "PowerShell"
}
],
"snippets": [
Expand Down
7 changes: 7 additions & 0 deletions scripts/Start-EditorServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ param(
# Are we running in PowerShell 5 or later?
$isPS5orLater = $PSVersionTable.PSVersion.Major -ge 5

# If PSReadline is present in the session, remove it so that runspace
# management is easier
if ((Get-Module PSReadline).Count -ne 0) {
Remove-Module PSReadline
}

# This variable will be assigned later to contain information about
# what happened while attempting to launch the PowerShell Editor
# Services host
Expand Down Expand Up @@ -161,6 +167,7 @@ else {
$languageServicePort = Get-AvailablePort
$debugServicePort = Get-AvailablePort

# Create the Editor Services host
$editorServicesHost =
Start-EditorServicesHost `
-HostName $HostName `
Expand Down
9 changes: 6 additions & 3 deletions src/debugAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import fs = require('fs');
import path = require('path');
import net = require('net');
import utils = require('./utils');
import logging = require('./logging');
import { Logger } from './logging';

// NOTE: The purpose of this file is to serve as a bridge between
// VS Code's debug adapter client (which communicates via stdio) and
Expand All @@ -11,13 +15,12 @@ import logging = require('./logging');
// relay between the two transports.

var logBasePath = path.resolve(__dirname, "../logs");
utils.ensurePathExists(logBasePath);

var debugAdapterLogWriter =
fs.createWriteStream(
path.resolve(
logBasePath,
logging.getLogName("DebugAdapterClient")));
"DebugAdapter.log"));

// Pause the stdin buffer until we're connected to the
// debug server
Expand Down
12 changes: 12 additions & 0 deletions src/feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import vscode = require('vscode');
import { LanguageClient } from 'vscode-languageclient';
export { LanguageClient } from 'vscode-languageclient';

export interface IFeature extends vscode.Disposable {
setLanguageClient(languageclient: LanguageClient);
dispose();
}
93 changes: 60 additions & 33 deletions src/features/Console.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import vscode = require('vscode');
import { IFeature } from '../feature';
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';

export namespace EvaluateRequest {
Expand Down Expand Up @@ -138,44 +143,66 @@ function onInputEntered(responseText: string): ShowInputPromptResponseBody {
}
}

export function registerConsoleCommands(client: LanguageClient): void {
export class ConsoleFeature implements IFeature {
private command: vscode.Disposable;
private languageClient: LanguageClient;
private consoleChannel: vscode.OutputChannel;

constructor() {
this.command =
vscode.commands.registerCommand('PowerShell.RunSelection', () => {
if (this.languageClient === undefined) {
// TODO: Log error message
return;
}

var editor = vscode.window.activeTextEditor;
var selectionRange: vscode.Range = undefined;

if (!editor.selection.isEmpty) {
selectionRange =
new vscode.Range(
editor.selection.start,
editor.selection.end);
}
else {
selectionRange = editor.document.lineAt(editor.selection.start.line).range;
}

this.languageClient.sendRequest(EvaluateRequest.type, {
expression: editor.document.getText(selectionRange)
});
});

this.consoleChannel = vscode.window.createOutputChannel("PowerShell Output");
}

vscode.commands.registerCommand('PowerShell.RunSelection', () => {
var editor = vscode.window.activeTextEditor;
var selectionRange: vscode.Range = undefined;
public setLanguageClient(languageClient: LanguageClient) {
this.languageClient = languageClient;

if (!editor.selection.isEmpty) {
selectionRange =
new vscode.Range(
editor.selection.start,
editor.selection.end);
}
else {
selectionRange = editor.document.lineAt(editor.selection.start.line).range;
}
this.languageClient.onRequest(
ShowChoicePromptRequest.type,
promptDetails => showChoicePrompt(promptDetails, this.languageClient));

client.sendRequest(EvaluateRequest.type, {
expression: editor.document.getText(selectionRange)
});
});
this.languageClient.onRequest(
ShowInputPromptRequest.type,
promptDetails => showInputPrompt(promptDetails, this.languageClient));

var consoleChannel = vscode.window.createOutputChannel("PowerShell Output");
client.onNotification(OutputNotification.type, (output) => {
var outputEditorExist = vscode.window.visibleTextEditors.some((editor) => {
return editor.document.languageId == 'Log'
});
if (!outputEditorExist)
consoleChannel.show(vscode.ViewColumn.Three);
consoleChannel.append(output.output);
});
this.languageClient.onNotification(OutputNotification.type, (output) => {
var outputEditorExist = vscode.window.visibleTextEditors.some((editor) => {
return editor.document.languageId == 'Log'
});

var t: Thenable<ShowChoicePromptResponseBody>;
if (!outputEditorExist) {
this.consoleChannel.show(vscode.ViewColumn.Three);
}

client.onRequest(
ShowChoicePromptRequest.type,
promptDetails => showChoicePrompt(promptDetails, client));
this.consoleChannel.append(output.output);
});
}

client.onRequest(
ShowInputPromptRequest.type,
promptDetails => showInputPrompt(promptDetails, client));
public dispose() {
this.command.dispose();
this.consoleChannel.dispose();
}
}
76 changes: 49 additions & 27 deletions src/features/ExpandAlias.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import vscode = require('vscode');
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
import Window = vscode.window;
import { IFeature } from '../feature';
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';

export namespace ExpandAliasRequest {
export const type: RequestType<string, any, void> = { get method() { return 'powerShell/expandAlias'; } };
}

export function registerExpandAliasCommand(client: LanguageClient): void {
var disposable = vscode.commands.registerCommand('PowerShell.ExpandAlias', () => {

var editor = Window.activeTextEditor;
var document = editor.document;
var selection = editor.selection;
var text, range;

var sls = selection.start;
var sle = selection.end;

if (
(sls.character === sle.character) &&
(sls.line === sle.line)
) {
text = document.getText();
range = new vscode.Range(0, 0, document.lineCount, text.length);
} else {
text = document.getText(selection);
range = new vscode.Range(sls.line, sls.character, sle.line, sle.character);
}

client.sendRequest(ExpandAliasRequest.type, text).then((result) => {
editor.edit((editBuilder) => {
editBuilder.replace(range, result);
export class ExpandAliasFeature implements IFeature {
private command: vscode.Disposable;
private languageClient: LanguageClient;

constructor() {
this.command = vscode.commands.registerCommand('PowerShell.ExpandAlias', () => {
if (this.languageClient === undefined) {
// TODO: Log error message
return;
}

var editor = Window.activeTextEditor;
var document = editor.document;
var selection = editor.selection;
var text, range;

var sls = selection.start;
var sle = selection.end;

if (
(sls.character === sle.character) &&
(sls.line === sle.line)
) {
text = document.getText();
range = new vscode.Range(0, 0, document.lineCount, text.length);
} else {
text = document.getText(selection);
range = new vscode.Range(sls.line, sls.character, sle.line, sle.character);
}

this.languageClient.sendRequest(ExpandAliasRequest.type, text).then((result) => {
editor.edit((editBuilder) => {
editBuilder.replace(range, result);
});
});
});
});
}

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}

public dispose() {
this.command.dispose();
}
}
Loading