add schema for code-snippets-files, #13182

This commit is contained in:
Johannes Rieken 2018-01-04 14:16:21 +01:00
parent 2cf2c09bfe
commit ea5b7eaa56
3 changed files with 77 additions and 32 deletions

View file

@ -68,6 +68,10 @@
"fileMatch": "%APP_SETTINGS_HOME%/snippets/*.json",
"url": "vscode://schemas/snippets"
},
{
"fileMatch": "%APP_SETTINGS_HOME%/snippets/*.code-snippets",
"url": "vscode://schemas/global-snippets"
},
{
"fileMatch": "/.vscode/extensions.json",
"url": "vscode://schemas/extensions"
@ -77,4 +81,4 @@
"devDependencies": {
"@types/node": "7.0.4"
}
}
}

View file

@ -7,7 +7,8 @@
"vscode": "0.10.x"
},
"activationEvents": [
"onLanguage:json", "onLanguage:jsonc"
"onLanguage:json",
"onLanguage:jsonc"
],
"enableProposedApi": true,
"main": "./client/out/jsonMain",
@ -53,7 +54,8 @@
".code-workspace",
"language-configuration.json",
"icon-theme.json",
"color-theme.json"
"color-theme.json",
".code-snippets"
],
"filenames": [
"settings.json",
@ -167,4 +169,4 @@
"devDependencies": {
"@types/node": "7.0.43"
}
}
}

View file

@ -208,40 +208,79 @@ export class Snippet {
}
const schemaId = 'vscode://schemas/snippets';
const schema: IJSONSchema = {
'id': schemaId,
'allowComments': true,
'defaultSnippets': [{
'label': nls.localize('snippetSchema.json.default', "Empty snippet"),
'body': { '${1:snippetName}': { 'prefix': '${2:prefix}', 'body': '${3:snippet}', 'description': '${4:description}' } }
const languageScopeSchemaId = 'vscode://schemas/snippets';
const languageScopeSchema: IJSONSchema = {
id: languageScopeSchemaId,
allowComments: true,
defaultSnippets: [{
label: nls.localize('snippetSchema.json.default', "Empty snippet"),
body: { '${1:snippetName}': { 'prefix': '${2:prefix}', 'body': '${3:snippet}', 'description': '${4:description}' } }
}],
'type': 'object',
'description': nls.localize('snippetSchema.json', 'User snippet configuration'),
'additionalProperties': {
'type': 'object',
'required': ['prefix', 'body'],
'properties': {
'prefix': {
'description': nls.localize('snippetSchema.json.prefix', 'The prefix to used when selecting the snippet in intellisense'),
'type': 'string'
type: 'object',
description: nls.localize('snippetSchema.json', 'User snippet configuration'),
additionalProperties: {
type: 'object',
required: ['prefix', 'body'],
properties: {
prefix: {
description: nls.localize('snippetSchema.json.prefix', 'The prefix to used when selecting the snippet in intellisense'),
type: 'string'
},
'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\'.'),
'type': ['string', 'array'],
'items': {
'type': 'string'
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\'.'),
type: ['string', 'array'],
items: {
type: 'string'
}
},
'description': {
'description': nls.localize('snippetSchema.json.description', 'The snippet description.'),
'type': 'string'
description: {
description: nls.localize('snippetSchema.json.description', 'The snippet description.'),
type: 'string'
}
},
'additionalProperties': false
additionalProperties: false
}
};
Registry
.as<JSONContributionRegistry.IJSONContributionRegistry>(JSONContributionRegistry.Extensions.JSONContribution)
.registerSchema(schemaId, schema);
const globalSchemaId = 'vscode://schemas/global-snippets';
const globalSchema: IJSONSchema = {
id: globalSchemaId,
allowComments: true,
defaultSnippets: [{
label: nls.localize('snippetSchema.json.default', "Empty snippet"),
body: { '${1:snippetName}': { 'scope': '${2:scope}', 'prefix': '${3:prefix}', 'body': '${4:snippet}', 'description': '${5:description}' } }
}],
type: 'object',
description: nls.localize('snippetSchema.json', 'User snippet configuration'),
additionalProperties: {
type: 'object',
required: ['prefix', 'body'],
properties: {
prefix: {
description: nls.localize('snippetSchema.json.prefix', 'The prefix to used when selecting the snippet in intellisense'),
type: 'string'
},
scope: {
description: nls.localize('snippetSchema.json.scope', "A list of language names to which this snippet applies, e.g 'typescript,javascript'."),
type: 'string'
},
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\'.'),
type: ['string', 'array'],
items: {
type: 'string'
}
},
description: {
description: nls.localize('snippetSchema.json.description', 'The snippet description.'),
type: 'string'
}
},
additionalProperties: false
}
};
const reg = Registry.as<JSONContributionRegistry.IJSONContributionRegistry>(JSONContributionRegistry.Extensions.JSONContribution);
reg.registerSchema(languageScopeSchemaId, languageScopeSchema);
reg.registerSchema(globalSchemaId, globalSchema);