Skip to content

Commit

Permalink
fix #41207
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jan 9, 2018
1 parent 779152c commit b10ef64
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ export class SnippetFile {

constructor(
readonly filepath: string,
private readonly _defaultScope: string,
readonly defaultScopes: string[],
private readonly _extension: IExtensionDescription
) {
this.isGlobalSnippets = extname(filepath) === '.code-snippets';
this.isUserSnippets = !this._extension;
}

select(selector: string, bucket: Snippet[]): void {
if (this.isGlobalSnippets) {
if (this.isGlobalSnippets || !this.isUserSnippets) {
this._scopeSelect(selector, bucket);
} else {
this._filepathSelect(selector, bucket);
Expand Down Expand Up @@ -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 {
Expand Down
44 changes: 25 additions & 19 deletions src/vs/workbench/parts/snippets/electron-browser/snippetsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
});
});
}

}
}
}
Expand All @@ -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));
Expand Down

0 comments on commit b10ef64

Please sign in to comment.