Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
2eebf162
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,发现更多精彩内容 >>
提交
2eebf162
编写于
12月 03, 2015
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - add ISuggestion.textEdit and fill it in when missing
上级
5148523b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
72 addition
and
48 deletion
+72
-48
src/vs/editor/common/modes.ts
src/vs/editor/common/modes.ts
+1
-0
src/vs/editor/contrib/suggest/common/suggest.ts
src/vs/editor/contrib/suggest/common/suggest.ts
+35
-12
src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts
...vs/workbench/api/common/extHostLanguageFeatureCommands.ts
+1
-1
src/vs/workbench/api/common/extHostLanguageFeatures.ts
src/vs/workbench/api/common/extHostLanguageFeatures.ts
+5
-17
src/vs/workbench/api/common/pluginHostTypeConverters.ts
src/vs/workbench/api/common/pluginHostTypeConverters.ts
+14
-13
src/vs/workbench/test/common/api/extHostLanguageFeatureCommands.test.ts
...ch/test/common/api/extHostLanguageFeatureCommands.test.ts
+16
-5
未找到文件。
src/vs/editor/common/modes.ts
浏览文件 @
2eebf162
...
...
@@ -395,6 +395,7 @@ export interface ISuggestion {
label
:
string
;
codeSnippet
:
string
;
type
:
string
;
textEdit
?:
EditorCommon
.
ISingleEditOperation
;
highlights
?:
IHighlight
[];
typeLabel
?:
string
;
documentationLabel
?:
string
;
...
...
src/vs/editor/contrib/suggest/common/suggest.ts
浏览文件 @
2eebf162
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
sequence
}
from
'
vs/base/common/async
'
;
import
{
IModel
,
IPosition
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IModel
,
IPosition
,
IRange
}
from
'
vs/editor/common/editorCommon
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
mixin
}
from
'
vs/base/common/objects
'
;
import
{
onUnexpectedError
,
illegalArgument
}
from
'
vs/base/common/errors
'
;
...
...
@@ -42,29 +42,52 @@ export function suggest(model: IModel, position: IPosition, triggerCharacter: st
// for each support in the group ask for suggestions
let
promises
=
supports
.
map
(
support
=>
{
return
support
.
suggest
(
resource
,
position
,
triggerCharacter
).
then
(
value
=>
{
return
support
.
suggest
(
resource
,
position
,
triggerCharacter
).
then
(
value
s
=>
{
let
result
:
ISuggestions2
[]
=
[];
for
(
let
suggest
ions
of
value
)
{
for
(
let
suggest
Result
of
values
)
{
if
(
!
suggest
ions
||
!
Array
.
isArray
(
suggest
ions
.
suggestions
)
||
suggest
ions
.
suggestions
.
length
===
0
)
{
if
(
!
suggest
Result
||
!
Array
.
isArray
(
suggest
Result
.
suggestions
)
||
suggest
Result
.
suggestions
.
length
===
0
)
{
continue
;
}
const
suggestions2
:
ISuggestions2
=
{
support
,
currentWord
:
suggestions
.
currentWord
,
incomplete
:
suggestions
.
incomplete
,
overwriteAfter
:
suggestions
.
overwriteAfter
,
overwriteBefore
:
suggestions
.
overwriteBefore
,
suggestions
:
suggestions
.
suggestions
currentWord
:
suggestResult
.
currentWord
,
incomplete
:
suggestResult
.
incomplete
,
overwriteAfter
:
suggestResult
.
overwriteAfter
,
overwriteBefore
:
suggestResult
.
overwriteBefore
,
suggestions
:
suggestResult
.
suggestions
}
const
defaultRange
:
IRange
=
{
startLineNumber
:
position
.
lineNumber
,
startColumn
:
position
.
column
,
endLineNumber
:
position
.
lineNumber
,
endColumn
:
position
.
column
};
if
(
typeof
suggestResult
.
overwriteBefore
===
'
number
'
&&
suggestResult
.
overwriteBefore
>
0
)
{
defaultRange
.
startColumn
-=
suggestResult
.
overwriteBefore
;
}
if
(
typeof
suggestResult
.
overwriteAfter
===
'
number
'
&&
suggestResult
.
overwriteAfter
>
0
)
{
defaultRange
.
endColumn
+=
suggestResult
.
overwriteAfter
}
for
(
let
suggestion
of
suggestResult
.
suggestions
)
{
if
(
!
suggestion
.
textEdit
)
{
suggestion
.
textEdit
=
{
text
:
suggestion
.
codeSnippet
,
range
:
defaultRange
};
}
}
// add additional properties
mixin
(
suggestions2
,
suggest
ions
,
false
);
mixin
(
suggestions2
,
suggest
Result
,
false
);
result
.
push
(
suggestions2
);
}
...
...
src/vs/workbench/api/common/extHostLanguageFeatureCommands.ts
浏览文件 @
2eebf162
...
...
@@ -168,7 +168,7 @@ export class ExtHostLanguageFeatureCommands {
for
(
let
group
of
value
)
{
for
(
let
suggestions
of
group
)
{
for
(
let
suggestion
of
suggestions
.
suggestions
)
{
const
item
=
typeConverters
.
Suggest
.
to
(
suggestion
,
suggestions
);
const
item
=
typeConverters
.
Suggest
.
to
(
suggestion
);
items
.
push
(
item
);
}
}
...
...
src/vs/workbench/api/common/extHostLanguageFeatures.ts
浏览文件 @
2eebf162
...
...
@@ -337,7 +337,7 @@ class DocumentFormattingAdapter implements modes.IFormattingSupport {
return
asWinJsPromise
(
token
=>
this
.
_provider
.
provideDocumentFormattingEdits
(
doc
,
<
any
>
options
,
token
)).
then
(
value
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
.
map
(
TypeConverters
.
fromTextEdit
);
return
value
.
map
(
TypeConverters
.
TextEdit
.
from
);
}
});
}
...
...
@@ -360,7 +360,7 @@ class RangeFormattingAdapter implements modes.IFormattingSupport {
return
asWinJsPromise
(
token
=>
this
.
_provider
.
provideDocumentRangeFormattingEdits
(
doc
,
ran
,
<
any
>
options
,
token
)).
then
(
value
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
.
map
(
TypeConverters
.
fromTextEdit
);
return
value
.
map
(
TypeConverters
.
TextEdit
.
from
);
}
});
}
...
...
@@ -385,7 +385,7 @@ class OnTypeFormattingAdapter implements modes.IFormattingSupport {
return
asWinJsPromise
(
token
=>
this
.
_provider
.
provideOnTypeFormattingEdits
(
doc
,
pos
,
ch
,
<
any
>
options
,
token
)).
then
(
value
=>
{
if
(
Array
.
isArray
(
value
))
{
return
value
.
map
(
TypeConverters
.
fromTextEdit
);
return
value
.
map
(
TypeConverters
.
TextEdit
.
from
);
}
});
}
...
...
@@ -489,7 +489,7 @@ class SuggestAdapter implements modes.ISuggestSupport {
for
(
let
i
=
0
;
i
<
value
.
length
;
i
++
)
{
const
item
=
value
[
i
];
const
[
suggestion
]
=
TypeConverters
.
Suggest
.
from
(
item
,
defaultSuggestions
);
SuggestAdapter
.
_convertCompletionIte
m
(
item
);
const
suggestion
=
TypeConverters
.
Suggest
.
fro
m
(
item
);
if
(
item
.
textEdit
)
{
...
...
@@ -540,22 +540,10 @@ class SuggestAdapter implements modes.ISuggestSupport {
return
TPromise
.
as
(
suggestion
);
}
return
asWinJsPromise
(
token
=>
this
.
_provider
.
resolveCompletionItem
(
item
,
token
)).
then
(
resolvedItem
=>
{
return
SuggestAdapter
.
_convertCompletionIte
m
(
resolvedItem
||
item
);
return
TypeConverters
.
Suggest
.
fro
m
(
resolvedItem
||
item
);
});
}
private
static
_convertCompletionItem
(
item
:
vscode
.
CompletionItem
):
modes
.
ISuggestion
{
return
{
label
:
item
.
label
,
codeSnippet
:
item
.
insertText
||
item
.
label
,
type
:
CompletionItemKind
[
item
.
kind
||
CompletionItemKind
.
Text
].
toString
().
toLowerCase
(),
typeLabel
:
item
.
detail
,
documentationLabel
:
item
.
documentation
,
sortText
:
item
.
sortText
,
filterText
:
item
.
filterText
};
}
getFilter
():
any
{
throw
new
Error
(
'
illegal state
'
);
}
...
...
src/vs/workbench/api/common/pluginHostTypeConverters.ts
浏览文件 @
2eebf162
...
...
@@ -168,10 +168,15 @@ export function fromRangeOrRangeWithMessage(ranges:vscode.Range[]|vscode.Decorat
}
}
export
function
fromTextEdit
(
edit
:
vscode
.
TextEdit
)
{
return
<
ISingleEditOperation
>
{
text
:
edit
.
newText
,
range
:
fromRange
(
edit
.
range
)
export
const
TextEdit
=
{
from
(
edit
:
vscode
.
TextEdit
):
ISingleEditOperation
{
return
<
ISingleEditOperation
>
{
text
:
edit
.
newText
,
range
:
fromRange
(
edit
.
range
)
}
},
to
(
edit
:
ISingleEditOperation
):
vscode
.
TextEdit
{
return
new
types
.
TextEdit
(
toRange
(
edit
.
range
),
edit
.
text
);
}
}
...
...
@@ -315,25 +320,21 @@ export function toDocumentHighlight(occurrence: modes.IOccurence): types.Documen
export
const
Suggest
=
{
from
(
item
:
vscode
.
CompletionItem
,
defaultContainer
:
modes
.
ISuggestResult
):
[
modes
.
ISuggestion
,
modes
.
ISuggestResult
]
{
from
(
item
:
vscode
.
CompletionItem
):
modes
.
ISuggestion
{
const
suggestion
:
modes
.
ISuggestion
=
{
label
:
item
.
label
,
codeSnippet
:
item
.
insertText
||
item
.
label
,
type
:
types
.
CompletionItemKind
[
item
.
kind
||
types
.
CompletionItemKind
.
Text
].
toString
().
toLowerCase
(),
typeLabel
:
item
.
detail
,
textEdit
:
item
.
textEdit
&&
TextEdit
.
from
(
item
.
textEdit
),
documentationLabel
:
item
.
documentation
,
sortText
:
item
.
sortText
,
filterText
:
item
.
filterText
};
if
(
item
.
textEdit
)
{
// TODO@joh
}
return
[
suggestion
,
defaultContainer
];
return
suggestion
;
},
to
(
suggestion
:
modes
.
ISuggestion
,
container
:
modes
.
ISuggestResult
):
types
.
CompletionItem
{
to
(
suggestion
:
modes
.
ISuggestion
):
types
.
CompletionItem
{
const
result
=
new
types
.
CompletionItem
(
suggestion
.
label
);
result
.
insertText
=
suggestion
.
codeSnippet
;
result
.
kind
=
types
.
CompletionItemKind
[
suggestion
.
type
.
charAt
(
0
).
toUpperCase
()
+
suggestion
.
type
.
substr
(
1
)];
...
...
@@ -341,7 +342,7 @@ export const Suggest = {
result
.
documentation
=
suggestion
.
documentationLabel
;
result
.
sortText
=
suggestion
.
sortText
;
result
.
filterText
=
suggestion
.
filterText
;
// todo@joh edit range!
result
.
textEdit
=
suggestion
.
textEdit
&&
<
any
>
TextEdit
.
to
(
suggestion
.
textEdit
);
return
result
;
}
}
...
...
src/vs/workbench/test/common/api/extHostLanguageFeatureCommands.test.ts
浏览文件 @
2eebf162
...
...
@@ -236,11 +236,11 @@ suite('ExtHostLanguageFeatureCommands', function() {
test
(
'
Suggest, back and forth
'
,
function
(
done
)
{
disposables
.
push
(
extHost
.
registerCompletionItemProvider
(
defaultSelector
,
<
vscode
.
CompletionItemProvider
>
{
provideCompletionItems
():
any
{
return
[
new
types
.
CompletionItem
(
'
item1
'
),
new
types
.
CompletionItem
(
'
item2
'
)
];
provideCompletionItems
(
doc
,
pos
):
any
{
let
a
=
new
types
.
CompletionItem
(
'
item1
'
);
let
b
=
new
types
.
CompletionItem
(
'
item2
'
);
b
.
textEdit
=
types
.
TextEdit
.
replace
(
new
types
.
Range
(
0
,
0
,
0
,
4
),
'
foo
'
);
return
[
a
,
b
];
}
},
[]));
...
...
@@ -249,7 +249,18 @@ suite('ExtHostLanguageFeatureCommands', function() {
assert
.
equal
(
values
.
length
,
2
);
let
[
first
,
second
]
=
values
;
assert
.
equal
(
first
.
label
,
'
item1
'
);
assert
.
equal
(
first
.
textEdit
.
newText
,
'
item1
'
);
assert
.
equal
(
first
.
textEdit
.
range
.
start
.
line
,
0
);
assert
.
equal
(
first
.
textEdit
.
range
.
start
.
character
,
0
);
assert
.
equal
(
first
.
textEdit
.
range
.
end
.
line
,
0
);
assert
.
equal
(
first
.
textEdit
.
range
.
end
.
character
,
0
);
assert
.
equal
(
second
.
label
,
'
item2
'
);
assert
.
equal
(
second
.
textEdit
.
newText
,
'
foo
'
);
assert
.
equal
(
second
.
textEdit
.
range
.
start
.
line
,
0
);
assert
.
equal
(
second
.
textEdit
.
range
.
start
.
character
,
0
);
assert
.
equal
(
second
.
textEdit
.
range
.
end
.
line
,
0
);
assert
.
equal
(
second
.
textEdit
.
range
.
end
.
character
,
4
);
done
();
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录