提交 9027646b 编写于 作者: R Rob Lourens

Fix ./ and absolute paths with glob patterns

上级 1a530ec1
......@@ -115,6 +115,7 @@ export class PatternInputWidget extends Widget {
let searchPaths: string[];
if (isGlobPattern) {
const segments = splitGlobAware(pattern, ',')
.map(s => s.trim())
.filter(s => !!s.length);
const groups = this.groupByPathsAndExprSegments(segments);
......@@ -122,6 +123,7 @@ export class PatternInputWidget extends Widget {
exprSegments = groups.exprSegments;
} else {
const segments = pattern.split(',')
.map(s => s.trim())
.filter(s => !!s.length);
const groups = this.groupByPathsAndExprSegments(segments);
......
......@@ -91,51 +91,48 @@ export class QueryBuilder {
const searchPaths: string[] = [];
const additionalIncludePatterns: string[] = [];
const workspace = this.workspaceContextService.getWorkspace();
if (workspace.roots.length < 2) {
for (const searchPath of options.searchPaths) {
// 1 open folder => just resolve the search paths to absolute paths
const { pathPortion, globPortion } = splitGlobFromPath(searchPath);
const absolutePathPortion = paths.isAbsolute(pathPortion) ?
pathPortion :
paths.join(workspace.roots[0].fsPath, pathPortion);
searchPaths.push(absolutePathPortion);
if (globPortion) {
additionalIncludePatterns.push(paths.join(absolutePathPortion, globPortion));
}
}
for (const searchPath of options.searchPaths) {
// 1 open folder => just resolve the search paths to absolute paths
const { pathPortion, globPortion } = splitGlobFromPath(searchPath);
const absolutePathPortions = this.expandAbsoluteSearchPaths(pathPortion);
searchPaths.push(...absolutePathPortions);
return {
searchPaths,
additionalIncludePatterns
};
if (globPortion) {
additionalIncludePatterns.push(...absolutePathPortions.map(abs => paths.join(abs, globPortion)));
}
}
// Is a multiroot workspace
// Resolve searchPaths, relative or absolute, against roots
for (const searchPath of options.searchPaths) {
if (paths.isAbsolute(searchPath)) {
searchPaths.push(searchPath); // later, pull out globs
} else {
const relativeSearchPathMatch = searchPath.match(/\.\/(.+)\/(.+)/);
if (relativeSearchPathMatch) {
const searchPathRoot = relativeSearchPathMatch[1];
const matchingRoots = workspace.roots.filter(root => paths.basename(root.fsPath) === searchPathRoot);
if (!matchingRoots.length) {
// throw new Error(nls.localize('search.invalidRootFolder', 'No root folder named {}', searchPathRoot));
} else {
searchPaths.push(...matchingRoots.map(root => paths.join(root.fsPath, relativeSearchPathMatch[2])));
}
return {
searchPaths,
additionalIncludePatterns
};
}
private expandAbsoluteSearchPaths(searchPath: string): string[] {
if (paths.isAbsolute(searchPath)) {
return [searchPath];
}
const workspace = this.workspaceContextService.getWorkspace();
if (workspace.roots.length === 1) {
return [paths.join(workspace.roots[0].fsPath, searchPath)];
} else {
const relativeSearchPathMatch = searchPath.match(/\.\/([^\/]+)(\/.+)?/);
if (relativeSearchPathMatch) {
const searchPathRoot = relativeSearchPathMatch[1];
const matchingRoots = workspace.roots.filter(root => paths.basename(root.fsPath) === searchPathRoot);
if (matchingRoots.length) {
return matchingRoots.map(root => paths.join(root.fsPath, relativeSearchPathMatch[2] || ''));
} else {
// Malformed ./ search path
// throw new Error(nls.localize('search.invalidRelativeInclude', 'Invalid folder include pattern: {}', searchPath));
// throw new Error(nls.localize('search.invalidRootFolder', 'No root folder named {}', searchPathRoot));
}
} else {
// Malformed ./ search path
// throw new Error(nls.localize('search.invalidRelativeInclude', 'Invalid folder include pattern: {}', searchPath));
}
}
return { searchPaths, additionalIncludePatterns };
return [];
}
}
......@@ -156,4 +153,4 @@ function splitGlobFromPath(searchPath: string): { pathPortion: string, globPorti
return {
pathPortion: searchPath
};
}
\ No newline at end of file
}
......@@ -398,13 +398,13 @@ function foldersToRgExcludeGlobs(folderQueries: IFolderSearch[], globalExclude:
}
function foldersToIncludeGlobs(folderQueries: IFolderSearch[], globalInclude: glob.IExpression): string[] {
const globArgs: string[] = [];
const globArgs = new Set<string>();
folderQueries.forEach(folderQuery => {
const result = globExprsToRgGlobs(globalInclude, folderQuery.folder);
globArgs.push(...result.globArgs);
result.globArgs.forEach(arg => globArgs.add(arg));
});
return globArgs;
return (<any>Array).from(globArgs);
}
function globExprsToRgGlobs(patterns: glob.IExpression, folder: string): IRgGlobResult {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册