Skip to content

Commit c43641c

Browse files
authored
Merge pull request #75 from Mastersam07/fix-tree-view
fix: show files that matches configured file patterns in tree view
2 parents ebd77d9 + fffe1ff commit c43641c

4 files changed

Lines changed: 122 additions & 56 deletions

File tree

.vscode/settings.json

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
// Place your settings in this file to overwrite default and user settings.
22
{
3-
"files.exclude": {
4-
"out": false, // set this to true to hide the "out" folder with the compiled JS files
5-
"dist": false // set this to true to hide the "dist" folder with the compiled JS files
6-
},
7-
"search.exclude": {
8-
"out": true, // set this to false to include "out" folder in search results
9-
"dist": true // set this to false to include "dist" folder in search results
10-
},
11-
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
12-
"typescript.tsc.autoDetect": "off",
13-
"yaml.schemas": {
14-
"./schema/schema.v0.json": [
15-
"tests/examples/*.yaml"
16-
]
17-
},
18-
"cSpell.words": [
19-
"airplane"
20-
],
21-
}
3+
"files.exclude": {
4+
"out": false, // set this to true to hide the "out" folder with the compiled JS files
5+
"dist": false // set this to true to hide the "dist" folder with the compiled JS files
6+
},
7+
"search.exclude": {
8+
"out": true, // set this to false to include "out" folder in search results
9+
"dist": true // set this to false to include "dist" folder in search results
10+
},
11+
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
12+
"typescript.tsc.autoDetect": "off",
13+
"yaml.schemas": {
14+
"./schema/schema.v0.json": ["tests/examples/*.yaml"]
15+
},
16+
"maestroWorkbench.filePatterns": ["tests/examples/*.yaml"],
17+
"cSpell.words": ["airplane"]
18+
}

package-lock.json

Lines changed: 53 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
"typescript": "^5.7.2"
191191
},
192192
"dependencies": {
193+
"minimatch": "^10.0.1",
193194
"yaml": "^2.7.0"
194195
}
195196
}

src/provider/treeView.ts

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from 'path';
22
import * as fs from 'fs';
33
import * as vscode from 'vscode';
44
import YAML from 'yaml';
5+
import { minimatch } from 'minimatch';
56

67
export class MaestroWorkBenchTreeViewProvider implements vscode.TreeDataProvider<vscode.TreeItem> {
78
private filePatterns: string[];
@@ -41,7 +42,7 @@ export class MaestroWorkBenchTreeViewProvider implements vscode.TreeDataProvider
4142
vscode.Uri.file(dep),
4243
FileType.Dependency,
4344
isMissing ? 'Missing dependency' : 'Dependency',
44-
isMissing ? 'error' : 'link'
45+
isMissing ? 'error' : undefined
4546
);
4647
});
4748
}
@@ -91,13 +92,24 @@ export class MaestroWorkBenchTreeViewProvider implements vscode.TreeDataProvider
9192
);
9293
});
9394

94-
const filePaths = fileItems
95+
const filteredItems = fileItems.filter(item => {
96+
if (item.contextValue === FileType.Folder) {
97+
return true;
98+
}
99+
100+
const workspaceRoot = vscode.workspace.workspaceFolders![0].uri.fsPath;
101+
const relativePath = path.relative(workspaceRoot, item.resourceUri.fsPath);
102+
103+
return this.shouldIncludeFile(relativePath);
104+
});
105+
106+
const filePaths = filteredItems
95107
.filter((item) => item.contextValue === FileType.File)
96108
.map((item) => item.resourceUri.fsPath);
97109

98110
this.analyzeDependencies(filePaths);
99111

100-
fileItems.forEach((item) => {
112+
filteredItems.forEach((item) => {
101113
if (item.contextValue === FileType.File) {
102114
const dependencies = this.dependencyMap.get(item.resourceUri.fsPath) || [];
103115
item.collapsibleState =
@@ -107,7 +119,14 @@ export class MaestroWorkBenchTreeViewProvider implements vscode.TreeDataProvider
107119
}
108120
});
109121

110-
return fileItems;
122+
return filteredItems;
123+
}
124+
125+
private shouldIncludeFile(relativePath: string): boolean {
126+
const normalizedPath = relativePath.replace(/\\/g, '/');
127+
return this.filePatterns.some(pattern =>
128+
minimatch(normalizedPath, pattern, { dot: true })
129+
);
111130
}
112131

113132
private createTreeItemsFromPaths(filePaths: string[], rootPath: string): FileItem[] {
@@ -154,33 +173,36 @@ export class MaestroWorkBenchTreeViewProvider implements vscode.TreeDataProvider
154173
const dependencies = new Set<string>();
155174

156175
parsedDocuments.forEach((doc) => {
157-
if (Array.isArray(doc)) {
158-
doc.forEach((flow) => {
159-
if (flow.runFlow && flow.runFlow.file) {
160-
const dependencyPath = path.resolve(path.dirname(filePath), flow.runFlow.file);
161-
dependencies.add(dependencyPath);
162-
}
163-
164-
if (flow.runScript && flow.runScript.file) {
165-
const dependencyPath = path.resolve(path.dirname(filePath), flow.runScript.file);
166-
dependencies.add(dependencyPath);
167-
}
168-
169-
if (flow.addMedia) {
170-
if (Array.isArray(flow.addMedia)) {
171-
flow.addMedia.forEach((mediaFile: string) => {
172-
const dependencyPath = path.resolve(path.dirname(filePath), mediaFile);
173-
dependencies.add(dependencyPath);
174-
});
175-
} else if (flow.addMedia.files && Array.isArray(flow.addMedia.files)) {
176-
flow.addMedia.files.forEach((mediaFile: string) => {
177-
const dependencyPath = path.resolve(path.dirname(filePath), mediaFile);
178-
dependencies.add(dependencyPath);
179-
});
180-
}
176+
const parsed = doc.toJS();
177+
const flows = Array.isArray(parsed) ? parsed : [parsed];
178+
179+
flows.forEach((flow) => {
180+
if (!flow) return;
181+
182+
if (flow.runFlow && flow.runFlow.file) {
183+
const dependencyPath = path.resolve(path.dirname(filePath), flow.runFlow.file);
184+
dependencies.add(dependencyPath);
185+
}
186+
187+
if (flow.runScript && flow.runScript.file) {
188+
const dependencyPath = path.resolve(path.dirname(filePath), flow.runScript.file);
189+
dependencies.add(dependencyPath);
190+
}
191+
192+
if (flow.addMedia) {
193+
if (Array.isArray(flow.addMedia)) {
194+
flow.addMedia.forEach((mediaFile: string) => {
195+
const dependencyPath = path.resolve(path.dirname(filePath), mediaFile);
196+
dependencies.add(dependencyPath);
197+
});
198+
} else if (flow.addMedia.files && Array.isArray(flow.addMedia.files)) {
199+
flow.addMedia.files.forEach((mediaFile: string) => {
200+
const dependencyPath = path.resolve(path.dirname(filePath), mediaFile);
201+
dependencies.add(dependencyPath);
202+
});
181203
}
182-
});
183-
}
204+
}
205+
});
184206
});
185207

186208
this.dependencyMap.set(filePath, Array.from(dependencies));

0 commit comments

Comments
 (0)