Skip to content

Commit 0b7932a

Browse files
authored
resource globs - normalize drive letters (microsoft#182259)
1 parent 2575777 commit 0b7932a

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

src/vs/base/common/extpath.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ export function hasDriveLetter(path: string, isWindowsOS: boolean = isWindows):
325325
return false;
326326
}
327327

328-
export function getDriveLetter(path: string): string | undefined {
329-
return hasDriveLetter(path) ? path[0] : undefined;
328+
export function getDriveLetter(path: string, isWindowsOS: boolean = isWindows): string | undefined {
329+
return hasDriveLetter(path, isWindowsOS) ? path[0] : undefined;
330330
}
331331

332332
export function indexOfPath(path: string, candidate: string, ignoreCase?: boolean): number {

src/vs/workbench/common/resources.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
1414
import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration';
1515
import { Schemas } from 'vs/base/common/network';
1616
import { ResourceSet } from 'vs/base/common/map';
17+
import { getDriveLetter } from 'vs/base/common/extpath';
1718

1819
interface IConfiguredExpression {
1920
readonly expression: IExpression;
@@ -130,9 +131,36 @@ export class ResourceGlobMatcher extends Disposable {
130131
return undefined;
131132
}
132133

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+
133161
return {
134-
expression,
135-
hasAbsolutePath: keys.some(key => expression[key] === true && isAbsolute(key))
162+
expression: massagedExpression,
163+
hasAbsolutePath
136164
};
137165
}
138166

src/vs/workbench/test/common/resources.test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suite('ResourceGlobMatcher', () => {
2727
});
2828
});
2929

30-
test('Basics', () => {
30+
test('Basics', async () => {
3131
const matcher = new ResourceGlobMatcher(() => configurationService.getValue(SETTING), e => e.affectsConfiguration(SETTING), contextService, configurationService);
3232

3333
// Matching
@@ -39,18 +39,29 @@ suite('ResourceGlobMatcher', () => {
3939
let eventCounter = 0;
4040
matcher.onExpressionChange(() => eventCounter++);
4141

42-
configurationService.setUserConfiguration(SETTING, { '**/*.foo': true });
42+
await configurationService.setUserConfiguration(SETTING, { '**/*.foo': true });
4343
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: (key: string) => key === SETTING } as any);
4444
assert.equal(eventCounter, 1);
4545

4646
assert.equal(matcher.matches(URI.file('/foo/bar.md')), false);
4747
assert.equal(matcher.matches(URI.file('/foo/bar.foo')), true);
4848

49-
configurationService.setUserConfiguration(SETTING, undefined);
49+
await configurationService.setUserConfiguration(SETTING, undefined);
5050
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: (key: string) => key === SETTING } as any);
5151
assert.equal(eventCounter, 2);
5252

5353
assert.equal(matcher.matches(URI.file('/foo/bar.md')), false);
5454
assert.equal(matcher.matches(URI.file('/foo/bar.foo')), false);
55+
56+
await configurationService.setUserConfiguration(SETTING, {
57+
'**/*.md': true,
58+
'**/*.txt': false,
59+
'C:/bar/**': true,
60+
'/bar/**': true
61+
});
62+
configurationService.onDidChangeConfigurationEmitter.fire({ affectsConfiguration: (key: string) => key === SETTING } as any);
63+
64+
assert.equal(matcher.matches(URI.file('/bar/foo.1')), true);
65+
assert.equal(matcher.matches(URI.file('C:/bar/foo.1')), true);
5566
});
5667
});

0 commit comments

Comments
 (0)