Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
fd875356
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fd875356
编写于
11月 03, 2018
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #62409 - resolve exclude patterns for searchPaths correctly
上级
07340673
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
54 addition
and
49 deletion
+54
-49
src/vs/workbench/parts/search/common/queryBuilder.ts
src/vs/workbench/parts/search/common/queryBuilder.ts
+50
-41
src/vs/workbench/parts/search/test/common/queryBuilder.test.ts
...s/workbench/parts/search/test/common/queryBuilder.test.ts
+4
-8
未找到文件。
src/vs/workbench/parts/search/common/queryBuilder.ts
浏览文件 @
fd875356
...
...
@@ -109,14 +109,9 @@ export class QueryBuilder {
let
excludePattern
=
this
.
parseExcludePattern
(
options
.
excludePattern
||
''
);
// Build folderQueries from searchPaths, if given, otherwise folderResources
let
folderQueries
=
folderResources
&&
folderResources
.
map
(
uri
=>
this
.
getFolderQueryForRoot
(
uri
,
options
));
if
(
searchPaths
&&
searchPaths
.
length
)
{
const
allRootExcludes
=
folderQueries
&&
this
.
mergeExcludesFromFolderQueries
(
folderQueries
);
folderQueries
=
searchPaths
.
map
(
searchPath
=>
this
.
getFolderQueryForSearchPath
(
searchPath
));
// TODO Rob
if
(
allRootExcludes
)
{
excludePattern
=
objects
.
mixin
(
excludePattern
||
Object
.
create
(
null
),
allRootExcludes
);
}
}
const
folderQueries
=
searchPaths
&&
searchPaths
.
length
?
searchPaths
.
map
(
searchPath
=>
this
.
getFolderQueryForSearchPath
(
searchPath
,
options
))
:
folderResources
&&
folderResources
.
map
(
uri
=>
this
.
getFolderQueryForRoot
(
uri
,
options
));
const
useRipgrep
=
!
folderResources
||
folderResources
.
every
(
folder
=>
{
const
folderConfig
=
this
.
configurationService
.
getValue
<
ISearchConfiguration
>
({
resource
:
folder
});
...
...
@@ -238,31 +233,6 @@ export class QueryBuilder {
return
Object
.
keys
(
excludeExpression
).
length
?
excludeExpression
:
undefined
;
}
private
mergeExcludesFromFolderQueries
(
folderQueries
:
IFolderQuery
[]):
glob
.
IExpression
|
undefined
{
const
mergedExcludes
=
folderQueries
.
reduce
((
merged
:
glob
.
IExpression
,
fq
:
IFolderQuery
)
=>
{
if
(
fq
.
excludePattern
)
{
objects
.
mixin
(
merged
,
this
.
getAbsoluteIExpression
(
fq
.
excludePattern
,
fq
.
folder
.
fsPath
));
}
return
merged
;
},
Object
.
create
(
null
));
// Don't return an empty IExpression
return
Object
.
keys
(
mergedExcludes
).
length
?
mergedExcludes
:
undefined
;
}
private
getAbsoluteIExpression
(
expr
:
glob
.
IExpression
,
root
:
string
):
glob
.
IExpression
{
return
Object
.
keys
(
expr
)
.
reduce
((
absExpr
:
glob
.
IExpression
,
key
:
string
)
=>
{
if
(
expr
[
key
]
&&
!
paths
.
isAbsolute
(
key
))
{
const
absPattern
=
paths
.
join
(
root
,
key
);
absExpr
[
absPattern
]
=
expr
[
key
];
}
return
absExpr
;
},
Object
.
create
(
null
));
}
private
getExcludesForFolder
(
folderConfig
:
ISearchConfiguration
,
options
:
ICommonQueryBuilderOptions
):
glob
.
IExpression
|
undefined
{
return
options
.
disregardExcludeSettings
?
undefined
:
...
...
@@ -331,13 +301,36 @@ export class QueryBuilder {
return
[];
}
private
getFolderQueryForSearchPath
(
searchPath
:
ISearchPathPattern
):
IFolderQuery
{
const
folder
=
searchPath
.
searchPath
;
const
folderConfig
=
this
.
configurationService
.
getValue
<
ISearchConfiguration
>
({
resource
:
folder
});
return
<
IFolderQuery
>
{
folder
,
private
getFolderQueryForSearchPath
(
searchPath
:
ISearchPathPattern
,
options
:
ICommonQueryBuilderOptions
):
IFolderQuery
{
const
searchPathWorkspaceFolder
=
this
.
workspaceContextService
.
getWorkspaceFolder
(
searchPath
.
searchPath
);
const
searchPathRelativePath
=
searchPathWorkspaceFolder
&&
searchPath
.
searchPath
.
path
.
substr
(
searchPathWorkspaceFolder
.
uri
.
path
.
length
+
1
);
const
rootConfig
=
this
.
getFolderQueryForRoot
(
searchPath
.
searchPath
,
options
);
let
resolvedExcludes
:
glob
.
IExpression
=
{};
if
(
searchPathWorkspaceFolder
&&
rootConfig
.
excludePattern
)
{
// Resolve excludes relative to the search path
for
(
let
excludePattern
in
rootConfig
.
excludePattern
)
{
const
{
pathPortion
,
globPortion
}
=
splitSimpleGlob
(
excludePattern
);
if
(
!
pathPortion
)
{
// **/foo
resolvedExcludes
[
globPortion
]
=
rootConfig
.
excludePattern
[
excludePattern
];
}
else
if
(
strings
.
startsWith
(
pathPortion
,
searchPathRelativePath
))
{
// searchPathRelativePath/something/**/foo
// Strip `searchPathRelativePath/`
const
resolvedPathPortion
=
pathPortion
.
substr
(
searchPathRelativePath
.
length
+
1
);
const
resolvedPattern
=
globPortion
?
resolvedPathPortion
+
globPortion
:
resolvedPathPortion
;
resolvedExcludes
[
resolvedPattern
]
=
rootConfig
.
excludePattern
[
excludePattern
];
}
}
}
return
{
...
rootConfig
,
...{
includePattern
:
searchPath
.
pattern
&&
patternListToIExpression
([
searchPath
.
pattern
]),
fileEncoding
:
folderConfig
.
files
&&
folderConfig
.
files
.
encoding
excludePattern
:
Object
.
keys
(
resolvedExcludes
).
length
?
resolvedExcludes
:
undefined
}
};
}
...
...
@@ -362,7 +355,7 @@ function splitGlobFromPath(searchPath: string): { pathPortion: string, globPorti
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.
// If the last slash was the only slash, then we now have '' or 'C:'
or '.'
. Append a slash.
pathPortion
+=
'
/
'
;
}
...
...
@@ -379,6 +372,22 @@ function splitGlobFromPath(searchPath: string): { pathPortion: string, globPorti
};
}
function
splitSimpleGlob
(
searchPath
:
string
):
{
pathPortion
:
string
,
globPortion
?:
string
}
{
const
globCharMatch
=
searchPath
.
match
(
/
[\*\{\}\(\)\[\]\?]
/
);
if
(
globCharMatch
)
{
const
globCharIdx
=
globCharMatch
.
index
;
return
{
pathPortion
:
searchPath
.
substr
(
0
,
globCharIdx
),
globPortion
:
searchPath
.
substr
(
globCharIdx
)
};
}
// No glob char
return
{
pathPortion
:
searchPath
};
}
function
patternListToIExpression
(
patterns
:
string
[]):
glob
.
IExpression
{
return
patterns
.
length
?
patterns
.
reduce
((
glob
,
cur
)
=>
{
glob
[
cur
]
=
true
;
return
glob
;
},
Object
.
create
(
null
))
:
...
...
src/vs/workbench/parts/search/test/common/queryBuilder.test.ts
浏览文件 @
fd875356
...
...
@@ -153,14 +153,11 @@ suite('QueryBuilder', () => {
<
ITextQuery
>
{
contentPattern
:
PATTERN_INFO
,
folderQueries
:
[{
folder
:
getUri
(
paths
.
join
(
ROOT_1
,
'
foo
'
))
}],
folder
:
getUri
(
paths
.
join
(
ROOT_1
,
'
foo
'
)),
excludePattern
:
{
[
paths
.
join
(
ROOT_1
,
'
foo/**/*.js
'
)]:
true
,
[
paths
.
join
(
ROOT_1
,
'
bar/**
'
)]:
{
'
when
'
:
'
$(basename).ts
'
[
'
**/*.js
'
]:
true
}
},
}
]
,
type
:
QueryType
.
Text
});
});
...
...
@@ -212,7 +209,6 @@ suite('QueryBuilder', () => {
folderQueries
:
[
{
folder
:
getUri
(
paths
.
join
(
ROOT_2
,
'
src
'
))
}
],
excludePattern
:
patternsToIExpression
(
paths
.
join
(
ROOT_1
,
'
foo/**/*.js
'
),
paths
.
join
(
ROOT_2
,
'
bar
'
)),
type
:
QueryType
.
Text
}
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录