mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
fix #41207
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user