Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1459e9a4
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,发现更多精彩内容 >>
提交
1459e9a4
编写于
9月 21, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
configure snippets offers to create workspace snippets, #8102
上级
94e11433
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
32 addition
and
16 deletion
+32
-16
src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts
...ench/parts/snippets/electron-browser/configureSnippets.ts
+32
-16
未找到文件。
src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts
浏览文件 @
1459e9a4
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
import
*
as
nls
from
'
vs/nls
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
writeFile
,
exists
}
from
'
vs/base/node/pfs
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IWindowService
}
from
'
vs/platform/windows/common/windows
'
;
import
{
IWindowService
}
from
'
vs/platform/windows/common/windows
'
;
...
@@ -18,6 +17,9 @@ import { URI } from 'vs/base/common/uri';
...
@@ -18,6 +17,9 @@ import { URI } from 'vs/base/common/uri';
import
{
ISnippetsService
}
from
'
vs/workbench/parts/snippets/electron-browser/snippets.contribution
'
;
import
{
ISnippetsService
}
from
'
vs/workbench/parts/snippets/electron-browser/snippets.contribution
'
;
import
{
values
}
from
'
vs/base/common/map
'
;
import
{
values
}
from
'
vs/base/common/map
'
;
import
{
IQuickPickItem
,
IQuickInputService
,
QuickPickInput
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
IQuickPickItem
,
IQuickInputService
,
QuickPickInput
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
SnippetSource
}
from
'
vs/workbench/parts/snippets/electron-browser/snippetsFile
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
const
id
=
'
workbench.action.openSnippets
'
;
const
id
=
'
workbench.action.openSnippets
'
;
...
@@ -41,7 +43,7 @@ async function computePicks(snippetService: ISnippetsService, envService: IEnvir
...
@@ -41,7 +43,7 @@ async function computePicks(snippetService: ISnippetsService, envService: IEnvir
for
(
const
file
of
await
snippetService
.
getSnippetFiles
())
{
for
(
const
file
of
await
snippetService
.
getSnippetFiles
())
{
if
(
!
file
.
isUserSnippets
)
{
if
(
file
.
source
===
SnippetSource
.
Extension
)
{
// skip extension snippets
// skip extension snippets
continue
;
continue
;
}
}
...
@@ -116,19 +118,20 @@ async function computePicks(snippetService: ISnippetsService, envService: IEnvir
...
@@ -116,19 +118,20 @@ async function computePicks(snippetService: ISnippetsService, envService: IEnvir
return
{
existing
,
future
};
return
{
existing
,
future
};
}
}
async
function
createGlobalSnippetFile
(
envService
:
IEnvironmentService
,
windowService
:
IWindow
Service
,
opener
:
IOpenerService
)
{
async
function
createGlobalSnippetFile
(
defaultPath
:
URI
,
windowService
:
IWindowService
,
fileService
:
IFile
Service
,
opener
:
IOpenerService
)
{
await
fileService
.
createFolder
(
defaultPath
);
await
timeout
(
100
);
// ensure quick pick closes...
await
timeout
(
100
);
// ensure quick pick closes...
const
defaultPath
=
join
(
envService
.
appSettingsHome
,
'
snippets
'
);
const
path
=
await
windowService
.
showSaveDialog
({
const
path
=
await
windowService
.
showSaveDialog
({
defaultPath
,
defaultPath
:
defaultPath
.
fsPath
,
filters
:
[{
name
:
'
Code Snippets
'
,
extensions
:
[
'
code-snippets
'
]
}]
filters
:
[{
name
:
'
Code Snippets
'
,
extensions
:
[
'
code-snippets
'
]
}]
});
});
if
(
!
path
||
dirname
(
path
)
!==
defaultPath
)
{
if
(
!
path
||
dirname
(
path
)
!==
defaultPath
.
fsPath
)
{
return
undefined
;
return
undefined
;
}
}
await
writeFile
(
path
,
[
await
fileService
.
updateContent
(
URI
.
file
(
path
),
[
'
{
'
,
'
{
'
,
'
\t
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
'
,
'
\t
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
'
,
'
\t
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
'
,
'
\t
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
'
,
...
@@ -152,8 +155,8 @@ async function createGlobalSnippetFile(envService: IEnvironmentService, windowSe
...
@@ -152,8 +155,8 @@ async function createGlobalSnippetFile(envService: IEnvironmentService, windowSe
await
opener
.
open
(
URI
.
file
(
path
));
await
opener
.
open
(
URI
.
file
(
path
));
}
}
async
function
createLanguageSnippetFile
(
pick
:
ISnippetPick
)
{
async
function
createLanguageSnippetFile
(
pick
:
ISnippetPick
,
fileService
:
IFileService
)
{
if
(
await
exists
(
pick
.
filepath
))
{
if
(
await
fileService
.
existsFile
(
URI
.
file
(
pick
.
filepath
)
))
{
return
;
return
;
}
}
const
contents
=
[
const
contents
=
[
...
@@ -173,7 +176,7 @@ async function createLanguageSnippetFile(pick: ISnippetPick) {
...
@@ -173,7 +176,7 @@ async function createLanguageSnippetFile(pick: ISnippetPick) {
'
\t
// }
'
,
'
\t
// }
'
,
'
}
'
'
}
'
].
join
(
'
\n
'
);
].
join
(
'
\n
'
);
await
writeFile
(
pick
.
filepath
,
contents
);
await
fileService
.
updateContent
(
URI
.
file
(
pick
.
filepath
)
,
contents
);
}
}
CommandsRegistry
.
registerCommand
(
id
,
async
accessor
=>
{
CommandsRegistry
.
registerCommand
(
id
,
async
accessor
=>
{
...
@@ -184,10 +187,24 @@ CommandsRegistry.registerCommand(id, async accessor => {
...
@@ -184,10 +187,24 @@ CommandsRegistry.registerCommand(id, async accessor => {
const
windowService
=
accessor
.
get
(
IWindowService
);
const
windowService
=
accessor
.
get
(
IWindowService
);
const
modeService
=
accessor
.
get
(
IModeService
);
const
modeService
=
accessor
.
get
(
IModeService
);
const
envService
=
accessor
.
get
(
IEnvironmentService
);
const
envService
=
accessor
.
get
(
IEnvironmentService
);
const
workspaceService
=
accessor
.
get
(
IWorkspaceContextService
);
const
fileService
=
accessor
.
get
(
IFileService
);
const
picks
=
await
computePicks
(
snippetService
,
envService
,
modeService
);
const
picks
=
await
computePicks
(
snippetService
,
envService
,
modeService
);
const
existing
:
QuickPickInput
[]
=
picks
.
existing
;
const
existing
:
QuickPickInput
[]
=
picks
.
existing
;
const
newGlobalPick
=
<
IQuickPickItem
>
{
label
:
nls
.
localize
(
'
new.global
'
,
"
New Global Snippets file...
"
)
};
type
GlobalSnippetPick
=
IQuickPickItem
&
{
uri
:
URI
};
const
globalSnippetPicks
:
GlobalSnippetPick
[]
=
[{
label
:
nls
.
localize
(
'
new.global
'
,
"
New Global Snippets file...
"
),
uri
:
URI
.
file
(
join
(
envService
.
appSettingsHome
,
'
snippets
'
))
}];
for
(
const
folder
of
workspaceService
.
getWorkspace
().
folders
)
{
globalSnippetPicks
.
push
({
label
:
nls
.
localize
(
'
new.folder
'
,
"
New Snippets file for '{0}'...
"
,
folder
.
name
),
uri
:
folder
.
toResource
(
'
.vscode
'
)
});
}
if
(
existing
.
length
>
0
)
{
if
(
existing
.
length
>
0
)
{
existing
.
unshift
({
type
:
'
separator
'
,
label
:
nls
.
localize
(
'
group.global
'
,
"
Existing Snippets
"
)
});
existing
.
unshift
({
type
:
'
separator
'
,
label
:
nls
.
localize
(
'
group.global
'
,
"
Existing Snippets
"
)
});
existing
.
push
({
type
:
'
separator
'
,
label
:
nls
.
localize
(
'
new.global.sep
'
,
"
New Snippets
"
)
});
existing
.
push
({
type
:
'
separator
'
,
label
:
nls
.
localize
(
'
new.global.sep
'
,
"
New Snippets
"
)
});
...
@@ -195,17 +212,16 @@ CommandsRegistry.registerCommand(id, async accessor => {
...
@@ -195,17 +212,16 @@ CommandsRegistry.registerCommand(id, async accessor => {
existing
.
push
({
type
:
'
separator
'
,
label
:
nls
.
localize
(
'
new.global.sep
'
,
"
New Snippets
"
)
});
existing
.
push
({
type
:
'
separator
'
,
label
:
nls
.
localize
(
'
new.global.sep
'
,
"
New Snippets
"
)
});
}
}
const
pick
=
await
quickInputService
.
pick
(
<
(
IQuickPickItem
|
ISnippetPick
)[]
>
[].
concat
(
existing
,
newGlobalPick
,
picks
.
future
),
{
const
pick
=
await
quickInputService
.
pick
(
<
(
IQuickPickItem
|
ISnippetPick
|
GlobalSnippetPick
)[]
>
[].
concat
(
existing
,
globalSnippetPicks
,
picks
.
future
),
{
placeHolder
:
nls
.
localize
(
'
openSnippet.pickLanguage
'
,
"
Select Snippets File or Create Snippets
"
),
placeHolder
:
nls
.
localize
(
'
openSnippet.pickLanguage
'
,
"
Select Snippets File or Create Snippets
"
),
matchOnDescription
:
true
matchOnDescription
:
true
});
});
if
(
pick
===
newGlobalPick
)
{
if
(
globalSnippetPicks
.
indexOf
(
pick
as
GlobalSnippetPick
)
>=
0
)
{
return
createGlobalSnippetFile
(
envService
,
windowService
,
opener
);
return
createGlobalSnippetFile
((
pick
as
GlobalSnippetPick
).
uri
,
windowService
,
fileService
,
opener
);
}
else
if
(
ISnippetPick
.
is
(
pick
))
{
}
else
if
(
ISnippetPick
.
is
(
pick
))
{
if
(
pick
.
hint
)
{
if
(
pick
.
hint
)
{
await
createLanguageSnippetFile
(
pick
);
await
createLanguageSnippetFile
(
pick
,
fileService
);
}
}
return
opener
.
open
(
URI
.
file
(
pick
.
filepath
));
return
opener
.
open
(
URI
.
file
(
pick
.
filepath
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录