Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
895bdd44
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,发现更多精彩内容 >>
提交
895bdd44
编写于
1月 03, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add Snippet#scopes and SnippetFile#select, #13182
上级
d95d5e1f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
112 addition
and
5 deletion
+112
-5
src/vs/workbench/parts/snippets/electron-browser/insertSnippet.ts
...orkbench/parts/snippets/electron-browser/insertSnippet.ts
+1
-0
src/vs/workbench/parts/snippets/electron-browser/snippets.contribution.ts
.../parts/snippets/electron-browser/snippets.contribution.ts
+1
-0
src/vs/workbench/parts/snippets/electron-browser/snippetsFile.ts
...workbench/parts/snippets/electron-browser/snippetsFile.ts
+40
-4
src/vs/workbench/parts/snippets/test/electron-browser/snippetFile.test.ts
.../parts/snippets/test/electron-browser/snippetFile.test.ts
+63
-0
src/vs/workbench/parts/snippets/test/electron-browser/snippetsRewrite.test.ts
...ts/snippets/test/electron-browser/snippetsRewrite.test.ts
+1
-1
src/vs/workbench/parts/snippets/test/electron-browser/snippetsService.test.ts
...ts/snippets/test/electron-browser/snippetsService.test.ts
+6
-0
未找到文件。
src/vs/workbench/parts/snippets/electron-browser/insertSnippet.ts
浏览文件 @
895bdd44
...
...
@@ -81,6 +81,7 @@ class InsertSnippetAction extends EditorAction {
undefined
,
undefined
,
undefined
,
undefined
,
snippet
,
undefined
));
...
...
src/vs/workbench/parts/snippets/electron-browser/snippets.contribution.ts
浏览文件 @
895bdd44
...
...
@@ -40,6 +40,7 @@ export class Snippet {
private
_isBogous
:
boolean
;
constructor
(
readonly
scopes
:
string
[],
readonly
name
:
string
,
readonly
prefix
:
string
,
readonly
description
:
string
,
...
...
src/vs/workbench/parts/snippets/electron-browser/snippetsFile.ts
浏览文件 @
895bdd44
...
...
@@ -9,9 +9,13 @@ import { readFile } from 'vs/base/node/pfs';
import
{
parse
as
jsonParse
}
from
'
vs/base/common/json
'
;
import
{
forEach
}
from
'
vs/base/common/collections
'
;
import
{
Snippet
}
from
'
vs/workbench/parts/snippets/electron-browser/snippets.contribution
'
;
import
{
endsWith
}
from
'
vs/base/common/strings
'
;
import
{
basename
}
from
'
path
'
;
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
interface
JsonSerializedSnippet
{
body
:
string
;
scope
:
string
;
prefix
:
string
|
string
[];
description
:
string
;
}
...
...
@@ -26,13 +30,35 @@ interface JsonSerializedSnippets {
export
class
SnippetFile
{
private
constructor
(
constructor
(
readonly
filepath
:
string
,
readonly
data
:
Snippet
[]
)
{
//
}
select
(
selector
:
string
,
bucket
:
Snippet
[]):
void
{
for
(
const
snippet
of
this
.
data
)
{
if
(
isFalsyOrEmpty
(
snippet
.
scopes
))
{
// always accept
bucket
.
push
(
snippet
);
}
else
{
// match
for
(
const
scope
of
snippet
.
scopes
)
{
if
(
scope
===
selector
)
{
bucket
.
push
(
snippet
);
break
;
// match only once!
}
}
}
}
let
idx
=
selector
.
lastIndexOf
(
'
.
'
);
if
(
idx
>=
0
)
{
this
.
select
(
selector
.
substring
(
0
,
idx
),
bucket
);
}
}
static
fromFile
(
filepath
:
string
,
source
:
string
,
isFromExtension
?:
boolean
):
Promise
<
SnippetFile
>
{
return
Promise
.
resolve
(
readFile
(
filepath
)).
then
(
value
=>
{
const
data
=
<
JsonSerializedSnippets
>
jsonParse
(
value
.
toString
());
...
...
@@ -41,11 +67,11 @@ export class SnippetFile {
forEach
(
data
,
entry
=>
{
const
{
key
:
name
,
value
:
scopeOrTemplate
}
=
entry
;
if
(
isJsonSerilziedSnippet
(
scopeOrTemplate
))
{
SnippetFile
.
_parseSnippet
(
name
,
scopeOrTemplate
,
source
,
isFromExtension
,
snippets
);
SnippetFile
.
_parseSnippet
(
filepath
,
name
,
scopeOrTemplate
,
source
,
isFromExtension
,
snippets
);
}
else
{
forEach
(
scopeOrTemplate
,
entry
=>
{
const
{
key
:
name
,
value
:
template
}
=
entry
;
SnippetFile
.
_parseSnippet
(
name
,
template
,
source
,
isFromExtension
,
snippets
);
SnippetFile
.
_parseSnippet
(
filepath
,
name
,
template
,
source
,
isFromExtension
,
snippets
);
});
}
});
...
...
@@ -54,7 +80,7 @@ export class SnippetFile {
});
}
private
static
_parseSnippet
(
name
:
string
,
snippet
:
JsonSerializedSnippet
,
source
:
string
,
isFromExtension
:
boolean
,
bucket
:
Snippet
[]):
void
{
private
static
_parseSnippet
(
filepath
:
string
,
name
:
string
,
snippet
:
JsonSerializedSnippet
,
source
:
string
,
isFromExtension
:
boolean
,
bucket
:
Snippet
[]):
void
{
let
{
prefix
,
body
,
description
}
=
snippet
;
...
...
@@ -66,7 +92,17 @@ export class SnippetFile {
return
;
}
let
scopes
:
string
[];
if
(
endsWith
(
filepath
,
'
.json
'
))
{
scopes
=
[
basename
(
filepath
,
'
.json
'
)];
}
else
if
(
typeof
snippet
.
scope
===
'
string
'
)
{
scopes
=
snippet
.
scope
.
split
(
'
,
'
);
}
else
{
scopes
=
[];
}
bucket
.
push
(
new
Snippet
(
scopes
,
name
,
prefix
,
description
,
...
...
src/vs/workbench/parts/snippets/test/electron-browser/snippetFile.test.ts
0 → 100644
浏览文件 @
895bdd44
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
Snippet
}
from
'
vs/workbench/parts/snippets/electron-browser/snippets.contribution
'
;
import
{
SnippetFile
}
from
'
vs/workbench/parts/snippets/electron-browser/snippetsFile
'
;
suite
(
'
Snippets
'
,
function
()
{
test
(
'
SnippetFile#select
'
,
function
()
{
let
file
=
new
SnippetFile
(
'
somepath/foo.json
'
,
[]);
let
bucket
:
Snippet
[]
=
[];
file
.
select
(
''
,
bucket
);
assert
.
equal
(
bucket
.
length
,
0
);
file
=
new
SnippetFile
(
'
somepath/foo.json
'
,
[
new
Snippet
([
'
foo
'
],
'
FooSnippet1
'
,
'
foo
'
,
''
,
'
snippet
'
,
'
test
'
),
new
Snippet
([
'
foo
'
],
'
FooSnippet2
'
,
'
foo
'
,
''
,
'
snippet
'
,
'
test
'
),
new
Snippet
([
'
bar
'
],
'
BarSnippet1
'
,
'
foo
'
,
''
,
'
snippet
'
,
'
test
'
),
new
Snippet
([
'
bar.comment
'
],
'
BarSnippet2
'
,
'
foo
'
,
''
,
'
snippet
'
,
'
test
'
),
new
Snippet
([
'
bar.strings
'
],
'
BarSnippet2
'
,
'
foo
'
,
''
,
'
snippet
'
,
'
test
'
),
new
Snippet
([
'
bazz
'
,
'
bazz
'
],
'
BazzSnippet1
'
,
'
foo
'
,
''
,
'
snippet
'
,
'
test
'
),
]);
bucket
=
[];
file
.
select
(
'
foo
'
,
bucket
);
assert
.
equal
(
bucket
.
length
,
2
);
bucket
=
[];
file
.
select
(
'
fo
'
,
bucket
);
assert
.
equal
(
bucket
.
length
,
0
);
bucket
=
[];
file
.
select
(
'
bar
'
,
bucket
);
assert
.
equal
(
bucket
.
length
,
1
);
bucket
=
[];
file
.
select
(
'
bar.comment
'
,
bucket
);
assert
.
equal
(
bucket
.
length
,
2
);
bucket
=
[];
file
.
select
(
'
bazz
'
,
bucket
);
assert
.
equal
(
bucket
.
length
,
1
);
});
test
(
'
SnippetFile#select - any scope
'
,
function
()
{
let
file
=
new
SnippetFile
(
'
somepath/foo.json
'
,
[
new
Snippet
([],
'
AnySnippet1
'
,
'
foo
'
,
''
,
'
snippet
'
,
'
test
'
),
new
Snippet
([
'
foo
'
],
'
FooSnippet1
'
,
'
foo
'
,
''
,
'
snippet
'
,
'
test
'
),
]);
let
bucket
:
Snippet
[]
=
[];
file
.
select
(
'
foo
'
,
bucket
);
assert
.
equal
(
bucket
.
length
,
2
);
});
});
src/vs/workbench/parts/snippets/test/electron-browser/snippetsRewrite.test.ts
浏览文件 @
895bdd44
...
...
@@ -45,7 +45,7 @@ suite('SnippetRewrite', function () {
});
test
(
'
lazy bogous variable rewrite
'
,
function
()
{
const
snippet
=
new
Snippet
(
'
foo
'
,
'
prefix
'
,
'
desc
'
,
'
This is ${bogous} because it is a ${var}
'
,
'
source
'
);
const
snippet
=
new
Snippet
(
[
'
fooLang
'
],
'
foo
'
,
'
prefix
'
,
'
desc
'
,
'
This is ${bogous} because it is a ${var}
'
,
'
source
'
);
assert
.
equal
(
snippet
.
body
,
'
This is ${bogous} because it is a ${var}
'
);
assert
.
equal
(
snippet
.
codeSnippet
,
'
This is ${1:bogous} because it is a ${2:var}
'
);
assert
.
equal
(
snippet
.
isBogous
,
true
);
...
...
src/vs/workbench/parts/snippets/test/electron-browser/snippetsService.test.ts
浏览文件 @
895bdd44
...
...
@@ -40,12 +40,14 @@ suite('SnippetsService', function () {
setup
(
function
()
{
modeService
=
new
ModeServiceImpl
();
snippetService
=
new
SimpleSnippetService
([
new
Snippet
(
[
'
fooLang
'
],
'
barTest
'
,
'
bar
'
,
''
,
'
barCodeSnippet
'
,
''
),
new
Snippet
(
[
'
fooLang
'
],
'
bazzTest
'
,
'
bazz
'
,
''
,
...
...
@@ -81,6 +83,7 @@ suite('SnippetsService', function () {
test
(
'
Cannot use "<?php" as user snippet prefix anymore, #26275
'
,
function
()
{
snippetService
=
new
SimpleSnippetService
([
new
Snippet
(
[
'
fooLang
'
],
''
,
'
<?php
'
,
''
,
...
...
@@ -113,6 +116,7 @@ suite('SnippetsService', function () {
test
(
'
No user snippets in suggestions, when inside the code, #30508
'
,
function
()
{
snippetService
=
new
SimpleSnippetService
([
new
Snippet
(
[
'
fooLang
'
],
''
,
'
foo
'
,
''
,
...
...
@@ -133,6 +137,7 @@ suite('SnippetsService', function () {
test
(
'
SnippetSuggest - ensure extension snippets come last
'
,
function
()
{
snippetService
=
new
SimpleSnippetService
([
new
Snippet
(
[
'
fooLang
'
],
'
second
'
,
'
second
'
,
''
,
...
...
@@ -140,6 +145,7 @@ suite('SnippetsService', function () {
''
,
true
),
new
Snippet
(
[
'
fooLang
'
],
'
first
'
,
'
first
'
,
''
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录