Skip to content

Commit 0d74bd3

Browse files
committed
[vscode-mlir] Add proper support for mlir markdown codeblocks
A special language contribution is required for properly supporting markdown code blocks in vscodes builtin markdown grammar, see https://github.com/mjbvz/vscode-fenced-code-block-grammar-injection-example for more details.
1 parent 81b293b commit 0d74bd3

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"fileTypes": [],
3+
"injectionSelector": "L:text.html.markdown",
4+
"patterns": [
5+
{
6+
"include": "#mlir-code-block"
7+
}
8+
],
9+
"repository": {
10+
"mlir-code-block": {
11+
"begin": "(^|\\G)(\\s*)(\\`{3,}|~{3,})\\s*(?i:(mlir)(\\s+[^`~]*)?$)",
12+
"name": "markup.fenced_code.block.markdown",
13+
"end": "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$",
14+
"beginCaptures": {
15+
"3": {
16+
"name": "punctuation.definition.markdown"
17+
},
18+
"4": {
19+
"name": "fenced_code.block.language.markdown"
20+
},
21+
"5": {
22+
"name": "fenced_code.block.language.attributes.markdown"
23+
}
24+
},
25+
"endCaptures": {
26+
"3": {
27+
"name": "punctuation.definition.markdown"
28+
}
29+
},
30+
"patterns": [
31+
{
32+
"begin": "(^|\\G)(\\s*)(.*)",
33+
"while": "(^|\\G)(?!\\s*([`~]{3,})\\s*$)",
34+
"contentName": "meta.embedded.block.mlir",
35+
"patterns": [
36+
{
37+
"include": "source.mlir"
38+
}
39+
]
40+
}
41+
]
42+
}
43+
},
44+
"scopeName": "markdown.mlir.codeblock"
45+
}

mlir/utils/vscode/package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mlir/utils/vscode/package.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-mlir",
33
"displayName": "MLIR",
44
"description": "MLIR Language Extension",
5-
"version": "0.0.1",
5+
"version": "0.0.2",
66
"publisher": "llvm-vs-code-extensions",
77
"homepage": "https://mlir.llvm.org/",
88
"icon": "icon.png",
@@ -44,8 +44,8 @@
4444
"vscode-test": "^1.3.0"
4545
},
4646
"repository": {
47-
"type": "git",
48-
"url": "https://github.com/llvm/vscode-mlir.git"
47+
"type": "git",
48+
"url": "https://github.com/llvm/vscode-mlir.git"
4949
},
5050
"contributes": {
5151
"languages": [
@@ -59,13 +59,27 @@
5959
".mlir"
6060
],
6161
"configuration": "./language-configuration.json"
62+
},
63+
{
64+
"id": "mlir-injection"
6265
}
6366
],
6467
"grammars": [
6568
{
6669
"language": "mlir",
6770
"scopeName": "source.mlir",
6871
"path": "./grammar.json"
72+
},
73+
{
74+
"language": "mlir-injection",
75+
"scopeName": "markdown.mlir.codeblock",
76+
"path": "markdown-grammar.json",
77+
"injectTo": [
78+
"text.html.markdown"
79+
],
80+
"embeddedLanguages": {
81+
"meta.embedded.block.mlir": "mlir"
82+
}
6983
}
7084
],
7185
"configuration": {

0 commit comments

Comments
 (0)