Skip to content

Commit e8c8198

Browse files
rkeithhilldaviwil
authored andcommitted
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 ccebc4d commit e8c8198

File tree

5 files changed

+58
-53
lines changed

5 files changed

+58
-53
lines changed

.vscode/settings.json

+7
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

+21-16
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",
@@ -169,18 +169,20 @@
169169
{
170170
"name": "pester",
171171
"owner": "powershell",
172-
"fileLocation": ["absolute"],
172+
"fileLocation": [
173+
"absolute"
174+
],
173175
"severity": "error",
174176
"pattern": [
175-
{
176-
"regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
177-
"message": 1
178-
},
179-
{
180-
"regexp": "^\\s+at\\s+[^,]+,\\s*(.*?):\\s+line\\s+(\\d+)$",
181-
"file": 1,
182-
"line": 2
183-
}
177+
{
178+
"regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
179+
"message": 1
180+
},
181+
{
182+
"regexp": "^\\s+at\\s+[^,]+,\\s*(.*?):\\s+line\\s+(\\d+)$",
183+
"file": 1,
184+
"line": 2
185+
}
184186
]
185187
}
186188
],
@@ -207,7 +209,6 @@
207209
"languages": [
208210
"powershell"
209211
],
210-
"startSessionCommand": "PowerShell.StartDebugSession",
211212
"configurationSnippets": [
212213
{
213214
"label": "PowerShell: Launch Current File",
@@ -242,7 +243,9 @@
242243
"request": "launch",
243244
"name": "PowerShell Launch Current File w/Args Prompt",
244245
"script": "^\"\\${file}\"",
245-
"args": [ "^\"\\${command:SpecifyScriptArgs}\"" ],
246+
"args": [
247+
"^\"\\${command:SpecifyScriptArgs}\""
248+
],
246249
"cwd": "^\"\\${file}\""
247250
}
248251
},
@@ -365,7 +368,9 @@
365368
"request": "launch",
366369
"name": "PowerShell Launch Current File w/Args Prompt",
367370
"script": "${file}",
368-
"args": [ "${command:SpecifyScriptArgs}" ],
371+
"args": [
372+
"${command:SpecifyScriptArgs}"
373+
],
369374
"cwd": "${file}"
370375
},
371376
{
@@ -425,7 +430,7 @@
425430
"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."
426431
},
427432
"powershell.codeFormatting.preset": {
428-
"type":"string",
433+
"type": "string",
429434
"enum": [
430435
"Custom",
431436
"Allman",

src/controls/animatedStatusBar.ts

+3-2
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

+26-34
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;
@@ -146,27 +150,14 @@ export class DebugSessionFeature implements IFeature {
146150
.start(`DebugSession-${this.sessionCount++}`)
147151
.then(
148152
sessionDetails => {
149-
this.startDebugger(
150-
config,
151-
sessionFilePath,
152-
sessionDetails);
153+
utils.writeSessionFile(sessionFilePath, sessionDetails);
153154
});
154155
}
155156
else {
156-
this.startDebugger(
157-
config,
158-
sessionFilePath,
159-
this.sessionManager.getSessionDetails());
157+
utils.writeSessionFile(sessionFilePath, this.sessionManager.getSessionDetails());
160158
}
161-
}
162159

163-
private startDebugger(
164-
config: any,
165-
sessionFilePath: string,
166-
sessionDetails: utils.EditorServicesSessionDetails) {
167-
168-
utils.writeSessionFile(sessionFilePath, sessionDetails);
169-
vscode.commands.executeCommand('vscode.startDebug', config);
160+
return config;
170161
}
171162
}
172163

@@ -204,7 +195,7 @@ export class SpecifyScriptArgsFeature implements IFeature {
204195
this.command.dispose();
205196
}
206197

207-
private specifyScriptArguments(): Thenable<string[]> {
198+
private specifyScriptArguments(): Thenable<string[] | string> {
208199
const powerShellDbgScriptArgsKey = 'powerShellDebugScriptArgs';
209200

210201
let options: vscode.InputBoxOptions = {
@@ -225,6 +216,7 @@ export class SpecifyScriptArgsFeature implements IFeature {
225216
if (this.emptyInputBoxBugFixed) {
226217
this.context.workspaceState.update(powerShellDbgScriptArgsKey, text);
227218
}
219+
228220
return new Array(text);
229221
}
230222

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export function activate(context: vscode.ExtensionContext): void {
121121
new NewFileOrProjectFeature(),
122122
new DocumentFormatterFeature(logger),
123123
new RemoteFilesFeature(),
124-
new DebugSessionFeature(sessionManager),
124+
new DebugSessionFeature(context, sessionManager),
125125
new PickPSHostProcessFeature(),
126126
new SpecifyScriptArgsFeature(context),
127127
new HelpCompletionFeature(),

0 commit comments

Comments
 (0)