Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
42561682
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,发现更多精彩内容 >>
提交
42561682
编写于
5月 01, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
validate on client (using faster ways), don't send repeated data, #95325
上级
8265dfec
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
38 deletion
+32
-38
src/vs/editor/contrib/suggest/completionModel.ts
src/vs/editor/contrib/suggest/completionModel.ts
+4
-0
src/vs/editor/contrib/suggest/suggest.ts
src/vs/editor/contrib/suggest/suggest.ts
+19
-1
src/vs/workbench/api/common/extHostLanguageFeatures.ts
src/vs/workbench/api/common/extHostLanguageFeatures.ts
+9
-37
未找到文件。
src/vs/editor/contrib/suggest/completionModel.ts
浏览文件 @
42561682
...
...
@@ -151,6 +151,10 @@ export class CompletionModel {
const
item
=
source
[
i
];
if
(
item
.
isInvalid
)
{
continue
;
// SKIP invalid items
}
// collect those supports that signaled having
// an incomplete result
if
(
item
.
container
.
incomplete
)
{
...
...
src/vs/editor/contrib/suggest/suggest.ts
浏览文件 @
42561682
...
...
@@ -53,6 +53,9 @@ export class CompletionItem {
readonly
sortTextLow
?:
string
;
readonly
filterTextLow
?:
string
;
// validation
readonly
isInvalid
:
boolean
=
false
;
// sorting, filtering
score
:
FuzzyScore
=
FuzzyScore
.
Default
;
distance
:
number
=
0
;
...
...
@@ -73,6 +76,9 @@ export class CompletionItem {
// ensure lower-variants (perf)
this
.
labelLow
=
this
.
textLabel
.
toLowerCase
();
// validate label
this
.
isInvalid
=
!
this
.
textLabel
;
this
.
sortTextLow
=
completion
.
sortText
&&
completion
.
sortText
.
toLowerCase
();
this
.
filterTextLow
=
completion
.
filterText
&&
completion
.
filterText
.
toLowerCase
();
...
...
@@ -81,10 +87,21 @@ export class CompletionItem {
this
.
editStart
=
new
Position
(
completion
.
range
.
startLineNumber
,
completion
.
range
.
startColumn
);
this
.
editInsertEnd
=
new
Position
(
completion
.
range
.
endLineNumber
,
completion
.
range
.
endColumn
);
this
.
editReplaceEnd
=
new
Position
(
completion
.
range
.
endLineNumber
,
completion
.
range
.
endColumn
);
// validate range
this
.
isInvalid
=
this
.
isInvalid
||
Range
.
spansMultipleLines
(
completion
.
range
)
||
completion
.
range
.
startLineNumber
!==
position
.
lineNumber
;
}
else
{
this
.
editStart
=
new
Position
(
completion
.
range
.
insert
.
startLineNumber
,
completion
.
range
.
insert
.
startColumn
);
this
.
editInsertEnd
=
new
Position
(
completion
.
range
.
insert
.
endLineNumber
,
completion
.
range
.
insert
.
endColumn
);
this
.
editReplaceEnd
=
new
Position
(
completion
.
range
.
replace
.
endLineNumber
,
completion
.
range
.
replace
.
endColumn
);
// validate ranges
this
.
isInvalid
=
this
.
isInvalid
||
Range
.
spansMultipleLines
(
completion
.
range
.
insert
)
||
Range
.
spansMultipleLines
(
completion
.
range
.
replace
)
||
completion
.
range
.
insert
.
startLineNumber
!==
position
.
lineNumber
||
completion
.
range
.
replace
.
startLineNumber
!==
position
.
lineNumber
||
Range
.
compareRangesUsingStarts
(
completion
.
range
.
insert
,
completion
.
range
.
replace
)
!==
0
;
}
// create the suggestion resolver
...
...
@@ -154,7 +171,7 @@ export function provideSuggestionItems(
context
:
modes
.
CompletionContext
=
{
triggerKind
:
modes
.
CompletionTriggerKind
.
Invoke
},
token
:
CancellationToken
=
CancellationToken
.
None
):
Promise
<
CompletionItem
[]
>
{
// const t1 = Date.now();
const
word
=
model
.
getWordAtPosition
(
position
);
const
defaultReplaceRange
=
word
?
new
Range
(
position
.
lineNumber
,
word
.
startColumn
,
position
.
lineNumber
,
word
.
endColumn
)
:
Range
.
fromPositions
(
position
);
const
defaultInsertRange
=
defaultReplaceRange
.
setEndPosition
(
position
.
lineNumber
,
position
.
column
);
...
...
@@ -227,6 +244,7 @@ export function provideSuggestionItems(
disposables
.
dispose
();
return
Promise
.
reject
<
any
>
(
canceled
());
}
// console.log(`${allSuggestions.length} items AFTER ${Date.now() - t1}ms`);
return
allSuggestions
.
sort
(
getSuggestionComparator
(
options
.
snippetSortOrder
));
});
...
...
src/vs/workbench/api/common/extHostLanguageFeatures.ts
浏览文件 @
42561682
...
...
@@ -876,33 +876,30 @@ class SuggestAdapter {
for
(
let
i
=
0
;
i
<
list
.
items
.
length
;
i
++
)
{
const
item
=
list
.
items
[
i
];
// check for bad completion item first
if
(
this
.
_validateCompletionItem
(
item
,
pos
))
{
const
dto
=
this
.
_convertCompletionItem
(
item
,
[
pid
,
i
],
insertRange
,
replaceRange
);
completions
.
push
(
dto
);
}
const
dto
=
this
.
_convertCompletionItem
(
item
,
[
pid
,
i
],
insertRange
,
replaceRange
);
completions
.
push
(
dto
);
}
return
result
;
}
async
resolveCompletionItem
(
_resource
:
URI
,
position
:
IPosition
,
id
:
extHostProtocol
.
ChainedCacheId
,
token
:
CancellationToken
):
Promise
<
extHostProtocol
.
ISuggestDataDto
|
undefined
>
{
async
resolveCompletionItem
(
_resource
:
URI
,
_
position
:
IPosition
,
id
:
extHostProtocol
.
ChainedCacheId
,
token
:
CancellationToken
):
Promise
<
extHostProtocol
.
ISuggestDataDto
|
undefined
>
{
if
(
typeof
this
.
_provider
.
resolveCompletionItem
!==
'
function
'
)
{
return
Promise
.
resolve
(
undefined
)
;
return
undefined
;
}
const
item
=
this
.
_cache
.
get
(...
id
);
if
(
!
item
)
{
return
Promise
.
resolve
(
undefined
)
;
return
undefined
;
}
const
pos
=
typeConvert
.
Position
.
to
(
position
);
const
_mustNotChange
=
SuggestAdapter
.
_mustNotChangeHash
(
item
);
const
_mayNotChange
=
SuggestAdapter
.
_mayNotChangeHash
(
item
);
const
resolvedItem
=
await
asPromise
(()
=>
this
.
_provider
.
resolveCompletionItem
!
(
item
,
token
));
if
(
!
resolvedItem
||
!
this
.
_validateCompletionItem
(
resolvedItem
,
pos
)
)
{
if
(
!
resolvedItem
)
{
return
undefined
;
}
...
...
@@ -952,14 +949,14 @@ class SuggestAdapter {
//
x
:
id
,
//
[
extHostProtocol
.
ISuggestDataDtoField
.
label
]:
item
.
label
,
[
extHostProtocol
.
ISuggestDataDtoField
.
label
]:
item
.
label
??
''
,
[
extHostProtocol
.
ISuggestDataDtoField
.
label2
]:
item
.
label2
,
[
extHostProtocol
.
ISuggestDataDtoField
.
kind
]:
item
.
kind
!==
undefined
?
typeConvert
.
CompletionItemKind
.
from
(
item
.
kind
)
:
undefined
,
[
extHostProtocol
.
ISuggestDataDtoField
.
kindModifier
]:
item
.
tags
&&
item
.
tags
.
map
(
typeConvert
.
CompletionItemTag
.
from
),
[
extHostProtocol
.
ISuggestDataDtoField
.
detail
]:
item
.
detail
,
[
extHostProtocol
.
ISuggestDataDtoField
.
documentation
]:
typeof
item
.
documentation
===
'
undefined
'
?
undefined
:
typeConvert
.
MarkdownString
.
fromStrict
(
item
.
documentation
),
[
extHostProtocol
.
ISuggestDataDtoField
.
sortText
]:
item
.
sortText
,
[
extHostProtocol
.
ISuggestDataDtoField
.
filterText
]:
item
.
filterText
,
[
extHostProtocol
.
ISuggestDataDtoField
.
sortText
]:
item
.
sortText
!==
item
.
label
?
item
.
sortText
:
undefined
,
[
extHostProtocol
.
ISuggestDataDtoField
.
filterText
]:
item
.
filterText
!==
item
.
label
?
item
.
filterText
:
undefined
,
[
extHostProtocol
.
ISuggestDataDtoField
.
preselect
]:
item
.
preselect
||
undefined
,
[
extHostProtocol
.
ISuggestDataDtoField
.
insertTextRules
]:
item
.
keepWhitespace
?
modes
.
CompletionItemInsertTextRule
.
KeepWhitespace
:
0
,
[
extHostProtocol
.
ISuggestDataDtoField
.
commitCharacters
]:
item
.
commitCharacters
,
...
...
@@ -1003,31 +1000,6 @@ class SuggestAdapter {
return
result
;
}
private
_validateCompletionItem
(
item
:
vscode
.
CompletionItem
,
position
:
vscode
.
Position
):
boolean
{
if
(
typeof
item
.
label
!==
'
string
'
||
item
.
label
.
length
===
0
)
{
this
.
_logService
.
warn
(
'
INVALID text edit -> must have at least a label
'
);
return
false
;
}
if
(
Range
.
isRange
(
item
.
range
))
{
if
(
!
item
.
range
.
isSingleLine
||
item
.
range
.
start
.
line
!==
position
.
line
)
{
this
.
_logService
.
trace
(
'
INVALID range -> must be single line and on the same line
'
);
return
false
;
}
}
else
if
(
item
.
range
)
{
if
(
!
item
.
range
.
inserting
.
isSingleLine
||
item
.
range
.
inserting
.
start
.
line
!==
position
.
line
||
!
item
.
range
.
replacing
.
isSingleLine
||
item
.
range
.
replacing
.
start
.
line
!==
position
.
line
||
!
item
.
range
.
inserting
.
start
.
isEqual
(
item
.
range
.
replacing
.
start
)
||
!
item
.
range
.
replacing
.
contains
(
item
.
range
.
inserting
)
)
{
this
.
_logService
.
trace
(
'
INVALID range -> must be single line, on the same line, insert range must be a prefix of replace range
'
);
return
false
;
}
}
return
true
;
}
private
static
_mustNotChangeHash
(
item
:
vscode
.
CompletionItem
)
{
const
res
=
JSON
.
stringify
([
item
.
label
,
item
.
sortText
,
item
.
filterText
,
item
.
insertText
,
item
.
range
]);
return
res
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录