Skip to content

Commit 526e6ae

Browse files
committed
feat: add D2 syntax highlighting
1 parent a3effbb commit 526e6ae

13 files changed

+3873
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This [EclipseⓇ](https://eclipse.org) plug-in adds syntax highlighting support
2727
1. Carbon - https://carbon-lang.dev
2828
1. COBOL - https://en.wikipedia.org/wiki/COBOL
2929
1. Crystal (`*.cr`) - https://crystal-lang.org/
30+
1. D2 - https://d2lang.com/
3031
1. Eclipse External null Annotations (`*.eea`) - https://wiki.eclipse.org/JDT_Core/Null_Analysis/External_Annotations#File_format
3132
1. EditorConfig - https://editorconfig.org
3233
1. Elm - https://elm-lang.org/
@@ -117,6 +118,7 @@ To install the plugin into an existing Eclipse installation do:
117118
| COBOL <img src="plugin/syntaxes/cobol/icon.png" width=16/> | file-extensions="cbl, cob, cobol, copy, cpy"<br />file-patterns="\*\*/broadcommfd.cobol-language-support/\*/copybooks/\*\*" | [development@eclipse-che4z/che-che4z-lsp-for-cobol](https://github.com/eclipse-che4z/che-che4z-lsp-for-cobol/tree/a7c03bd1b94caba382fb7ec6e0ef6e8cdd2bd079/clients/cobol-lsp-vscode-extension)
118119
| Crystal <img src="plugin/syntaxes/crystal/icon.png" width=16/> | file-extensions="cr" | [master@crystal-lang-tools/vscode-crystal-lang](https://github.com/crystal-lang-tools/vscode-crystal-lang/tree/c7675e289f54fd0d6f4ba94f5c950e06a9a8202a/) [[upstream]](https://github.com/Microsoft/vscode/blob/3f1f36333d3453f67a36b6bfb1206e9159e9c4f0/extensions/ruby/syntaxes/ruby.tmLanguage.json)
119120
| Crystal Slang <img src="plugin/syntaxes/crystal/icon.png" width=16/> | file-extensions="slang" | [master@crystal-lang-tools/vscode-crystal-lang](https://github.com/crystal-lang-tools/vscode-crystal-lang/tree/c7675e289f54fd0d6f4ba94f5c950e06a9a8202a/)
121+
| d2 <img src="plugin/syntaxes/d2/d2.png" width=16/> | file-extensions="d2" | [master@terrastruct/d2-vscode](https://github.com/terrastruct/d2-vscode/tree/88d9716009f9b8d65bfd6dea96064c94a5cf275f/)
120122
| EditorConfig <img src="plugin/syntaxes/editorconfig/icon.png" width=16/> | file-extensions="editorconfig" | [main@editorconfig/editorconfig-vscode](https://github.com/editorconfig/editorconfig-vscode/tree/ca06ffc5aabaa51f133a6dd568ca14858a727e44/)
121123
| Elm <img src="plugin/syntaxes/elm/icon.png" width=16/> | file-extensions="elm" | [main@elm-tooling/elm-language-client-vscode](https://github.com/elm-tooling/elm-language-client-vscode/tree/a32f6a908c113ea4710d18b612a7ecd70f0a2c8b/)
122124
| Embedded Crystal <img src="plugin/syntaxes/crystal/icon.png" width=16/> | file-extensions="ecr" | [master@crystal-lang-tools/vscode-crystal-lang](https://github.com/crystal-lang-tools/vscode-crystal-lang/tree/c7675e289f54fd0d6f4ba94f5c950e06a9a8202a/)

plugin/plugin.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,62 @@
372372
<snippet name="Crystal Slang Example" path="syntaxes/crystal/slang.example.slang" scopeName="text.slang" />
373373
</extension>
374374

375+
<!-- ======================================== -->
376+
<!-- d2/d2: d2 -->
377+
<!-- ======================================== -->
378+
<extension point="org.eclipse.core.contenttype.contentTypes">
379+
<content-type id="extra-syntax-highlighting.d2" name="d2" base-type="extra-syntax-highlighting.basetype" priority="normal"
380+
file-extensions="d2" />
381+
</extension>
382+
<extension point="org.eclipse.tm4e.registry.grammars">
383+
<grammar scopeName="source.d2" path="syntaxes/d2/d2.tmLanguage.json" />
384+
<scopeNameContentTypeBinding scopeName="source.d2" contentTypeId="extra-syntax-highlighting.d2" />
385+
</extension>
386+
387+
<extension point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
388+
<languageConfiguration contentTypeId="extra-syntax-highlighting.d2" path="syntaxes/d2/d2.language-configuration.json" />
389+
</extension>
390+
391+
<extension point="org.eclipse.ui.genericeditor.icons">
392+
<icon contentType="extra-syntax-highlighting.d2" icon="syntaxes/d2/d2.png"/>
393+
</extension>
394+
395+
<extension point="org.eclipse.tm4e.ui.snippets">
396+
<snippet name="d2 Example" path="syntaxes/d2/d2.example.d2" scopeName="source.d2" />
397+
</extension>
398+
399+
<!-- ======================================== -->
400+
<!-- d2/d2-markdown-injection: d2-markdown-injection -->
401+
<!-- ======================================== -->
402+
<extension point="org.eclipse.core.contenttype.contentTypes">
403+
<content-type id="extra-syntax-highlighting.d2-markdown-injection" name="d2-markdown-injection" base-type="extra-syntax-highlighting.basetype" priority="normal"
404+
file-names="PREVENT_FILE_ASSOCIATION_INHERITANCE" />
405+
</extension>
406+
<extension point="org.eclipse.tm4e.registry.grammars">
407+
<grammar scopeName="markdown.d2.codeblock" path="syntaxes/d2/d2-markdown-injection.tmLanguage.json" />
408+
<scopeNameContentTypeBinding scopeName="markdown.d2.codeblock" contentTypeId="extra-syntax-highlighting.d2-markdown-injection" />
409+
</extension>
410+
411+
<extension point="org.eclipse.ui.genericeditor.icons">
412+
<icon contentType="extra-syntax-highlighting.d2-markdown-injection" icon="syntaxes/d2/icon.png"/>
413+
</extension>
414+
415+
<!-- ======================================== -->
416+
<!-- d2/markdown.d2: markdown.d2 -->
417+
<!-- ======================================== -->
418+
<extension point="org.eclipse.core.contenttype.contentTypes">
419+
<content-type id="extra-syntax-highlighting.markdown.d2" name="markdown.d2" base-type="extra-syntax-highlighting.basetype" priority="normal"
420+
file-names="PREVENT_FILE_ASSOCIATION_INHERITANCE" />
421+
</extension>
422+
<extension point="org.eclipse.tm4e.registry.grammars">
423+
<grammar scopeName="text.html.markdown.d2" path="syntaxes/d2/markdown.d2.tmLanguage.json" />
424+
<scopeNameContentTypeBinding scopeName="text.html.markdown.d2" contentTypeId="extra-syntax-highlighting.markdown.d2" />
425+
</extension>
426+
427+
<extension point="org.eclipse.ui.genericeditor.icons">
428+
<icon contentType="extra-syntax-highlighting.markdown.d2" icon="syntaxes/d2/icon.png"/>
429+
</extension>
430+
375431
<!-- ======================================== -->
376432
<!-- dot/dot: GraphViz DOT File -->
377433
<!-- ======================================== -->

plugin/syntaxes/d2/LICENSE.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright 2022 Terrastruct, Inc.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are
4+
permitted provided that the following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice, this list of
7+
conditions and the following disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice, this list of
10+
conditions and the following disclaimer in the documentation and/or other materials
11+
provided with the distribution.
12+
13+
3. Neither the name of the copyright holder nor the names of its contributors may be used
14+
to endorse or promote products derived from this software without specific prior written
15+
permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20+
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
24+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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": "#d2-code-block"
7+
}
8+
],
9+
"repository": {
10+
"d2-code-block": {
11+
"begin": "(^|\\G)(\\s*)(\\`{3,}|~{3,})\\s*(?i:(d2)(\\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.d2",
35+
"patterns": [
36+
{
37+
"include": "source.d2"
38+
}
39+
]
40+
}
41+
]
42+
}
43+
},
44+
"scopeName": "markdown.d2.codeblock"
45+
}

plugin/syntaxes/d2/d2.example.d2

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Title, description, theme, and layout
2+
title: "Terrastruct D2 Full Language Feature Demo"
3+
description: "This diagram showcases all major D2 language features."
4+
theme: "cool" // try "minty", "neutral", "monochrome", "sketch"
5+
layout: dagre-left
6+
7+
// Reusable styles
8+
class redbox {
9+
style.fill: "#ffcccc"
10+
style.stroke: "#cc0000"
11+
style.stroke-dash: 4
12+
}
13+
14+
class server {
15+
icon: server
16+
shape: cube
17+
style.fill: "#e0f7fa"
18+
style.stroke: "#00838f"
19+
}
20+
21+
// Groups/subgraphs
22+
cloud {
23+
label: "Cloud Infra"
24+
style.fill: "#f0f0ff"
25+
style.stroke: "#3333aa"
26+
style.stroke-width: 2
27+
28+
aws: AWS {
29+
shape: cloud
30+
icon: cloud
31+
}
32+
33+
db: "Database" {
34+
shape: cylinder
35+
icon: database
36+
style.fill: "#fff3e0"
37+
style.stroke: "#ff6f00"
38+
}
39+
}
40+
41+
// Main flow
42+
User {
43+
shape: person
44+
icon: user
45+
style.fill: "#d0f0c0"
46+
style.stroke: "#33691e"
47+
}
48+
49+
User -> aws: "Sends request"
50+
aws -> db: "Fetch data"
51+
aws -> AppServer: "Returns result"
52+
53+
// Use class
54+
AppServer: "App Server" {
55+
class: server
56+
note: "Handles logic"
57+
}
58+
59+
// Group with layout direction
60+
frontend {
61+
direction: right
62+
WebUI: "Web UI" {
63+
shape: component
64+
icon: globe
65+
class: redbox
66+
}
67+
68+
WebUI -> AppServer: "Calls API"
69+
}
70+
71+
// Automation with loop
72+
for i in [1,2,3] {
73+
queue$i: "Queue $i" {
74+
shape: queue
75+
style.fill: "#ffe0b2"
76+
}
77+
78+
AppServer -> queue$i
79+
queue$i -> db
80+
}
81+
82+
// Conditional rendering
83+
if true {
84+
Analytics: "Analytics Service" {
85+
icon: graph
86+
shape: component
87+
}
88+
89+
db -> Analytics: "Export logs"
90+
}
91+
92+
// State transition diagram
93+
stateDiagram {
94+
AuthFlow: "Auth Flow"
95+
AuthFlow.Register -> AuthFlow.Login: "Success"
96+
AuthFlow.Login -> AuthFlow.Dashboard: "Valid Token"
97+
AuthFlow.Login -> AuthFlow.Error: "Failed"
98+
AuthFlow.Error -> AuthFlow.Login: "Retry"
99+
}
100+
101+
// External image
102+
Logo: "Company Logo" {
103+
image: "https://d2lang.com/logo.svg"
104+
shape: image
105+
style.stroke: none
106+
}
107+
108+
// Invisible helper node (automation)
109+
Invisible {
110+
style.opacity: 0
111+
note: "Invisible helper node"
112+
}
113+
AppServer -> Invisible -> Analytics
114+
115+
// Inline styling
116+
db.style {
117+
fill: "#ffeecc"
118+
stroke: "#ff9900"
119+
stroke-dash: 2
120+
}
121+
122+
// Bi-directional edge
123+
AppServer <-> WebUI: "Sync State"
124+
125+
// Custom edge styling
126+
WebUI -> Logo {
127+
label: "Loads assets"
128+
style.stroke: "#999"
129+
style.stroke-dash: 5
130+
style.arrowhead: vee
131+
}
132+
133+
// Markdown labels and notes
134+
AppServer.note: """
135+
## Server Info
136+
- 🧠 CPU: 8 cores
137+
- 💾 RAM: 32 GB
138+
"""
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"comments": {
3+
"lineComment": "#",
4+
"blockComment": ["\"\"\"", "\"\"\""]
5+
},
6+
"brackets": [
7+
["{", "}"],
8+
["[", "]"],
9+
["(", ")"],
10+
["|`", "`|"]
11+
],
12+
"autoClosingPairs": [
13+
["{", "}"],
14+
["[", "]"],
15+
["(", ")"],
16+
["'", "'"],
17+
["\"", "\""],
18+
["|`", "`|"]
19+
],
20+
"surroundingPairs": [
21+
["{", "}"],
22+
["[", "]"],
23+
["(", ")"],
24+
["'", "'"],
25+
["\"", "\""]
26+
],
27+
"indentationRules": {
28+
"increaseIndentPattern": "(?:\\|`+[^|`\\s]*\\s*|[{[]\\s*(?:#.*)?)$",
29+
"decreaseIndentPattern": "^\\s*(?:`+\\||[}\\]])"
30+
},
31+
"onEnterRules": [
32+
{
33+
"previousLineText": "[^\\\\]$|^$",
34+
"beforeText": "\\\\$",
35+
"action": { "indent": "indent" }
36+
},
37+
{
38+
"previousLineText": "\\\\$",
39+
"beforeText": "[^\\\\]$",
40+
"action": { "indent": "outdent" }
41+
},
42+
{
43+
"beforeText": "^\\s*#.*$",
44+
"action": { "indent": "none", "appendText": "# " }
45+
},
46+
{
47+
"#": "This instructs VS Code to not align indentation to the indentation of lines above if there is a newline in between. To see what it prevents, delete the action field below to disable this rule and insert ' meow' in a file (two spaces and then the string meow). Now hit enter. Your cursor will be aligned with the m in meow. Now press backspace. Now if you press enter again, VS Code will insert a third line but instead of matching the no indent of the previous empty line, it will match the indent of the last non empty line which means your cursor will again be aligned with the m in meow except with a newline in between. Now follow the same steps with this rule enabled and you'll see that on the third line VS Code respects your outdent on the second line. Your cursor will remain in the first column unaligned with the m in meow.",
48+
"beforeText": "^$",
49+
"action": { "indent": "none" }
50+
}
51+
]
52+
}

plugin/syntaxes/d2/d2.png

456 Bytes
Loading

0 commit comments

Comments
 (0)