Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct message for global and snippet templates #67060

Merged
merged 2 commits into from
Feb 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function computePicks(snippetService: ISnippetsService, envService: IEnvir
return { existing, future };
}

async function createGlobalSnippetFile(defaultPath: URI, windowService: IWindowService, notificationService: INotificationService, fileService: IFileService, opener: IOpenerService) {
async function createSnippetFile(scope: string, defaultPath: URI, windowService: IWindowService, notificationService: INotificationService, fileService: IFileService, opener: IOpenerService) {

await fileService.createFolder(defaultPath);
await timeout(100); // ensure quick pick closes...
Expand All @@ -140,7 +140,7 @@ async function createGlobalSnippetFile(defaultPath: URI, windowService: IWindowS

await fileService.updateContent(resource, [
'{',
'\t// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and ',
'\t// Place your ' + scope + ' 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// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is ',
'\t// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: ',
Expand Down Expand Up @@ -202,13 +202,17 @@ CommandsRegistry.registerCommand(id, async (accessor): Promise<any> => {
const picks = await computePicks(snippetService, envService, modeService);
const existing: QuickPickInput[] = picks.existing;

type GlobalSnippetPick = IQuickPickItem & { uri: URI };
const globalSnippetPicks: GlobalSnippetPick[] = [{
type SnippetPick = IQuickPickItem & { uri: URI } & { scope: string };
const globalSnippetPicks: SnippetPick[] = [{
scope: nls.localize('new.global_scope', 'global'),
label: nls.localize('new.global', "New Global Snippets file..."),
uri: URI.file(join(envService.appSettingsHome, 'snippets'))
}];

const workspaceSnippetPicks: SnippetPick[] = [];
for (const folder of workspaceService.getWorkspace().folders) {
globalSnippetPicks.push({
workspaceSnippetPicks.push({
scope: nls.localize('new.workspace_scope', "{0} workspace", folder.name),
label: nls.localize('new.folder', "New Snippets file for '{0}'...", folder.name),
uri: folder.toResource('.vscode')
});
Expand All @@ -221,13 +225,15 @@ CommandsRegistry.registerCommand(id, async (accessor): Promise<any> => {
existing.push({ type: 'separator', label: nls.localize('new.global.sep', "New Snippets") });
}

const pick = await quickInputService.pick(([] as QuickPickInput[]).concat(existing, globalSnippetPicks, picks.future), {
const pick = await quickInputService.pick(([] as QuickPickInput[]).concat(existing, globalSnippetPicks, workspaceSnippetPicks, picks.future), {
placeHolder: nls.localize('openSnippet.pickLanguage', "Select Snippets File or Create Snippets"),
matchOnDescription: true
});

if (globalSnippetPicks.indexOf(pick as GlobalSnippetPick) >= 0) {
return createGlobalSnippetFile((pick as GlobalSnippetPick).uri, windowService, notificationService, fileService, opener);
if (globalSnippetPicks.indexOf(pick as SnippetPick) >= 0) {
return createSnippetFile((pick as SnippetPick).scope, (pick as SnippetPick).uri, windowService, notificationService, fileService, opener);
} else if (workspaceSnippetPicks.indexOf(pick as SnippetPick) >= 0) {
return createSnippetFile((pick as SnippetPick).scope, (pick as SnippetPick).uri, windowService, notificationService, fileService, opener);
} else if (ISnippetPick.is(pick)) {
if (pick.hint) {
await createLanguageSnippetFile(pick, fileService);
Expand Down