Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a1f78c66
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,发现更多精彩内容 >>
提交
a1f78c66
编写于
9月 21, 2017
作者:
J
Johannes Rieken
提交者:
GitHub
9月 21, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34055 from mjbvz/fix-752
Add optional CompletionContext to provideCompletionItems
上级
1da857a4
336be693
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
224 addition
and
44 deletion
+224
-44
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+17
-1
src/vs/editor/contrib/suggest/browser/suggest.ts
src/vs/editor/contrib/suggest/browser/suggest.ts
+5
-3
src/vs/editor/contrib/suggest/browser/suggestController.ts
src/vs/editor/contrib/suggest/browser/suggestController.ts
+1
-1
src/vs/editor/contrib/suggest/browser/suggestModel.ts
src/vs/editor/contrib/suggest/browser/suggestModel.ts
+19
-10
src/vs/editor/contrib/suggest/test/browser/suggestModel.test.ts
.../editor/contrib/suggest/test/browser/suggestModel.test.ts
+47
-12
src/vs/editor/standalone/browser/standaloneLanguages.ts
src/vs/editor/standalone/browser/standaloneLanguages.ts
+29
-7
src/vs/monaco.d.ts
src/vs/monaco.d.ts
+26
-1
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+37
-1
src/vs/workbench/api/electron-browser/mainThreadLanguageFeatures.ts
...kbench/api/electron-browser/mainThreadLanguageFeatures.ts
+2
-2
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+1
-0
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+1
-1
src/vs/workbench/api/node/extHostLanguageFeatures.ts
src/vs/workbench/api/node/extHostLanguageFeatures.ts
+6
-4
src/vs/workbench/api/node/extHostTypeConverters.ts
src/vs/workbench/api/node/extHostTypeConverters.ts
+22
-0
src/vs/workbench/api/node/extHostTypes.ts
src/vs/workbench/api/node/extHostTypes.ts
+10
-0
src/vs/workbench/parts/debug/electron-browser/repl.ts
src/vs/workbench/parts/debug/electron-browser/repl.ts
+1
-1
未找到文件。
src/vs/editor/common/modes.ts
浏览文件 @
a1f78c66
...
...
@@ -247,6 +247,22 @@ export interface ISuggestResult {
dispose
?():
void
;
}
/**
* How a suggest provider was triggered.
*/
export
enum
SuggestTriggerKind
{
Invoke
=
0
,
TriggerCharacter
=
1
}
/**
* @internal
*/
export
interface
SuggestContext
{
triggerKind
:
SuggestTriggerKind
;
triggerCharacter
?:
string
;
}
/**
* @internal
*/
...
...
@@ -254,7 +270,7 @@ export interface ISuggestSupport {
triggerCharacters
?:
string
[];
provideCompletionItems
(
model
:
editorCommon
.
IModel
,
position
:
Position
,
token
:
CancellationToken
):
ISuggestResult
|
Thenable
<
ISuggestResult
>
;
provideCompletionItems
(
model
:
editorCommon
.
IModel
,
position
:
Position
,
context
:
SuggestContext
,
token
:
CancellationToken
):
ISuggestResult
|
Thenable
<
ISuggestResult
>
;
resolveCompletionItem
?(
model
:
editorCommon
.
IModel
,
position
:
Position
,
item
:
ISuggestion
,
token
:
CancellationToken
):
ISuggestion
|
Thenable
<
ISuggestion
>
;
}
...
...
src/vs/editor/contrib/suggest/browser/suggest.ts
浏览文件 @
a1f78c66
...
...
@@ -12,7 +12,7 @@ import { onUnexpectedExternalError } from 'vs/base/common/errors';
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IModel
,
IEditorContribution
,
ICommonCodeEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
CommonEditorRegistry
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
ISuggestResult
,
ISuggestSupport
,
ISuggestion
,
SuggestRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
ISuggestResult
,
ISuggestSupport
,
ISuggestion
,
SuggestRegistry
,
SuggestContext
,
SuggestTriggerKind
}
from
'
vs/editor/common/modes
'
;
import
{
Position
,
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
RawContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
...
...
@@ -42,7 +42,7 @@ export function setSnippetSuggestSupport(support: ISuggestSupport): ISuggestSupp
return
old
;
}
export
function
provideSuggestionItems
(
model
:
IModel
,
position
:
Position
,
snippetConfig
:
SnippetConfig
=
'
bottom
'
,
onlyFrom
?:
ISuggestSupport
[]):
TPromise
<
ISuggestionItem
[]
>
{
export
function
provideSuggestionItems
(
model
:
IModel
,
position
:
Position
,
snippetConfig
:
SnippetConfig
=
'
bottom
'
,
onlyFrom
?:
ISuggestSupport
[]
,
context
?:
SuggestContext
):
TPromise
<
ISuggestionItem
[]
>
{
const
allSuggestions
:
ISuggestionItem
[]
=
[];
const
acceptSuggestion
=
createSuggesionFilter
(
snippetConfig
);
...
...
@@ -57,6 +57,8 @@ export function provideSuggestionItems(model: IModel, position: Position, snippe
supports
.
unshift
([
_snippetSuggestSupport
]);
}
const
suggestConext
=
context
||
{
triggerKind
:
SuggestTriggerKind
.
Invoke
};
// add suggestions from contributed providers - providers are ordered in groups of
// equal score and once a group produces a result the process stops
let
hasResult
=
false
;
...
...
@@ -73,7 +75,7 @@ export function provideSuggestionItems(model: IModel, position: Position, snippe
return
undefined
;
}
return
asWinJsPromise
(
token
=>
support
.
provideCompletionItems
(
model
,
position
,
token
)).
then
(
container
=>
{
return
asWinJsPromise
(
token
=>
support
.
provideCompletionItems
(
model
,
position
,
suggestConext
,
token
)).
then
(
container
=>
{
const
len
=
allSuggestions
.
length
;
...
...
src/vs/editor/contrib/suggest/browser/suggestController.ts
浏览文件 @
a1f78c66
...
...
@@ -209,7 +209,7 @@ export class SuggestController implements IEditorContribution {
}
triggerSuggest
(
onlyFrom
?:
ISuggestSupport
[]):
void
{
this
.
_model
.
trigger
(
false
,
false
,
onlyFrom
);
this
.
_model
.
trigger
(
{
auto
:
false
}
,
false
,
onlyFrom
);
this
.
_editor
.
revealLine
(
this
.
_editor
.
getPosition
().
lineNumber
,
ScrollType
.
Smooth
);
this
.
_editor
.
focus
();
}
...
...
src/vs/editor/contrib/suggest/browser/suggestModel.ts
浏览文件 @
a1f78c66
...
...
@@ -11,7 +11,7 @@ import Event, { Emitter } from 'vs/base/common/event';
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ICommonCodeEditor
,
IModel
,
IWordAtPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ISuggestSupport
,
SuggestRegistry
,
StandardTokenType
}
from
'
vs/editor/common/modes
'
;
import
{
ISuggestSupport
,
SuggestRegistry
,
StandardTokenType
,
SuggestTriggerKind
}
from
'
vs/editor/common/modes
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
provideSuggestionItems
,
getSuggestionComparator
,
ISuggestionItem
}
from
'
./suggest
'
;
import
{
CompletionModel
}
from
'
./completionModel
'
;
...
...
@@ -31,6 +31,11 @@ export interface ISuggestEvent {
auto
:
boolean
;
}
export
interface
SuggestTriggerContext
{
auto
:
boolean
;
triggerCharacter
?:
string
;
}
export
class
LineContext
{
static
shouldAutoTrigger
(
editor
:
ICommonCodeEditor
):
boolean
{
...
...
@@ -201,7 +206,7 @@ export class SuggestModel implements IDisposable {
}
}
}
this
.
trigger
(
true
,
Boolean
(
this
.
completionModel
),
supports
,
items
);
this
.
trigger
(
{
auto
:
true
,
triggerCharacter
:
lastChar
}
,
Boolean
(
this
.
completionModel
),
supports
,
items
);
}
});
}
...
...
@@ -237,7 +242,7 @@ export class SuggestModel implements IDisposable {
if
(
!
SuggestRegistry
.
has
(
this
.
editor
.
getModel
()))
{
this
.
cancel
();
}
else
{
this
.
trigger
(
this
.
_state
===
State
.
Auto
,
true
);
this
.
trigger
(
{
auto
:
this
.
_state
===
State
.
Auto
}
,
true
);
}
}
}
...
...
@@ -311,7 +316,7 @@ export class SuggestModel implements IDisposable {
}
this
.
triggerAutoSuggestPromise
=
null
;
this
.
trigger
(
true
);
this
.
trigger
(
{
auto
:
true
}
);
});
}
}
...
...
@@ -326,14 +331,14 @@ export class SuggestModel implements IDisposable {
}
}
public
trigger
(
auto
:
boolean
,
retrigger
:
boolean
=
false
,
onlyFrom
?:
ISuggestSupport
[],
existingItems
?:
ISuggestionItem
[]):
void
{
public
trigger
(
context
:
SuggestTriggerContext
,
retrigger
:
boolean
=
false
,
onlyFrom
?:
ISuggestSupport
[],
existingItems
?:
ISuggestionItem
[]):
void
{
const
model
=
this
.
editor
.
getModel
();
if
(
!
model
)
{
return
;
}
const
auto
=
context
.
auto
;
const
ctx
=
new
LineContext
(
model
,
this
.
editor
.
getPosition
(),
auto
);
if
(
!
LineContext
.
isInEditableRange
(
this
.
editor
))
{
...
...
@@ -350,7 +355,11 @@ export class SuggestModel implements IDisposable {
this
.
requestPromise
=
provideSuggestionItems
(
model
,
this
.
editor
.
getPosition
(),
this
.
editor
.
getConfiguration
().
contribInfo
.
snippetSuggestions
,
onlyFrom
onlyFrom
,
{
triggerCharacter
:
context
.
triggerCharacter
,
triggerKind
:
context
.
triggerCharacter
?
SuggestTriggerKind
.
TriggerCharacter
:
SuggestTriggerKind
.
Invoke
}
).
then
(
items
=>
{
this
.
requestPromise
=
null
;
...
...
@@ -394,7 +403,7 @@ export class SuggestModel implements IDisposable {
if
(
ctx
.
column
<
this
.
context
.
column
)
{
// typed -> moved cursor LEFT -> retrigger if still on a word
if
(
ctx
.
leadingWord
.
word
)
{
this
.
trigger
(
this
.
context
.
auto
,
true
);
this
.
trigger
(
{
auto
:
this
.
context
.
auto
}
,
true
);
}
else
{
this
.
cancel
();
}
...
...
@@ -409,7 +418,7 @@ export class SuggestModel implements IDisposable {
if
(
ctx
.
column
>
this
.
context
.
column
&&
this
.
completionModel
.
incomplete
&&
ctx
.
leadingWord
.
word
.
length
!==
0
)
{
// typed -> moved cursor RIGHT & incomple model & still on a word -> retrigger
const
{
complete
,
incomplete
}
=
this
.
completionModel
.
resolveIncompleteInfo
();
this
.
trigger
(
this
.
_state
===
State
.
Auto
,
true
,
incomplete
,
complete
);
this
.
trigger
(
{
auto
:
this
.
_state
===
State
.
Auto
}
,
true
,
incomplete
,
complete
);
}
else
{
// typed -> moved cursor RIGHT -> update UI
...
...
@@ -425,7 +434,7 @@ export class SuggestModel implements IDisposable {
if
(
LineContext
.
shouldAutoTrigger
(
this
.
editor
)
&&
this
.
context
.
leadingWord
.
endColumn
<
ctx
.
leadingWord
.
startColumn
)
{
// retrigger when heading into a new word
this
.
trigger
(
this
.
context
.
auto
,
true
);
this
.
trigger
(
{
auto
:
this
.
context
.
auto
}
,
true
);
return
;
}
...
...
src/vs/editor/contrib/suggest/test/browser/suggestModel.test.ts
浏览文件 @
a1f78c66
...
...
@@ -11,7 +11,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
import
{
ICommonCodeEditor
,
Handler
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ISuggestSupport
,
ISuggestResult
,
SuggestRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
ISuggestSupport
,
ISuggestResult
,
SuggestRegistry
,
SuggestTriggerKind
}
from
'
vs/editor/common/modes
'
;
import
{
SuggestModel
,
LineContext
}
from
'
vs/editor/contrib/suggest/browser/suggestModel
'
;
import
{
MockCodeEditor
,
MockScopeLocation
}
from
'
vs/editor/test/common/mocks/mockCodeEditor
'
;
import
{
ServiceCollection
}
from
'
vs/platform/instantiation/common/serviceCollection
'
;
...
...
@@ -149,25 +149,25 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
// cancel on trigger
assertEvent
(
model
.
onDidCancel
,
function
()
{
model
.
trigger
(
false
);
model
.
trigger
(
{
auto
:
false
}
);
},
function
(
event
)
{
assert
.
equal
(
event
.
retrigger
,
false
);
}),
assertEvent
(
model
.
onDidCancel
,
function
()
{
model
.
trigger
(
false
,
true
);
model
.
trigger
(
{
auto
:
false
}
,
true
);
},
function
(
event
)
{
assert
.
equal
(
event
.
retrigger
,
true
);
}),
assertEvent
(
model
.
onDidTrigger
,
function
()
{
model
.
trigger
(
true
);
model
.
trigger
(
{
auto
:
true
}
);
},
function
(
event
)
{
assert
.
equal
(
event
.
auto
,
true
);
}),
assertEvent
(
model
.
onDidTrigger
,
function
()
{
model
.
trigger
(
false
);
model
.
trigger
(
{
auto
:
false
}
);
},
function
(
event
)
{
assert
.
equal
(
event
.
auto
,
false
);
})
...
...
@@ -183,12 +183,12 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
return
withOracle
(
model
=>
{
return
TPromise
.
join
([
assertEvent
(
model
.
onDidCancel
,
function
()
{
model
.
trigger
(
true
);
model
.
trigger
(
{
auto
:
true
}
);
},
function
(
event
)
{
assert
.
equal
(
event
.
retrigger
,
false
);
}),
assertEvent
(
model
.
onDidSuggest
,
function
()
{
model
.
trigger
(
false
);
model
.
trigger
(
{
auto
:
false
}
);
},
function
(
event
)
{
assert
.
equal
(
event
.
auto
,
false
);
assert
.
equal
(
event
.
isFrozen
,
false
);
...
...
@@ -239,7 +239,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
return
assertEvent
(
model
.
onDidSuggest
,
()
=>
{
// make sure completionModel starts here!
model
.
trigger
(
true
);
model
.
trigger
(
{
auto
:
true
}
);
},
event
=>
{
return
assertEvent
(
model
.
onDidSuggest
,
()
=>
{
...
...
@@ -338,7 +338,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
editor
.
setPosition
({
lineNumber
:
1
,
column
:
3
});
return
assertEvent
(
model
.
onDidSuggest
,
()
=>
{
model
.
trigger
(
false
);
model
.
trigger
(
{
auto
:
false
}
);
},
event
=>
{
assert
.
equal
(
event
.
auto
,
false
);
assert
.
equal
(
event
.
isFrozen
,
false
);
...
...
@@ -363,7 +363,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
editor
.
setPosition
({
lineNumber
:
1
,
column
:
3
});
return
assertEvent
(
model
.
onDidSuggest
,
()
=>
{
model
.
trigger
(
false
);
model
.
trigger
(
{
auto
:
false
}
);
},
event
=>
{
assert
.
equal
(
event
.
auto
,
false
);
assert
.
equal
(
event
.
isFrozen
,
false
);
...
...
@@ -400,7 +400,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
editor
.
setPosition
({
lineNumber
:
1
,
column
:
4
});
return
assertEvent
(
model
.
onDidSuggest
,
()
=>
{
model
.
trigger
(
false
);
model
.
trigger
(
{
auto
:
false
}
);
},
event
=>
{
assert
.
equal
(
event
.
auto
,
false
);
assert
.
equal
(
event
.
completionModel
.
incomplete
,
true
);
...
...
@@ -437,7 +437,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
editor
.
setPosition
({
lineNumber
:
1
,
column
:
4
});
return
assertEvent
(
model
.
onDidSuggest
,
()
=>
{
model
.
trigger
(
false
);
model
.
trigger
(
{
auto
:
false
}
);
},
event
=>
{
assert
.
equal
(
event
.
auto
,
false
);
assert
.
equal
(
event
.
completionModel
.
incomplete
,
true
);
...
...
@@ -457,4 +457,39 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
});
});
});
test
(
'
Trigger character is provided in suggest context
'
,
function
()
{
let
triggerCharacter
=
''
;
disposables
.
push
(
SuggestRegistry
.
register
({
scheme
:
'
test
'
},
{
triggerCharacters
:
[
'
.
'
],
provideCompletionItems
(
doc
,
pos
,
context
)
{
assert
.
equal
(
context
.
triggerKind
,
SuggestTriggerKind
.
TriggerCharacter
);
triggerCharacter
=
context
.
triggerCharacter
;
return
<
ISuggestResult
>
{
currentWord
:
''
,
incomplete
:
false
,
suggestions
:
[
{
label
:
'
foo.bar
'
,
type
:
'
property
'
,
insertText
:
'
foo.bar
'
,
overwriteBefore
:
pos
.
column
-
1
}
]
};
}
}));
model
.
setValue
(
''
);
return
withOracle
((
model
,
editor
)
=>
{
return
assertEvent
(
model
.
onDidSuggest
,
()
=>
{
editor
.
setPosition
({
lineNumber
:
1
,
column
:
1
});
editor
.
trigger
(
'
keyboard
'
,
Handler
.
Type
,
{
text
:
'
foo.
'
});
},
event
=>
{
assert
.
equal
(
triggerCharacter
,
'
.
'
);
});
});
});
});
src/vs/editor/standalone/browser/standaloneLanguages.ts
浏览文件 @
a1f78c66
...
...
@@ -373,8 +373,8 @@ export function registerCompletionItemProvider(languageId: string, provider: Com
let
adapter
=
new
SuggestAdapter
(
provider
);
return
modes
.
SuggestRegistry
.
register
(
languageId
,
{
triggerCharacters
:
provider
.
triggerCharacters
,
provideCompletionItems
:
(
model
:
editorCommon
.
IReadOnlyModel
,
position
:
Position
,
token
:
CancellationToken
):
Thenable
<
modes
.
ISuggestResult
>
=>
{
return
adapter
.
provideCompletionItems
(
model
,
position
,
token
);
provideCompletionItems
:
(
model
:
editorCommon
.
IReadOnlyModel
,
position
:
Position
,
context
:
modes
.
SuggestContext
,
token
:
CancellationToken
):
Thenable
<
modes
.
ISuggestResult
>
=>
{
return
adapter
.
provideCompletionItems
(
model
,
position
,
context
,
token
);
},
resolveCompletionItem
:
(
model
:
editorCommon
.
IReadOnlyModel
,
position
:
Position
,
suggestion
:
modes
.
ISuggestion
,
token
:
CancellationToken
):
Thenable
<
modes
.
ISuggestion
>
=>
{
return
adapter
.
resolveCompletionItem
(
model
,
position
,
suggestion
,
token
);
...
...
@@ -537,6 +537,25 @@ export interface CompletionList {
*/
items
:
CompletionItem
[];
}
/**
* Contains additional information about the context in which
* [completion provider](#CompletionItemProvider.provideCompletionItems) is triggered.
*/
export
interface
CompletionContext
{
/**
* How the completion was triggered.
*/
triggerKind
:
modes
.
SuggestTriggerKind
;
/**
* Character that triggered the completion item provider.
*
* `undefined` if provider was not triggered by a character.
*/
triggerCharacter
?:
string
;
}
/**
* The completion item provider interface defines the contract between extensions and
* the [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
...
...
@@ -553,7 +572,8 @@ export interface CompletionItemProvider {
/**
* Provide completion items for the given position and document.
*/
provideCompletionItems
(
model
:
editorCommon
.
IReadOnlyModel
,
position
:
Position
,
token
:
CancellationToken
):
CompletionItem
[]
|
Thenable
<
CompletionItem
[]
>
|
CompletionList
|
Thenable
<
CompletionList
>
;
provideCompletionItems
(
document
:
editorCommon
.
IReadOnlyModel
,
position
:
Position
,
token
:
CancellationToken
,
context
:
CompletionContext
):
CompletionItem
[]
|
Thenable
<
CompletionItem
[]
>
|
CompletionList
|
Thenable
<
CompletionList
>
;
/**
* Given a completion item fill in more data, like [doc-comment](#CompletionItem.documentation)
* or [details](#CompletionItem.detail).
...
...
@@ -590,6 +610,7 @@ function convertKind(kind: CompletionItemKind): modes.SuggestionType {
}
return
'
property
'
;
}
class
SuggestAdapter
{
private
_provider
:
CompletionItemProvider
;
...
...
@@ -639,9 +660,9 @@ class SuggestAdapter {
return
suggestion
;
}
provideCompletionItems
(
model
:
editorCommon
.
IReadOnlyModel
,
position
:
Position
,
token
:
CancellationToken
):
Thenable
<
modes
.
ISuggestResult
>
{
return
toThenable
<
CompletionItem
[]
|
CompletionList
>
(
this
.
_provider
.
provideCompletionItems
(
model
,
position
,
token
)
).
then
(
value
=>
{
provideCompletionItems
(
model
:
editorCommon
.
IReadOnlyModel
,
position
:
Position
,
context
:
modes
.
SuggestContext
,
token
:
CancellationToken
):
Thenable
<
modes
.
ISuggestResult
>
{
const
result
=
this
.
_provider
.
provideCompletionItems
(
model
,
position
,
token
,
context
);
return
toThenable
<
CompletionItem
[]
|
CompletionList
>
(
result
).
then
(
value
=>
{
const
result
:
modes
.
ISuggestResult
=
{
suggestions
:
[]
};
...
...
@@ -738,6 +759,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
DocumentHighlightKind
:
modes
.
DocumentHighlightKind
,
CompletionItemKind
:
CompletionItemKind
,
SymbolKind
:
modes
.
SymbolKind
,
IndentAction
:
IndentAction
IndentAction
:
IndentAction
,
SuggestTriggerKind
:
modes
.
SuggestTriggerKind
};
}
src/vs/monaco.d.ts
浏览文件 @
a1f78c66
...
...
@@ -4229,6 +4229,23 @@ declare module monaco.languages {
items
:
CompletionItem
[];
}
/**
* Contains additional information about the context in which
* [completion provider](#CompletionItemProvider.provideCompletionItems) is triggered.
*/
export
interface
CompletionContext
{
/**
* How the completion was triggered.
*/
triggerKind
:
SuggestTriggerKind
;
/**
* Character that triggered the completion item provider.
*
* `undefined` if provider was not triggered by a character.
*/
triggerCharacter
?:
string
;
}
/**
* The completion item provider interface defines the contract between extensions and
* the [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
...
...
@@ -4245,7 +4262,7 @@ declare module monaco.languages {
/**
* Provide completion items for the given position and document.
*/
provideCompletionItems
(
model
:
editor
.
IReadOnlyModel
,
position
:
Position
,
token
:
CancellationToken
):
CompletionItem
[]
|
Thenable
<
CompletionItem
[]
>
|
CompletionList
|
Thenable
<
CompletionList
>
;
provideCompletionItems
(
document
:
editor
.
IReadOnlyModel
,
position
:
Position
,
token
:
CancellationToken
,
context
:
CompletionContext
):
CompletionItem
[]
|
Thenable
<
CompletionItem
[]
>
|
CompletionList
|
Thenable
<
CompletionList
>
;
/**
* Given a completion item fill in more data, like [doc-comment](#CompletionItem.documentation)
* or [details](#CompletionItem.detail).
...
...
@@ -4496,6 +4513,14 @@ declare module monaco.languages {
provideHover
(
model
:
editor
.
IReadOnlyModel
,
position
:
Position
,
token
:
CancellationToken
):
Hover
|
Thenable
<
Hover
>
;
}
/**
* How a suggest provider was triggered.
*/
export
enum
SuggestTriggerKind
{
Invoke
=
0
,
TriggerCharacter
=
1
,
}
/**
* Represents a parameter of a callable-signature. A parameter can
* have a label and a doc-comment.
...
...
src/vs/vscode.d.ts
浏览文件 @
a1f78c66
...
...
@@ -2723,6 +2723,40 @@ declare module 'vscode' {
constructor
(
items
?:
CompletionItem
[],
isIncomplete
?:
boolean
);
}
/**
* How a [completion provider](#CompletionItemProvider) was triggered
*/
export
enum
CompletionTriggerKind
{
/**
* Completion was triggered normally.
*/
Invoke
=
0
,
/**
* Completion was triggered by a trigger character.
*/
TriggerCharacter
=
1
}
/**
* Contains additional information about the context in which
* [completion provider](#CompletionItemProvider.provideCompletionItems) is triggered.
*/
export
interface
CompletionContext
{
/**
* How the completion was triggered.
*/
readonly
triggerKind
:
CompletionTriggerKind
;
/**
* Character that triggered the completion item provider.
*
* `undefined` if provider was not triggered by a character.
*
* The trigger character is already in the document when the completion provider is triggered.
*/
readonly
triggerCharacter
?:
string
;
}
/**
* The completion item provider interface defines the contract between extensions and
* [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
...
...
@@ -2745,10 +2779,12 @@ declare module 'vscode' {
* @param document The document in which the command was invoked.
* @param position The position at which the command was invoked.
* @param token A cancellation token.
* @param context How the completion was triggered.
*
* @return An array of completions, a [completion list](#CompletionList), or a thenable that resolves to either.
* The lack of a result can be signaled by returning `undefined`, `null`, or an empty array.
*/
provideCompletionItems
(
document
:
TextDocument
,
position
:
Position
,
token
:
CancellationToken
):
ProviderResult
<
CompletionItem
[]
|
CompletionList
>
;
provideCompletionItems
(
document
:
TextDocument
,
position
:
Position
,
token
:
CancellationToken
,
context
:
CompletionContext
):
ProviderResult
<
CompletionItem
[]
|
CompletionList
>
;
/**
* Given a completion item fill in more data, like [doc-comment](#CompletionItem.documentation)
...
...
src/vs/workbench/api/electron-browser/mainThreadLanguageFeatures.ts
浏览文件 @
a1f78c66
...
...
@@ -233,8 +233,8 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
this
.
_registrations
[
handle
]
=
modes
.
SuggestRegistry
.
register
(
selector
,
<
modes
.
ISuggestSupport
>
{
triggerCharacters
,
provideCompletionItems
:
(
model
:
IReadOnlyModel
,
position
:
EditorPosition
,
token
:
CancellationToken
):
Thenable
<
modes
.
ISuggestResult
>
=>
{
return
wireCancellationToken
(
token
,
this
.
_proxy
.
$provideCompletionItems
(
handle
,
model
.
uri
,
position
)).
then
(
result
=>
{
provideCompletionItems
:
(
model
:
IReadOnlyModel
,
position
:
EditorPosition
,
context
:
modes
.
SuggestContext
,
token
:
CancellationToken
):
Thenable
<
modes
.
ISuggestResult
>
=>
{
return
wireCancellationToken
(
token
,
this
.
_proxy
.
$provideCompletionItems
(
handle
,
model
.
uri
,
position
,
context
)).
then
(
result
=>
{
if
(
!
result
)
{
return
result
;
}
...
...
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
a1f78c66
...
...
@@ -563,6 +563,7 @@ export function createApiFactory(
CompletionItem
:
extHostTypes
.
CompletionItem
,
CompletionItemKind
:
extHostTypes
.
CompletionItemKind
,
CompletionList
:
extHostTypes
.
CompletionList
,
CompletionTriggerKind
:
extHostTypes
.
CompletionTriggerKind
,
Diagnostic
:
extHostTypes
.
Diagnostic
,
DiagnosticSeverity
:
extHostTypes
.
DiagnosticSeverity
,
Disposable
:
extHostTypes
.
Disposable
,
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
a1f78c66
...
...
@@ -552,7 +552,7 @@ export interface ExtHostLanguageFeaturesShape {
$provideWorkspaceSymbols
(
handle
:
number
,
search
:
string
):
TPromise
<
modes
.
SymbolInformation
[]
>
;
$resolveWorkspaceSymbol
(
handle
:
number
,
symbol
:
modes
.
SymbolInformation
):
TPromise
<
modes
.
SymbolInformation
>
;
$provideRenameEdits
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
,
newName
:
string
):
TPromise
<
modes
.
WorkspaceEdit
>
;
$provideCompletionItems
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
):
TPromise
<
IExtHostSuggestResult
>
;
$provideCompletionItems
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
,
context
:
modes
.
SuggestContext
):
TPromise
<
IExtHostSuggestResult
>
;
$resolveCompletionItem
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
,
suggestion
:
modes
.
ISuggestion
):
TPromise
<
modes
.
ISuggestion
>
;
$releaseCompletionItems
(
handle
:
number
,
id
:
number
):
void
;
$provideSignatureHelp
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
):
TPromise
<
modes
.
SignatureHelp
>
;
...
...
src/vs/workbench/api/node/extHostLanguageFeatures.ts
浏览文件 @
a1f78c66
...
...
@@ -486,12 +486,14 @@ class SuggestAdapter {
this
.
_provider
=
provider
;
}
provideCompletionItems
(
resource
:
URI
,
position
:
IPosition
):
TPromise
<
IExtHostSuggestResult
>
{
provideCompletionItems
(
resource
:
URI
,
position
:
IPosition
,
context
:
modes
.
SuggestContext
):
TPromise
<
IExtHostSuggestResult
>
{
const
doc
=
this
.
_documents
.
getDocumentData
(
resource
).
document
;
const
pos
=
TypeConverters
.
toPosition
(
position
);
return
asWinJsPromise
<
vscode
.
CompletionItem
[]
|
vscode
.
CompletionList
>
(
token
=>
this
.
_provider
.
provideCompletionItems
(
doc
,
pos
,
token
)).
then
(
value
=>
{
return
asWinJsPromise
<
vscode
.
CompletionItem
[]
|
vscode
.
CompletionList
>
(
token
=>
{
return
this
.
_provider
.
provideCompletionItems
(
doc
,
pos
,
token
,
TypeConverters
.
CompletionContext
.
from
(
context
));
}).
then
(
value
=>
{
const
_id
=
this
.
_idPool
++
;
...
...
@@ -1001,8 +1003,8 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
return
this
.
_createDisposable
(
handle
);
}
$provideCompletionItems
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
):
TPromise
<
IExtHostSuggestResult
>
{
return
this
.
_withAdapter
(
handle
,
SuggestAdapter
,
adapter
=>
adapter
.
provideCompletionItems
(
resource
,
position
));
$provideCompletionItems
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
,
context
:
modes
.
SuggestContext
):
TPromise
<
IExtHostSuggestResult
>
{
return
this
.
_withAdapter
(
handle
,
SuggestAdapter
,
adapter
=>
adapter
.
provideCompletionItems
(
resource
,
position
,
context
));
}
$resolveCompletionItem
(
handle
:
number
,
resource
:
URI
,
position
:
IPosition
,
suggestion
:
modes
.
ISuggestion
):
TPromise
<
modes
.
ISuggestion
>
{
...
...
src/vs/workbench/api/node/extHostTypeConverters.ts
浏览文件 @
a1f78c66
...
...
@@ -307,6 +307,28 @@ export function toDocumentHighlight(occurrence: modes.DocumentHighlight): types.
return
new
types
.
DocumentHighlight
(
toRange
(
occurrence
.
range
),
occurrence
.
kind
);
}
export
namespace
CompletionTriggerKind
{
export
function
from
(
kind
:
modes
.
SuggestTriggerKind
)
{
switch
(
kind
)
{
case
modes
.
SuggestTriggerKind
.
TriggerCharacter
:
return
types
.
CompletionTriggerKind
.
TriggerCharacter
;
case
modes
.
SuggestTriggerKind
.
Invoke
:
default
:
return
types
.
CompletionTriggerKind
.
Invoke
;
}
}
}
export
namespace
CompletionContext
{
export
function
from
(
context
:
modes
.
SuggestContext
):
types
.
CompletionContext
{
return
{
triggerKind
:
CompletionTriggerKind
.
from
(
context
.
triggerKind
),
triggerCharacter
:
context
.
triggerCharacter
};
}
}
export
const
CompletionItemKind
=
{
from
(
kind
:
types
.
CompletionItemKind
):
modes
.
SuggestionType
{
...
...
src/vs/workbench/api/node/extHostTypes.ts
浏览文件 @
a1f78c66
...
...
@@ -879,6 +879,16 @@ export class SignatureHelp {
}
}
export
enum
CompletionTriggerKind
{
Invoke
=
0
,
TriggerCharacter
=
1
}
export
interface
CompletionContext
{
triggerKind
:
CompletionTriggerKind
;
triggerCharacter
:
string
;
}
export
enum
CompletionItemKind
{
Text
=
0
,
Method
=
1
,
...
...
src/vs/workbench/parts/debug/electron-browser/repl.ts
浏览文件 @
a1f78c66
...
...
@@ -180,7 +180,7 @@ export class Repl extends Panel implements IPrivateReplService {
modes
.
SuggestRegistry
.
register
({
scheme
:
debug
.
DEBUG_SCHEME
},
{
triggerCharacters
:
[
'
.
'
],
provideCompletionItems
:
(
model
:
IReadOnlyModel
,
position
:
Position
,
token
:
CancellationToken
):
Thenable
<
modes
.
ISuggestResult
>
=>
{
provideCompletionItems
:
(
model
:
IReadOnlyModel
,
position
:
Position
,
_context
:
modes
.
SuggestContext
,
token
:
CancellationToken
):
Thenable
<
modes
.
ISuggestResult
>
=>
{
const
word
=
this
.
replInput
.
getModel
().
getWordAtPosition
(
position
);
const
overwriteBefore
=
word
?
word
.
word
.
length
:
0
;
const
text
=
this
.
replInput
.
getModel
().
getLineContent
(
position
.
lineNumber
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录