提交 75fd5a7f 编写于 作者: R Rob Lourens

Fix QueryBuilder issues with trailing / and file:///

上级 3afa94a4
......@@ -141,7 +141,7 @@ export class QueryBuilder {
const pathPortions = this.expandAbsoluteSearchPaths(pathPortion);
return pathPortions.map(searchPath => {
return <ISearchPathPattern>{
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)
};
}
......
......@@ -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'),
<ISearchPathsResult>{
searchPaths: [{ searchPath: uri.parse('/foo/bar') }]
searchPaths: [{ searchPath: getUri('/foo/bar') }]
}
],
[
'/foo/bar,a',
fixPath('/foo/bar') + ',' + 'a',
<ISearchPathsResult>{
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'),
<ISearchPathsResult>{
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'),
<ISearchPathsResult>{
searchPaths: [{
searchPath: uri.parse('/foo/bar'),
searchPath: getUri('/foo/bar'),
pattern: '**/*.ts'
}]
}
],
[
'/foo/bar/*a/b/c',
fixPath('/foo/bar/*a/b/c'),
<ISearchPathsResult>{
searchPaths: [{
searchPath: uri.parse('/foo/bar'),
searchPath: getUri('/foo/bar'),
pattern: '*a/b/c'
}]
}
],
[
'/*a/b/c',
fixPath('/*a/b/c'),
<ISearchPathsResult>{
searchPaths: [{
searchPath: uri.parse('/'),
searchPath: getUri('/'),
pattern: '*a/b/c'
}]
}
],
[
'/foo/{b,c}ar',
fixPath('/foo/{b,c}ar'),
<ISearchPathsResult>{
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'),
<ISearchPathsResult>{
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册