Skip to content

Commit 495188c

Browse files
committed
Support absolute path searches
1 parent 5e6097b commit 495188c

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Example 'tasks.json' file to build project in monorepo with lerna
4040

4141
## Arguments
4242

43-
* `masks` `<string | string[]>` Masks to file search
43+
* `masks` `<string | string[]>` Masks to file search. Masks starting with `"/"` are searched as absolute paths, not relative to `workspaceFolder`.
4444
* `display` `<DisplayType | DisplayConfig>` File names presentation type
4545
* `output` `<DisplayType | DisplayConfig>` Output presentation type
4646

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"name": "lunatic-file-picker",
2+
"name": "file-picker",
33
"displayName": "file-picker",
44
"description": "Simple tool select file from your project by name or json content",
5-
"version": "0.1.1",
6-
"publisher": "DmitriyMuraviov",
5+
"version": "0.1.3",
6+
"publisher": "dfarley1",
77
"repository": {
88
"type": "git",
9-
"url": "https://github.com/mrLunatic/vsCodeFilePicker.git"
9+
"url": "https://github.com/dfarley1/vsCodeFilePicker.git"
1010
},
1111
"engines": {
1212
"vscode": "^1.25.0"

src/PickCommand.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,49 @@ export class PickCommand {
101101
private getOutput(file: string, root: string): string | undefined {
102102
return this.getProperty(file, root, this._args.output);
103103
}
104-
public async Invoke(): Promise<string | undefined> {
104+
105+
private async getAbsoluteMap(mask: string): Promise<Map<vscode.QuickPickItem, string>> {
105106
const map = new Map<vscode.QuickPickItem, string>();
106-
const masks = this.getMasks();
107+
var files = await this.getFilesAsync(mask);
108+
for (const file of files) {
109+
const key = this.getDisplay(file, "/");
110+
const value = this.getOutput(file, "/");
111+
if (key != undefined && value != undefined) {
112+
map.set(key, value);
113+
}
114+
}
115+
return map;
116+
}
117+
118+
private async getWorkspaceMap(mask: string): Promise<Map<vscode.QuickPickItem, string>> {
119+
const map = new Map<vscode.QuickPickItem, string>();
120+
107121
for (const folder of vscode.workspace.workspaceFolders) {
108122
const root = folder.uri.fsPath;
109-
for (const mask of masks) {
110-
var files = await this.getFilesAsync(path.join(root, mask));
111-
for (const file of files) {
112-
const key = this.getDisplay(file, root);
113-
const value = this.getOutput(file, root);
114-
if (key != undefined && value != undefined) {
115-
map.set(key, value);
116-
}
123+
var files = await this.getFilesAsync(path.join(root, mask));
124+
for (const file of files) {
125+
const key = this.getDisplay(file, root);
126+
const value = this.getOutput(file, root);
127+
if (key != undefined && value != undefined) {
128+
map.set(key, value);
117129
}
118130
}
119131
}
132+
133+
return map;
134+
}
135+
136+
public async Invoke(): Promise<string | undefined> {
137+
var map: Map<vscode.QuickPickItem, string>;
138+
const masks = this.getMasks();
139+
140+
for (const mask of masks) {
141+
if (mask.startsWith("/")) {
142+
map = await this.getAbsoluteMap(mask);
143+
} else {
144+
map = await this.getWorkspaceMap(mask);
145+
}
146+
}
120147
const names = Array.from(map.keys());
121148
if (names.length == 0) {
122149
await vscode.window.showInformationMessage("No files found");

0 commit comments

Comments
 (0)