From b10ef64bc9beb0d959f8e879c8dd706a6e3d4e77 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Tue, 9 Jan 2018 09:41:50 -0800 Subject: [PATCH] fix #41207 --- .../snippets/electron-browser/snippetsFile.ts | 8 ++-- .../electron-browser/snippetsService.ts | 44 +++++++++++-------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/vs/workbench/parts/snippets/electron-browser/snippetsFile.ts b/src/vs/workbench/parts/snippets/electron-browser/snippetsFile.ts index 3ae6bdea3a6..88dee69e79a 100644 --- a/src/vs/workbench/parts/snippets/electron-browser/snippetsFile.ts +++ b/src/vs/workbench/parts/snippets/electron-browser/snippetsFile.ts @@ -141,7 +141,7 @@ export class SnippetFile { constructor( readonly filepath: string, - private readonly _defaultScope: string, + readonly defaultScopes: string[], private readonly _extension: IExtensionDescription ) { this.isGlobalSnippets = extname(filepath) === '.code-snippets'; @@ -149,7 +149,7 @@ export class SnippetFile { } select(selector: string, bucket: Snippet[]): void { - if (this.isGlobalSnippets) { + if (this.isGlobalSnippets || !this.isUserSnippets) { this._scopeSelect(selector, bucket); } else { this._filepathSelect(selector, bucket); @@ -229,8 +229,8 @@ export class SnippetFile { } let scopes: string[]; - if (this._defaultScope) { - scopes = [this._defaultScope]; + if (this.defaultScopes) { + scopes = this.defaultScopes; } else if (typeof snippet.scope === 'string') { scopes = snippet.scope.split(',').filter(s => !isFalsyOrWhitespace(s)); } else { diff --git a/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts b/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts index b4ec60a65ad..d86d0eccb2c 100644 --- a/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts +++ b/src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts @@ -163,27 +163,33 @@ class SnippetsService implements ISnippetsService { continue; } - const file = new SnippetFile(contribution.path, contribution.language, extension.description); - this._files.set(file.filepath, file); + if (this._files.has(contribution.path)) { + this._files.get(contribution.path).defaultScopes.push(contribution.language); - if (this._environmentService.isExtensionDevelopment) { - file.load().then(file => { - // warn about bad tabstop/variable usage - if (file.data.some(snippet => snippet.isBogous)) { + } else { + const file = new SnippetFile(contribution.path, [contribution.language], extension.description); + this._files.set(file.filepath, file); + + if (this._environmentService.isExtensionDevelopment) { + file.load().then(file => { + // warn about bad tabstop/variable usage + if (file.data.some(snippet => snippet.isBogous)) { + extension.collector.warn(localize( + 'badVariableUse', + "One or more snippets from the extension '{0}' very likely confuse snippet-variables and snippet-placeholders (see https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-syntax for more details)", + extension.description.name + )); + } + }, err => { + // generic error extension.collector.warn(localize( - 'badVariableUse', - "One or more snippets from the extension '{0}' very likely confuse snippet-variables and snippet-placeholders (see https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-syntax for more details)", - extension.description.name + 'badFile', + "The snippet file \"{0}\" could not be read.", + file.filepath )); - } - }, err => { - // generic error - extension.collector.warn(localize( - 'badFile', - "The snippet file \"{0}\" could not be read.", - file.filepath - )); - }); + }); + } + } } } @@ -195,7 +201,7 @@ class SnippetsService implements ISnippetsService { const ext = extname(filepath); if (ext === '.json') { const langName = basename(filepath, '.json'); - this._files.set(filepath, new SnippetFile(filepath, langName, undefined)); + this._files.set(filepath, new SnippetFile(filepath, [langName], undefined)); } else if (ext === '.code-snippets') { this._files.set(filepath, new SnippetFile(filepath, undefined, undefined));