未验证 提交 8e89438a 编写于 作者: J Johannes Rieken 提交者: GitHub

Merge pull request #59092 from noamyogev84/feature_42838

Allow snippet json prefix to be an array to support multiple prefixes for the same snippet
...@@ -41,7 +41,7 @@ const languageScopeSchema: IJSONSchema = { ...@@ -41,7 +41,7 @@ const languageScopeSchema: IJSONSchema = {
properties: { properties: {
prefix: { prefix: {
description: nls.localize('snippetSchema.json.prefix', 'The prefix to used when selecting the snippet in intellisense'), description: nls.localize('snippetSchema.json.prefix', 'The prefix to used when selecting the snippet in intellisense'),
type: 'string' type: ['string', 'array']
}, },
body: { body: {
description: nls.localize('snippetSchema.json.body', 'The snippet content. Use \'$1\', \'${1:defaultText}\' to define cursor positions, use \'$0\' for the final cursor position. Insert variable values with \'${varName}\' and \'${varName:defaultText}\', e.g \'This is file: $TM_FILENAME\'.'), description: nls.localize('snippetSchema.json.body', 'The snippet content. Use \'$1\', \'${1:defaultText}\' to define cursor positions, use \'$0\' for the final cursor position. Insert variable values with \'${varName}\' and \'${varName:defaultText}\', e.g \'This is file: $TM_FILENAME\'.'),
...@@ -76,7 +76,7 @@ const globalSchema: IJSONSchema = { ...@@ -76,7 +76,7 @@ const globalSchema: IJSONSchema = {
properties: { properties: {
prefix: { prefix: {
description: nls.localize('snippetSchema.json.prefix', 'The prefix to used when selecting the snippet in intellisense'), description: nls.localize('snippetSchema.json.prefix', 'The prefix to used when selecting the snippet in intellisense'),
type: 'string' type: ['string', 'array']
}, },
scope: { scope: {
description: nls.localize('snippetSchema.json.scope', "A list of language names to which this snippet applies, e.g 'typescript,javascript'."), description: nls.localize('snippetSchema.json.scope', "A list of language names to which this snippet applies, e.g 'typescript,javascript'."),
......
...@@ -234,7 +234,7 @@ export class SnippetFile { ...@@ -234,7 +234,7 @@ export class SnippetFile {
body = body.join('\n'); body = body.join('\n');
} }
if (typeof prefix !== 'string' || typeof body !== 'string') { if ((typeof prefix !== 'string' && !Array.isArray(prefix)) || typeof body !== 'string') {
return; return;
} }
...@@ -264,14 +264,17 @@ export class SnippetFile { ...@@ -264,14 +264,17 @@ export class SnippetFile {
} }
} }
bucket.push(new Snippet( let prefixes = Array.isArray(prefix) ? prefix : [prefix];
scopes, prefixes.forEach(p => {
name, bucket.push(new Snippet(
prefix, scopes,
description, name,
body, p,
source, description,
this.source body,
)); source,
this.source
));
});
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册