From ff188f2d306b7dcd73f9adb7e9c5e370eb6ee0c1 Mon Sep 17 00:00:00 2001 From: weartist Date: Wed, 14 Dec 2022 19:44:39 +0800 Subject: [PATCH 1/4] add the snippet source when the snippet with the same name appears --- .../browser/commands/configureSnippets.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts index baee9823a1f..424e4e20280 100644 --- a/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts +++ b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts @@ -38,6 +38,7 @@ async function computePicks(snippetService: ISnippetsService, userDataProfileSer const future: ISnippetPick[] = []; const seen = new Set(); + const added = new Set(); for (const file of await snippetService.getSnippetFiles()) { @@ -52,7 +53,13 @@ async function computePicks(snippetService: ISnippetsService, userDataProfileSer // list scopes for global snippets const names = new Set(); + let source: string | undefined; + outer: for (const snippet of file.data) { + if (snippet.source && !source) { + source = snippet.source; + } + for (const scope of snippet.scopes) { const name = languageService.getLanguageName(scope); if (name) { @@ -66,13 +73,19 @@ async function computePicks(snippetService: ISnippetsService, userDataProfileSer } } + let desc = names.size === 0 + ? nls.localize('global.scope', "(global)") + : nls.localize('global.1', "({0})", [...names].join(', ')); + if (added.has(basename(file.location)) && source) { + desc = source + ' ' + desc; + } + existing.push({ label: basename(file.location), filepath: file.location, - description: names.size === 0 - ? nls.localize('global.scope', "(global)") - : nls.localize('global.1', "({0})", [...names].join(', ')) + description: desc }); + added.add(basename(file.location)); } else { // language snippet From 8c7be66b782070e1a684a82d93ce2d96a0eb28dd Mon Sep 17 00:00:00 2001 From: weartist Date: Thu, 15 Dec 2022 11:30:59 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contrib/snippets/browser/commands/configureSnippets.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts index 424e4e20280..477a6507f4c 100644 --- a/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts +++ b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts @@ -56,7 +56,7 @@ async function computePicks(snippetService: ISnippetsService, userDataProfileSer let source: string | undefined; outer: for (const snippet of file.data) { - if (snippet.source && !source) { + if (!source) { source = snippet.source; } @@ -77,7 +77,7 @@ async function computePicks(snippetService: ISnippetsService, userDataProfileSer ? nls.localize('global.scope', "(global)") : nls.localize('global.1', "({0})", [...names].join(', ')); if (added.has(basename(file.location)) && source) { - desc = source + ' ' + desc; + desc = nls.localize('detail.label', "({0} {1})", source, desc); } existing.push({ From b937d6dd43e8f954acd10a3f79fa5dd0d3cf8d01 Mon Sep 17 00:00:00 2001 From: weartist Date: Thu, 15 Dec 2022 16:04:41 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../browser/commands/configureSnippets.ts | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts index 477a6507f4c..249d0241e6f 100644 --- a/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts +++ b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts @@ -38,7 +38,7 @@ async function computePicks(snippetService: ISnippetsService, userDataProfileSer const future: ISnippetPick[] = []; const seen = new Set(); - const added = new Set(); + const added = new Map(); for (const file of await snippetService.getSnippetFiles()) { @@ -73,19 +73,26 @@ async function computePicks(snippetService: ISnippetsService, userDataProfileSer } } - let desc = names.size === 0 - ? nls.localize('global.scope', "(global)") - : nls.localize('global.1', "({0})", [...names].join(', ')); - if (added.has(basename(file.location)) && source) { - desc = nls.localize('detail.label', "({0} {1})", source, desc); - } - - existing.push({ + const snippet: ISnippetPick = { label: basename(file.location), filepath: file.location, - description: desc - }); - added.add(basename(file.location)); + description: names.size === 0 + ? nls.localize('global.scope', "(global)") + : nls.localize('global.1', "({0})", [...names].join(', ')) + }; + existing.push(snippet); + + if (!source) { + continue; + } + + const detail = nls.localize('detail.label', "({0})", source); + const lastItem = added.get(basename(file.location)); + if (lastItem) { + snippet.detail = detail; + lastItem.snippet.detail = lastItem.detail; + } + added.set(basename(file.location), { snippet, detail }); } else { // language snippet From af088153c3e31c930867b536194567ba7d5c5117 Mon Sep 17 00:00:00 2001 From: Johannes Date: Mon, 19 Dec 2022 16:56:59 +0100 Subject: [PATCH 4/4] also show relative path of snippet --- .../snippets/browser/commands/configureSnippets.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts index 249d0241e6f..907a9206aab 100644 --- a/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts +++ b/src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts @@ -12,6 +12,7 @@ import * as nls from 'vs/nls'; import { MenuId } from 'vs/platform/actions/common/actions'; import { IFileService } from 'vs/platform/files/common/files'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; +import { ILabelService } from 'vs/platform/label/common/label'; import { IOpenerService } from 'vs/platform/opener/common/opener'; import { IQuickInputService, IQuickPickItem, QuickPickInput } from 'vs/platform/quickinput/common/quickInput'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; @@ -32,7 +33,7 @@ interface ISnippetPick extends IQuickPickItem { hint?: true; } -async function computePicks(snippetService: ISnippetsService, userDataProfileService: IUserDataProfileService, languageService: ILanguageService) { +async function computePicks(snippetService: ISnippetsService, userDataProfileService: IUserDataProfileService, languageService: ILanguageService, labelService: ILabelService) { const existing: ISnippetPick[] = []; const future: ISnippetPick[] = []; @@ -86,7 +87,7 @@ async function computePicks(snippetService: ISnippetsService, userDataProfileSer continue; } - const detail = nls.localize('detail.label', "({0})", source); + const detail = nls.localize('detail.label', "({0}) {1}", source, labelService.getUriLabel(file.location, { relative: true })); const lastItem = added.get(basename(file.location)); if (lastItem) { snippet.detail = detail; @@ -252,8 +253,9 @@ export class ConfigureSnippets extends SnippetsAction { const workspaceService = accessor.get(IWorkspaceContextService); const fileService = accessor.get(IFileService); const textFileService = accessor.get(ITextFileService); + const labelService = accessor.get(ILabelService); - const picks = await computePicks(snippetService, userDataProfileService, languageService); + const picks = await computePicks(snippetService, userDataProfileService, languageService, labelService); const existing: QuickPickInput[] = picks.existing; type SnippetPick = IQuickPickItem & { uri: URI } & { scope: string };