|
1 | 1 | import * as vscode from "vscode"; |
2 | 2 | import * as url from "url"; |
3 | | -import { AtelierAPI } from "../../api"; |
4 | 3 | import { StudioOpenDialog } from "../../queries"; |
5 | 4 | import { studioOpenDialogFromURI } from "../../utils/FileProviderUtil"; |
| 5 | +import { notNull } from "../../utils"; |
| 6 | +import { DocumentContentProvider } from "../DocumentContentProvider"; |
6 | 7 |
|
7 | 8 | export class FileSearchProvider implements vscode.FileSearchProvider { |
8 | 9 | /** |
@@ -32,40 +33,26 @@ export class FileSearchProvider implements vscode.FileSearchProvider { |
32 | 33 | filter = ""; |
33 | 34 | } |
34 | 35 | let counter = 0; |
| 36 | + if (token.isCancellationRequested) { |
| 37 | + return; |
| 38 | + } |
35 | 39 | return studioOpenDialogFromURI(options.folder, { flat: true, filter: filter }) |
36 | 40 | .then((data) => { |
37 | 41 | return data.result.content; |
38 | 42 | }) |
39 | 43 | .then((data: StudioOpenDialog[]) => { |
40 | | - const api = new AtelierAPI(options.folder); |
41 | 44 | return data |
42 | 45 | .map((item: StudioOpenDialog) => { |
43 | | - // item.Type only matters here if it is 5 (CSP) |
44 | | - if (item.Type == "5" && !csp) { |
| 46 | + if (token.isCancellationRequested) { |
45 | 47 | return null; |
46 | 48 | } |
47 | | - if (item.Type !== "5") { |
48 | | - if (item.Name.startsWith("%") && api.ns !== "%SYS") { |
49 | | - return null; |
50 | | - } |
51 | | - // Convert dotted name to slashed one, treating the likes of ABC.1.int or DEF.T1.int in the same way |
52 | | - // as the Studio dialog does. |
53 | | - const nameParts = item.Name.split("."); |
54 | | - const dotParts = nameParts |
55 | | - .slice(-2) |
56 | | - .join(".") |
57 | | - .match(/^[A-Z]?\d*[.](mac|int|inc)$/) |
58 | | - ? 3 |
59 | | - : 2; |
60 | | - item.Name = nameParts.slice(0, -dotParts).join("/") + "/" + nameParts.slice(-dotParts).join("."); |
61 | | - } |
62 | 49 | if (!options.maxResults || ++counter <= options.maxResults) { |
63 | | - return vscode.Uri.parse(`${options.folder.scheme}://${options.folder.authority}/${item.Name}`, true); |
| 50 | + return DocumentContentProvider.getUri(item.Name, "", "", true, options.folder); |
64 | 51 | } else { |
65 | 52 | return null; |
66 | 53 | } |
67 | 54 | }) |
68 | | - .filter((el) => el !== null); |
| 55 | + .filter(notNull); |
69 | 56 | }); |
70 | 57 | } |
71 | 58 | } |
0 commit comments