Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
8977e39e
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,发现更多精彩内容 >>
提交
8977e39e
编写于
7月 21, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
first end-2-end for choice in snippets, #17545
上级
49ffef11
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
60 addition
and
50 deletion
+60
-50
src/vs/editor/contrib/snippet/browser/snippetController2.ts
src/vs/editor/contrib/snippet/browser/snippetController2.ts
+15
-0
src/vs/editor/contrib/snippet/browser/snippetSession.ts
src/vs/editor/contrib/snippet/browser/snippetSession.ts
+9
-1
src/vs/editor/contrib/suggest/browser/suggest.ts
src/vs/editor/contrib/suggest/browser/suggest.ts
+26
-1
src/vs/workbench/parts/snippets/electron-browser/tabCompletion.ts
...orkbench/parts/snippets/electron-browser/tabCompletion.ts
+10
-48
未找到文件。
src/vs/editor/contrib/snippet/browser/snippetController2.ts
浏览文件 @
8977e39e
...
...
@@ -12,6 +12,8 @@ import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import
{
SnippetSession
}
from
'
./snippetSession
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
{
showSimpleSuggestions
}
from
'
vs/editor/contrib/suggest/browser/suggest
'
;
import
{
ISuggestion
}
from
'
vs/editor/common/modes
'
;
@
commonEditorContribution
export
class
SnippetController2
{
...
...
@@ -110,6 +112,19 @@ export class SnippetController2 {
this
.
_inSnippet
.
set
(
true
);
this
.
_hasPrevTabstop
.
set
(
!
this
.
_session
.
isAtFirstPlaceholder
);
this
.
_hasNextTabstop
.
set
(
!
this
.
_session
.
isAtLastPlaceholder
);
const
{
choice
}
=
this
.
_session
;
if
(
choice
)
{
const
suggestions
=
choice
.
options
.
map
((
option
,
i
)
=>
{
return
<
ISuggestion
>
{
label
:
option
.
value
,
insertText
:
option
.
value
,
type
:
'
value
'
,
sortText
:
String
(
i
)
};
});
showSimpleSuggestions
(
this
.
_editor
,
suggestions
);
}
}
finish
():
void
{
...
...
src/vs/editor/contrib/snippet/browser/snippetSession.ts
浏览文件 @
8977e39e
...
...
@@ -9,7 +9,7 @@ import 'vs/css!./snippetSession';
import
{
getLeadingWhitespace
}
from
'
vs/base/common/strings
'
;
import
{
ICommonCodeEditor
,
IModel
,
TrackedRangeStickiness
,
IIdentifiedSingleEditOperation
}
from
'
vs/editor/common/editorCommon
'
;
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
import
{
TextmateSnippet
,
Placeholder
,
SnippetParser
}
from
'
./snippetParser
'
;
import
{
TextmateSnippet
,
Placeholder
,
Choice
,
SnippetParser
}
from
'
./snippetParser
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
...
...
@@ -155,6 +155,10 @@ export class OneSnippet {
return
ret
;
}
get
choice
():
Choice
{
return
this
.
_placeholderGroups
[
this
.
_placeholderGroupsIdx
][
0
].
choice
;
}
merge
(
others
:
OneSnippet
[]):
void
{
const
model
=
this
.
_editor
.
getModel
();
...
...
@@ -409,6 +413,10 @@ export class SnippetSession {
return
this
.
_snippets
[
0
].
hasPlaceholder
;
}
get
choice
():
Choice
{
return
this
.
_snippets
[
0
].
choice
;
}
isSelectionWithinPlaceholders
():
boolean
{
if
(
!
this
.
hasPlaceholder
)
{
...
...
src/vs/editor/contrib/suggest/browser/suggest.ts
浏览文件 @
8977e39e
...
...
@@ -10,7 +10,7 @@ import { compareIgnoreCase } from 'vs/base/common/strings';
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
onUnexpectedExternalError
}
from
'
vs/base/common/errors
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IModel
}
from
'
vs/editor/common/editorCommon
'
;
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
{
Position
,
IPosition
}
from
'
vs/editor/common/core/position
'
;
...
...
@@ -216,3 +216,28 @@ CommonEditorRegistry.registerDefaultLanguageCommand('_executeCompletionItemProvi
return
result
;
});
});
interface
SuggestController
extends
IEditorContribution
{
triggerSuggest
(
onlyFrom
?:
ISuggestSupport
[]):
void
;
}
let
_suggestions
:
ISuggestion
[];
let
_provider
=
new
class
implements
ISuggestSupport
{
provideCompletionItems
():
ISuggestResult
{
return
_suggestions
&&
{
suggestions
:
_suggestions
};
}
};
SuggestRegistry
.
register
(
'
*
'
,
_provider
);
/**
*
* @param editor
* @param suggestions
*/
export
function
showSimpleSuggestions
(
editor
:
ICommonCodeEditor
,
suggestions
:
ISuggestion
[])
{
_suggestions
=
suggestions
;
editor
.
getContribution
<
SuggestController
>
(
'
editor.contrib.suggestController
'
).
triggerSuggest
([
_provider
]);
_suggestions
=
undefined
;
}
src/vs/workbench/parts/snippets/electron-browser/tabCompletion.ts
浏览文件 @
8977e39e
...
...
@@ -16,43 +16,10 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
CommonEditorRegistry
,
commonEditorContribution
,
EditorCommand
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
SnippetController2
}
from
'
vs/editor/contrib/snippet/browser/snippetController2
'
;
import
{
SuggestController
}
from
'
vs/editor/contrib/suggest/browser/suggestController
'
;
import
{
ISuggestSupport
,
ISuggestResult
,
SuggestRegistry
}
from
'
vs/editor/common/modes
'
;
import
{
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
showSimpleSuggestions
}
from
'
vs/editor/contrib/suggest/browser/suggest
'
;
import
{
IConfigurationRegistry
,
Extensions
as
ConfigExt
}
from
'
vs/platform/configuration/common/configurationRegistry
'
;
import
{
EditorContextKeys
}
from
'
vs/editor/common/editorContextKeys
'
;
class
TabCompletionProvider
implements
ISuggestSupport
{
position
:
Position
;
snippets
:
ISnippet
[];
reset
():
this
{
return
this
.
set
(
undefined
,
undefined
);
}
set
(
position
:
Position
,
snippets
:
ISnippet
[]):
this
{
this
.
position
=
position
;
this
.
snippets
=
snippets
;
return
this
;
}
provideCompletionItems
(
model
:
editorCommon
.
IModel
,
position
:
Position
):
ISuggestResult
{
if
(
!
this
.
snippets
||
this
.
position
.
lineNumber
!==
position
.
lineNumber
||
this
.
position
.
column
>
position
.
column
)
{
return
undefined
;
}
const
delta
=
position
.
column
-
this
.
position
.
column
;
const
suggestions
:
SnippetSuggestion
[]
=
[];
for
(
const
snippet
of
this
.
snippets
)
{
suggestions
.
push
(
new
SnippetSuggestion
(
snippet
,
delta
+
snippet
.
prefix
.
length
));
}
return
{
suggestions
};
}
}
@
commonEditorContribution
export
class
TabCompletionController
implements
editorCommon
.
IEditorContribution
{
...
...
@@ -65,9 +32,8 @@ export class TabCompletionController implements editorCommon.IEditorContribution
private
readonly
_editor
:
editorCommon
.
ICommonCodeEditor
;
private
readonly
_snippetController
:
SnippetController2
;
private
readonly
_suggestController
:
SuggestController
;
private
readonly
_tabCompletionProvider
:
TabCompletionProvider
;
private
readonly
_dispoables
:
IDisposable
[]
=
[];
private
readonly
_snippets
:
ISnippet
[]
=
[];
constructor
(
editor
:
editorCommon
.
ICommonCodeEditor
,
...
...
@@ -76,14 +42,11 @@ export class TabCompletionController implements editorCommon.IEditorContribution
)
{
this
.
_editor
=
editor
;
this
.
_snippetController
=
SnippetController2
.
get
(
editor
);
this
.
_suggestController
=
SuggestController
.
get
(
editor
);
this
.
_tabCompletionProvider
=
new
TabCompletionProvider
();
this
.
_dispoables
.
push
(
SuggestRegistry
.
register
(
'
*
'
,
this
.
_tabCompletionProvider
));
const
hasSnippets
=
TabCompletionController
.
ContextKey
.
bindTo
(
contextKeyService
);
this
.
_dispoables
.
push
(
editor
.
onDidChangeCursorSelection
(
e
=>
{
let
snippets
:
ISnippet
[]
=
[]
;
this
.
_snippets
.
length
=
0
;
let
selectFn
:
(
snippet
:
ISnippet
)
=>
boolean
;
if
(
e
.
selection
.
isEmpty
())
{
...
...
@@ -100,13 +63,12 @@ export class TabCompletionController implements editorCommon.IEditorContribution
if
(
selectFn
)
{
snippetService
.
visitSnippets
(
editor
.
getModel
().
getLanguageIdentifier
().
id
,
s
=>
{
if
(
selectFn
(
s
))
{
snippets
.
push
(
s
);
this
.
_
snippets
.
push
(
s
);
}
return
true
;
});
}
this
.
_tabCompletionProvider
.
set
(
editor
.
getPosition
(),
snippets
);
hasSnippets
.
set
(
this
.
_tabCompletionProvider
.
snippets
.
length
>
0
);
hasSnippets
.
set
(
this
.
_snippets
.
length
>
0
);
}));
}
...
...
@@ -119,15 +81,15 @@ export class TabCompletionController implements editorCommon.IEditorContribution
}
performSnippetCompletions
():
void
{
const
{
snippets
}
=
this
.
_tabCompletionProvider
;
if
(
snippets
.
length
===
1
)
{
if
(
this
.
_
snippets
.
length
===
1
)
{
// one -> just insert
const
[
snippet
]
=
snippets
;
const
[
snippet
]
=
this
.
_
snippets
;
this
.
_snippetController
.
insert
(
snippet
.
codeSnippet
,
snippet
.
prefix
.
length
,
0
);
}
else
if
(
snippets
.
length
>
1
)
{
}
else
if
(
this
.
_
snippets
.
length
>
1
)
{
// two or more -> show IntelliSense box
this
.
_suggestController
.
triggerSuggest
([
this
.
_tabCompletionProvider
]
);
showSimpleSuggestions
(
this
.
_editor
,
this
.
_snippets
.
map
(
snippet
=>
new
SnippetSuggestion
(
snippet
,
snippet
.
prefix
.
length
))
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录