Skip to content

Commit b8b8b0b

Browse files
authored
Merge pull request PowerShell#431 from PowerShell/daviwil/debug-launch
Add startSessionCommand handler for debugger configuration
2 parents 5b32676 + aa99387 commit b8b8b0b

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"activationEvents": [
2929
"onLanguage:powershell",
3030
"onCommand:PowerShell.NewProjectFromTemplate",
31-
"onCommand:PowerShell.OpenExamplesFolder"
31+
"onCommand:PowerShell.OpenExamplesFolder",
32+
"onCommand:PowerShell.StartDebugSession"
3233
],
3334
"dependencies": {
3435
"vscode-languageclient": "1.3.1"
@@ -163,7 +164,8 @@
163164
},
164165
"program": "./out/debugAdapter.js",
165166
"runtime": "node",
166-
167+
"languages": ["powershell"],
168+
"startSessionCommand": "PowerShell.StartDebugSession",
167169
"configurationSnippets": [
168170
{
169171
"label": "PowerShell: Launch Current Script Configuration",

src/features/DebugSession.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
import vscode = require('vscode');
6+
import { IFeature } from '../feature';
7+
import { LanguageClient } from 'vscode-languageclient';
8+
9+
export class DebugSessionFeature implements IFeature {
10+
private command: vscode.Disposable;
11+
private examplesPath: string;
12+
13+
constructor() {
14+
this.command = vscode.commands.registerCommand(
15+
'PowerShell.StartDebugSession',
16+
config => { this.startDebugSession(config); });
17+
}
18+
19+
public setLanguageClient(languageclient: LanguageClient) {
20+
}
21+
22+
public dispose() {
23+
this.command.dispose();
24+
}
25+
26+
private startDebugSession(config: any) {
27+
if (!config.request) {
28+
// No launch.json, create the default configuration
29+
config.type = 'PowerShell';
30+
config.name = 'PowerShell Launch Current File';
31+
config.request = 'launch';
32+
config.args = [];
33+
config.script = vscode.window.activeTextEditor.document.fileName;
34+
}
35+
36+
if (config.request === 'launch') {
37+
// Make sure there's a usable working directory if possible
38+
config.cwd = config.cwd || vscode.workspace.rootPath || config.script;
39+
}
40+
41+
vscode.commands.executeCommand('vscode.startDebug', config);
42+
}
43+
}

src/main.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { PowerShellLanguageId } from './utils';
1313
import { ConsoleFeature } from './features/Console';
1414
import { ExamplesFeature } from './features/Examples';
1515
import { OpenInISEFeature } from './features/OpenInISE';
16-
import { NewFileOrProjectFeature } from './features/NewFileOrProject';
1716
import { ExpandAliasFeature } from './features/ExpandAlias';
1817
import { ShowHelpFeature } from './features/ShowOnlineHelp';
18+
import { CodeActionsFeature } from './features/CodeActions';
19+
import { DebugSessionFeature } from './features/DebugSession';
20+
import { SelectPSSARulesFeature } from './features/SelectPSSARules';
1921
import { FindModuleFeature } from './features/PowerShellFindModule';
22+
import { NewFileOrProjectFeature } from './features/NewFileOrProject';
2023
import { ExtensionCommandsFeature } from './features/ExtensionCommands';
21-
import { SelectPSSARulesFeature } from './features/SelectPSSARules';
22-
import { CodeActionsFeature } from './features/CodeActions';
2324

2425
// NOTE: We will need to find a better way to deal with the required
2526
// PS Editor Services version...
@@ -101,7 +102,8 @@ export function activate(context: vscode.ExtensionContext): void {
101102
new ExtensionCommandsFeature(),
102103
new SelectPSSARulesFeature(),
103104
new CodeActionsFeature(),
104-
new NewFileOrProjectFeature()
105+
new NewFileOrProjectFeature(),
106+
new DebugSessionFeature()
105107
];
106108

107109
sessionManager =

0 commit comments

Comments
 (0)