Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
da9d758e
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,发现更多精彩内容 >>
提交
da9d758e
编写于
5月 17, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #65145
上级
b1aad4b7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
19 deletion
+31
-19
src/vs/workbench/contrib/snippets/browser/configureSnippets.ts
...s/workbench/contrib/snippets/browser/configureSnippets.ts
+31
-19
未找到文件。
src/vs/workbench/contrib/snippets/browser/configureSnippets.ts
浏览文件 @
da9d758e
...
...
@@ -7,10 +7,8 @@ import * as nls from 'vs/nls';
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IWindowService
}
from
'
vs/platform/windows/common/windows
'
;
import
{
join
,
basename
,
dirname
,
extname
}
from
'
vs/base/common/path
'
;
import
{
join
,
basename
,
extname
}
from
'
vs/base/common/path
'
;
import
{
MenuRegistry
,
MenuId
}
from
'
vs/platform/actions/common/actions
'
;
import
{
timeout
}
from
'
vs/base/common/async
'
;
import
{
IOpenerService
}
from
'
vs/platform/opener/common/opener
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
ISnippetsService
}
from
'
vs/workbench/contrib/snippets/browser/snippets.contribution
'
;
...
...
@@ -19,8 +17,9 @@ import { IQuickPickItem, IQuickInputService, QuickPickInput } from 'vs/platform/
import
{
SnippetSource
}
from
'
vs/workbench/contrib/snippets/browser/snippetsFile
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
INotificationService
}
from
'
vs/platform/notification/common/notification
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
isValidBasename
}
from
'
vs/base/common/extpath
'
;
import
{
joinPath
}
from
'
vs/base/common/resources
'
;
const
id
=
'
workbench.action.openSnippets
'
;
...
...
@@ -121,24 +120,39 @@ async function computePicks(snippetService: ISnippetsService, envService: IEnvir
return
{
existing
,
future
};
}
async
function
createSnippetFile
(
scope
:
string
,
defaultPath
:
URI
,
windowService
:
IWindowService
,
notificationService
:
INotificationService
,
fileService
:
IFileService
,
textFileService
:
ITextFileService
,
opener
:
IOpenerService
)
{
async
function
createSnippetFile
(
scope
:
string
,
defaultPath
:
URI
,
quickInputService
:
IQuickInputService
,
fileService
:
IFileService
,
textFileService
:
ITextFileService
,
opener
:
IOpenerService
)
{
function
createSnippetUri
(
input
:
string
)
{
const
filename
=
extname
(
input
)
!==
'
.code-snippets
'
?
`
${
input
}
.code-snippets`
:
input
;
return
joinPath
(
defaultPath
,
filename
);
}
await
fileService
.
createFolder
(
defaultPath
);
await
timeout
(
100
);
// ensure quick pick closes...
const
path
=
await
windowService
.
showSaveDialog
({
defaultPath
:
defaultPath
.
fsPath
,
filters
:
[{
name
:
'
Code Snippets
'
,
extensions
:
[
'
code-snippets
'
]
}]
const
input
=
await
quickInputService
.
input
({
placeHolder
:
nls
.
localize
(
'
name
'
,
"
Type snippet file name
"
),
async
validateInput
(
input
)
{
if
(
!
input
)
{
return
nls
.
localize
(
'
bad_name1
'
,
"
Invalid file name
"
);
}
if
(
!
isValidBasename
(
input
))
{
return
nls
.
localize
(
'
bad_name2
'
,
"
'{0}' is not a valid file name
"
,
input
);
}
if
(
await
fileService
.
exists
(
createSnippetUri
(
input
)))
{
return
nls
.
localize
(
'
bad_name3
'
,
"
'{0}' already exists
"
,
input
);
}
return
undefined
;
}
});
if
(
!
path
)
{
return
undefined
;
}
const
resource
=
URI
.
file
(
path
);
if
(
dirname
(
resource
.
fsPath
)
!==
defaultPath
.
fsPath
)
{
notificationService
.
error
(
nls
.
localize
(
'
badPath
'
,
"
Snippets must be inside this folder: '{0}'.
"
,
defaultPath
.
fsPath
));
if
(
!
input
)
{
return
undefined
;
}
const
resource
=
createSnippetUri
(
input
);
await
textFileService
.
write
(
resource
,
[
'
{
'
,
'
\t
// Place your
'
+
scope
+
'
snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
'
,
...
...
@@ -193,10 +207,8 @@ CommandsRegistry.registerCommand(id, async (accessor): Promise<any> => {
const
snippetService
=
accessor
.
get
(
ISnippetsService
);
const
quickInputService
=
accessor
.
get
(
IQuickInputService
);
const
opener
=
accessor
.
get
(
IOpenerService
);
const
windowService
=
accessor
.
get
(
IWindowService
);
const
modeService
=
accessor
.
get
(
IModeService
);
const
envService
=
accessor
.
get
(
IEnvironmentService
);
const
notificationService
=
accessor
.
get
(
INotificationService
);
const
workspaceService
=
accessor
.
get
(
IWorkspaceContextService
);
const
fileService
=
accessor
.
get
(
IFileService
);
const
textFileService
=
accessor
.
get
(
ITextFileService
);
...
...
@@ -233,9 +245,9 @@ CommandsRegistry.registerCommand(id, async (accessor): Promise<any> => {
});
if
(
globalSnippetPicks
.
indexOf
(
pick
as
SnippetPick
)
>=
0
)
{
return
createSnippetFile
((
pick
as
SnippetPick
).
scope
,
(
pick
as
SnippetPick
).
uri
,
windowService
,
notification
Service
,
fileService
,
textFileService
,
opener
);
return
createSnippetFile
((
pick
as
SnippetPick
).
scope
,
(
pick
as
SnippetPick
).
uri
,
quickInput
Service
,
fileService
,
textFileService
,
opener
);
}
else
if
(
workspaceSnippetPicks
.
indexOf
(
pick
as
SnippetPick
)
>=
0
)
{
return
createSnippetFile
((
pick
as
SnippetPick
).
scope
,
(
pick
as
SnippetPick
).
uri
,
windowService
,
notification
Service
,
fileService
,
textFileService
,
opener
);
return
createSnippetFile
((
pick
as
SnippetPick
).
scope
,
(
pick
as
SnippetPick
).
uri
,
quickInput
Service
,
fileService
,
textFileService
,
opener
);
}
else
if
(
ISnippetPick
.
is
(
pick
))
{
if
(
pick
.
hint
)
{
await
createLanguageSnippetFile
(
pick
,
fileService
,
textFileService
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录