Skip to content

Commit

Permalink
Merge pull request microsoft#82 from heejaechang/bugFix3
Browse files Browse the repository at this point in the history
fixed issue introduced by my previous fourslash changes where wild ca…
  • Loading branch information
erictraut authored Feb 7, 2020
2 parents 27b5be3 + 76e1001 commit 6ec5d62
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"eslint": "eslint ./**/*.ts",
"tslint": "tslint --project tsconfig.json --fix",
"watch": "tsc --watch",
"test": "jest",
"test": "jest --detectOpenHandles --forceExit",
"test:all": "npm run test && cd pyright/server && npm run test"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion server/pyright/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"build:cli": "node ./copyTypeshedFallback.js && npm run eslint && webpack --config webpack.config-cli.js",
"eslint": "eslint src/**/*.ts",
"watch": "tsc --watch",
"test": "jest"
"test": "jest --detectOpenHandles --forceExit"
},
"dependencies": {
"assert": "^2.0.0",
Expand Down
29 changes: 16 additions & 13 deletions server/pyright/server/src/common/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

import * as path from 'path';
import Char from 'typescript-char';
import { URI } from 'vscode-uri';
import { some } from './collectionUtils';
import { compareValues, Comparison, GetCanonicalFileName, identity } from './core';
import * as debug from './debug';
import { getStringComparer, equateStringsCaseInsensitive, equateStringsCaseSensitive, compareStringsCaseSensitive, compareStringsCaseInsensitive } from './stringUtils';
import { compareStringsCaseInsensitive, compareStringsCaseSensitive, equateStringsCaseInsensitive,
equateStringsCaseSensitive, getStringComparer } from './stringUtils';
import { VirtualFileSystem } from './vfs';
import { URI } from 'vscode-uri';

export interface FileSpec {
// File specs can contain wildcard characters (**, *, ?). This
Expand Down Expand Up @@ -503,8 +504,8 @@ export function getWildcardRegexPattern(rootPath: string, fileSpec: string): str
const pathComponents = getPathComponents(absolutePath);

const escapedSeparator = getRegexEscapedSeparator();
const doubleAsteriskRegexFragment = `(${escapedSeparator}[^${escapedSeparator}.][^${escapedSeparator}]*)*?`;
const reservedCharacterPattern = new RegExp(`[^\\w\\s${escapedSeparator}]`, "g");
const doubleAsteriskRegexFragment = `(${ escapedSeparator }[^${ escapedSeparator }.][^${ escapedSeparator }]*)*?`;
const reservedCharacterPattern = new RegExp(`[^\\w\\s${ escapedSeparator }]`, "g");

// Strip the directory separator from the root component.
if (pathComponents.length > 0) {
Expand All @@ -525,10 +526,11 @@ export function getWildcardRegexPattern(rootPath: string, fileSpec: string): str
regExPattern += component.replace(
reservedCharacterPattern, match => {
if (match === '*') {
return `[^${escapedSeparator}]*`;
return `[^${ escapedSeparator }]*`;
} else if (match === '?') {
return `[^${escapedSeparator}]`;
return `[^${ escapedSeparator }]`;
} else {
// escaping anything that is not reserved characters - word/space/separator
return '\\' + match;
}
});
Expand Down Expand Up @@ -580,7 +582,7 @@ export function getWildcardRoot(rootPath: string, fileSpec: string): string {
export function getFileSpec(rootPath: string, fileSpec: string): FileSpec {
let regExPattern = getWildcardRegexPattern(rootPath, fileSpec);
const escapedSeparator = getRegexEscapedSeparator();
regExPattern = `^(${regExPattern})($|${escapedSeparator})`;
regExPattern = `^(${ regExPattern })($|${ escapedSeparator })`;

const regExp = new RegExp(regExPattern);
const wildcardRoot = getWildcardRoot(rootPath, fileSpec);
Expand All @@ -592,7 +594,8 @@ export function getFileSpec(rootPath: string, fileSpec: string): FileSpec {
}

export function getRegexEscapedSeparator() {
return path.sep === '/' ? '\\/' : '\\\\';
// we don't need to escape "/" in typescript regular expression
return path.sep === '/' ? '/' : '\\\\';
}

/**
Expand All @@ -612,10 +615,6 @@ export function isDiskPathRoot(path: string) {
}

//// Path Comparisons

// check path for these segments: '', '.'. '..'
const relativePathSegmentRegExp = /(^|\/)\.{0,2}($|\/)/;

function comparePathsWorker(a: string, b: string, componentComparer: (a: string, b: string) => Comparison) {
if (a === b) return Comparison.EqualTo;
if (a === undefined) return Comparison.LessThan;
Expand All @@ -630,6 +629,10 @@ function comparePathsWorker(a: string, b: string, componentComparer: (a: string,
return result;
}

// check path for these segments: '', '.'. '..'
const escapedSeparator = getRegexEscapedSeparator();
const relativePathSegmentRegExp = new RegExp(`(^|${escapedSeparator}).{0,2}($|${escapedSeparator})`);

// NOTE: Performance optimization - shortcut if there are no relative path segments in
// the non-root portion of the path
const aRest = a.substring(aRoot.length);
Expand Down Expand Up @@ -731,5 +734,5 @@ export function convertUriToPath(uriString: string): string {
}

export function convertPathToUri(path: string): string {
return URI.file(path).toString();
return URI.file(path).toString();
}
2 changes: 1 addition & 1 deletion server/pyright/server/src/tests/pathUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ test('comparePaths4', () => {
});

test('comparePaths5', () => {
assert.equal(comparePaths('/a/b/c/', '/a/b/c'), Comparison.GreaterThan);
assert.equal(comparePaths('/a/b/c/', '/a/b/c'), Comparison.EqualTo);
});

test('containsPath1', () => {
Expand Down

0 comments on commit 6ec5d62

Please sign in to comment.