Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
24d0f5f8
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,发现更多精彩内容 >>
提交
24d0f5f8
编写于
7月 25, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
prep for #31124
上级
122cc332
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
27 deletion
+48
-27
src/vs/editor/contrib/snippet/browser/snippetParser.ts
src/vs/editor/contrib/snippet/browser/snippetParser.ts
+20
-3
src/vs/editor/contrib/snippet/browser/snippetVariables.ts
src/vs/editor/contrib/snippet/browser/snippetVariables.ts
+6
-2
src/vs/editor/contrib/snippet/test/browser/snippetVariables.test.ts
...tor/contrib/snippet/test/browser/snippetVariables.test.ts
+22
-22
未找到文件。
src/vs/editor/contrib/snippet/browser/snippetParser.ts
浏览文件 @
24d0f5f8
...
...
@@ -167,6 +167,19 @@ export abstract class Marker {
return
this
.
_children
;
}
get
snippet
():
TextmateSnippet
{
let
candidate
:
Marker
=
this
;
while
(
true
)
{
if
(
!
candidate
)
{
return
undefined
;
}
if
(
candidate
instanceof
TextmateSnippet
)
{
return
candidate
;
}
candidate
=
candidate
.
parent
;
}
}
toString
()
{
return
''
;
}
...
...
@@ -269,8 +282,8 @@ export class Variable extends Marker {
super
();
}
resolve
(
resolver
:
{
resolve
(
name
:
string
):
string
}
):
boolean
{
const
value
=
resolver
.
resolve
(
this
.
name
);
resolve
(
resolver
:
VariableResolver
):
boolean
{
const
value
=
resolver
.
resolve
(
this
);
if
(
value
!==
undefined
)
{
this
.
_children
=
[
new
Text
(
value
)];
return
true
;
...
...
@@ -289,6 +302,10 @@ export class Variable extends Marker {
}
}
export
interface
VariableResolver
{
resolve
(
variable
:
Variable
):
string
|
undefined
;
}
function
walk
(
marker
:
Marker
[],
visitor
:
(
marker
:
Marker
)
=>
boolean
):
void
{
const
stack
=
[...
marker
];
while
(
stack
.
length
>
0
)
{
...
...
@@ -362,7 +379,7 @@ export class TextmateSnippet extends Marker {
return
Marker
.
toString
(
this
.
children
);
}
resolveVariables
(
resolver
:
{
resolve
(
name
:
string
):
string
}
):
this
{
resolveVariables
(
resolver
:
VariableResolver
):
this
{
this
.
walk
(
candidate
=>
{
if
(
candidate
instanceof
Variable
)
{
if
(
candidate
.
resolve
(
resolver
))
{
...
...
src/vs/editor/contrib/snippet/browser/snippetVariables.ts
浏览文件 @
24d0f5f8
...
...
@@ -8,8 +8,9 @@
import
{
basename
,
dirname
}
from
'
vs/base/common/paths
'
;
import
{
IModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
VariableResolver
,
Variable
}
from
'
vs/editor/contrib/snippet/browser/snippetParser
'
;
export
class
EditorSnippetVariableResolver
{
export
class
EditorSnippetVariableResolver
implements
VariableResolver
{
static
readonly
VariableNames
=
Object
.
freeze
({
'
SELECTION
'
:
true
,
...
...
@@ -30,7 +31,10 @@ export class EditorSnippetVariableResolver {
//
}
resolve
(
name
:
string
):
string
{
resolve
(
variable
:
Variable
):
string
{
const
{
name
}
=
variable
;
if
(
name
===
'
SELECTION
'
||
name
===
'
TM_SELECTED_TEXT
'
)
{
return
this
.
_model
.
getValueInRange
(
this
.
_selection
)
||
undefined
;
...
...
src/vs/editor/contrib/snippet/test/browser/snippetVariables.test.ts
浏览文件 @
24d0f5f8
...
...
@@ -9,7 +9,7 @@ import { isWindows } from 'vs/base/common/platform';
import
URI
from
'
vs/base/common/uri
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
EditorSnippetVariableResolver
}
from
'
vs/editor/contrib/snippet/browser/snippetVariables
'
;
import
{
SnippetParser
}
from
'
vs/editor/contrib/snippet/browser/snippetParser
'
;
import
{
SnippetParser
,
Variable
}
from
'
vs/editor/contrib/snippet/browser/snippetParser
'
;
import
{
Model
}
from
'
vs/editor/common/model/model
'
;
suite
(
'
Snippet Variables Resolver
'
,
function
()
{
...
...
@@ -32,58 +32,58 @@ suite('Snippet Variables Resolver', function () {
});
test
(
'
editor variables, basics
'
,
function
()
{
assert
.
equal
(
resolver
.
resolve
(
'
TM_FILENAME
'
),
'
text.txt
'
);
assert
.
equal
(
resolver
.
resolve
(
'
something
'
),
undefined
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_FILENAME
'
)
),
'
text.txt
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
something
'
)
),
undefined
);
});
test
(
'
editor variables, file/dir
'
,
function
()
{
assert
.
equal
(
resolver
.
resolve
(
'
TM_FILENAME
'
),
'
text.txt
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_FILENAME
'
)
),
'
text.txt
'
);
if
(
!
isWindows
)
{
assert
.
equal
(
resolver
.
resolve
(
'
TM_DIRECTORY
'
),
'
/foo/files
'
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_FILEPATH
'
),
'
/foo/files/text.txt
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_DIRECTORY
'
)
),
'
/foo/files
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_FILEPATH
'
)
),
'
/foo/files/text.txt
'
);
}
resolver
=
new
EditorSnippetVariableResolver
(
Model
.
createFromString
(
''
,
undefined
,
undefined
,
URI
.
parse
(
'
http://www.pb.o/abc/def/ghi
'
)),
new
Selection
(
1
,
1
,
1
,
1
)
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_FILENAME
'
),
'
ghi
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_FILENAME
'
)
),
'
ghi
'
);
if
(
!
isWindows
)
{
assert
.
equal
(
resolver
.
resolve
(
'
TM_DIRECTORY
'
),
'
/abc/def
'
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_FILEPATH
'
),
'
/abc/def/ghi
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_DIRECTORY
'
)
),
'
/abc/def
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_FILEPATH
'
)
),
'
/abc/def/ghi
'
);
}
resolver
=
new
EditorSnippetVariableResolver
(
Model
.
createFromString
(
''
,
undefined
,
undefined
,
URI
.
parse
(
'
mem:fff.ts
'
)),
new
Selection
(
1
,
1
,
1
,
1
)
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_DIRECTORY
'
),
''
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_FILEPATH
'
),
'
fff.ts
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_DIRECTORY
'
)
),
''
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_FILEPATH
'
)
),
'
fff.ts
'
);
});
test
(
'
editor variables, selection
'
,
function
()
{
resolver
=
new
EditorSnippetVariableResolver
(
model
,
new
Selection
(
1
,
2
,
2
,
3
));
assert
.
equal
(
resolver
.
resolve
(
'
TM_SELECTED_TEXT
'
),
'
his is line one
\n
th
'
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_CURRENT_LINE
'
),
'
this is line two
'
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_LINE_INDEX
'
),
'
1
'
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_LINE_NUMBER
'
),
'
2
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_SELECTED_TEXT
'
)
),
'
his is line one
\n
th
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_CURRENT_LINE
'
)
),
'
this is line two
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_LINE_INDEX
'
)
),
'
1
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_LINE_NUMBER
'
)
),
'
2
'
);
resolver
=
new
EditorSnippetVariableResolver
(
model
,
new
Selection
(
2
,
3
,
1
,
2
));
assert
.
equal
(
resolver
.
resolve
(
'
TM_SELECTED_TEXT
'
),
'
his is line one
\n
th
'
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_CURRENT_LINE
'
),
'
this is line one
'
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_LINE_INDEX
'
),
'
0
'
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_LINE_NUMBER
'
),
'
1
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_SELECTED_TEXT
'
)
),
'
his is line one
\n
th
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_CURRENT_LINE
'
)
),
'
this is line one
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_LINE_INDEX
'
)
),
'
0
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_LINE_NUMBER
'
)
),
'
1
'
);
resolver
=
new
EditorSnippetVariableResolver
(
model
,
new
Selection
(
1
,
2
,
1
,
2
));
assert
.
equal
(
resolver
.
resolve
(
'
TM_SELECTED_TEXT
'
),
undefined
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_SELECTED_TEXT
'
)
),
undefined
);
assert
.
equal
(
resolver
.
resolve
(
'
TM_CURRENT_WORD
'
),
'
this
'
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_CURRENT_WORD
'
)
),
'
this
'
);
resolver
=
new
EditorSnippetVariableResolver
(
model
,
new
Selection
(
3
,
1
,
3
,
1
));
assert
.
equal
(
resolver
.
resolve
(
'
TM_CURRENT_WORD
'
),
undefined
);
assert
.
equal
(
resolver
.
resolve
(
new
Variable
(
'
TM_CURRENT_WORD
'
)
),
undefined
);
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录