Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
bda1d3ee
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,发现更多精彩内容 >>
提交
bda1d3ee
编写于
5月 01, 2020
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
don't wait for snippet completions before asking for other completions, also use async-await #95325
上级
42561682
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
69 deletion
+64
-69
src/vs/editor/contrib/suggest/suggest.ts
src/vs/editor/contrib/suggest/suggest.ts
+64
-69
未找到文件。
src/vs/editor/contrib/suggest/suggest.ts
浏览文件 @
bda1d3ee
...
...
@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
first
}
from
'
vs/base/common/async
'
;
import
{
onUnexpectedExternalError
,
canceled
,
isPromiseCanceledError
}
from
'
vs/base/common/errors
'
;
import
{
IEditorContribution
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
...
...
@@ -164,98 +163,94 @@ export function setSnippetSuggestSupport(support: modes.CompletionItemProvider):
return
old
;
}
export
function
provideSuggestionItems
(
export
async
function
provideSuggestionItems
(
model
:
ITextModel
,
position
:
Position
,
options
:
CompletionOptions
=
CompletionOptions
.
default
,
context
:
modes
.
CompletionContext
=
{
triggerKind
:
modes
.
CompletionTriggerKind
.
Invoke
},
token
:
CancellationToken
=
CancellationToken
.
None
):
Promise
<
CompletionItem
[]
>
{
// const t1 = Date.now();
position
=
position
.
clone
();
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
);
// const wordUntil = model.getWordUntilPosition(position);
// const defaultRange = new Range(position.lineNumber, wordUntil.startColumn, position.lineNumber, wordUntil.endColumn);
position
=
position
.
clone
();
const
defaultRange
=
{
replace
:
defaultReplaceRange
,
insert
:
defaultReplaceRange
.
setEndPosition
(
position
.
lineNumber
,
position
.
column
)
};
// get provider groups, always add snippet suggestion provider
const
supports
=
modes
.
CompletionProviderRegistry
.
orderedGroups
(
model
);
const
result
:
CompletionItem
[]
=
[];
const
disposables
=
new
DisposableStore
(
);
// add snippets provider unless turned off
if
(
!
options
.
kindFilter
.
has
(
modes
.
CompletionItemKind
.
Snippet
)
&&
_snippetSuggestSupport
)
{
supports
.
unshift
([
_snippetSuggestSupport
]);
}
const
onCompletionList
=
(
provider
:
modes
.
CompletionItemProvider
,
container
:
modes
.
CompletionList
|
null
|
undefined
)
=>
{
if
(
!
container
)
{
return
;
}
for
(
let
suggestion
of
container
.
suggestions
||
[])
{
if
(
!
options
.
kindFilter
.
has
(
suggestion
.
kind
))
{
// fill in default range when missing
if
(
!
suggestion
.
range
)
{
suggestion
.
range
=
defaultRange
;
}
// fill in default sortText when missing
if
(
!
suggestion
.
sortText
)
{
suggestion
.
sortText
=
typeof
suggestion
.
label
===
'
string
'
?
suggestion
.
label
:
suggestion
.
label
.
name
;
}
result
.
push
(
new
CompletionItem
(
position
,
suggestion
,
container
,
provider
,
model
));
}
}
if
(
isDisposable
(
container
))
{
disposables
.
add
(
container
);
}
};
const
allSuggestions
:
CompletionItem
[]
=
[];
const
disposables
=
new
DisposableStore
();
let
hasResult
=
false
;
// ask for snippets in parallel to asking "real" providers. Only do something if configured to
// do so - no snippet filter, no special-providers-only request
const
snippetCompletions
=
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
if
(
!
_snippetSuggestSupport
||
options
.
kindFilter
.
has
(
modes
.
CompletionItemKind
.
Snippet
))
{
resolve
();
}
if
(
options
.
providerFilter
.
size
>
0
&&
!
options
.
providerFilter
.
has
(
_snippetSuggestSupport
))
{
resolve
();
}
Promise
.
resolve
(
_snippetSuggestSupport
.
provideCompletionItems
(
model
,
position
,
context
,
token
)).
then
(
list
=>
{
onCompletionList
(
_snippetSuggestSupport
,
list
);
resolve
();
},
reject
);
});
// add suggestions from contributed providers - providers are ordered in groups of
// equal score and once a group produces a result the process stops
const
factory
=
supports
.
map
(
supports
=>
()
=>
{
// get provider groups, always add snippet suggestion provider
for
(
let
providerGroup
of
modes
.
CompletionProviderRegistry
.
orderedGroups
(
model
))
{
// for each support in the group ask for suggestions
return
Promise
.
all
(
supports
.
map
(
provider
=>
{
let
lenBefore
=
result
.
length
;
await
Promise
.
all
(
providerGroup
.
map
(
async
provider
=>
{
if
(
options
.
providerFilter
.
size
>
0
&&
!
options
.
providerFilter
.
has
(
provider
))
{
return
undefined
;
return
;
}
try
{
const
list
=
await
provider
.
provideCompletionItems
(
model
,
position
,
context
,
token
);
onCompletionList
(
provider
,
list
);
}
catch
(
err
)
{
onUnexpectedExternalError
(
err
);
}
return
Promise
.
resolve
(
provider
.
provideCompletionItems
(
model
,
position
,
context
,
token
)).
then
(
container
=>
{
const
len
=
allSuggestions
.
length
;
if
(
container
)
{
for
(
let
suggestion
of
container
.
suggestions
||
[])
{
if
(
!
options
.
kindFilter
.
has
(
suggestion
.
kind
))
{
// fill in default range when missing
if
(
!
suggestion
.
range
)
{
suggestion
.
range
=
{
insert
:
defaultInsertRange
,
replace
:
defaultReplaceRange
};
}
// fill in default sortText when missing
if
(
!
suggestion
.
sortText
)
{
suggestion
.
sortText
=
typeof
suggestion
.
label
===
'
string
'
?
suggestion
.
label
:
suggestion
.
label
.
name
;
}
allSuggestions
.
push
(
new
CompletionItem
(
position
,
suggestion
,
container
,
provider
,
model
));
}
}
if
(
isDisposable
(
container
))
{
disposables
.
add
(
container
);
}
}
if
(
len
!==
allSuggestions
.
length
&&
provider
!==
_snippetSuggestSupport
)
{
hasResult
=
true
;
}
},
onUnexpectedExternalError
);
}));
});
const
result
=
first
(
factory
,
()
=>
{
// stop on result or cancellation
return
hasResult
||
token
.
isCancellationRequested
;
}).
then
(()
=>
{
if
(
token
.
isCancellationRequested
)
{
disposables
.
dispose
();
return
Promise
.
reject
<
any
>
(
canceled
());
if
(
lenBefore
!==
result
.
length
||
token
.
isCancellationRequested
)
{
break
;
}
// console.log(`${allSuggestions.length} items AFTER ${Date.now() - t1}ms`);
return
allSuggestions
.
sort
(
getSuggestionComparator
(
options
.
snippetSortOrder
));
});
}
// result.then(items => {
// console.log(model.getWordUntilPosition(position), items.map(item => `${item.suggestion.label}, type=${item.suggestion.type}, incomplete?${item.container.incomplete}, overwriteBefore=${item.suggestion.overwriteBefore}`));
// return items;
// }, err => {
// console.warn(model.getWordUntilPosition(position), err);
// });
await
snippetCompletions
;
return
result
;
if
(
token
.
isCancellationRequested
)
{
disposables
.
dispose
();
return
Promise
.
reject
<
any
>
(
canceled
());
}
// console.log(`${result.length} items AFTER ${Date.now() - t1}ms`);
return
result
.
sort
(
getSuggestionComparator
(
options
.
snippetSortOrder
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录