Skip to content

Commit

Permalink
Test filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Oct 30, 2023
1 parent 0c1ec02 commit ddb20d7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/vscode-extension/src/projectsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,26 @@ function createLangIcon(context: vscode.ExtensionContext, name: LanguageType) {
};
}

function canShowTask(id: string, hideTasks: Set<string>): boolean {
if (hideTasks.size === 0 || !hideTasks.has(id)) {
function canShowTask(target: string, hideTasks: Set<string>): boolean {
if (hideTasks.size === 0) {
return true;
}

if (hideTasks.has(':') || hideTasks.has('*:*')) {
return false;
}

for (const target of hideTasks) {
const [scope = '', task = ''] = target.split(':', 2);
for (const hideTarget of hideTasks) {
if (target === hideTarget) {
return false;
}

const [scope = '', task = ''] = hideTarget.split(':', 2);
const scopePattern = scope === '' || scope === '*' ? '^[^:]+' : `^${scope}`;
const taskPattern = task === '' || task === '*' ? '[^:]+$' : `${task}$`;
const pattern = new RegExp(`${scopePattern}:${taskPattern}`, 'i');

if (pattern.test(id)) {
if (pattern.test(target)) {
return false;
}
}
Expand Down Expand Up @@ -130,9 +134,9 @@ class ProjectItem extends TreeItem {
this.tooltip = `${metadata.name} - ${metadata.description}`;
}

this.tasks = Object.entries(project.tasks)
.filter(([id, _]) => canShowTask(id, this.parent.hideTasks))
.map(([_, task]) => new TaskItem(this, task));
this.tasks = Object.values(project.tasks)
.filter((task) => canShowTask(task.target, this.parent.hideTasks))
.map((task) => new TaskItem(this, task));

this.resourceUri = Uri.file(
path.join(project.root, LANGUAGE_MANIFESTS[language] || 'moon.yml'),
Expand Down

0 comments on commit ddb20d7

Please sign in to comment.