Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
ca1d4ad2
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
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,发现更多精彩内容 >>
提交
ca1d4ad2
编写于
3月 19, 2018
作者:
M
Matt Bierner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use `isInString` for highlights
上级
f15bf0e7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
24 deletion
+19
-24
extensions/typescript/src/features/documentHighlightProvider.ts
...ions/typescript/src/features/documentHighlightProvider.ts
+19
-24
未找到文件。
extensions/typescript/src/features/documentHighlightProvider.ts
浏览文件 @
ca1d4ad2
...
...
@@ -3,13 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
DocumentHighlightProvider
,
DocumentHighlight
,
DocumentHighlightKind
,
TextDocument
,
Position
,
Range
,
CancellationToken
}
from
'
vscode
'
;
import
{
DocumentHighlightProvider
,
DocumentHighlight
,
DocumentHighlightKind
,
TextDocument
,
Position
,
CancellationToken
}
from
'
vscode
'
;
import
*
as
Proto
from
'
../protocol
'
;
import
{
ITypeScriptServiceClient
}
from
'
../typescriptService
'
;
import
*
as
typeConverters
from
'
../utils/typeConverters
'
;
const
stringDelimiters
=
[
'
"
'
,
'
\'
'
,
'
`
'
];
export
default
class
TypeScriptDocumentHighlightProvider
implements
DocumentHighlightProvider
{
public
constructor
(
private
readonly
client
:
ITypeScriptServiceClient
...
...
@@ -20,34 +20,29 @@ export default class TypeScriptDocumentHighlightProvider implements DocumentHigh
position
:
Position
,
token
:
CancellationToken
):
Promise
<
DocumentHighlight
[]
>
{
const
file
path
=
this
.
client
.
normalizePath
(
resource
.
uri
);
if
(
!
file
path
)
{
const
file
=
this
.
client
.
normalizePath
(
resource
.
uri
);
if
(
!
file
)
{
return
[];
}
const
args
=
typeConverters
.
Position
.
toFileLocationRequestArgs
(
file
path
,
position
);
const
args
=
typeConverters
.
Position
.
toFileLocationRequestArgs
(
file
,
position
);
try
{
const
response
=
await
this
.
client
.
execute
(
'
occurrences
'
,
args
,
token
);
const
data
=
response
.
body
;
if
(
data
&&
data
.
length
)
{
// Workaround for https://github.com/Microsoft/TypeScript/issues/12780
// Don't highlight string occurrences
const
firstOccurrence
=
data
[
0
];
if
(
this
.
client
.
apiVersion
.
has213Features
()
&&
firstOccurrence
.
start
.
offset
>
1
)
{
// Check to see if contents around first occurrence are string delimiters
const
contents
=
resource
.
getText
(
new
Range
(
firstOccurrence
.
start
.
line
-
1
,
firstOccurrence
.
start
.
offset
-
1
-
1
,
firstOccurrence
.
end
.
line
-
1
,
firstOccurrence
.
end
.
offset
-
1
+
1
));
if
(
contents
&&
contents
.
length
>
2
&&
stringDelimiters
.
indexOf
(
contents
[
0
])
>=
0
&&
contents
[
0
]
===
contents
[
contents
.
length
-
1
])
{
return
[];
}
}
return
data
.
map
(
item
=>
new
DocumentHighlight
(
typeConverters
.
Range
.
fromTextSpan
(
item
),
item
.
isWriteAccess
?
DocumentHighlightKind
.
Write
:
DocumentHighlightKind
.
Read
));
if
(
response
&&
response
.
body
)
{
return
response
.
body
.
filter
(
x
=>
!
x
.
isInString
)
.
map
(
documentHighlightFromOccurance
);
}
return
[];
}
catch
{
return
[];
// noop
}
return
[];
}
}
function
documentHighlightFromOccurance
(
occurrence
:
Proto
.
OccurrencesResponseItem
):
DocumentHighlight
{
return
new
DocumentHighlight
(
typeConverters
.
Range
.
fromTextSpan
(
occurrence
),
occurrence
.
isWriteAccess
?
DocumentHighlightKind
.
Write
:
DocumentHighlightKind
.
Read
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录