Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
6bc6ba5b
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,发现更多精彩内容 >>
提交
6bc6ba5b
编写于
11月 21, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add variable-builder methods to snippet string, #4956
上级
417214fb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
64 addition
and
0 deletion
+64
-0
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+23
-0
src/vs/workbench/api/node/extHostTypes.ts
src/vs/workbench/api/node/extHostTypes.ts
+25
-0
src/vs/workbench/test/node/api/extHostTypes.test.ts
src/vs/workbench/test/node/api/extHostTypes.test.ts
+16
-0
未找到文件。
src/vs/vscode.d.ts
浏览文件 @
6bc6ba5b
...
@@ -2048,6 +2048,7 @@ declare module 'vscode' {
...
@@ -2048,6 +2048,7 @@ declare module 'vscode' {
* the [`value`](#SnippetString.value) of this snippet string.
* the [`value`](#SnippetString.value) of this snippet string.
*
*
* @param string A value to append 'as given'. The string will be escaped.
* @param string A value to append 'as given'. The string will be escaped.
* @return This snippet string.
*/
*/
appendText
(
string
:
string
):
SnippetString
;
appendText
(
string
:
string
):
SnippetString
;
...
@@ -2057,6 +2058,7 @@ declare module 'vscode' {
...
@@ -2057,6 +2058,7 @@ declare module 'vscode' {
*
*
* @param number The number of this tabstop, defaults to an auto-incremet
* @param number The number of this tabstop, defaults to an auto-incremet
* value starting at 1.
* value starting at 1.
* @return This snippet string.
*/
*/
appendTabstop
(
number
?:
number
):
SnippetString
;
appendTabstop
(
number
?:
number
):
SnippetString
;
...
@@ -2068,8 +2070,29 @@ declare module 'vscode' {
...
@@ -2068,8 +2070,29 @@ declare module 'vscode' {
* with which a nested snippet can be created.
* with which a nested snippet can be created.
* @param number The number of this tabstop, defaults to an auto-incremet
* @param number The number of this tabstop, defaults to an auto-incremet
* value starting at 1.
* value starting at 1.
* @return This snippet string.
*/
*/
appendPlaceholder
(
value
:
string
|
((
snippet
:
SnippetString
)
=>
any
),
number
?:
number
):
SnippetString
;
appendPlaceholder
(
value
:
string
|
((
snippet
:
SnippetString
)
=>
any
),
number
?:
number
):
SnippetString
;
/**
* Builder-function that appends a variable (`$VAR`) to
* the [`value`](#SnippetString.value) of this snippet string.
*
* @param name The name of the variable - excluding the `$`.
* @return This snippet string.
*/
appendVariable
(
name
:
string
):
SnippetString
;
/**
* Builder-function that appends a variable and default value (`${VAR:fallback}`) to
* the [`value`](#SnippetString.value) of this snippet string.
*
* @param name The name of the variable (excluding the `$`)
* @param defaultValue The default value which is used when the variable name cannot
* be resolved - either a string or a function with which a nested snippet can be created.
* @return This snippet string.
*/
appendVariable
(
name
:
string
,
defaultValue
:
string
|
((
snippet
:
SnippetString
)
=>
any
)):
SnippetString
;
}
}
/**
/**
...
...
src/vs/workbench/api/node/extHostTypes.ts
浏览文件 @
6bc6ba5b
...
@@ -561,6 +561,31 @@ export class SnippetString {
...
@@ -561,6 +561,31 @@ export class SnippetString {
this
.
value
+=
value
;
this
.
value
+=
value
;
this
.
value
+=
'
}
'
;
this
.
value
+=
'
}
'
;
return
this
;
}
appendVariable
(
name
:
string
,
defaultValue
?:
string
|
((
snippet
:
SnippetString
)
=>
any
)):
SnippetString
{
if
(
typeof
defaultValue
===
'
function
'
)
{
const
nested
=
new
SnippetString
();
nested
.
_tabstop
=
this
.
_tabstop
;
defaultValue
(
nested
);
this
.
_tabstop
=
nested
.
_tabstop
;
defaultValue
=
nested
.
value
;
}
else
if
(
typeof
defaultValue
===
'
string
'
)
{
defaultValue
=
defaultValue
.
replace
(
/
\$
|}/g
,
'
\\
$&
'
);
}
this
.
value
+=
'
${
'
;
this
.
value
+=
name
;
if
(
defaultValue
)
{
this
.
value
+=
'
:
'
;
this
.
value
+=
defaultValue
;
}
this
.
value
+=
'
}
'
;
return
this
;
return
this
;
}
}
}
}
...
...
src/vs/workbench/test/node/api/extHostTypes.test.ts
浏览文件 @
6bc6ba5b
...
@@ -452,5 +452,21 @@ suite('ExtHostTypes', function () {
...
@@ -452,5 +452,21 @@ suite('ExtHostTypes', function () {
string
.
appendText
(
'
foo
'
).
appendPlaceholder
(
b
=>
b
.
appendText
(
'
abc
'
).
appendPlaceholder
(
'
nested
'
)).
appendText
(
'
bar
'
);
string
.
appendText
(
'
foo
'
).
appendPlaceholder
(
b
=>
b
.
appendText
(
'
abc
'
).
appendPlaceholder
(
'
nested
'
)).
appendText
(
'
bar
'
);
assert
.
equal
(
string
.
value
,
'
foo${1:abc${2:nested}}bar
'
);
assert
.
equal
(
string
.
value
,
'
foo${1:abc${2:nested}}bar
'
);
string
=
new
types
.
SnippetString
();
string
.
appendVariable
(
'
foo
'
);
assert
.
equal
(
string
.
value
,
'
${foo}
'
);
string
=
new
types
.
SnippetString
();
string
.
appendText
(
'
foo
'
).
appendVariable
(
'
TM_SELECTED_TEXT
'
).
appendText
(
'
bar
'
);
assert
.
equal
(
string
.
value
,
'
foo${TM_SELECTED_TEXT}bar
'
);
string
=
new
types
.
SnippetString
();
string
.
appendVariable
(
'
BAR
'
,
b
=>
b
.
appendPlaceholder
(
'
ops
'
));
assert
.
equal
(
string
.
value
,
'
${BAR:${1:ops}}
'
);
string
=
new
types
.
SnippetString
();
string
.
appendVariable
(
'
BAR
'
,
b
=>
{
});
assert
.
equal
(
string
.
value
,
'
${BAR}
'
);
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录