Explorar el Código

vscode: Expand where Elvish code can get highlighted.

- Highlight Elvish code blocks in Markdown.

- Highlight Elvish transcripts, either in .ttyshot files or in Markdown code
  blocks.

- Remove the syntaxes directory in repo root now that the syntaxes live inside
  vscode/syntaxes.

- Bump VS Code extension version to 0.1.2.
Qi Xiao hace 1 año
padre
commit
c115a5d47a

+ 0 - 3
syntaxes/README.md

@@ -1,3 +0,0 @@
-This directory exists so that `elvish.tmLanguage.json` can be discovered by
-[Linguist](https://github.com/github/linguist), which expects such files to live
-inside a directory called `grammars` or `syntaxes`.

+ 0 - 1
syntaxes/elvish.tmLanguage.json

@@ -1 +0,0 @@
-../vscode/elvish.tmLanguage.json

+ 1 - 0
vscode/LICENSE

@@ -0,0 +1 @@
+../LICENSE

+ 52 - 15
vscode/package.json

@@ -2,7 +2,7 @@
     "name": "elvish",
     "displayName": "Elvish",
     "description": "Elvish language support for Visual Studio Code",
-    "version": "0.1.1",
+    "version": "0.1.2",
     "publisher": "elves",
     "license": "BSD-2-Clause",
     "icon": "icon.png",
@@ -21,17 +21,55 @@
     ],
     "main": "./extension.js",
     "contributes": {
-        "languages": [{
-            "id": "elvish",
-            "aliases": ["Elvish", "elvish"],
-            "extensions": [".elv"],
-            "configuration": "./language-configuration.json"
-        }],
-        "grammars": [{
-            "language": "elvish",
-            "scopeName": "source.elvish",
-            "path": "./elvish.tmLanguage.json"
-        }],
+        "languages": [
+            {
+                "id": "elvish",
+                "aliases": [
+                    "Elvish",
+                    "elvish"
+                ],
+                "extensions": [
+                    ".elv"
+                ],
+                "configuration": "./language-configuration.json"
+            },
+            {
+                "id": "elvish-transcript",
+                "aliases": [
+                    "Elvish transcript",
+                    "elvish transcript"
+                ],
+                "extensions": [
+                    ".ttyshot"
+                ]
+            }
+        ],
+        "grammars": [
+            {
+                "language": "elvish",
+                "scopeName": "source.elvish",
+                "path": "./syntaxes/elvish.tmLanguage.json"
+            },
+            {
+                "language": "elvish-transcript",
+                "scopeName": "source.elvish-transcript",
+                "path": "./syntaxes/elvish-transcript.tmLanguage.json",
+                "embeddedLanguages": {
+                    "meta.embedded.block.elvish": "elvish"
+                }
+            },
+            {
+                "scopeName": "source.elvish.in.markdown",
+                "path": "./syntaxes/elvish-in-markdown.tmLanguage.json",
+                "injectTo": [
+                    "text.html.markdown"
+                ],
+                "embeddedLanguages": {
+                    "meta.embedded.block.elvish": "elvish",
+                    "meta.embedded.block.elvish-transcript": "elvish-transcript"
+                }
+            }
+        ],
         "configuration": {
             "title": "Elvish",
             "properties": {
@@ -48,9 +86,8 @@
             }
         }
     },
-	"scripts": {
-	},
+    "scripts": {},
     "dependencies": {
         "vscode-languageclient": "^7.0.0"
     }
-}
+}

+ 73 - 0
vscode/syntaxes/elvish-in-markdown.tmLanguage.json

@@ -0,0 +1,73 @@
+{
+	"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
+	"scopeName": "source.elvish.in.markdown",
+	"injectionSelector": "L:text.html.markdown",
+	"patterns": [
+		{
+			"name": "markup.fenced_code.block.markdown",
+			"begin": "(^|\\G)(\\s*)(\\`{3,}|~{3,})\\s*(?i:(elvish)((\\s+|:|,|\\{|\\?)[^`~]*)?$)",
+			"end": "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$",
+			"beginCaptures": {
+				"3": {
+					"name": "punctuation.definition.markdown"
+				},
+				"4": {
+					"name": "fenced_code.block.language.markdown"
+				},
+				"5": {
+					"name": "fenced_code.block.language.attributes.markdown"
+				}
+			},
+			"endCaptures": {
+				"3": {
+					"name": "punctuation.definition.markdown"
+				}
+			},
+			"patterns": [
+				{
+					"begin": "(^|\\G)(\\s*)(.*)",
+					"while": "(^|\\G)(?!\\s*([`~]{3,})\\s*$)",
+					"contentName": "meta.embedded.block.elvish",
+					"patterns": [
+						{
+							"include": "source.elvish"
+						}
+					]
+				}
+			]
+		},
+		{
+			"name": "markup.fenced_code.block.markdown",
+			"begin": "(^|\\G)(\\s*)(\\`{3,}|~{3,})\\s*(?i:(elvish-transcript)((\\s+|:|,|\\{|\\?)[^`~]*)?$)",
+			"end": "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$",
+			"beginCaptures": {
+				"3": {
+					"name": "punctuation.definition.markdown"
+				},
+				"4": {
+					"name": "fenced_code.block.language.markdown"
+				},
+				"5": {
+					"name": "fenced_code.block.language.attributes.markdown"
+				}
+			},
+			"endCaptures": {
+				"3": {
+					"name": "punctuation.definition.markdown"
+				}
+			},
+			"patterns": [
+				{
+					"begin": "(^|\\G)(\\s*)(.*)",
+					"while": "(^|\\G)(?!\\s*([`~]{3,})\\s*$)",
+					"contentName": "meta.embedded.block.elvish-transcript",
+					"patterns": [
+						{
+							"include": "source.elvish-transcript"
+						}
+					]
+				}
+			]
+		}
+	]
+}

