Skip to content

Commit b325257

Browse files
committed
Update to use DebugConfigurationProvider
Fix #1046 Fix warning in status bar about ThemeColor This fix requires PSES PR 556 to eliminate one PSES cause of the debug adapter to crash. Also npm generated a package-lock.json file which, from what I've read, should be checked in. I haven't included it in this PR - yet. Thoughts? Also, I updated min VSCode version to 1.17.0. I'm not sure when the new DebugConfigurationProvider API was intro'd. I have tested with 1.17.2 and it works there so I'm reasonably confident it will work in 1.17.0. We might be able to reach back a bit further. We'd have to find out when this API was intro'd.
1 parent bd9f012 commit b325257

File tree

5 files changed

+58
-53
lines changed

5 files changed

+58
-53
lines changed

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
"editor.insertSpaces": true,
55
"files.trimTrailingWhitespace": true,
66

7+
"search.exclude": {
8+
"**/node_modules": true,
9+
"**/bower_components": true,
10+
"logs/": true,
11+
"out/": true
12+
},
13+
714
// Lock the TypeScript SDK path to the version we use
815
"typescript.tsdk": "./node_modules/typescript/lib"
916
}

package.json

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"publisher": "ms-vscode",
66
"description": "Develop PowerShell scripts in Visual Studio Code!",
77
"engines": {
8-
"vscode": "^1.12.0"
8+
"vscode": "^1.17.0"
99
},
1010
"license": "SEE LICENSE IN LICENSE.txt",
1111
"homepage": "https://github.com/PowerShell/vscode-powershell/blob/master/README.md",
@@ -26,10 +26,10 @@
2626
},
2727
"main": "./out/src/main",
2828
"activationEvents": [
29+
"onDebug",
2930
"onLanguage:powershell",
3031
"onCommand:PowerShell.NewProjectFromTemplate",
3132
"onCommand:PowerShell.OpenExamplesFolder",
32-
"onCommand:PowerShell.StartDebugSession",
3333
"onCommand:PowerShell.PickPSHostProcess",
3434
"onCommand:PowerShell.SpecifyScriptArgs",
3535
"onCommand:PowerShell.ShowSessionConsole",
@@ -164,18 +164,20 @@
164164
{
165165
"name": "pester",
166166
"owner": "powershell",
167-
"fileLocation": ["absolute"],
167+
"fileLocation": [
168+
"absolute"
169+
],
168170
"severity": "error",
169171
"pattern": [
170-
{
171-
"regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
172-
"message": 1
173-
},
174-
{
175-
"regexp": "^\\s+at\\s+[^,]+,\\s*(.*?):\\s+line\\s+(\\d+)$",
176-
"file": 1,
177-
"line": 2
178-
}
172+
{
173+
"regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
174+
"message": 1
175+
},
176+
{
177+
"regexp": "^\\s+at\\s+[^,]+,\\s*(.*?):\\s+line\\s+(\\d+)$",
178+
"file": 1,
179+
"line": 2
180+
}
179181
]
180182
}
181183
],
@@ -202,7 +204,6 @@
202204
"languages": [
203205
"powershell"
204206
],
205-
"startSessionCommand": "PowerShell.StartDebugSession",
206207
"configurationSnippets": [
207208
{
208209
"label": "PowerShell: Launch Current File",
@@ -237,7 +238,9 @@
237238
"request": "launch",
238239
"name": "PowerShell Launch Current File w/Args Prompt",
239240
"script": "^\"\\${file}\"",
240-
"args": [ "^\"\\${command:SpecifyScriptArgs}\"" ],
241+
"args": [
242+
"^\"\\${command:SpecifyScriptArgs}\""
243+
],
241244
"cwd": "^\"\\${file}\""
242245
}
243246
},
@@ -360,7 +363,9 @@
360363
"request": "launch",
361364
"name": "PowerShell Launch Current File w/Args Prompt",
362365
"script": "${file}",
363-
"args": [ "${command:SpecifyScriptArgs}" ],
366+
"args": [
367+
"${command:SpecifyScriptArgs}"
368+
],
364369
"cwd": "${file}"
365370
},
366371
{
@@ -415,7 +420,7 @@
415420
"description": "Specifies the path to a PowerShell Script Analyzer settings file. To override the default settings for all projects, enter an absolute path, or enter a path relative to your workspace."
416421
},
417422
"powershell.codeFormatting.preset": {
418-
"type":"string",
423+
"type": "string",
419424
"enum": [
420425
"Custom",
421426
"Allman",

src/controls/animatedStatusBar.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import {
66
StatusBarItem,
77
StatusBarAlignment,
8+
ThemeColor,
89
Disposable,
910
window} from "vscode";
1011

@@ -49,11 +50,11 @@ class AnimatedStatusBarItem implements StatusBarItem {
4950
this.statusBarItem.tooltip = value;
5051
}
5152

52-
public get color(): string {
53+
public get color(): string | ThemeColor {
5354
return this.statusBarItem.color;
5455
}
5556

56-
public set color(value: string) {
57+
public set color(value: string | ThemeColor) {
5758
this.statusBarItem.color = value;
5859
}
5960

src/features/DebugSession.ts

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,45 @@
55
import vscode = require('vscode');
66
import utils = require('../utils');
77
import Settings = require('../settings');
8+
import { dirname } from 'path';
89
import { IFeature } from '../feature';
910
import { SessionManager } from '../session';
1011
import { LanguageClient, RequestType, NotificationType } from 'vscode-languageclient';
12+
import { CancellationToken, DebugConfiguration, DebugConfigurationProvider,
13+
ExtensionContext, ProviderResult, WorkspaceFolder } from 'vscode';
1114

12-
export namespace StartDebuggerNotification {
13-
export const type = new NotificationType<void, void>('powerShell/startDebugger');
14-
}
15-
16-
export class DebugSessionFeature implements IFeature {
15+
export class DebugSessionFeature implements IFeature, DebugConfigurationProvider {
1716

1817
private sessionCount: number = 1;
1918
private command: vscode.Disposable;
2019
private examplesPath: string;
2120

22-
constructor(private sessionManager: SessionManager) {
23-
this.command = vscode.commands.registerCommand(
24-
'PowerShell.StartDebugSession',
25-
config => { this.startDebugSession(config); });
21+
constructor(context: ExtensionContext, private sessionManager: SessionManager) {
22+
// Register a debug configuration provider
23+
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('PowerShell', this));
2624
}
2725

2826
public setLanguageClient(languageClient: LanguageClient) {
29-
languageClient.onNotification(
30-
StartDebuggerNotification.type,
31-
none => this.startDebugSession({
32-
request: 'launch',
33-
type: 'PowerShell',
34-
name: 'PowerShell Interactive Session'
35-
}));
3627
}
3728

3829
public dispose() {
3930
this.command.dispose();
4031
}
4132

42-
private startDebugSession(config: any) {
33+
// DebugConfigurationProvider method
34+
provideDebugConfigurations(
35+
folder: WorkspaceFolder | undefined,
36+
token?: CancellationToken): ProviderResult<DebugConfiguration[]> {
37+
38+
// Currently all debugger initialConfigurations are specified in package.json
39+
return [];
40+
}
41+
42+
// DebugConfigurationProvider method
43+
resolveDebugConfiguration(
44+
folder: WorkspaceFolder | undefined,
45+
config: DebugConfiguration,
46+
token?: CancellationToken): ProviderResult<DebugConfiguration> {
4347

4448
let currentDocument = vscode.window.activeTextEditor.document;
4549
let debugCurrentScript = (config.script === "${file}") || !config.request;
@@ -136,27 +140,14 @@ export class DebugSessionFeature implements IFeature {
136140
.start(`DebugSession-${this.sessionCount++}`)
137141
.then(
138142
sessionDetails => {
139-
this.startDebugger(
140-
config,
141-
sessionFilePath,
142-
sessionDetails);
143+
utils.writeSessionFile(sessionFilePath, sessionDetails);
143144
});
144145
}
145146
else {
146-
this.startDebugger(
147-
config,
148-
sessionFilePath,
149-
this.sessionManager.getSessionDetails());
147+
utils.writeSessionFile(sessionFilePath, this.sessionManager.getSessionDetails());
150148
}
151-
}
152149

153-
private startDebugger(
154-
config: any,
155-
sessionFilePath: string,
156-
sessionDetails: utils.EditorServicesSessionDetails) {
157-
158-
utils.writeSessionFile(sessionFilePath, sessionDetails);
159-
vscode.commands.executeCommand('vscode.startDebug', config);
150+
return config;
160151
}
161152
}
162153

@@ -194,7 +185,7 @@ export class SpecifyScriptArgsFeature implements IFeature {
194185
this.command.dispose();
195186
}
196187

197-
private specifyScriptArguments(): Thenable<string[]> {
188+
private specifyScriptArguments(): Thenable<string[] | string> {
198189
const powerShellDbgScriptArgsKey = 'powerShellDebugScriptArgs';
199190

200191
let options: vscode.InputBoxOptions = {
@@ -215,6 +206,7 @@ export class SpecifyScriptArgsFeature implements IFeature {
215206
if (this.emptyInputBoxBugFixed) {
216207
this.context.workspaceState.update(powerShellDbgScriptArgsKey, text);
217208
}
209+
218210
return new Array(text);
219211
}
220212

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function activate(context: vscode.ExtensionContext): void {
119119
new NewFileOrProjectFeature(),
120120
new DocumentFormatterFeature(logger),
121121
new RemoteFilesFeature(),
122-
new DebugSessionFeature(sessionManager),
122+
new DebugSessionFeature(context, sessionManager),
123123
new PickPSHostProcessFeature(),
124124
new SpecifyScriptArgsFeature(context),
125125
new HelpCompletionFeature(),

0 commit comments

Comments
 (0)