Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
56c6946b
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,发现更多精彩内容 >>
提交
56c6946b
编写于
5月 09, 2020
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix issue with searching using workspace folder name. Add file search integration tests
Fix #97352
上级
306235b1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
135 addition
and
16 deletion
+135
-16
src/vs/workbench/services/search/common/search.ts
src/vs/workbench/services/search/common/search.ts
+4
-4
src/vs/workbench/services/search/node/fileSearch.ts
src/vs/workbench/services/search/node/fileSearch.ts
+13
-9
src/vs/workbench/services/search/test/node/fileSearch.integrationTest.ts
...h/services/search/test/node/fileSearch.integrationTest.ts
+111
-0
src/vs/workbench/services/search/test/node/rawSearchService.test.ts
...kbench/services/search/test/node/rawSearchService.test.ts
+6
-2
src/vs/workbench/services/search/test/node/textSearch.integrationTest.ts
...h/services/search/test/node/textSearch.integrationTest.ts
+1
-1
未找到文件。
src/vs/workbench/services/search/common/search.ts
浏览文件 @
56c6946b
...
...
@@ -183,7 +183,7 @@ export function resultIsMatch(result: ITextSearchResult): result is ITextSearchM
}
export
interface
IProgressMessage
{
message
?
:
string
;
message
:
string
;
}
export
type
ISearchProgressItem
=
IFileMatch
|
IProgressMessage
;
...
...
@@ -192,8 +192,8 @@ export function isFileMatch(p: ISearchProgressItem): p is IFileMatch {
return
!!
(
<
IFileMatch
>
p
).
resource
;
}
export
function
isProgressMessage
(
p
:
ISearchProgressItem
):
p
is
IProgressMessage
{
return
!
isFileMatch
(
p
)
;
export
function
isProgressMessage
(
p
:
ISearchProgressItem
|
ISerializedSearchProgressItem
):
p
is
IProgressMessage
{
return
!
!
(
p
as
IProgressMessage
).
message
;
}
export
interface
ISearchCompleteStats
{
...
...
@@ -468,7 +468,7 @@ export interface IRawFileMatch {
*
* If not given, the search algorithm should use `relativePath`.
*/
searchPath
?:
string
;
searchPath
:
string
|
undefined
;
}
export
interface
ISearchEngine
<
T
>
{
...
...
src/vs/workbench/services/search/node/fileSearch.ts
浏览文件 @
56c6946b
...
...
@@ -24,9 +24,8 @@ import { IFileQuery, IFolderQuery, IProgressMessage, ISearchEngineStats, IRawFil
import
{
spawnRipgrepCmd
}
from
'
./ripgrepFileSearch
'
;
import
{
prepareQuery
}
from
'
vs/base/common/fuzzyScorer
'
;
interface
IDirectoryEntry
{
interface
IDirectoryEntry
extends
IRawFileMatch
{
base
:
string
;
relativePath
:
string
;
basename
:
string
;
}
...
...
@@ -122,7 +121,7 @@ export class FileWalker {
}
// File: Check for match on file pattern and include pattern
this
.
matchFile
(
onResult
,
{
relativePath
:
extraFilePath
.
fsPath
/* no workspace relative path */
});
this
.
matchFile
(
onResult
,
{
relativePath
:
extraFilePath
.
fsPath
/* no workspace relative path */
,
searchPath
:
undefined
});
});
this
.
cmdSW
=
StopWatch
.
create
(
false
);
...
...
@@ -260,7 +259,7 @@ export class FileWalker {
}
// TODO: Optimize siblings clauses with ripgrep here.
this
.
addDirectoryEntries
(
tree
,
rootFolder
,
relativeFiles
,
onResult
);
this
.
addDirectoryEntries
(
folderQuery
,
tree
,
rootFolder
,
relativeFiles
,
onResult
);
if
(
last
)
{
this
.
matchDirectoryTree
(
tree
,
rootFolder
,
onResult
);
...
...
@@ -389,13 +388,17 @@ export class FileWalker {
return
tree
;
}
private
addDirectoryEntries
({
pathToEntries
}:
IDirectoryTree
,
base
:
string
,
relativeFiles
:
string
[],
onResult
:
(
result
:
IRawFileMatch
)
=>
void
)
{
private
addDirectoryEntries
(
folderQuery
:
IFolderQuery
,
{
pathToEntries
}:
IDirectoryTree
,
base
:
string
,
relativeFiles
:
string
[],
onResult
:
(
result
:
IRawFileMatch
)
=>
void
)
{
// Support relative paths to files from a root resource (ignores excludes)
if
(
relativeFiles
.
indexOf
(
this
.
filePattern
)
!==
-
1
)
{
this
.
matchFile
(
onResult
,
{
base
:
base
,
relativePath
:
this
.
filePattern
});
this
.
matchFile
(
onResult
,
{
base
,
relativePath
:
this
.
filePattern
,
searchPath
:
this
.
getSearchPath
(
folderQuery
,
this
.
filePattern
)
});
}
function
add
(
relativePath
:
string
)
{
const
add
=
(
relativePath
:
string
)
=>
{
const
basename
=
path
.
basename
(
relativePath
);
const
dirname
=
path
.
dirname
(
relativePath
);
let
entries
=
pathToEntries
[
dirname
];
...
...
@@ -406,9 +409,10 @@ export class FileWalker {
entries
.
push
({
base
,
relativePath
,
basename
basename
,
searchPath
:
this
.
getSearchPath
(
folderQuery
,
relativePath
),
});
}
}
;
relativeFiles
.
forEach
(
add
);
}
...
...
src/vs/workbench/services/search/test/node/fileSearch.integrationTest.ts
0 → 100644
浏览文件 @
56c6946b
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
{
getPathFromAmdModule
}
from
'
vs/base/common/amd
'
;
import
*
as
path
from
'
vs/base/common/path
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
IFileQuery
,
IFolderQuery
,
ISerializedSearchProgressItem
,
isProgressMessage
,
QueryType
}
from
'
vs/workbench/services/search/common/search
'
;
import
{
SearchService
}
from
'
vs/workbench/services/search/node/rawSearchService
'
;
const
TEST_FIXTURES
=
path
.
normalize
(
getPathFromAmdModule
(
require
,
'
./fixtures
'
));
const
TEST_FIXTURES2
=
path
.
normalize
(
getPathFromAmdModule
(
require
,
'
./fixtures2
'
));
const
EXAMPLES_FIXTURES
=
path
.
join
(
TEST_FIXTURES
,
'
examples
'
);
const
MORE_FIXTURES
=
path
.
join
(
TEST_FIXTURES
,
'
more
'
);
const
TEST_ROOT_FOLDER
:
IFolderQuery
=
{
folder
:
URI
.
file
(
TEST_FIXTURES
)
};
const
ROOT_FOLDER_QUERY
:
IFolderQuery
[]
=
[
TEST_ROOT_FOLDER
];
const
MULTIROOT_QUERIES
:
IFolderQuery
[]
=
[
{
folder
:
URI
.
file
(
EXAMPLES_FIXTURES
),
folderName
:
'
examples_folder
'
},
{
folder
:
URI
.
file
(
MORE_FIXTURES
)
}
];
async
function
doSearchTest
(
query
:
IFileQuery
,
expectedResultCount
:
number
|
Function
):
Promise
<
void
>
{
const
svc
=
new
SearchService
();
const
results
:
ISerializedSearchProgressItem
[]
=
[];
await
svc
.
doFileSearch
(
query
,
e
=>
{
if
(
!
isProgressMessage
(
e
))
{
if
(
Array
.
isArray
(
e
))
{
results
.
push
(...
e
);
}
else
{
results
.
push
(
e
);
}
}
});
assert
.
equal
(
results
.
length
,
expectedResultCount
,
`rg
${
results
.
length
}
!==
${
expectedResultCount
}
`
);
}
suite
(
'
FileSearch-integration
'
,
function
()
{
this
.
timeout
(
1000
*
60
);
// increase timeout for this suite
test
(
'
File - simple
'
,
()
=>
{
const
config
:
IFileQuery
=
{
type
:
QueryType
.
File
,
folderQueries
:
ROOT_FOLDER_QUERY
};
return
doSearchTest
(
config
,
14
);
});
test
(
'
File - filepattern
'
,
()
=>
{
const
config
:
IFileQuery
=
{
type
:
QueryType
.
File
,
folderQueries
:
ROOT_FOLDER_QUERY
,
filePattern
:
'
anotherfile
'
};
return
doSearchTest
(
config
,
1
);
});
test
(
'
File - exclude
'
,
()
=>
{
const
config
:
IFileQuery
=
{
type
:
QueryType
.
File
,
folderQueries
:
ROOT_FOLDER_QUERY
,
filePattern
:
'
file
'
,
excludePattern
:
{
'
**/anotherfolder/**
'
:
true
}
};
return
doSearchTest
(
config
,
2
);
});
test
(
'
File - multiroot
'
,
()
=>
{
const
config
:
IFileQuery
=
{
type
:
QueryType
.
File
,
folderQueries
:
MULTIROOT_QUERIES
,
filePattern
:
'
file
'
,
excludePattern
:
{
'
**/anotherfolder/**
'
:
true
}
};
return
doSearchTest
(
config
,
2
);
});
test
(
'
File - multiroot with folder name
'
,
()
=>
{
const
config
:
IFileQuery
=
{
type
:
QueryType
.
File
,
folderQueries
:
MULTIROOT_QUERIES
,
filePattern
:
'
examples_folder anotherfile
'
};
return
doSearchTest
(
config
,
1
);
});
test
(
'
File - multiroot with folder name and sibling exclude
'
,
()
=>
{
const
config
:
IFileQuery
=
{
type
:
QueryType
.
File
,
folderQueries
:
[
{
folder
:
URI
.
file
(
TEST_FIXTURES
),
folderName
:
'
folder1
'
},
{
folder
:
URI
.
file
(
TEST_FIXTURES2
)
}
],
filePattern
:
'
folder1 site
'
,
excludePattern
:
{
'
*.css
'
:
{
when
:
'
$(basename).less
'
}
}
};
return
doSearchTest
(
config
,
1
);
});
});
src/vs/workbench/services/search/test/node/rawSearchService.test.ts
浏览文件 @
56c6946b
...
...
@@ -83,6 +83,7 @@ suite('RawSearchService', () => {
const
rawMatch
:
IRawFileMatch
=
{
base
:
path
.
normalize
(
'
/some
'
),
relativePath
:
'
where
'
,
searchPath
:
undefined
};
const
match
:
ISerializedFileMatch
=
{
...
...
@@ -232,7 +233,8 @@ suite('RawSearchService', () => {
base
:
path
.
normalize
(
'
/some/where
'
),
relativePath
,
basename
:
relativePath
,
size
:
3
size
:
3
,
searchPath
:
undefined
}));
const
Engine
=
TestSearchEngine
.
bind
(
null
,
()
=>
matches
.
shift
()
!
);
const
service
=
new
RawSearchService
();
...
...
@@ -291,7 +293,8 @@ suite('RawSearchService', () => {
base
:
path
.
normalize
(
'
/some/where
'
),
relativePath
,
basename
:
relativePath
,
size
:
3
size
:
3
,
searchPath
:
undefined
}));
const
Engine
=
TestSearchEngine
.
bind
(
null
,
()
=>
matches
.
shift
()
!
);
const
service
=
new
RawSearchService
();
...
...
@@ -340,6 +343,7 @@ suite('RawSearchService', () => {
matches
.
push
({
base
:
path
.
normalize
(
'
/some/where
'
),
relativePath
:
'
bc
'
,
searchPath
:
undefined
});
const
results
:
any
[]
=
[];
const
cb
:
IProgressCallback
=
value
=>
{
...
...
src/vs/workbench/services/search/test/node/textSearch.integrationTest.ts
浏览文件 @
56c6946b
...
...
@@ -46,7 +46,7 @@ function doSearchTest(query: ITextQuery, expectedResultCount: number | Function)
});
}
suite
(
'
Search-integration
'
,
function
()
{
suite
(
'
Text
Search-integration
'
,
function
()
{
this
.
timeout
(
1000
*
60
);
// increase timeout for this suite
test
(
'
Text: GameOfLife
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录