From 29d575b76ce092b5e913bcc496ba9ad082a09420 Mon Sep 17 00:00:00 2001 From: gangachris Date: Thu, 24 Jan 2019 13:44:51 +0100 Subject: [PATCH 1/2] correct message for global and snippet templates --- .../electron-browser/configureSnippets.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts b/src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts index a545024ae54f3..57964993e2dd9 100644 --- a/src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts +++ b/src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts @@ -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... @@ -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: ', @@ -207,8 +207,12 @@ CommandsRegistry.registerCommand(id, async (accessor): Promise => { label: nls.localize('new.global', "New Global Snippets file..."), uri: URI.file(join(envService.appSettingsHome, 'snippets')) }]; + + type WorkspaceSnippetPick = IQuickPickItem & { uri: URI } & { name: string }; + const workspaceSnippetPicks: WorkspaceSnippetPick[] = []; for (const folder of workspaceService.getWorkspace().folders) { - globalSnippetPicks.push({ + workspaceSnippetPicks.push({ + name: folder.name, label: nls.localize('new.folder', "New Snippets file for '{0}'...", folder.name), uri: folder.toResource('.vscode') }); @@ -221,13 +225,15 @@ CommandsRegistry.registerCommand(id, async (accessor): Promise => { 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); + return createSnippetFile('global', (pick as GlobalSnippetPick).uri, windowService, notificationService, fileService, opener); + } else if (workspaceSnippetPicks.indexOf(pick as WorkspaceSnippetPick) >= 0) { + return createSnippetFile((pick as WorkspaceSnippetPick).name + ' workspace', (pick as WorkspaceSnippetPick).uri, windowService, notificationService, fileService, opener); } else if (ISnippetPick.is(pick)) { if (pick.hint) { await createLanguageSnippetFile(pick, fileService); From aa6bae2a1a9dcb24b2791f335ea5fb9149782c5a Mon Sep 17 00:00:00 2001 From: gangachris Date: Wed, 6 Feb 2019 16:03:33 +0100 Subject: [PATCH 2/2] localize snippet scope names --- .../electron-browser/configureSnippets.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts b/src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts index 57964993e2dd9..9875977f27d06 100644 --- a/src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts +++ b/src/vs/workbench/parts/snippets/electron-browser/configureSnippets.ts @@ -202,17 +202,17 @@ CommandsRegistry.registerCommand(id, async (accessor): Promise => { 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')) }]; - type WorkspaceSnippetPick = IQuickPickItem & { uri: URI } & { name: string }; - const workspaceSnippetPicks: WorkspaceSnippetPick[] = []; + const workspaceSnippetPicks: SnippetPick[] = []; for (const folder of workspaceService.getWorkspace().folders) { workspaceSnippetPicks.push({ - name: folder.name, + 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') }); @@ -230,10 +230,10 @@ CommandsRegistry.registerCommand(id, async (accessor): Promise => { matchOnDescription: true }); - if (globalSnippetPicks.indexOf(pick as GlobalSnippetPick) >= 0) { - return createSnippetFile('global', (pick as GlobalSnippetPick).uri, windowService, notificationService, fileService, opener); - } else if (workspaceSnippetPicks.indexOf(pick as WorkspaceSnippetPick) >= 0) { - return createSnippetFile((pick as WorkspaceSnippetPick).name + ' workspace', (pick as WorkspaceSnippetPick).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);