Skip to content

Commit

Permalink
Add snippets as a language (#185017)
Browse files Browse the repository at this point in the history
* Add snippets as a language

* Snippets -> Code Snippets

* Add tests

* json.snippets -> json.comments.snippets
  • Loading branch information
alexr00 authored Jul 28, 2023
1 parent 34442b8 commit 5f9fc78
Show file tree
Hide file tree
Showing 7 changed files with 11,002 additions and 11 deletions.
7 changes: 1 addition & 6 deletions extensions/configuration-editing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
".code-workspace",
"language-configuration.json",
"icon-theme.json",
"color-theme.json",
".code-snippets"
"color-theme.json"
],
"filenames": [
"settings.json",
Expand All @@ -54,10 +53,6 @@
"profiles.json",
"devcontainer.json",
".devcontainer.json"
],
"filenamePatterns": [
"**/User/snippets/*.json",
"**/User/profiles/*/snippets/*.json"
]
}, {
"id": "json",
Expand Down
10 changes: 6 additions & 4 deletions extensions/json/build/update-grammars.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

var updateGrammar = require('vscode-grammar-updater');

function adaptJSON(grammar, name, replacementScope) {
function adaptJSON(grammar, name, replacementScope, replaceeScope = 'json') {
grammar.name = name;
grammar.scopeName = `source${replacementScope}`;

const regex = new RegExp(`\.${replaceeScope}`, 'g');
var fixScopeNames = function (rule) {
if (typeof rule.name === 'string') {
rule.name = rule.name.replace(/\.json/g, replacementScope);
rule.name = rule.name.replace(regex, replacementScope);
}
if (typeof rule.contentName === 'string') {
rule.contentName = rule.contentName.replace(/\.json/g, replacementScope);
rule.contentName = rule.contentName.replace(regex, replacementScope);
}
for (var property in rule) {
var value = rule[property];
Expand All @@ -35,3 +35,5 @@ var tsGrammarRepo = 'microsoft/vscode-JSON.tmLanguage';
updateGrammar.update(tsGrammarRepo, 'JSON.tmLanguage', './syntaxes/JSON.tmLanguage.json');
updateGrammar.update(tsGrammarRepo, 'JSON.tmLanguage', './syntaxes/JSONC.tmLanguage.json', grammar => adaptJSON(grammar, 'JSON with Comments', '.json.comments'));
updateGrammar.update(tsGrammarRepo, 'JSON.tmLanguage', './syntaxes/JSONL.tmLanguage.json', grammar => adaptJSON(grammar, 'JSON Lines', '.json.lines'));

updateGrammar.update('jeff-hykin/better-snippet-syntax', 'autogenerated/jsonc.tmLanguage.json', './syntaxes/snippets.tmLanguage.json', grammar => adaptJSON(grammar, 'Snippets', '.json.comments.snippets', 'json.comments'));
12 changes: 12 additions & 0 deletions extensions/json/cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
},
"license": "MIT",
"version": "0.0.0"
},
{
"component": {
"type": "git",
"git": {
"name": "jeff-hykin/better-snippet-syntax",
"repositoryUrl": "https://github.com/jeff-hykin/better-snippet-syntax",
"commitHash": "2b1bb124cb2b9c75c3c80eae1b8f3a043841d654"
}
},
"license": "MIT",
"version": "1.0.2"
}
],
"version": 1
Expand Down
21 changes: 20 additions & 1 deletion extensions/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
".jslintrc",
".jsonld",
".geojson",
".ipynb",
".ipynb",
".vuerc"
],
"filenames": [
Expand Down Expand Up @@ -77,6 +77,20 @@
],
"filenames": [],
"configuration": "./language-configuration.json"
},
{
"id": "snippets",
"aliases": [
"Code Snippets"
],
"extensions": [
".code-snippets"
],
"filenamePatterns": [
"**/User/snippets/*.json",
"**/User/profiles/*/snippets/*.json"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
Expand All @@ -94,6 +108,11 @@
"language": "jsonl",
"scopeName": "source.json.lines",
"path": "./syntaxes/JSONL.tmLanguage.json"
},
{
"language": "snippets",
"scopeName": "source.json.comments.snippets",
"path": "./syntaxes/snippets.tmLanguage.json"
}
]
},
Expand Down
7,463 changes: 7,463 additions & 0 deletions extensions/json/syntaxes/snippets.tmLanguage.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
// Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. The scope defines in watch languages the snippet is applicable. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted.Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
"MSFT Copyright Header": {
"scope": "javascript,typescript,css",
"prefix": [
"header",
"stub",
"copyright"
],
"body": [
"/*---------------------------------------------------------------------------------------------",
" * Copyright (c) Microsoft Corporation. All rights reserved.",
" * Licensed under the MIT License. See License.txt in the project root for license information.",
" *--------------------------------------------------------------------------------------------*/",
"",
"$0"
],
"description": "Insert Copyright Statement"
},
"TS -> Inject Service": {
"scope": "typescript",
"description": "Constructor Injection Pattern",
"prefix": "@inject",
"body": "@$1 private readonly _$2: ${1},$0"
},
"TS -> Event & Emitter": {
"scope": "typescript",
"prefix": "emitter",
"description": "Add emitter and event properties",
"body": [
"private readonly _onDid$1 = new Emitter<$2>();",
"readonly onDid$1: Event<$2> = this._onDid$1.event;"
],
}
}
Loading

0 comments on commit 5f9fc78

Please sign in to comment.