Skip to content

Commit f2766b1

Browse files
committed
Try to eliminate unnecessary search exclusion filters
1 parent 2d2404e commit f2766b1

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/providers/FileSystemProvider/TextSearchProvider.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,8 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
111111
if (!params.get("filter")) {
112112
// Unless isfs spec already includes a non-empty filter (which it rarely does), apply includes and excludes at the server side.
113113
// Convert **/ separators and /** suffix into multiple *-patterns that simulate these elements of glob syntax.
114-
//
115-
// When 'Use Exclude Settings and Ignore Files' is enabled (which is typical) options.excludes will also contain entries from files.exclude and search.exclude settings.
116-
// This will result in additional server-side filtering which is superfluous but harmless other than perhaps incurring a small(?) performance cost.
117114

118-
// Function to convert glob-style filters into ones the server understands
115+
// Function to convert glob-style filters into ones that the server understands
119116
const convertFilters = (filters: string[]): string[] => {
120117
// Use map to prevent duplicates in final result
121118
const filterMap = new Map<string, void>();
@@ -140,9 +137,11 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
140137
};
141138

142139
// Invoke our recursive function
143-
filters.forEach((value) => {
144-
recurse(value);
145-
});
140+
filters
141+
.filter((value) => csp || !value.match(/\.([a-z]+|\*)\/\*\*$/)) // drop superfluous entries ending .xyz/** or .*/** when not handling CSP files
142+
.forEach((value) => {
143+
recurse(value);
144+
});
146145

147146
// Convert map to array and return it
148147
const results: string[] = [];
@@ -152,7 +151,27 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
152151
return results;
153152
};
154153

155-
const filterExclude = convertFilters(options.excludes).join(",'");
154+
// Function to get one of the two kinds of exclude settings as an array
155+
const getConfigExcludes = (key: string) => {
156+
return Object.entries(vscode.workspace.getConfiguration(key, options.folder).get("exclude"))
157+
.filter((value) => value[1] === true)
158+
.map((value) => value[0]);
159+
};
160+
161+
// Build an array containing the files.exclude settings followed by the search.exclude ones,
162+
// then try to remove exactly those from the end of the ones passed to us when "Use Exclude Settings and Ignore Files" is on.
163+
const configurationExcludes = getConfigExcludes("files").concat(getConfigExcludes("search"));
164+
const ourExcludes = options.excludes;
165+
while (configurationExcludes.length > 0) {
166+
if (configurationExcludes.pop() !== ourExcludes.pop()) {
167+
break;
168+
}
169+
}
170+
171+
// If we successfully removed them all, the ones that remain were explicitly entered in the "files to exclude" field of Search, so use them.
172+
// If removal was unsuccessful use the whole set.
173+
const filterExclude = convertFilters(!configurationExcludes.length ? ourExcludes : options.excludes).join(",'");
174+
156175
const filterInclude =
157176
options.includes.length > 0
158177
? convertFilters(options.includes).join(",")

0 commit comments

Comments
 (0)