Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
542b0145
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,发现更多精彩内容 >>
提交
542b0145
编写于
12月 11, 2019
作者:
J
Jackson Kearl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Dim the line numbers of context results
上级
70fb5c6c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
7 deletion
+43
-7
extensions/search-result/src/extension.ts
extensions/search-result/src/extension.ts
+36
-7
extensions/theme-defaults/themes/hc_black.json
extensions/theme-defaults/themes/hc_black.json
+7
-0
未找到文件。
extensions/search-result/src/extension.ts
浏览文件 @
542b0145
...
...
@@ -13,8 +13,26 @@ const DIRECTIVES = ['# Query:', '# Flags:', '# Including:', '# Excluding:', '# C
const
FLAGS
=
[
'
RegExp
'
,
'
CaseSensitive
'
,
'
IgnoreExcludeSettings
'
,
'
WordMatch
'
];
let
cachedLastParse
:
{
version
:
number
,
parse
:
ParsedSearchResults
,
uri
:
vscode
.
Uri
}
|
undefined
;
let
documentChangeListener
:
vscode
.
Disposable
|
undefined
;
export
function
activate
(
context
:
vscode
.
ExtensionContext
)
{
const
contextLineDecorations
=
vscode
.
window
.
createTextEditorDecorationType
({
opacity
:
'
0.7
'
});
const
matchLineDecorations
=
vscode
.
window
.
createTextEditorDecorationType
({
fontWeight
:
'
bold
'
});
const
decorate
=
(
editor
:
vscode
.
TextEditor
)
=>
{
const
parsed
=
parseSearchResults
(
editor
.
document
).
filter
(
isResultLine
);
const
contextRanges
=
parsed
.
filter
(
line
=>
line
.
isContext
).
map
(
line
=>
line
.
prefixRange
);
const
matchRanges
=
parsed
.
filter
(
line
=>
!
line
.
isContext
).
map
(
line
=>
line
.
prefixRange
);
editor
.
setDecorations
(
contextLineDecorations
,
contextRanges
);
editor
.
setDecorations
(
matchLineDecorations
,
matchRanges
);
};
if
(
vscode
.
window
.
activeTextEditor
&&
vscode
.
window
.
activeTextEditor
.
document
.
languageId
===
'
search-result
'
)
{
decorate
(
vscode
.
window
.
activeTextEditor
);
}
context
.
subscriptions
.
push
(
vscode
.
commands
.
registerCommand
(
'
searchResult.rerunSearch
'
,
()
=>
vscode
.
commands
.
executeCommand
(
'
search.action.rerunEditorSearch
'
)),
vscode
.
commands
.
registerCommand
(
'
searchResult.rerunSearchWithContext
'
,
()
=>
vscode
.
commands
.
executeCommand
(
'
search.action.rerunEditorSearchWithContext
'
)),
...
...
@@ -84,15 +102,24 @@ export function activate(context: vscode.ExtensionContext) {
}
}),
vscode
.
window
.
onDidChangeActiveTextEditor
(
e
=>
{
if
(
e
?.
document
.
languageId
===
'
search-result
'
)
{
vscode
.
window
.
onDidChangeActiveTextEditor
(
e
ditor
=>
{
if
(
e
ditor
?.
document
.
languageId
===
'
search-result
'
)
{
// Clear the parse whenever we open a new editor.
// Conservative because things like the URI might remain constant even if the contents change, and re-parsing even large files is relatively fast.
cachedLastParse
=
undefined
;
documentChangeListener
?.
dispose
();
documentChangeListener
=
vscode
.
workspace
.
onDidChangeTextDocument
(
doc
=>
{
if
(
doc
.
document
.
uri
===
editor
.
document
.
uri
)
{
decorate
(
editor
);
}
});
decorate
(
editor
);
}
}),
{
dispose
()
{
cachedLastParse
=
undefined
;
}
}
{
dispose
()
{
cachedLastParse
=
undefined
;
documentChangeListener
?.
dispose
();
}
}
);
}
...
...
@@ -129,12 +156,13 @@ function relativePathToUri(path: string, resultsUri: vscode.Uri): vscode.Uri | u
}
type
ParsedSearchFileLine
=
{
type
:
'
file
'
,
location
:
vscode
.
LocationLink
,
allLocations
:
vscode
.
LocationLink
[],
path
:
string
};
type
ParsedSearchResultLine
=
{
type
:
'
result
'
,
location
:
vscode
.
LocationLink
};
type
ParsedSearchResultLine
=
{
type
:
'
result
'
,
location
:
vscode
.
LocationLink
,
isContext
:
boolean
,
prefixRange
:
vscode
.
Range
};
type
ParsedSearchResults
=
Array
<
ParsedSearchFileLine
|
ParsedSearchResultLine
>
;
const
isFileLine
=
(
line
:
ParsedSearchResultLine
|
ParsedSearchFileLine
):
line
is
ParsedSearchFileLine
=>
line
.
type
===
'
file
'
;
const
isResultLine
=
(
line
:
ParsedSearchResultLine
|
ParsedSearchFileLine
):
line
is
ParsedSearchResultLine
=>
line
.
type
===
'
result
'
;
function
parseSearchResults
(
document
:
vscode
.
TextDocument
,
token
:
vscode
.
CancellationToken
):
ParsedSearchResults
{
function
parseSearchResults
(
document
:
vscode
.
TextDocument
,
token
?
:
vscode
.
CancellationToken
):
ParsedSearchResults
{
if
(
cachedLastParse
&&
cachedLastParse
.
uri
===
document
.
uri
&&
cachedLastParse
.
version
===
document
.
version
)
{
return
cachedLastParse
.
parse
;
...
...
@@ -147,7 +175,8 @@ function parseSearchResults(document: vscode.TextDocument, token: vscode.Cancell
let
currentTargetLocations
:
vscode
.
LocationLink
[]
|
undefined
=
undefined
;
for
(
let
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
if
(
token
.
isCancellationRequested
)
{
return
[];
}
// TODO: This is probably always false, given we're pegging the thread...
if
(
token
?.
isCancellationRequested
)
{
return
[];
}
const
line
=
lines
[
i
];
const
fileLine
=
FILE_LINE_REGEX
.
exec
(
line
);
...
...
@@ -186,7 +215,7 @@ function parseSearchResults(document: vscode.TextDocument, token: vscode.Cancell
currentTargetLocations
?.
push
(
location
);
links
[
i
]
=
{
type
:
'
result
'
,
location
};
links
[
i
]
=
{
type
:
'
result
'
,
location
,
isContext
:
seperator
===
'
'
,
prefixRange
:
new
vscode
.
Range
(
i
,
0
,
i
,
metadataOffset
)
};
}
}
...
...
extensions/theme-defaults/themes/hc_black.json
浏览文件 @
542b0145
...
...
@@ -114,6 +114,13 @@
"settings"
:
{
"foreground"
:
"#CE9178"
}
},
{
"name"
:
"HC Search Editor context line override"
,
"scope"
:
"meta.resultLinePrefix.contextLinePrefix.search"
,
"settings"
:
{
"foreground"
:
"#CBEDCB"
,
}
}
]
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录