Skip to content

Commit

Permalink
Improve appearance of NPM scripts tree
Browse files Browse the repository at this point in the history
Fixes #123091
  • Loading branch information
alexr00 committed Nov 11, 2021
1 parent 64da3b1 commit 9efa55c
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions extensions/npm/src/npmView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,24 @@ type ExplorerCommands = 'open' | 'run';
class NpmScript extends TreeItem {
task: Task;
package: PackageJSON;

constructor(_context: ExtensionContext, packageJson: PackageJSON, task: Task, public taskLocation?: Location) {
super(task.name, TreeItemCollapsibleState.None);
taskLocation?: Location;

constructor(_context: ExtensionContext, packageJson: PackageJSON, task: TaskWithLocation) {
const name = packageJson.path.length > 0
? task.task.name.substring(0, task.task.name.length - packageJson.path.length - 2)
: task.task.name;
super(name, TreeItemCollapsibleState.None);
this.taskLocation = task.location;
const command: ExplorerCommands = workspace.getConfiguration('npm').get<ExplorerCommands>('scriptExplorerAction') || 'open';

const commandList = {
'open': {
title: 'Edit Script',
command: 'vscode.open',
arguments: [
taskLocation?.uri,
taskLocation ? <TextDocumentShowOptions>{
selection: new Range(taskLocation.range.start, taskLocation.range.start)
this.taskLocation?.uri,
this.taskLocation ? <TextDocumentShowOptions>{
selection: new Range(this.taskLocation.range.start, this.taskLocation.range.start)
} : undefined
]
},
Expand All @@ -100,16 +105,17 @@ class NpmScript extends TreeItem {
};
this.contextValue = 'script';
this.package = packageJson;
this.task = task;
this.task = task.task;
this.command = commandList[command];

if (task.group && task.group === TaskGroup.Clean) {
if (this.task.group && this.task.group === TaskGroup.Clean) {
this.iconPath = new ThemeIcon('wrench-subaction');
} else {
this.iconPath = new ThemeIcon('wrench');
}
if (task.detail) {
this.tooltip = task.detail;
if (this.task.detail) {
this.tooltip = this.task.detail;
this.description = this.task.detail;
}
}

Expand Down Expand Up @@ -301,7 +307,7 @@ export class NpmScriptsTreeDataProvider implements TreeDataProvider<TreeItem> {
folder.addPackage(packageJson);
packages.set(fullPath, packageJson);
}
let script = new NpmScript(this.extensionContext, packageJson, each.task, each.location);
let script = new NpmScript(this.extensionContext, packageJson, each);
packageJson.addScript(script);
}
});
Expand Down

0 comments on commit 9efa55c

Please sign in to comment.