Skip to content

Commit 783df42

Browse files
committed
Convert globs to NFD on Mac (microsoft#24074)
1 parent eb6fbe6 commit 783df42

3 files changed

Lines changed: 34 additions & 22 deletions

File tree

src/vs/base/common/strings.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,19 @@ export function regExpLeadsToEndlessLoop(regexp: RegExp): boolean {
238238
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize}
239239
*/
240240
export const canNormalize = typeof ((<any>'').normalize) === 'function';
241-
const nonAsciiCharactersPattern = /[^\u0000-\u0080]/;
242-
const normalizedCache = new BoundedMap<string>(10000); // bounded to 10000 elements
241+
242+
const nfcCache = new BoundedMap<string>(10000); // bounded to 10000 elements
243243
export function normalizeNFC(str: string): string {
244+
return normalize(str, 'NFC', nfcCache);
245+
}
246+
247+
const nfdCache = new BoundedMap<string>(10000); // bounded to 10000 elements
248+
export function normalizeNFD(str: string): string {
249+
return normalize(str, 'NFD', nfdCache);
250+
}
251+
252+
const nonAsciiCharactersPattern = /[^\u0000-\u0080]/;
253+
function normalize(str: string, form: string, normalizedCache: BoundedMap<string>): string {
244254
if (!canNormalize || !str) {
245255
return str;
246256
}
@@ -252,7 +262,7 @@ export function normalizeNFC(str: string): string {
252262

253263
let res: string;
254264
if (nonAsciiCharactersPattern.test(str)) {
255-
res = (<any>str).normalize('NFC');
265+
res = (<any>str).normalize(form);
256266
} else {
257267
res = str;
258268
}

src/vs/workbench/services/search/node/ripgrepFileSearch.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import * as cp from 'child_process';
77
import { rgPath } from 'vscode-ripgrep';
88

9+
import { isMacintosh as isMac } from 'vs/base/common/platform';
910
import * as glob from 'vs/base/common/glob';
11+
import { normalizeNFD } from 'vs/base/common/strings';
1012

1113
import { IFolderSearch } from './search';
1214
import { foldersToIncludeGlobs, foldersToRgExcludeGlobs } from './ripgrepTextSearch';
@@ -24,14 +26,14 @@ function getRgArgs(folderQuery: IFolderSearch, includePattern: glob.IExpression,
2426

2527
// includePattern can't have siblingClauses
2628
foldersToIncludeGlobs([folderQuery], includePattern, false).forEach(globArg => {
27-
args.push('-g', globArg);
29+
args.push('-g', isMac ? normalizeNFD(globArg) : globArg);
2830
});
2931

3032
let siblingClauses: glob.IExpression;
3133

3234
const rgGlobs = foldersToRgExcludeGlobs([folderQuery], excludePattern, undefined, false);
3335
rgGlobs.globArgs
34-
.forEach(rgGlob => args.push('-g', `!${rgGlob}`));
36+
.forEach(rgGlob => args.push('-g', `!${isMac ? normalizeNFD(rgGlob) : rgGlob}`));
3537
siblingClauses = rgGlobs.siblingClauses;
3638

3739
// Don't use .gitignore or .ignore

src/vs/workbench/services/search/test/node/search.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,24 +234,24 @@ suite('FileSearchEngine', () => {
234234
});
235235
});
236236

237-
// test('Files: *.* exclude with unicode', function (done: () => void) {
238-
// let engine = new FileSearchEngine({
239-
// folderQueries: ROOT_FOLDER_QUERY,
240-
// filePattern: '*.*',
241-
// excludePattern: { '**/üm laut汉语': true }
242-
// });
237+
test('Files: *.* exclude with unicode', function (done: () => void) {
238+
let engine = new FileSearchEngine({
239+
folderQueries: ROOT_FOLDER_QUERY,
240+
filePattern: '*.*',
241+
excludePattern: { '**/üm laut汉语': true }
242+
});
243243

244-
// let count = 0;
245-
// engine.search((result) => {
246-
// if (result) {
247-
// count++;
248-
// }
249-
// }, () => { }, (error) => {
250-
// assert.ok(!error);
251-
// assert.equal(count, 13);
252-
// done();
253-
// });
254-
// });
244+
let count = 0;
245+
engine.search((result) => {
246+
if (result) {
247+
count++;
248+
}
249+
}, () => { }, (error) => {
250+
assert.ok(!error);
251+
assert.equal(count, 13);
252+
done();
253+
});
254+
});
255255

256256
test('Files: multiroot with exclude', function (done: () => void) {
257257
const folderQueries: IFolderSearch[] = [

0 commit comments

Comments
 (0)