Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
27647f07
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,发现更多精彩内容 >>
提交
27647f07
编写于
5月 05, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip
上级
17ea7e51
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
93 addition
and
32 deletion
+93
-32
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
+38
-0
src/vs/editor/contrib/snippet/common/snippetParser.ts
src/vs/editor/contrib/snippet/common/snippetParser.ts
+5
-9
src/vs/editor/contrib/snippet/test/browser/editorSnippets.test.ts
...ditor/contrib/snippet/test/browser/editorSnippets.test.ts
+41
-0
src/vs/editor/contrib/snippet/test/common/snippetParser.test.ts
.../editor/contrib/snippet/test/common/snippetParser.test.ts
+9
-23
未找到文件。
src/vs/editor/contrib/snippet/browser/editorSnippets.ts
0 → 100644
浏览文件 @
27647f07
/*---------------------------------------------------------------------------------------------
* 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
{
getLeadingWhitespace
}
from
'
vs/base/common/strings
'
;
import
{
ICommonCodeEditor
,
IModel
}
from
'
vs/editor/common/editorCommon
'
;
import
{
TextmateSnippet
}
from
'
../common/snippetParser
'
;
export
class
SnippetSession
{
private
readonly
_editor
:
ICommonCodeEditor
;
private
readonly
_model
:
IModel
;
private
readonly
_snippets
:
TextmateSnippet
[]
=
[];
constructor
(
editor
:
ICommonCodeEditor
,
snippet
:
TextmateSnippet
)
{
this
.
_editor
=
editor
;
this
.
_model
=
editor
.
getModel
();
for
(
const
selection
of
editor
.
getSelections
())
{
// for each selection get the leading 'reference' whitespace and
// adjust the snippet accordingly. this makes one snippet per selection/cursor
const
line
=
this
.
_model
.
getLineContent
(
selection
.
startLineNumber
);
const
leadingWhitespace
=
getLeadingWhitespace
(
line
,
0
,
selection
.
startColumn
-
1
);
const
newSnippet
=
snippet
.
withIndentation
(
whitespace
=>
this
.
_model
.
normalizeIndentation
(
leadingWhitespace
+
whitespace
));
this
.
_snippets
.
push
(
newSnippet
);
// const offset = this._model.getOffsetAt(selection.getStartPosition());
// for (const placeholder of snippet.getPlaceholders()) {
// const pos = this._model.getPositionAt(offset + snippet.offset(placeholder));
// this._model.deltaDecorations
// }
}
}
}
src/vs/editor/contrib/snippet/common/snippetParser.ts
浏览文件 @
27647f07
...
...
@@ -231,20 +231,16 @@ export class TextmateSnippet {
return
pos
;
}
placeholders
():
Map
<
string
,
Placeholder
[]
>
{
const
map
=
new
Map
<
string
,
Placeholder
[]
>
();
getPlaceholders
():
Placeholder
[]
{
const
ret
:
Placeholder
[]
=
[];
walk
(
this
.
marker
,
candidate
=>
{
if
(
candidate
instanceof
Placeholder
)
{
let
array
=
map
.
get
(
candidate
.
name
);
if
(
!
array
)
{
map
.
set
(
candidate
.
name
,
[
candidate
]);
}
else
{
array
.
push
(
candidate
);
}
ret
.
push
(
candidate
);
}
return
true
;
});
return
map
;
return
ret
;
}
get
value
()
{
...
...
src/vs/editor/contrib/snippet/test/browser/editorSnippets.test.ts
0 → 100644
浏览文件 @
27647f07
/*---------------------------------------------------------------------------------------------
* 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
{
Selection
}
from
'
vs/editor/common/core/selection
'
;
import
{
SnippetSession
}
from
'
vs/editor/contrib/snippet/browser/editorSnippets
'
;
import
{
SnippetParser
}
from
'
vs/editor/contrib/snippet/common/snippetParser
'
;
import
{
ICommonCodeEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
mockCodeEditor
}
from
'
vs/editor/test/common/mocks/mockCodeEditor
'
;
suite
(
'
Editor Contrib - Snippets
'
,
()
=>
{
let
editor
:
ICommonCodeEditor
;
setup
(()
=>
{
editor
=
mockCodeEditor
([
'
function foo() {
'
,
'
\t
console.log(a)
'
,
'
}
'
],
{});
});
teardown
(()
=>
{
editor
.
dispose
();
});
test
(
'
snippets
'
,
()
=>
{
editor
.
setSelections
([
new
Selection
(
1
,
1
,
1
,
1
),
new
Selection
(
2
,
2
,
2
,
2
),
]);
new
SnippetSession
(
editor
,
SnippetParser
.
parse
(
'
foo
\n
${1:bar}
\n
foo
'
));
assert
.
ok
(
true
);
});
});
src/vs/editor/contrib/snippet/test/common/snippetParser.test.ts
浏览文件 @
27647f07
...
...
@@ -332,35 +332,21 @@ suite('SnippetParser', () => {
test
(
'
TextmateSnippet#placeholder
'
,
()
=>
{
let
snippet
=
SnippetParser
.
parse
(
'
te$1xt
'
);
let
placeholders
=
snippet
.
placeholders
();
assert
.
equal
(
placeholders
.
size
,
1
);
let
array
=
placeholders
.
get
(
'
1
'
);
assert
.
equal
(
array
.
length
,
1
);
let
placeholders
=
snippet
.
getPlaceholders
();
assert
.
equal
(
placeholders
.
length
,
1
);
snippet
=
SnippetParser
.
parse
(
'
te$1xt$1
'
);
placeholders
=
snippet
.
placeholders
();
assert
.
equal
(
placeholders
.
size
,
1
);
array
=
placeholders
.
get
(
'
1
'
);
assert
.
equal
(
array
.
length
,
2
);
placeholders
=
snippet
.
getPlaceholders
();
assert
.
equal
(
placeholders
.
length
,
2
);
snippet
=
SnippetParser
.
parse
(
'
te$1xt$2
'
);
placeholders
=
snippet
.
placeholders
();
assert
.
equal
(
placeholders
.
size
,
2
);
array
=
placeholders
.
get
(
'
1
'
);
assert
.
equal
(
array
.
length
,
1
);
array
=
placeholders
.
get
(
'
2
'
);
assert
.
equal
(
array
.
length
,
1
);
placeholders
=
snippet
.
getPlaceholders
();
assert
.
equal
(
placeholders
.
length
,
2
);
snippet
=
SnippetParser
.
parse
(
'
${1:bar${2:foo}bar}
'
);
placeholders
=
snippet
.
placeholders
();
assert
.
equal
(
placeholders
.
size
,
2
);
array
=
placeholders
.
get
(
'
1
'
);
assert
.
equal
(
array
.
length
,
1
);
assert
.
equal
(
snippet
.
offset
(
array
[
0
]),
0
);
array
=
placeholders
.
get
(
'
2
'
);
assert
.
equal
(
array
.
length
,
1
);
assert
.
equal
(
snippet
.
offset
(
array
[
0
]),
3
);
placeholders
=
snippet
.
getPlaceholders
();
assert
.
equal
(
placeholders
.
length
,
2
);
});
test
(
'
TextmateSnippet#withIndentation
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录