-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5ede180
Showing
14 changed files
with
4,177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.DS_Store | ||
node_modules | ||
*.vsix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Extension", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"args": ["--extensionDevelopmentPath=${workspaceFolder}"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Changelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright 2022 Terrastruct, Inc. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are | ||
permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of | ||
conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of | ||
conditions and the following disclaimer in the documentation and/or other materials | ||
provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used | ||
to endorse or promote products derived from this software without specific prior written | ||
permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<div align="center"> | ||
<h1 align="center"> | ||
<img src="./docs/assets/logo.svg" alt="D2" /> | ||
</h1> | ||
|
||
VSCode extension for [D2](https://d2-lang.com) files. | ||
<br /> | ||
<br /> | ||
</div> | ||
|
||
Currently only supports syntax highlighting of `.d2` files. | ||
|
||
```d2 | ||
x -> y | ||
# d2-vscode can syntax highlight nested markdown correctly. | ||
y: |`md | ||
# d2-vscode | ||
VSCode extension for [D2](https://d2-lang.com) files. | ||
`| | ||
``` | ||
|
||
## Contributing | ||
|
||
To package and install the extension locally, run: | ||
|
||
```sh | ||
npm install -g vsce | ||
npm run dev | ||
``` | ||
|
||
You can run rerun `npm run dev` after any change to install the updated extension. | ||
|
||
Sometimes VS Code will not pick up the new extension without being restarted so you | ||
can also run the following on macOS: | ||
|
||
```sh | ||
# Where d2-testing is some folder in which you want to test the extension. | ||
osascript -e 'quit app "Visual Studio Code"'; yarn dev && code ~/d2-testing | ||
``` | ||
|
||
### launch.json | ||
|
||
We have a `.vscode/launch.json` that enables starting a separate debug VS Code with the | ||
extension installed without affecting your existing VS Code instance. To use, open | ||
`d2-vscode` with VS Code and hit `F5`. Press `CMD+R` after making changes to restart the | ||
debug VS Code with the updated extension. | ||
|
||
### Generating tmLanguage.json | ||
|
||
To regenerate `d2.tmLanguage.json` after updating `d2.tmLanguage.yaml`: | ||
|
||
```sh | ||
brew install yq | ||
npm run gen | ||
``` | ||
|
||
note: `npm run dev` will regenerate for you. | ||
|
||
### Debugging Keybind | ||
|
||
Highly recommend the following keybind for inspecting the textmate scopes under the cursor. | ||
|
||
```json | ||
{ | ||
"key": "cmd+i", | ||
"command": "editor.action.inspectTMScopes" | ||
} | ||
``` | ||
|
||
### Offline Distribution | ||
|
||
See https://code.visualstudio.com/docs/editor/extension-marketplace#_install-from-a-vsix | ||
|
||
```sh | ||
npm install -g vsce | ||
npm run pkg | ||
# To install: | ||
# code --install-extension d2.vsix | ||
# To uninstall: | ||
# code --uninstall-extension terrastruct.d2 | ||
``` | ||
|
||
### markdown.tmLanguage.json | ||
|
||
Syntax file used for markdown embedded within d2 block strings. | ||
|
||
1. Copied from VS Code's markdown-basics extension. | ||
2. Renamed to `markdown.d2` and scope to `text.html.markdown.d2` | ||
3. Then with vim: | ||
``` | ||
%s/\(?:\)\?\^|\\\\G/\1(?!.*`\\\\|)(?:\^|\\\\G)/g | ||
``` | ||
|
||
- This replacement ensures the markdown syntax never matches on block string | ||
terminators. | ||
|
||
4. Then with sed: | ||
```sh | ||
gsed -i -E 's/\[ \]\{[^}]*?\}/\\\\s*/' markdown.tmLanguage.json | ||
``` | ||
|
||
- This replacement ensures that the markdown syntax doesn't consider leading spaces to be | ||
the beginning of an indented code block as in d2, block strings are indented for | ||
readability without the indentation being part of the string contents. | ||
|
||
5. Now delete the `list` from `#block`. Lists for some reason eat the block string | ||
terminator. e.g. with them enabled the following syntax after the terminating `|` | ||
will remain markdown: | ||
```d2 | ||
my shape: |md | ||
1. first | ||
| | ||
should be d2 but VS Code highlights as markdown. | ||
``` | ||
6. Add `fenced_code_block_d2` based on `fenced_code_block_css` to allow embedding markdown | ||
with d2 within d2. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"comments": { | ||
"lineComment": "#", | ||
"blockComment": [ "\"\"\"", "\"\"\"" ] | ||
}, | ||
"brackets": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"], | ||
["|`", "`|"] | ||
], | ||
"autoClosingPairs": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"], | ||
["'", "'"], | ||
["\"", "\""], | ||
["|`", "`|"] | ||
], | ||
"surroundingPairs": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"], | ||
["'", "'"], | ||
["\"", "\""] | ||
], | ||
"indentationRules": { | ||
"increaseIndentPattern": "(?:\\|`+[^|`\\s]*\\s*|[{[]\\s*(?:#.*)?)$", | ||
"decreaseIndentPattern": "^\\s*(?:`+\\||[}\\]])" | ||
}, | ||
"onEnterRules": [ | ||
{ | ||
"previousLineText": "[^\\\\]$|^$", | ||
"beforeText": "\\\\$", | ||
"action": { "indent": "indent" } | ||
}, | ||
{ | ||
"previousLineText": "\\\\$", | ||
"beforeText": "[^\\\\]$", | ||
"action": { "indent": "outdent" } | ||
}, | ||
{ | ||
"beforeText": "^\\s*#.*$", | ||
"action": { "indent": "none", "appendText": "# " } | ||
}, | ||
{ | ||
"#": "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.", | ||
"beforeText": "^$", | ||
"action": { "indent": "none" } | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"name": "d2", | ||
"version": "0.0.1", | ||
"publisher": "terrastruct", | ||
"engines": { | ||
"vscode": "^1.0.0" | ||
}, | ||
"license": "BSD-3-Clause", | ||
"displayName": "d2", | ||
"description": "Support for .d2 files.", | ||
"categories": [ | ||
"Programming Languages", | ||
"Themes" | ||
], | ||
"keywords": [ | ||
"diagram", | ||
"diagramming", | ||
"model", | ||
"modelling", | ||
"visual", | ||
"uml", | ||
"mindmap" | ||
], | ||
"contributes": { | ||
"languages": [ | ||
{ | ||
"id": "d2", | ||
"extensions": [ | ||
".d2" | ||
], | ||
"configuration": "./language-configuration.json", | ||
"icon": { | ||
"light": "d2-icon.png", | ||
"dark": "d2-icon.png" | ||
} | ||
}, | ||
{ | ||
"id": "markdown.d2" | ||
} | ||
], | ||
"grammars": [ | ||
{ | ||
"language": "d2", | ||
"scopeName": "source.d2", | ||
"path": "./syntaxes/d2.tmLanguage.json" | ||
}, | ||
{ | ||
"language": "markdown.d2", | ||
"scopeName": "text.html.markdown.d2", | ||
"path": "./syntaxes/markdown.tmLanguage.json" | ||
} | ||
], | ||
"themes": [ | ||
{ | ||
"label": "D2 Light", | ||
"uiTheme": "vs", | ||
"path": "./themes/light-color-theme.json" | ||
}, | ||
{ | ||
"label": "D2 Dark", | ||
"uiTheme": "vs-dark", | ||
"path": "./themes/dark-color-theme.json" | ||
} | ||
] | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/terrastruct/d2-vscode/issues", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/terrastruct/d2-vscode" | ||
}, | ||
"homepage": "https://d2-lang.com", | ||
"icon": "d2-icon.png", | ||
"preview": true, | ||
"scripts": { | ||
"dev": "code --uninstall-extension terrastruct.d2; yarn gen && yarn pkg && code --install-extension d2.vsix", | ||
"gen": "yq --output-format json syntaxes/d2.tmLanguage.yaml > syntaxes/d2.tmLanguage.json", | ||
"pkg": "vsce package --out d2.vsix" | ||
} | ||
} |
Oops, something went wrong.