Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
19bc6c27
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
19bc6c27
编写于
7月 12, 2017
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement ./ and absolute path searching per #27226
上级
457fa64f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
92 addition
and
14 deletion
+92
-14
src/vs/workbench/parts/search/browser/patternInputWidget.ts
src/vs/workbench/parts/search/browser/patternInputWidget.ts
+3
-6
src/vs/workbench/parts/search/browser/searchViewlet.ts
src/vs/workbench/parts/search/browser/searchViewlet.ts
+23
-4
src/vs/workbench/parts/search/common/searchQuery.ts
src/vs/workbench/parts/search/common/searchQuery.ts
+66
-4
未找到文件。
src/vs/workbench/parts/search/browser/patternInputWidget.ts
浏览文件 @
19bc6c27
...
...
@@ -115,7 +115,6 @@ export class PatternInputWidget extends Widget {
let
searchPaths
:
string
[];
if
(
isGlobPattern
)
{
const
segments
=
splitGlobAware
(
pattern
,
'
,
'
)
.
map
(
s
=>
strings
.
ltrim
(
s
.
trim
(),
'
./
'
))
.
filter
(
s
=>
!!
s
.
length
);
const
groups
=
this
.
groupByPathsAndExprSegments
(
segments
);
...
...
@@ -123,7 +122,6 @@ export class PatternInputWidget extends Widget {
exprSegments
=
groups
.
exprSegments
;
}
else
{
const
segments
=
pattern
.
split
(
'
,
'
)
.
map
(
s
=>
strings
.
ltrim
(
s
.
trim
(),
'
./
'
))
.
filter
(
s
=>
!!
s
.
length
);
const
groups
=
this
.
groupByPathsAndExprSegments
(
segments
);
...
...
@@ -144,15 +142,14 @@ export class PatternInputWidget extends Widget {
private
groupByPathsAndExprSegments
(
segments
:
string
[])
{
const
isSearchPath
=
(
segment
:
string
)
=>
{
// A
n segment is a search path if it is an absolute path and doesn't contain any glob characters
return
paths
.
isAbsolute
(
segment
)
&&
!
segment
.
match
(
/
[\*\{\}\(\)\[\]\?]
/
);
// A
segment is a search path if it is an absolute path or starts with ./
return
paths
.
isAbsolute
(
segment
)
||
strings
.
startsWith
(
segment
,
'
./
'
);
};
const
groups
=
collections
.
groupBy
(
segments
,
segment
=>
isSearchPath
(
segment
)
?
'
searchPaths
'
:
'
exprSegments
'
);
groups
.
searchPaths
=
groups
.
searchPaths
||
[];
groups
.
exprSegments
=
(
groups
.
exprSegments
||
[])
.
map
(
segment
=>
strings
.
trim
(
segment
,
'
/
'
));
groups
.
exprSegments
=
groups
.
exprSegments
||
[];
return
groups
;
}
...
...
src/vs/workbench/parts/search/browser/searchViewlet.ts
浏览文件 @
19bc6c27
...
...
@@ -17,6 +17,7 @@ import env = require('vs/base/common/platform');
import
{
Delayer
}
from
'
vs/base/common/async
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
strings
=
require
(
'
vs/base/common/strings
'
);
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
dom
=
require
(
'
vs/base/browser/dom
'
);
import
{
IAction
,
Action
}
from
'
vs/base/common/actions
'
;
import
{
StandardKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
...
...
@@ -897,13 +898,24 @@ export class SearchViewlet extends Viewlet {
const
workspace
=
this
.
contextService
.
getWorkspace
();
if
(
workspace
)
{
if
(
workspace
.
roots
.
length
===
1
)
{
//
Fallback to old way for single root workspac
e
folderPath
=
this
.
contextService
.
toWorkspaceRelativePath
(
resource
);
//
Show relative path from the root for single-root mod
e
folderPath
=
paths
.
relative
(
workspace
.
roots
[
0
].
fsPath
,
resource
.
fsPath
);
if
(
folderPath
&&
folderPath
!==
'
.
'
)
{
folderPath
=
'
./
'
+
folderPath
;
}
}
else
{
folderPath
=
resource
.
fsPath
;
const
owningRoot
=
this
.
contextService
.
getRoot
(
resource
);
if
(
owningRoot
)
{
const
owningRootBasename
=
paths
.
basename
(
owningRoot
.
fsPath
);
// If this root is the only one with its basename, use a relative ./ path. If there is another, use an absolute path
const
isUniqueRoot
=
workspace
.
roots
.
filter
(
root
=>
paths
.
basename
(
root
.
fsPath
)
===
owningRootBasename
).
length
===
1
;
if
(
isUniqueRoot
)
{
folderPath
=
`./
${
owningRootBasename
}
/
${
paths
.
relative
(
owningRoot
.
fsPath
,
resource
.
fsPath
)}
`
;
}
else
{
folderPath
=
resource
.
fsPath
;
}
}
}
}
...
...
@@ -977,7 +989,14 @@ export class SearchViewlet extends Viewlet {
};
const
folderResources
=
this
.
contextService
.
hasWorkspace
()
?
this
.
contextService
.
getWorkspace
().
roots
:
[];
this
.
onQueryTriggered
(
this
.
queryBuilder
.
text
(
content
,
folderResources
,
options
),
excludePatternText
,
includePatternText
);
let
query
:
ISearchQuery
;
// try {
query
=
this
.
queryBuilder
.
text
(
content
,
folderResources
,
options
);
// } catch (e) {
// // TODO@roblou show error popup
// }
this
.
onQueryTriggered
(
query
,
excludePatternText
,
includePatternText
);
if
(
!
preserveFocus
)
{
this
.
searchWidget
.
focus
(
false
);
// focus back to input field
...
...
src/vs/workbench/parts/search/common/searchQuery.ts
浏览文件 @
19bc6c27
...
...
@@ -4,15 +4,20 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
nls
=
require
(
'
vs/nls
'
);
import
{
IExpression
}
from
'
vs/base/common/glob
'
;
import
{
mixin
}
from
'
vs/base/common/objects
'
;
import
*
as
objects
from
'
vs/base/common/objects
'
;
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
uri
from
'
vs/base/common/uri
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IPatternInfo
,
IQueryOptions
,
IFolderQueryOptions
,
ISearchQuery
,
QueryType
,
ISearchConfiguration
,
getExcludes
}
from
'
vs/platform/search/common/search
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
export
class
QueryBuilder
{
constructor
(
@
IConfigurationService
private
configurationService
:
IConfigurationService
)
{
constructor
(
@
IConfigurationService
private
configurationService
:
IConfigurationService
,
@
IWorkspaceContextService
private
workspaceContextService
:
IWorkspaceContextService
)
{
}
public
text
(
contentPattern
:
IPatternInfo
,
folderResources
?:
uri
[],
options
?:
IQueryOptions
):
ISearchQuery
{
...
...
@@ -38,6 +43,8 @@ export class QueryBuilder {
return
folderConfig
.
search
.
useRipgrep
;
});
const
searchPaths
=
this
.
getSearchPaths
(
options
).
searchPaths
;
return
{
type
,
folderQueries
,
...
...
@@ -52,7 +59,7 @@ export class QueryBuilder {
useRipgrep
,
disregardIgnoreFiles
:
options
.
disregardIgnoreFiles
,
disregardExcludeSettings
:
options
.
disregardExcludeSettings
,
searchPaths
:
options
.
searchPaths
searchPaths
};
}
...
...
@@ -62,9 +69,64 @@ export class QueryBuilder {
if
(
options
.
disregardExcludeSettings
)
{
return
null
;
}
else
if
(
options
.
excludePattern
)
{
return
mixin
(
options
.
excludePattern
,
settingsExcludePattern
,
false
/* no overwrite */
);
return
objects
.
mixin
(
options
.
excludePattern
,
settingsExcludePattern
,
false
/* no overwrite */
);
}
else
{
return
settingsExcludePattern
;
}
}
private
getSearchPaths
(
options
:
IQueryOptions
):
{
searchPaths
:
string
[],
additionalIncludePatterns
:
string
[]
}
{
if
(
!
this
.
workspaceContextService
.
hasWorkspace
()
||
!
options
.
searchPaths
)
{
// No workspace => ignore search paths
return
{
searchPaths
:
[],
additionalIncludePatterns
:
[]
};
}
const
workspace
=
this
.
workspaceContextService
.
getWorkspace
();
if
(
workspace
.
roots
.
length
<
2
)
{
// 1 open folder => just resolve the search paths to absolute paths
const
searchPaths
=
options
.
searchPaths
.
map
(
searchPath
=>
{
const
relativeSearchPathMatch
=
searchPath
.
match
(
/
\.\/(
.+
)
/
);
if
(
relativeSearchPathMatch
)
{
return
paths
.
join
(
workspace
.
roots
[
0
].
fsPath
,
relativeSearchPathMatch
[
1
]);
}
else
{
return
null
;
}
});
return
{
searchPaths
,
additionalIncludePatterns
:
[]
};
}
// Is a multiroot workspace
const
searchPaths
:
string
[]
=
[];
const
additionalIncludePatterns
:
string
[]
=
[];
// 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
));
}
searchPaths
.
push
(...
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
));
}
}
}
return
{
searchPaths
,
additionalIncludePatterns
};
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录