From ea5b7eaa564cd08016c9b2e06d0e8b4a4e02e7c6 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 4 Jan 2018 14:16:21 +0100 Subject: [PATCH] add schema for code-snippets-files, #13182 --- extensions/configuration-editing/package.json | 6 +- extensions/json/package.json | 8 +- .../electron-browser/snippets.contribution.ts | 95 +++++++++++++------ 3 files changed, 77 insertions(+), 32 deletions(-) diff --git a/extensions/configuration-editing/package.json b/extensions/configuration-editing/package.json index 17394b271f5..78cdda924b9 100644 --- a/extensions/configuration-editing/package.json +++ b/extensions/configuration-editing/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/extensions/json/package.json b/extensions/json/package.json index afffbf02d82..31f13d8017b 100644 --- a/extensions/json/package.json +++ b/extensions/json/package.json @@ -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" } -} \ No newline at end of file +} diff --git a/src/vs/workbench/parts/snippets/electron-browser/snippets.contribution.ts b/src/vs/workbench/parts/snippets/electron-browser/snippets.contribution.ts index e296217693a..7a8a76cba0d 100644 --- a/src/vs/workbench/parts/snippets/electron-browser/snippets.contribution.ts +++ b/src/vs/workbench/parts/snippets/electron-browser/snippets.contribution.ts @@ -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.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.Extensions.JSONContribution); +reg.registerSchema(languageScopeSchemaId, languageScopeSchema); +reg.registerSchema(globalSchemaId, globalSchema);