Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
58da79c8
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,发现更多精彩内容 >>
提交
58da79c8
编写于
5月 05, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make sure adjust indentation creates a copy of the snippet, #16037
上级
823b3db4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
17 deletion
+48
-17
src/vs/editor/contrib/snippet/common/snippetParser.ts
src/vs/editor/contrib/snippet/common/snippetParser.ts
+38
-10
src/vs/editor/contrib/snippet/test/common/snippetParser.test.ts
.../editor/contrib/snippet/test/common/snippetParser.test.ts
+10
-7
未找到文件。
src/vs/editor/contrib/snippet/common/snippetParser.ts
浏览文件 @
58da79c8
...
...
@@ -151,6 +151,13 @@ export class Text extends Marker {
len
():
number
{
return
this
.
string
.
length
;
}
with
(
string
:
string
):
Text
{
if
(
this
.
string
!==
string
)
{
return
new
Text
(
string
);
}
else
{
return
this
;
}
}
}
export
class
Placeholder
extends
Marker
{
...
...
@@ -160,6 +167,9 @@ export class Placeholder extends Marker {
toString
()
{
return
Marker
.
toString
(
this
.
defaultValue
);
}
with
(
defaultValue
:
Marker
[]):
Placeholder
{
return
new
Placeholder
(
this
.
name
,
defaultValue
);
}
}
export
class
Variable
extends
Marker
{
...
...
@@ -169,14 +179,17 @@ export class Variable extends Marker {
constructor
(
public
name
:
string
=
''
,
public
defaultValue
:
Marker
[])
{
super
();
}
get
isDefined
():
boolean
{
return
this
.
resolvedValue
!==
undefined
;
}
toString
()
{
return
this
.
isDefined
?
this
.
resolvedValue
:
Marker
.
toString
(
this
.
defaultValue
);
}
with
(
defaultValue
:
Marker
[]):
Variable
{
let
ret
=
new
Variable
(
this
.
name
,
defaultValue
);
ret
.
resolvedValue
=
this
.
resolvedValue
;
return
ret
;
}
}
export
function
walk
(
marker
:
Marker
[],
visitor
:
(
marker
:
Marker
)
=>
boolean
):
void
{
const
stack
=
[...
marker
];
...
...
@@ -234,26 +247,41 @@ export class TextmateSnippet {
return
map
;
}
adjustIndentation
(
normalizer
:
(
whitespace
:
string
)
=>
string
):
void
{
withIndentation
(
normalizer
:
(
whitespace
:
string
)
=>
string
):
TextmateSnippet
{
// create a new snippet because this can be
// different for each and every cursor
const
newMarker
=
[...
this
.
marker
];
TextmateSnippet
.
_adjustIndentation
(
newMarker
,
normalizer
);
return
new
TextmateSnippet
(
newMarker
);
}
walk
(
this
.
marker
,
candidate
=>
{
private
static
_adjustIndentation
(
marker
:
Marker
[],
normalizer
:
(
whitespace
:
string
)
=>
string
):
void
{
for
(
let
i
=
0
;
i
<
marker
.
length
;
i
++
)
{
const
candidate
=
marker
[
i
];
if
(
candidate
instanceof
Text
)
{
//check for newline characters and adjust indent
let
regex
=
/
\r\n
|
\r
|
\n
/g
;
let
match
:
RegExpMatchArray
;
while
(
match
=
regex
.
exec
(
candidate
.
string
))
{
let
value
=
candidate
.
string
;
while
(
match
=
regex
.
exec
(
value
))
{
let
pos
=
regex
.
lastIndex
;
let
whitespace
=
getLeadingWhitespace
(
candidate
.
string
,
pos
);
let
whitespace
=
getLeadingWhitespace
(
value
,
pos
);
let
normalized
=
normalizer
(
whitespace
);
if
(
whitespace
!==
normalized
)
{
candidate
.
string
=
candidate
.
string
.
substr
(
0
,
pos
)
value
=
value
.
substr
(
0
,
pos
)
+
normalized
+
candidate
.
string
.
substr
(
pos
+
whitespace
.
length
);
+
value
.
substr
(
pos
+
whitespace
.
length
);
marker
[
i
]
=
candidate
.
with
(
value
);
}
}
}
else
if
(
candidate
instanceof
Placeholder
||
candidate
instanceof
Variable
)
{
// recurse with a copied array
let
children
=
[...
candidate
.
defaultValue
];
TextmateSnippet
.
_adjustIndentation
(
children
,
normalizer
);
marker
[
i
]
=
candidate
.
with
(
children
);
}
return
true
;
});
}
}
}
...
...
src/vs/editor/contrib/snippet/test/common/snippetParser.test.ts
浏览文件 @
58da79c8
...
...
@@ -363,21 +363,24 @@ suite('SnippetParser', () => {
assert
.
equal
(
snippet
.
offset
(
array
[
0
]),
3
);
});
test
(
'
TextmateSnippet#
adjust
Indentation
'
,
()
=>
{
test
(
'
TextmateSnippet#
with
Indentation
'
,
()
=>
{
let
snippet
=
SnippetParser
.
parse
(
'
foo
\n
bar
'
);
assert
.
equal
(
Marker
.
toString
(
snippet
.
marker
),
'
foo
\n
bar
'
);
snippet
.
adjustIndentation
(
s
=>
s
.
replace
(
/ /
,
'
\t
'
));
assert
.
equal
(
Marker
.
toString
(
snippet
.
marker
),
'
foo
\n\t
bar
'
);
let
newSnippet
=
snippet
.
withIndentation
(
s
=>
s
.
replace
(
/ /
,
'
\t
'
));
assert
.
equal
(
Marker
.
toString
(
snippet
.
marker
),
'
foo
\n
bar
'
);
assert
.
equal
(
Marker
.
toString
(
newSnippet
.
marker
),
'
foo
\n\t
bar
'
);
snippet
=
SnippetParser
.
parse
(
'
foo
\r\n
bar
\r\n
far
'
);
assert
.
equal
(
Marker
.
toString
(
snippet
.
marker
),
'
foo
\r\n
bar
\r\n
far
'
);
snippet
.
adjustIndentation
(
s
=>
s
.
replace
(
/ /
,
'
\t
'
));
assert
.
equal
(
Marker
.
toString
(
snippet
.
marker
),
'
foo
\r\n\t
bar
\r\n\t
far
'
);
newSnippet
=
snippet
.
withIndentation
(
s
=>
s
.
replace
(
/ /
,
'
\t
'
));
assert
.
equal
(
Marker
.
toString
(
snippet
.
marker
),
'
foo
\r\n
bar
\r\n
far
'
);
assert
.
equal
(
Marker
.
toString
(
newSnippet
.
marker
),
'
foo
\r\n\t
bar
\r\n\t
far
'
);
snippet
=
SnippetParser
.
parse
(
'
foo${1:bar
\r
far
\r
boo}
'
);
assert
.
equal
(
Marker
.
toString
(
snippet
.
marker
),
'
foobar
\r
far
\r
boo
'
);
snippet
.
adjustIndentation
(
s
=>
s
.
replace
(
/ /
,
'
\t
'
));
assert
.
equal
(
Marker
.
toString
(
snippet
.
marker
),
'
foobar
\r\t
far
\r\t
boo
'
);
newSnippet
=
snippet
.
withIndentation
(
s
=>
s
.
replace
(
/ /
,
'
\t
'
));
assert
.
equal
(
Marker
.
toString
(
snippet
.
marker
),
'
foobar
\r
far
\r
boo
'
);
assert
.
equal
(
Marker
.
toString
(
newSnippet
.
marker
),
'
foobar
\r\t
far
\r\t
boo
'
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录