Skip to content

Add new "attach" and "interactive" debugging configurations #423

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
Jan 10, 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
1 change: 1 addition & 0 deletions examples/PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'PSReservedParams',
'PSShouldProcess',
'PSUseApprovedVerbs',
'PSAvoidUsingAliases',
'PSUseDeclaredVarsMoreThanAssigments')

# Do not analyze the following rules. Use ExcludeRules when you have
Expand Down
58 changes: 52 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@

"configurationSnippets": [
{
"label": "PowerShell: Launch Current File Configuration",
"label": "PowerShell: Launch Current Script Configuration",
"description": "A new configuration for launching the current opened PowerShell script",
"body": {
"type": "PowerShell",
Expand All @@ -172,7 +172,7 @@
}
},
{
"label": "PowerShell: Launch Configuration",
"label": "PowerShell: Launch Script Configuration",
"description": "A new configuration for launching a PowerShell script",
"body": {
"type": "PowerShell",
Expand All @@ -182,22 +182,39 @@
"args": [],
"cwd": "^\"\\${workspaceRoot}\""
}
},
{
"label": "PowerShell: Attach to PowerShell Process Configuration",
"description": "A new configuration for debugging a runspace in another process.",
"body": {
"type": "PowerShell",
"request": "attach",
"name": "PowerShell Attach to Process",
"processId": "${ProcessId}",
"runspaceId": "1"
}
},
{
"label": "PowerShell: Launch Interactive Session Configuration",
"description": "A new configuration for debugging an interactive session.",
"body": {
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Interactive Session"
}
}
],

"configurationAttributes": {
"launch": {
"required": [
"script"
],
"properties": {
"program": {
"type": "string",
"description": "Deprecated. Please use the 'script' property instead to specify the absolute path to the PowerShell script to launch under the debugger."
},
"script": {
"type": "string",
"description": "Absolute path to the PowerShell script to launch under the debugger."
"description": "Optional: Absolute path to the PowerShell script to launch under the debugger."
},
"args": {
"type": "array",
Expand All @@ -213,6 +230,23 @@
"default": "${workspaceRoot}"
}
}
},
"attach": {
"properties": {
"computerName": {
"type": "string",
"description": "Optional: The computer name to which a remote session will be established. Works only on PowerShell 4 and above."
},
"processId": {
"type": "number",
"description": "The ID of the process to be attached. Works only on PowerShell 5 and above."
},
"runspaceId": {
"type": "number",
"description": "Optional: The ID of the runspace to debug in the attached process. Defaults to 1. Works only on PowerShell 5 and above.",
"default": 1
}
}
}
},
"initialConfigurations": [
Expand All @@ -223,6 +257,18 @@
"script": "${file}",
"args": [],
"cwd": "${file}"
},
{
"type": "PowerShell",
"request": "attach",
"name": "PowerShell Attach",
"processId": "12345"
},
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Interactive Session",
"cwd": "${workspaceRoot}"
}
]
}
Expand Down
40 changes: 40 additions & 0 deletions src/features/ExtensionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export namespace OpenFileRequest {
{ get method() { return 'editor/openFile'; } };
}

export namespace CloseFileRequest {
export const type: RequestType<string, EditorOperationResponse, void> =
{ get method() { return 'editor/closeFile'; } };
}

export namespace ShowErrorMessageRequest {
export const type: RequestType<string, EditorOperationResponse, void> =
{ get method() { return 'editor/showErrorMessage'; } };
Expand Down Expand Up @@ -198,6 +203,10 @@ export class ExtensionCommandsFeature implements IFeature {
OpenFileRequest.type,
filePath => this.openFile(filePath));

this.languageClient.onRequest(
CloseFileRequest.type,
filePath => this.closeFile(filePath));

this.languageClient.onRequest(
ShowInformationMessageRequest.type,
message => this.showInformationMessage(message));
Expand Down Expand Up @@ -317,6 +326,37 @@ export class ExtensionCommandsFeature implements IFeature {
return promise;
}

private closeFile(filePath: string): Thenable<EditorOperationResponse> {

var promise: Thenable<EditorOperationResponse>;

// Make sure the file path is absolute
if (!path.win32.isAbsolute(filePath))
{
filePath = path.win32.resolve(
vscode.workspace.rootPath,
filePath);
}

// Normalize file path case for comparison
var normalizedFilePath = filePath.toLowerCase();

if (vscode.workspace.textDocuments.find(doc => doc.fileName.toLowerCase() == normalizedFilePath))
{
promise =
vscode.workspace.openTextDocument(filePath)
.then(doc => vscode.window.showTextDocument(doc))
.then(editor => vscode.commands.executeCommand("workbench.action.closeActiveEditor"))
.then(_ => EditorOperationResponse.Completed);
}
else
{
promise = Promise.resolve(EditorOperationResponse.Completed);
}

return promise;
}

private setSelection(details: SetSelectionRequestArguments): EditorOperationResponse {
vscode.window.activeTextEditor.selections = [
new vscode.Selection(
Expand Down
38 changes: 38 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ export class SessionManager {
}
}

private setStatusBarVersionString(
runspaceDetails: RunspaceDetails) {

var versionString =
this.versionDetails.architecture === "x86"
? `${runspaceDetails.powerShellVersion.displayVersion} (${runspaceDetails.powerShellVersion.architecture})`
: runspaceDetails.powerShellVersion.displayVersion;

if (runspaceDetails.runspaceType != RunspaceType.Local) {
versionString += ` [${runspaceDetails.connectionString}]`
}

this.setSessionStatus(
versionString,
SessionStatus.Running);
}

private registerCommands() : void {
this.registeredCommands = [
vscode.commands.registerCommand('PowerShell.RestartSession', () => { this.restartSession(); }),
Expand Down Expand Up @@ -365,6 +382,10 @@ export class SessionManager {
this.setSessionFailure("Could not start language service: ", reason);
});

this.languageServerClient.onNotification(
RunspaceChangedEvent.type,
(runspaceDetails) => { this.setStatusBarVersionString(runspaceDetails); });

this.languageServerClient.start();
}
catch (e)
Expand Down Expand Up @@ -623,3 +644,20 @@ export interface PowerShellVersionDetails {
edition: string;
architecture: string;
}

export enum RunspaceType {
Local,
Process,
Remote
}

export interface RunspaceDetails {
powerShellVersion: PowerShellVersionDetails;
runspaceType: RunspaceType;
connectionString: string;
}

export namespace RunspaceChangedEvent {
export const type: NotificationType<RunspaceDetails> =
{ get method() { return 'powerShell/runspaceChanged'; } };
}