mirror of
https://github.com/microsoft/vscode.git
synced 2026-03-02 14:58:43 +00:00
add schema for code-snippets-files, #13182
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user