From 75fd5a7f29602537705a221006aeee7fa1445a9d Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Mon, 24 Jul 2017 17:37:00 -0700 Subject: [PATCH] Fix QueryBuilder issues with trailing / and file:/// --- .../parts/search/common/queryBuilder.ts | 10 ++++- .../search/test/common/queryBuilder.test.ts | 38 +++++++++---------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/vs/workbench/parts/search/common/queryBuilder.ts b/src/vs/workbench/parts/search/common/queryBuilder.ts index 4d9052311cd..bc7445ab0b7 100644 --- a/src/vs/workbench/parts/search/common/queryBuilder.ts +++ b/src/vs/workbench/parts/search/common/queryBuilder.ts @@ -141,7 +141,7 @@ export class QueryBuilder { const pathPortions = this.expandAbsoluteSearchPaths(pathPortion); return pathPortions.map(searchPath => { return { - searchPath: uri.parse(searchPath), + searchPath: uri.file(searchPath), pattern: globPortion }; }); @@ -198,8 +198,14 @@ function splitGlobFromPath(searchPath: string): { pathPortion: string, globPorti const globCharIdx = globCharMatch.index; const lastSlashMatch = searchPath.substr(0, globCharIdx).match(/[/|\\][^/\\]*$/); if (lastSlashMatch) { + let pathPortion = searchPath.substr(0, lastSlashMatch.index); + if (!pathPortion.match(/[/\\]/)) { + // If the last slash was the only slash, then we now have '' or 'C:'. Append a slash. + pathPortion += '/'; + } + return { - pathPortion: searchPath.substr(0, lastSlashMatch.index) || '/', + pathPortion, globPortion: searchPath.substr(lastSlashMatch.index + 1) }; } diff --git a/src/vs/workbench/parts/search/test/common/queryBuilder.test.ts b/src/vs/workbench/parts/search/test/common/queryBuilder.test.ts index 69f0e389d5e..2ae2bdf0764 100644 --- a/src/vs/workbench/parts/search/test/common/queryBuilder.test.ts +++ b/src/vs/workbench/parts/search/test/common/queryBuilder.test.ts @@ -17,10 +17,10 @@ import { TestContextService } from 'vs/workbench/test/workbenchTestServices'; import { ISearchQuery, QueryType, IPatternInfo } from 'vs/platform/search/common/search'; -suite.only('SearchQuery', () => { +suite('QueryBuilder', () => { const PATTERN_INFO: IPatternInfo = { pattern: 'a' }; const ROOT_1 = fixPath('/foo/root1'); - const ROOT_1_URI = uri.parse(ROOT_1); + const ROOT_1_URI = getUri(ROOT_1); let instantiationService: TestInstantiationService; let queryBuilder: QueryBuilder; @@ -102,56 +102,56 @@ suite.only('SearchQuery', () => { test('absolute includes', () => { [ [ - '/foo/bar', + fixPath('/foo/bar'), { - searchPaths: [{ searchPath: uri.parse('/foo/bar') }] + searchPaths: [{ searchPath: getUri('/foo/bar') }] } ], [ - '/foo/bar,a', + fixPath('/foo/bar') + ',' + 'a', { - searchPaths: [{ searchPath: uri.parse('/foo/bar') }], + searchPaths: [{ searchPath: getUri('/foo/bar') }], includePattern: patternsToIExpression(globalGlob('a')) } ], [ - '/foo/bar, /1/2', + fixPath('/foo/bar') + ',' + fixPath('/1/2'), { - searchPaths: [{ searchPath: uri.parse('/foo/bar') }, { searchPath: uri.parse('/1/2') }] + searchPaths: [{ searchPath: getUri('/foo/bar') }, { searchPath: getUri('/1/2') }] } ], [ - '/foo/bar/**/*.ts', + fixPath('/foo/bar/**/*.ts'), { searchPaths: [{ - searchPath: uri.parse('/foo/bar'), + searchPath: getUri('/foo/bar'), pattern: '**/*.ts' }] } ], [ - '/foo/bar/*a/b/c', + fixPath('/foo/bar/*a/b/c'), { searchPaths: [{ - searchPath: uri.parse('/foo/bar'), + searchPath: getUri('/foo/bar'), pattern: '*a/b/c' }] } ], [ - '/*a/b/c', + fixPath('/*a/b/c'), { searchPaths: [{ - searchPath: uri.parse('/'), + searchPath: getUri('/'), pattern: '*a/b/c' }] } ], [ - '/foo/{b,c}ar', + fixPath('/foo/{b,c}ar'), { searchPaths: [{ - searchPath: uri.parse('/foo'), + searchPath: getUri('/foo'), pattern: '{b,c}ar' }] } @@ -179,7 +179,7 @@ suite.only('SearchQuery', () => { } ], [ - './a/*b/c, /project/foo', + './a/*b/c, ' + fixPath('/project/foo'), { searchPaths: [ { @@ -329,11 +329,11 @@ function patternsToIExpression(...patterns: string[]): IExpression { } function getUri(slashPath: string): uri { - return uri.parse(fixPath(slashPath)); + return uri.file(fixPath(slashPath)); } function fixPath(slashPath: string): string { return process.platform === 'win32' ? - paths.join('c:', ...slashPath.split('/')) : + (slashPath.match(/^c:/) ? slashPath : paths.join('c:', ...slashPath.split('/'))) : slashPath; } \ No newline at end of file -- GitLab