Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
cef3b30d
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,发现更多精彩内容 >>
未验证
提交
cef3b30d
编写于
1月 17, 2018
作者:
J
Johannes Rieken
提交者:
GitHub
1月 17, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #41653 from usernamehw/time_variables_for_snippets
Add time variables for snippets
上级
5cfe3b3f
d6d307ed
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
4 deletion
+58
-4
src/vs/editor/contrib/snippet/snippetSession.ts
src/vs/editor/contrib/snippet/snippetSession.ts
+3
-2
src/vs/editor/contrib/snippet/snippetVariables.ts
src/vs/editor/contrib/snippet/snippetVariables.ts
+33
-1
src/vs/editor/contrib/snippet/test/snippetVariables.test.ts
src/vs/editor/contrib/snippet/test/snippetVariables.test.ts
+22
-1
未找到文件。
src/vs/editor/contrib/snippet/snippetSession.ts
浏览文件 @
cef3b30d
...
...
@@ -15,7 +15,7 @@ import { Range } from 'vs/editor/common/core/range';
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
groupBy
}
from
'
vs/base/common/arrays
'
;
import
{
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
SelectionBasedVariableResolver
,
CompositeSnippetVariableResolver
,
ModelBasedVariableResolver
,
ClipboardBasedVariableResolver
}
from
'
./snippetVariables
'
;
import
{
SelectionBasedVariableResolver
,
CompositeSnippetVariableResolver
,
ModelBasedVariableResolver
,
ClipboardBasedVariableResolver
,
TimeBasedVariableResolver
}
from
'
./snippetVariables
'
;
import
{
ModelDecorationOptions
}
from
'
vs/editor/common/model/textModel
'
;
import
{
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
IClipboardService
}
from
'
vs/platform/clipboard/common/clipboardService
'
;
...
...
@@ -318,7 +318,8 @@ export class SnippetSession {
.
resolveVariables
(
new
CompositeSnippetVariableResolver
([
modelBasedVariableResolver
,
new
ClipboardBasedVariableResolver
(
clipboardService
,
idx
,
indexedSelections
.
length
),
new
SelectionBasedVariableResolver
(
model
,
selection
)
new
SelectionBasedVariableResolver
(
model
,
selection
),
new
TimeBasedVariableResolver
]));
const
offset
=
model
.
getOffsetAt
(
start
)
+
delta
;
...
...
src/vs/editor/contrib/snippet/snippetVariables.ts
浏览文件 @
cef3b30d
...
...
@@ -9,10 +9,17 @@ import { basename, dirname } from 'vs/base/common/paths';
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
VariableResolver
,
Variable
,
Text
}
from
'
vs/editor/contrib/snippet/snippetParser
'
;
import
{
getLeadingWhitespace
,
commonPrefixLength
,
isFalsyOrWhitespace
}
from
'
vs/base/common/strings
'
;
import
{
getLeadingWhitespace
,
commonPrefixLength
,
isFalsyOrWhitespace
,
pad
}
from
'
vs/base/common/strings
'
;
import
{
IClipboardService
}
from
'
vs/platform/clipboard/common/clipboardService
'
;
export
const
KnownSnippetVariableNames
=
Object
.
freeze
({
'
CURRENT_YEAR
'
:
true
,
'
CURRENT_YEAR_SHORT
'
:
true
,
'
CURRENT_MONTH
'
:
true
,
'
CURRENT_DATE
'
:
true
,
'
CURRENT_HOUR
'
:
true
,
'
CURRENT_MINUTE
'
:
true
,
'
CURRENT_SECOND
'
:
true
,
'
SELECTION
'
:
true
,
'
CLIPBOARD
'
:
true
,
'
TM_SELECTED_TEXT
'
:
true
,
...
...
@@ -170,3 +177,28 @@ export class ClipboardBasedVariableResolver implements VariableResolver {
}
}
}
export
class
TimeBasedVariableResolver
implements
VariableResolver
{
resolve
(
variable
:
Variable
):
string
{
const
{
name
}
=
variable
;
if
(
name
===
'
CURRENT_YEAR
'
)
{
return
String
(
new
Date
().
getFullYear
());
}
else
if
(
name
===
'
CURRENT_YEAR_SHORT
'
)
{
return
String
(
new
Date
().
getFullYear
()).
slice
(
-
2
);
}
else
if
(
name
===
'
CURRENT_MONTH
'
)
{
return
pad
((
new
Date
().
getMonth
().
valueOf
()
+
1
),
2
);
}
else
if
(
name
===
'
CURRENT_DATE
'
)
{
return
pad
(
new
Date
().
getDate
().
valueOf
(),
2
);
}
else
if
(
name
===
'
CURRENT_HOUR
'
)
{
return
pad
(
new
Date
().
getHours
().
valueOf
(),
2
);
}
else
if
(
name
===
'
CURRENT_MINUTE
'
)
{
return
pad
(
new
Date
().
getMinutes
().
valueOf
(),
2
);
}
else
if
(
name
===
'
CURRENT_SECOND
'
)
{
return
pad
(
new
Date
().
getSeconds
().
valueOf
(),
2
);
}
return
undefined
;
}
}
src/vs/editor/contrib/snippet/test/snippetVariables.test.ts
浏览文件 @
cef3b30d
...
...
@@ -8,7 +8,7 @@ import * as assert from 'assert';
import
{
isWindows
}
from
'
vs/base/common/platform
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
SelectionBasedVariableResolver
,
CompositeSnippetVariableResolver
,
ModelBasedVariableResolver
,
ClipboardBasedVariableResolver
}
from
'
vs/editor/contrib/snippet/snippetVariables
'
;
import
{
SelectionBasedVariableResolver
,
CompositeSnippetVariableResolver
,
ModelBasedVariableResolver
,
ClipboardBasedVariableResolver
,
TimeBasedVariableResolver
}
from
'
vs/editor/contrib/snippet/snippetVariables
'
;
import
{
SnippetParser
,
Variable
,
VariableResolver
}
from
'
vs/editor/contrib/snippet/snippetParser
'
;
import
{
TextModel
}
from
'
vs/editor/common/model/textModel
'
;
import
{
IClipboardService
}
from
'
vs/platform/clipboard/common/clipboardService
'
;
...
...
@@ -261,4 +261,25 @@ suite('Snippet Variables Resolver', function () {
resolver
=
new
ClipboardBasedVariableResolver
(
clipboardService
,
0
,
2
);
assertVariableResolve
(
resolver
,
'
CLIPBOARD
'
,
'
line1
'
);
});
function
assertVariableResolve3
(
resolver
:
VariableResolver
,
varName
:
string
)
{
const
snippet
=
new
SnippetParser
().
parse
(
`$
${
varName
}
`
);
const
variable
=
<
Variable
>
snippet
.
children
[
0
];
assert
.
equal
(
variable
.
resolve
(
resolver
),
true
,
`
${
varName
}
failed to resolve`
);
}
test
(
'
Add time variables for snippets #41631
'
,
function
()
{
const
resolver
=
new
TimeBasedVariableResolver
;
assertVariableResolve3
(
resolver
,
'
CURRENT_YEAR
'
);
assertVariableResolve3
(
resolver
,
'
CURRENT_YEAR_SHORT
'
);
assertVariableResolve3
(
resolver
,
'
CURRENT_MONTH
'
);
assertVariableResolve3
(
resolver
,
'
CURRENT_DATE
'
);
assertVariableResolve3
(
resolver
,
'
CURRENT_HOUR
'
);
assertVariableResolve3
(
resolver
,
'
CURRENT_MINUTE
'
);
assertVariableResolve3
(
resolver
,
'
CURRENT_SECOND
'
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录