Skip to content

Commit 5d8467d

Browse files
committed
Add inline action for running 'debug scripts'
1 parent 7dd1326 commit 5d8467d

5 files changed

Lines changed: 41 additions & 3 deletions

File tree

extensions/npm/package.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@
5353
},
5454
{
5555
"command": "npm.debugScript",
56-
"title": "%command.debug%"
56+
"title": "%command.debug%",
57+
"icon": {
58+
"light": "resources/light/debug.svg",
59+
"dark": "resources/dark/debug.svg"
60+
}
5761
},
5862
{
5963
"command": "npm.openScript",
@@ -93,11 +97,20 @@
9397
"group": "navigation@2"
9498
},
9599
{
96-
"command": "npm.runScript",
100+
"command": "npm.runScript",
97101
"when": "view == npm && viewItem == script",
98102
"group": "inline"
99103
},
100104
{
105+
"command": "npm.runScript",
106+
"when": "view == npm && viewItem == debugScript",
107+
"group": "inline"
108+
},
109+
{
110+
"command": "npm.debugScript",
111+
"when": "view == npm && viewItem == debugScript",
112+
"group": "inline"
113+
}, {
101114
"command": "npm.debugScript",
102115
"when": "view == npm && viewItem == script",
103116
"group": "navigation@3"
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 7 additions & 0 deletions
Loading

extensions/npm/src/npmView.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class NpmScript extends TreeItem {
7272
constructor(context: ExtensionContext, packageJson: PackageJSON, task: Task) {
7373
super(task.name, TreeItemCollapsibleState.None);
7474
this.contextValue = 'script';
75+
if (task.group && task.group === TaskGroup.Rebuild) {
76+
this.contextValue = 'debugScript';
77+
}
7578
this.package = packageJson;
7679
this.task = task;
7780
this.command = {
@@ -141,7 +144,7 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
141144
workspace.executeTask(script.task);
142145
}
143146

144-
private async extractDebugArg(scripts: any, task: Task): Promise<[string, number] | undefined> {
147+
private extractDebugArg(scripts: any, task: Task): [string, number] | undefined {
145148
let script: string = scripts[task.name];
146149

147150
let match = script.match(/--(inspect|debug)(-brk)?(=(\d*))?/);

extensions/npm/src/tasks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ function isExcluded(folder: WorkspaceFolder, packageJsonUri: Uri) {
157157
return false;
158158
}
159159

160+
function isDebugScript(script: string): boolean {
161+
let match = script.match(/--(inspect|debug)(-brk)?(=(\d*))?/);
162+
return match !== null;
163+
}
164+
160165
async function provideNpmScriptsForFolder(packageJsonUri: Uri): Promise<Task[]> {
161166
let emptyTasks: Task[] = [];
162167

@@ -183,6 +188,9 @@ async function provideNpmScriptsForFolder(packageJsonUri: Uri): Promise<Task[]>
183188
if (prePostScripts.has(each)) {
184189
task.group = TaskGroup.Clean; // hack: use Clean group to tag pre/post scripts
185190
}
191+
if (isDebugScript(scripts![each])) {
192+
task.group = TaskGroup.Rebuild; // hack: use Rebuild group to tag debug scripts
193+
}
186194
result.push(task);
187195
});
188196
// always add npm install (without a problem matcher)

0 commit comments

Comments
 (0)