Skip to content

Commit 9efa55c

Browse files
committed
Improve appearance of NPM scripts tree
Fixes microsoft#123091
1 parent 64da3b1 commit 9efa55c

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

extensions/npm/src/npmView.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,24 @@ type ExplorerCommands = 'open' | 'run';
7676
class NpmScript extends TreeItem {
7777
task: Task;
7878
package: PackageJSON;
79-
80-
constructor(_context: ExtensionContext, packageJson: PackageJSON, task: Task, public taskLocation?: Location) {
81-
super(task.name, TreeItemCollapsibleState.None);
79+
taskLocation?: Location;
80+
81+
constructor(_context: ExtensionContext, packageJson: PackageJSON, task: TaskWithLocation) {
82+
const name = packageJson.path.length > 0
83+
? task.task.name.substring(0, task.task.name.length - packageJson.path.length - 2)
84+
: task.task.name;
85+
super(name, TreeItemCollapsibleState.None);
86+
this.taskLocation = task.location;
8287
const command: ExplorerCommands = workspace.getConfiguration('npm').get<ExplorerCommands>('scriptExplorerAction') || 'open';
8388

8489
const commandList = {
8590
'open': {
8691
title: 'Edit Script',
8792
command: 'vscode.open',
8893
arguments: [
89-
taskLocation?.uri,
90-
taskLocation ? <TextDocumentShowOptions>{
91-
selection: new Range(taskLocation.range.start, taskLocation.range.start)
94+
this.taskLocation?.uri,
95+
this.taskLocation ? <TextDocumentShowOptions>{
96+
selection: new Range(this.taskLocation.range.start, this.taskLocation.range.start)
9297
} : undefined
9398
]
9499
},
@@ -100,16 +105,17 @@ class NpmScript extends TreeItem {
100105
};
101106
this.contextValue = 'script';
102107
this.package = packageJson;
103-
this.task = task;
108+
this.task = task.task;
104109
this.command = commandList[command];
105110

106-
if (task.group && task.group === TaskGroup.Clean) {
111+
if (this.task.group && this.task.group === TaskGroup.Clean) {
107112
this.iconPath = new ThemeIcon('wrench-subaction');
108113
} else {
109114
this.iconPath = new ThemeIcon('wrench');
110115
}
111-
if (task.detail) {
112-
this.tooltip = task.detail;
116+
if (this.task.detail) {
117+
this.tooltip = this.task.detail;
118+
this.description = this.task.detail;
113119
}
114120
}
115121

@@ -301,7 +307,7 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
301307
folder.addPackage(packageJson);
302308
packages.set(fullPath, packageJson);
303309
}
304-
let script = new NpmScript(this.extensionContext, packageJson, each.task, each.location);
310+
let script = new NpmScript(this.extensionContext, packageJson, each);
305311
packageJson.addScript(script);
306312
}
307313
});

0 commit comments

Comments
 (0)