diff --git a/.gitmodules b/.gitmodules index 635bae6780..80cbe20362 100644 --- a/.gitmodules +++ b/.gitmodules @@ -407,6 +407,9 @@ [submodule "vendor/grammars/d.tmbundle"] path = vendor/grammars/d.tmbundle url = https://github.com/textmate/d.tmbundle +[submodule "vendor/grammars/d2-vscode"] + path = vendor/grammars/d2-vscode + url = https://github.com/terrastruct/d2-vscode.git [submodule "vendor/grammars/dart-syntax-highlight"] path = vendor/grammars/dart-syntax-highlight url = https://github.com/dart-lang/dart-syntax-highlight diff --git a/grammars.yml b/grammars.yml index e468bb0ea8..6c0178c20f 100644 --- a/grammars.yml +++ b/grammars.yml @@ -333,6 +333,9 @@ vendor/grammars/cython: - source.cython vendor/grammars/d.tmbundle: - source.d +vendor/grammars/d2-vscode: +- source.d2 +- text.html.markdown.d2 vendor/grammars/dart-syntax-highlight: - source.dart vendor/grammars/data-weave-tmLanguage: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 5ba6167e37..83de87b7b4 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1398,6 +1398,16 @@ D-ObjDump: tm_scope: objdump.x86asm ace_mode: assembly_x86 language_id: 81 +D2: + type: markup + color: "#526ee8" + extensions: + - ".d2" + aliases: + - d2lang + tm_scope: source.d2 + ace_mode: text + language_id: 37531557 DIGITAL Command Language: type: programming aliases: diff --git a/samples/D2/anthias-diagram-overview.d2 b/samples/D2/anthias-diagram-overview.d2 new file mode 100644 index 0000000000..9d490afb54 --- /dev/null +++ b/samples/D2/anthias-diagram-overview.d2 @@ -0,0 +1,55 @@ +direction: down + +classes: { + containers: { + shape: rectangle + } +} + +user: "User" { + shape: person +} + +database: "SQLite3" { + shape: cylinder +} + +a { + label: null + style.fill: transparent + style.stroke: transparent +} + +b { + label: null + style.fill: transparent + style.stroke: transparent +} + +b.display: "Display (Monitor or TV)" { + style.3d: true +} + +anthias-nginx.class: containers +b.anthias-viewer.class: containers +a.anthias-server.class: containers +a.anthias-websocket.class: containers +a.anthias-celery.class: containers +a.redis.class: containers + +user -> anthias-nginx +anthias-nginx <-> a.anthias-server +anthias-nginx -> a.anthias-websocket + +a.anthias-server <-> a.anthias-celery +a.anthias-websocket <-> a.anthias-server +a.anthias-celery -> a.redis: "in-memory data" +a.redis <-> a.anthias-server + +b.anthias-viewer <-> database: "assets data" + +a.anthias-server <-> b.anthias-viewer: "assets data" +a.anthias-server <-> database +a.anthias-celery <-> database + +b.anthias-viewer -> b.display: "current asset" diff --git a/samples/D2/calc_algo.d2 b/samples/D2/calc_algo.d2 new file mode 100644 index 0000000000..f083a9f1e2 --- /dev/null +++ b/samples/D2/calc_algo.d2 @@ -0,0 +1,148 @@ + +cTrnDao: CalcTrnDao { + q: Query { + ByTime + ByCategory + ByAccount + ByPurpose + } + sql: "SQL: O(trns.count) time | O(trns.notDel.count) space" { + "SELECT amount, currency, type FROM transactions WHERE ..." + } + trns: "List" { + CalcTrn { + shape: class + + amount: Double + currency: String + type: TransactionType + } + } + + q -> sql -> trns +} + +rawStatsFlow: RawStatsFlow { + in: Input { + shape: class + trns: List + } + + p: "Process: O(trns.count) time | O(currs.unique.count) space" { + "trns.forEach { aggregate incomes, expense by currencies + count them }" + } + + out: RawStats { + shape: class + incomes: Map + expenses: Map + incomesCount: Int + expensesCount: Int + } + + in -> p -> out +} + +cTrndao.trns -> rawStatsFlow.in.trns + +# RatesFlow +ratesDao: RatesDao { + sql: "SQL: O(rates.count) time | O(rates.baseCurr.count) space" { + "SELECT rate, currency FROM exchange_rates WHERE baseCurrency = ?" + } + out: "List" { + Rate { + shape: class + rate: Double + currency: String + } + } + sql -> out +} + +ratesOverrideDao: RateOverrideDao { + sql: "SQL: O(rates.override.count) time | O(rates.override.baseCurr.count) space" { + "SELECT rate, currency FROM exchange_rates_override WHERE baseCurrency = ? AND sync != $DELETING" + } + out: "List" { + Rate { + shape: class + rate: Double + currency: String + } + } + sql -> out +} + +ratesFlow: RatesFlow { + deps: Dependencies { + ratesDao + ratesOverrideDao + baseCurrencyFlow + } + p: "Process: O(rates.override.count) time | O(1) space" { + 1: "baseCurrency.flatMapLatest {}" + 2: "combine(rateDao.findByBaseCurr(), ratesOverridedao.findByBaseCurr())" + 3: "Override rate with the manual set ones" + + 1 -> 2 -> 3 + + } + out: "RatesData" { + shape: class + baseCurrency: String + rates: Map + } + + deps.ratesDao -> p: Reacts + deps.ratesOverrideDao -> p: Reacts + deps.baseCurrencyFlow -> p: Reacts + p -> out +} + +ratesDao -> ratesFlow.deps +ratesOverrideDao -> ratesFlow.deps + + +# ExchangeStatsFlow +exFlow: ExchangeStatsFlow { + deps: Dependencies { + ratesFlow: "rates: RatesFlow" + } + + in: Input { + shape: class + rawStats: RawStats + outputCurrency: String + } + + p: "Process: O(curr.unique.count) space-time" { + incs_loop: "rawStats.incomes.forEach {}" + incs_exchange: "exchange to output currency" + incs_sum: "sum & count" + + incs_loop -> incs_exchange -> incs_sum + + exps_loop: "rawStats.expenses.forEach {}" + exps_exchange: "exchange to output currency" + exps_sum: "sum & count" + + exps_loop -> exps_exchange -> exps_sum + } + + out: Stats { + shape: class + income: Value + expense: Value + incomesCount: Int + expensesCount: Int + } + + deps.ratesFlow -> p: Reacts to rates changes + in.rawStats -> p + p.incs_sum -> out + p.exps_sum -> out +} + +ratesFlow.out -> exFlow.deps.ratesFlow: Reacts +rawStatsFlow.out -> exFlow.in.rawStats diff --git a/vendor/README.md b/vendor/README.md index 879c8c09fb..e6e8580b8d 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -126,6 +126,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting - **Cython:** [textmate/cython.tmbundle](https://github.com/textmate/cython.tmbundle) - **D:** [textmate/d.tmbundle](https://github.com/textmate/d.tmbundle) - **D-ObjDump:** [nanoant/assembly.tmbundle](https://github.com/nanoant/assembly.tmbundle) +- **D2:** [terrastruct/d2-vscode](https://github.com/terrastruct/d2-vscode) - **DM:** [PJB3005/atomic-dreams](https://github.com/PJB3005/atomic-dreams) - **DNS Zone:** [sixty4k/st2-zonefile](https://github.com/sixty4k/st2-zonefile) - **DTrace:** [textmate/c.tmbundle](https://github.com/textmate/c.tmbundle) diff --git a/vendor/grammars/d2-vscode b/vendor/grammars/d2-vscode new file mode 160000 index 0000000000..8f1fef4f73 --- /dev/null +++ b/vendor/grammars/d2-vscode @@ -0,0 +1 @@ +Subproject commit 8f1fef4f732ffbf8a2cf70676c15bc9791c010a7 diff --git a/vendor/licenses/git_submodule/d2-vscode.dep.yml b/vendor/licenses/git_submodule/d2-vscode.dep.yml new file mode 100644 index 0000000000..044479a4fb --- /dev/null +++ b/vendor/licenses/git_submodule/d2-vscode.dep.yml @@ -0,0 +1,35 @@ +--- +name: d2-vscode +version: 8f1fef4f732ffbf8a2cf70676c15bc9791c010a7 +type: git_submodule +homepage: https://github.com/terrastruct/d2-vscode.git +license: bsd-3-clause +licenses: +- sources: LICENSE.txt + text: | + 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. +notices: []