95
changed = true;
96
}
98
>
99
>
// Always set for resources outside workspace as well
100
>
const globalNewExpression = this.doGetExpression(undefined);
101
>
const globalCurrentExpression = this.mapFolderToConfiguredExpression.get(ResourceGlobMatcher.NO_FOLDER);
102
>
if (globalNewExpression) {
103
>
if (!globalCurrentExpression || !equals(globalCurrentExpression.expression, globalNewExpression.expression)) {
104
>
changed = true;
105
>
106
>
this.mapFolderToParsedExpression.set(ResourceGlobMatcher.NO_FOLDER, parse(globalNewExpression.expression));
107
>
this.mapFolderToConfiguredExpression.set(ResourceGlobMatcher.NO_FOLDER, globalNewExpression);
108
>
}
109
>
} else {
110
>
if (globalCurrentExpression) {
111
>
changed = true;
112
>
113
>
this.mapFolderToParsedExpression.delete(ResourceGlobMatcher.NO_FOLDER);
114
>
this.mapFolderToConfiguredExpression.delete(ResourceGlobMatcher.NO_FOLDER);
115
>
}
116
>
}
117
>
118
>
if (fromEvent && changed) {
119
>
this._onExpressionChange.fire();
120
>
}
121
>
}
122
123
private doGetExpression(resource: URI | undefined): IConfiguredExpression | undefined {
124
>
const expression = this.getExpression(resource);
resources.ts
125
>
if (!expression) {
126
>
return undefined;
127
>
}
128
>
129
>
const keys = Object.keys(expression);
130
>
if (keys.length === 0) {
131
return undefined;
132
}
134
>
let hasAbsolutePath = false;
135
>
136
>
// Check the expression for absolute paths/globs
137
>
// and specifically for Windows, make sure the
138
>
// drive letter is lowercased, because we later
139
>
// check with `URI.fsPath` which is always putting
140
>
// the drive letter lowercased.
141
>
142
>
const massagedExpression: IExpression = Object.create(null);
143
>
for (const key of keys) {
144
>
if (!hasAbsolutePath) {
145
>
hasAbsolutePath = isAbsolute(key);
146
>
}
147
>
148
>
let massagedKey = key;
149
>
150
>
const driveLetter = getDriveLetter(massagedKey, true /* probe for windows */);
151
>
if (driveLetter) {
152
>
const driveLetterLower = driveLetter.toLowerCase();
153
>
if (driveLetter !== driveLetter.toLowerCase()) {
154
>
massagedKey = `${driveLetterLower}${massagedKey.substring(1)}`;
155
>
}
156
>
}
157
>
158
>
massagedExpression[massagedKey] = expression[key];
159
>
}
160
>
161
>
return {
162
>
expression: massagedExpression,
163
>
hasAbsolutePath
164
>
};
165
>
}
166
167
matches(
169
>
hasSibling?: (name: string) => boolean
170
>
): boolean {
171
>
if (this.mapFolderToParsedExpression.size === 0) {
172
>
return false; // return early: no expression for this matcher
173
>
}
174
>
175
>
const folder = this.contextService.getWorkspaceFolder(resource);
176
>
let expressionForFolder: ParsedExpression | undefined;
177
>
let expressionConfigForFolder: IConfiguredExpression | undefined;
178
>
if (folder && this.mapFolderToParsedExpression.has(folder.uri.toString())) {
179
expressionForFolder = this.mapFolderToParsedExpression.get(folder.uri.toString());
180
expressionConfigForFolder = this.mapFolderToConfiguredExpression.get(folder.uri.toString());
182
>
expressionForFolder = this.mapFolderToParsedExpression.get(ResourceGlobMatcher.NO_FOLDER);
183
>
expressionConfigForFolder = this.mapFolderToConfiguredExpression.get(ResourceGlobMatcher.NO_FOLDER);
184
>
}
185
>
186
>
if (!expressionForFolder) {
187
return false; // return early: no expression for this resource
188
}
190
>
// If the resource if from a workspace, convert its absolute path to a relative
191
>
// path so that glob patterns have a higher probability to match. For example
192
>
// a glob pattern of "src/**" will not match on an absolute path "/folder/src/file.txt"
193
>
// but can match on "src/file.txt"
194
>
195
>
let resourcePathToMatch: string | undefined;
196
>
if (folder) {
197
resourcePathToMatch = relativePath(folder.uri, resource);
199
>
resourcePathToMatch = this.uriToPath(resource);
200
>
}
201
>
202
>
if (typeof resourcePathToMatch === 'string' && !!expressionForFolder(resourcePathToMatch, undefined, hasSibling)) {
203
>
return true;
204
>
}
205
>
206
>
// If the configured expression has an absolute path, we also check for absolute paths
207
>
// to match, otherwise we potentially miss out on matches. We only do that if we previously
208
>
// matched on the relative path.
209
>
210
>
if (resourcePathToMatch !== this.uriToPath(resource) && expressionConfigForFolder?.hasAbsolutePath) {
211
return !!expressionForFolder(this.uriToPath(resource), undefined, hasSibling);
212
}
214
>
return false;
215
>
}
216
217
private uriToPath(uri: URI): string {
219
>
return uri.fsPath;
220
>
}
221
222
return uri.path;
224
}