+ 20 - 0
vscode/syntaxes/elvish-transcript.tmLanguage.json

@@ -0,0 +1,20 @@
+{
+	"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
+	"name": "Elvish transcript",
+	"scopeName": "source.elvish-transcript",
+	"fileTypes": [
+		"ttyshot"
+	],
+	"patterns": [
+		{
+			"begin": "(^|\\G)[~/][^ ]*> ",
+			"while": "(^|\\G)   ",
+			"contentName": "meta.embedded.block.elvish",
+			"patterns": [
+				{
+					"include": "source.elvish"
+				}
+			]
+		}
+	]
+}

+ 8 - 8
vscode/elvish.tmLanguage.json → vscode/syntaxes/elvish.tmLanguage.json

@@ -34,7 +34,7 @@
 			"match": "\\$[\\w\\d_:~-]+"
 		},
 		{
-			"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(var|set|tmp|del)((\\s+[\\w\\d_:~-]+)+)",
+			"match": "(?<=\\G|^|\\{ |\\{\t|\\(|\\||\\;)\\s*(var|set|tmp|del)((\\s+[\\w\\d_:~-]+)+)",
 			"captures": {
 				"1": {
 					"name": "keyword.other.elvish"
@@ -45,7 +45,7 @@
 			}
 		},
 		{
-			"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(for)\\s+([\\w\\d_:~-]+)",
+			"match": "(?<=\\G|^|\\{ |\\{\t|\\(|\\||\\;)\\s*(for)\\s+([\\w\\d_:~-]+)",
 			"captures": {
 				"1": {
 					"name": "keyword.control.elvish"
@@ -68,16 +68,16 @@
 		},
 
 		{
-			"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(nop|!=|!=s|%|\\*|\\+|-gc|-ifaddrs|-log|-override-wcwidth|-stack|-|/|<|<=|<=s|<s|==|==s|>|>=|>=s|>s|all|assoc|base|bool|break|call|cd|compare|constantly|continue|count|defer|deprecate|dissoc|drop|each|eawk|echo|eq|eval|exact-num|exec|exit|external|fail|fg|float64|from-json|from-lines|from-terminated|get-env|has-env|has-external|has-key|has-value|is|keys|kind-of|make-map|multi-error|nop|not-eq|not|ns|num|one|only-bytes|only-values|order|peach|pprint|print|printf|put|rand|randint|range|read-line|read-upto|repeat|repr|resolve|return|run-parallel|search-external|set-env|show|sleep|slurp|src|styled|styled-segment|take|tilde-abbr|time|to-json|to-lines|to-string|to-terminated|unset-env|use-mod|wcswidth)(?=[\\s)}<>;|&])",
+			"match": "(?<=\\G|^|\\{ |\\{\t|\\(|\\||\\;)\\s*(nop|!=|!=s|%|\\*|\\+|-gc|-ifaddrs|-log|-override-wcwidth|-stack|-|/|<|<=|<=s|<s|==|==s|>|>=|>=s|>s|all|assoc|base|bool|break|call|cd|compare|constantly|continue|count|defer|deprecate|dissoc|drop|each|eawk|echo|eq|eval|exact-num|exec|exit|external|fail|fg|float64|from-json|from-lines|from-terminated|get-env|has-env|has-external|has-key|has-value|is|keys|kind-of|make-map|multi-error|nop|not-eq|not|ns|num|one|only-bytes|only-values|order|peach|pprint|print|printf|put|rand|randint|range|read-line|read-upto|repeat|repr|resolve|return|run-parallel|search-external|set-env|show|sleep|slurp|src|styled|styled-segment|take|tilde-abbr|time|to-json|to-lines|to-string|to-terminated|unset-env|use-mod|wcswidth)(?=[\\s)}<>;|&])",
 			"captures": {
 				"1": {
-					"name": "support.function"
+					"name": "support.function.elvish"
 				}
 			}
 		},
 
 		{
-			"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(and|or|coalesce)(?=[\\s)}<>;|&])",
+			"match": "(?<=\\G|^|\\{ |\\{\t|\\(|\\||\\;)\\s*(and|or|coalesce)(?=[\\s)}<>;|&])",
 			"captures": {
 				"1": {
 					"name": "keyword.operator.elvish"
@@ -85,7 +85,7 @@
 			}
 		},
 		{
-			"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(use|var|set|tmp|del|pragma|fn)(?=[\\s)}<>;|&])",
+			"match": "(?<=\\G|^|\\{ |\\{\t|\\(|\\||\\;)\\s*(use|var|set|tmp|del|pragma|fn)(?=[\\s)}<>;|&])",
 			"captures": {
 				"1": {
 					"name": "keyword.other.elvish"
@@ -93,7 +93,7 @@
 			}
 		},
 		{
-			"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(while|for|try|if)(?=[\\s)}<>;|&])",
+			"match": "(?<=\\G|^|\\{ |\\{\t|\\(|\\||\\;)\\s*(while|for|try|if)(?=[\\s)}<>;|&])",
 			"captures": {
 				"1": {
 					"name": "keyword.control.elvish"
@@ -114,4 +114,4 @@
 			"match": "[*?|&;<>()\\[\\]{}]"
 		}
 	]
-}
+}