Skip to content

Commit

Permalink
Merge pull request #67060 from gangachris/fix/snippet_template_type_n…
Browse files Browse the repository at this point in the history
…aming

correct message for global and snippet templates
  • Loading branch information
jrieken authored Feb 7, 2019
2 parents f15a6fa + aa6bae2 commit 8d9b6ed
Showing 1 changed file with 14 additions and 8 deletions.
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

0 comments on commit 8d9b6ed

Please sign in to comment.