Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
edb8abe5
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,发现更多精彩内容 >>
提交
edb8abe5
编写于
11月 17, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add builder-style functionality to the SnippetString, #3210
上级
96245689
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
103 addition
and
4 deletion
+103
-4
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+29
-1
src/vs/workbench/api/node/extHostTypes.ts
src/vs/workbench/api/node/extHostTypes.ts
+36
-2
src/vs/workbench/test/node/api/extHostTypes.test.ts
src/vs/workbench/test/node/api/extHostTypes.test.ts
+38
-1
未找到文件。
src/vs/vscode.d.ts
浏览文件 @
edb8abe5
...
...
@@ -2039,7 +2039,35 @@ declare module 'vscode' {
*/
value
:
string
;
constructor
(
value
:
string
);
constructor
(
value
?:
string
);
/**
* Builder-function that appends the given string to
* the [`value`](#SnippetString.value) of this snippet string.
*
* @param string A value to append 'as given'. The string will be escaped.
*/
appendText
(
string
:
string
):
SnippetString
;
/**
* Builder-function that appends a tabstop (`$1`, `$2` etc) to
* the [`value`](#SnippetString.value) of this snippet string.
*
* @param number The number of this tabstop, defaults to an auto-incremet
* value starting at 1.
*/
appendTabstop
(
number
?:
number
):
SnippetString
;
/**
* Builder-function that appends a placeholder (`${1:value}`) to
* the [`value`](#SnippetString.value) of this snippet string.
*
* @param value The value of this placeholder - either a string or a function
* with which a nested snippet can be created.
* @param number The number of this tabstop, defaults to an auto-incremet
* value starting at 1.
*/
appendPlaceholder
(
value
:
string
|
((
snippet
:
SnippetString
)
=>
any
),
number
?:
number
):
SnippetString
;
}
/**
...
...
src/vs/workbench/api/node/extHostTypes.ts
浏览文件 @
edb8abe5
...
...
@@ -524,10 +524,44 @@ export class WorkspaceEdit {
export
class
SnippetString
{
private
_tabstop
:
number
=
1
;
value
:
string
;
constructor
(
value
:
string
)
{
this
.
value
=
value
;
constructor
(
value
?:
string
)
{
this
.
value
=
value
||
''
;
}
appendText
(
string
:
string
):
SnippetString
{
this
.
value
+=
string
.
replace
(
/
\$
/g
,
'
\\
$
'
);
return
this
;
}
appendTabstop
(
number
:
number
=
this
.
_tabstop
++
):
SnippetString
{
this
.
value
+=
'
$
'
;
this
.
value
+=
number
;
return
this
;
}
appendPlaceholder
(
value
:
string
|
((
snippet
:
SnippetString
)
=>
any
),
number
:
number
=
this
.
_tabstop
++
):
SnippetString
{
if
(
typeof
value
===
'
function
'
)
{
const
nested
=
new
SnippetString
();
nested
.
_tabstop
=
this
.
_tabstop
;
value
(
nested
);
this
.
_tabstop
=
nested
.
_tabstop
;
value
=
nested
.
value
;
}
else
{
value
=
value
.
replace
(
/
\$
|}/g
,
'
\\
$&
'
);
}
this
.
value
+=
'
${
'
;
this
.
value
+=
number
;
this
.
value
+=
'
:
'
;
this
.
value
+=
value
;
this
.
value
+=
'
}
'
;
return
this
;
}
}
...
...
src/vs/workbench/test/node/api/extHostTypes.test.ts
浏览文件 @
edb8abe5
...
...
@@ -416,4 +416,41 @@ suite('ExtHostTypes', function () {
assert
.
ok
(
info
.
location
instanceof
types
.
Location
);
assert
.
equal
(
info
.
location
.
uri
,
undefined
);
});
});
\ No newline at end of file
test
(
'
SnippetString, builder-methods
'
,
function
()
{
let
string
:
types
.
SnippetString
;
string
=
new
types
.
SnippetString
();
assert
.
equal
(
string
.
appendText
(
'
I need $ and $
'
).
value
,
'
I need
\\
$ and
\\
$
'
);
string
=
new
types
.
SnippetString
();
string
.
appendPlaceholder
(
'
fo$o}
'
);
assert
.
equal
(
string
.
value
,
'
${1:fo
\\
$o
\\
}}
'
);
string
=
new
types
.
SnippetString
();
string
.
appendText
(
'
foo
'
).
appendTabstop
(
0
).
appendText
(
'
bar
'
);
assert
.
equal
(
string
.
value
,
'
foo$0bar
'
);
string
=
new
types
.
SnippetString
();
string
.
appendText
(
'
foo
'
).
appendTabstop
().
appendText
(
'
bar
'
);
assert
.
equal
(
string
.
value
,
'
foo$1bar
'
);
string
=
new
types
.
SnippetString
();
string
.
appendText
(
'
foo
'
).
appendTabstop
(
42
).
appendText
(
'
bar
'
);
assert
.
equal
(
string
.
value
,
'
foo$42bar
'
);
string
=
new
types
.
SnippetString
();
string
.
appendText
(
'
foo
'
).
appendPlaceholder
(
'
farboo
'
).
appendText
(
'
bar
'
);
assert
.
equal
(
string
.
value
,
'
foo${1:farboo}bar
'
);
string
=
new
types
.
SnippetString
();
string
.
appendText
(
'
foo
'
).
appendPlaceholder
(
'
far$boo
'
).
appendText
(
'
bar
'
);
assert
.
equal
(
string
.
value
,
'
foo${1:far
\\
$boo}bar
'
);
string
=
new
types
.
SnippetString
();
string
.
appendText
(
'
foo
'
).
appendPlaceholder
(
b
=>
b
.
appendText
(
'
abc
'
).
appendPlaceholder
(
'
nested
'
)).
appendText
(
'
bar
'
);
assert
.
equal
(
string
.
value
,
'
foo${1:abc${2:nested}}bar
'
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录