@likec4/language-server 1.18.0 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LikeC4FileSystem.d.ts +13 -0
- package/dist/LikeC4FileSystem.js +27 -0
- package/dist/Rpc.d.ts +9 -0
- package/dist/Rpc.js +126 -0
- package/dist/ast.d.ts +200 -0
- package/dist/ast.js +276 -0
- package/dist/browser.d.ts +6 -20
- package/dist/browser.js +13 -0
- package/dist/formatting/LikeC4Formatter.d.ts +27 -0
- package/dist/formatting/LikeC4Formatter.js +261 -0
- package/dist/formatting/utils.d.ts +6 -0
- package/dist/formatting/utils.js +15 -0
- package/dist/generated/ast.d.ts +1242 -0
- package/dist/generated/ast.js +1945 -0
- package/dist/generated/grammar.d.ts +6 -0
- package/dist/generated/grammar.js +3 -0
- package/dist/generated/module.d.ts +9 -0
- package/dist/generated/module.js +23 -0
- package/dist/generated-lib/icons.d.ts +1 -0
- package/dist/{likec4lib.mjs → generated-lib/icons.js} +1 -6
- package/dist/index.d.ts +8 -31
- package/dist/index.js +13 -0
- package/dist/like-c4.langium +845 -0
- package/dist/likec4lib.d.ts +4 -6
- package/dist/likec4lib.js +4 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +73 -0
- package/dist/lsp/CodeLensProvider.d.ts +9 -0
- package/dist/lsp/CodeLensProvider.js +40 -0
- package/dist/lsp/CompletionProvider.d.ts +6 -0
- package/dist/lsp/CompletionProvider.js +135 -0
- package/dist/lsp/DocumentHighlightProvider.d.ts +9 -0
- package/dist/lsp/DocumentHighlightProvider.js +10 -0
- package/dist/lsp/DocumentLinkProvider.d.ts +11 -0
- package/dist/lsp/DocumentLinkProvider.js +49 -0
- package/dist/lsp/DocumentSymbolProvider.d.ts +23 -0
- package/dist/lsp/DocumentSymbolProvider.js +202 -0
- package/dist/lsp/HoverProvider.d.ts +10 -0
- package/dist/lsp/HoverProvider.js +69 -0
- package/dist/lsp/RenameProvider.d.ts +5 -0
- package/dist/lsp/RenameProvider.js +6 -0
- package/dist/lsp/SemanticTokenProvider.d.ts +7 -0
- package/dist/lsp/SemanticTokenProvider.js +297 -0
- package/dist/lsp/index.d.ts +7 -0
- package/dist/lsp/index.js +7 -0
- package/dist/model/deployments-index.d.ts +60 -0
- package/dist/model/deployments-index.js +181 -0
- package/dist/model/fqn-computation.d.ts +3 -0
- package/dist/model/fqn-computation.js +72 -0
- package/dist/model/fqn-index.d.ts +25 -0
- package/dist/model/fqn-index.js +96 -0
- package/dist/model/index.d.ts +6 -0
- package/dist/model/index.js +6 -0
- package/dist/model/model-builder.d.ts +32 -0
- package/dist/model/model-builder.js +598 -0
- package/dist/model/model-locator.d.ts +23 -0
- package/dist/model/model-locator.js +126 -0
- package/dist/model/model-parser-where.d.ts +3 -0
- package/dist/model/model-parser-where.js +70 -0
- package/dist/model/model-parser.d.ts +292 -0
- package/dist/model/model-parser.js +72 -0
- package/dist/model/parser/Base.d.ts +28 -0
- package/dist/model/parser/Base.js +87 -0
- package/dist/model/parser/DeploymentModelParser.d.ts +33 -0
- package/dist/model/parser/DeploymentModelParser.js +162 -0
- package/dist/model/parser/DeploymentViewParser.d.ts +38 -0
- package/dist/model/parser/DeploymentViewParser.js +98 -0
- package/dist/model/parser/FqnRefParser.d.ts +29 -0
- package/dist/model/parser/FqnRefParser.js +108 -0
- package/dist/model/parser/GlobalsParser.d.ts +66 -0
- package/dist/model/parser/GlobalsParser.js +80 -0
- package/dist/model/parser/ModelParser.d.ts +27 -0
- package/dist/model/parser/ModelParser.js +122 -0
- package/dist/model/parser/PredicatesParser.d.ts +34 -0
- package/dist/model/parser/PredicatesParser.js +272 -0
- package/dist/model/parser/SpecificationParser.d.ts +27 -0
- package/dist/model/parser/SpecificationParser.js +120 -0
- package/dist/model/parser/ViewsParser.d.ts +64 -0
- package/dist/model/parser/ViewsParser.js +377 -0
- package/dist/model-change/ModelChanges.d.ts +15 -0
- package/dist/model-change/ModelChanges.js +89 -0
- package/dist/model-change/changeElementStyle.d.ts +16 -0
- package/dist/model-change/changeElementStyle.js +136 -0
- package/dist/model-change/changeViewLayout.d.ts +12 -0
- package/dist/model-change/changeViewLayout.js +32 -0
- package/dist/model-change/saveManualLayout.d.ts +11 -0
- package/dist/model-change/saveManualLayout.js +27 -0
- package/dist/module.d.ts +62 -0
- package/dist/module.js +123 -0
- package/dist/protocol.d.ts +20 -23
- package/dist/protocol.js +14 -0
- package/dist/references/index.d.ts +3 -0
- package/dist/references/index.js +3 -0
- package/dist/references/name-provider.d.ts +9 -0
- package/dist/references/name-provider.js +33 -0
- package/dist/references/scope-computation.d.ts +20 -0
- package/dist/references/scope-computation.js +281 -0
- package/dist/references/scope-provider.d.ts +16 -0
- package/dist/references/scope-provider.js +165 -0
- package/dist/shared/NodeKindProvider.d.ts +15 -0
- package/dist/shared/NodeKindProvider.js +108 -0
- package/dist/shared/WorkspaceManager.d.ts +18 -0
- package/dist/shared/WorkspaceManager.js +36 -0
- package/dist/shared/WorkspaceSymbolProvider.d.ts +3 -0
- package/dist/shared/WorkspaceSymbolProvider.js +3 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared/index.js +3 -0
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.js +1 -0
- package/dist/test/setup.d.ts +1 -0
- package/dist/test/setup.js +7 -0
- package/dist/test/testServices.d.ts +22 -0
- package/dist/test/testServices.js +119 -0
- package/dist/utils/elementRef.d.ts +11 -0
- package/dist/utils/elementRef.js +15 -0
- package/dist/utils/fqnRef.d.ts +8 -0
- package/dist/utils/fqnRef.js +46 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/printDocs.d.ts +2 -0
- package/dist/utils/printDocs.js +1 -0
- package/dist/utils/stringHash.d.ts +1 -0
- package/dist/utils/stringHash.js +5 -0
- package/dist/validation/_shared.d.ts +3 -0
- package/dist/validation/_shared.js +22 -0
- package/dist/validation/deployment-checks.d.ts +6 -0
- package/dist/validation/deployment-checks.js +114 -0
- package/dist/validation/dynamic-view-rule.d.ts +4 -0
- package/dist/validation/dynamic-view-rule.js +16 -0
- package/dist/validation/dynamic-view-step.d.ts +4 -0
- package/dist/validation/dynamic-view-step.js +33 -0
- package/dist/validation/element.d.ts +4 -0
- package/dist/validation/element.js +49 -0
- package/dist/validation/index.d.ts +15 -0
- package/dist/validation/index.js +152 -0
- package/dist/validation/property-checks.d.ts +6 -0
- package/dist/validation/property-checks.js +38 -0
- package/dist/validation/relation.d.ts +5 -0
- package/dist/validation/relation.js +56 -0
- package/dist/validation/specification.d.ts +11 -0
- package/dist/validation/specification.js +136 -0
- package/dist/validation/view-predicates/element-with.d.ts +4 -0
- package/dist/validation/view-predicates/element-with.js +30 -0
- package/dist/validation/view-predicates/expanded-element.d.ts +4 -0
- package/dist/validation/view-predicates/expanded-element.js +11 -0
- package/dist/validation/view-predicates/expression-v2.d.ts +5 -0
- package/dist/validation/view-predicates/expression-v2.js +83 -0
- package/dist/validation/view-predicates/incoming.d.ts +4 -0
- package/dist/validation/view-predicates/incoming.js +15 -0
- package/dist/validation/view-predicates/index.d.ts +6 -0
- package/dist/validation/view-predicates/index.js +6 -0
- package/dist/validation/view-predicates/outgoing.d.ts +4 -0
- package/dist/validation/view-predicates/outgoing.js +15 -0
- package/dist/validation/view-predicates/relation-with.d.ts +4 -0
- package/dist/validation/view-predicates/relation-with.js +12 -0
- package/dist/validation/view.d.ts +4 -0
- package/dist/validation/view.js +23 -0
- package/dist/view-utils/assignNavigateTo.d.ts +2 -0
- package/dist/view-utils/assignNavigateTo.js +25 -0
- package/dist/view-utils/index.d.ts +2 -0
- package/dist/view-utils/index.js +2 -0
- package/dist/view-utils/manual-layout.d.ts +7 -0
- package/dist/view-utils/manual-layout.js +99 -0
- package/dist/view-utils/resolve-relative-paths.d.ts +2 -0
- package/dist/view-utils/resolve-relative-paths.js +78 -0
- package/package.json +36 -53
- package/src/LikeC4FileSystem.ts +22 -21
- package/src/ast.ts +44 -133
- package/src/browser.ts +10 -11
- package/src/generated/ast.ts +177 -177
- package/src/generated/grammar.ts +1 -1
- package/src/index.ts +10 -8
- package/src/like-c4.langium +37 -34
- package/src/logger.ts +34 -55
- package/src/lsp/CompletionProvider.ts +4 -4
- package/src/lsp/HoverProvider.ts +5 -3
- package/src/lsp/SemanticTokenProvider.ts +2 -2
- package/src/model/deployments-index.ts +18 -14
- package/src/model/model-builder.ts +10 -8
- package/src/model/model-parser.ts +62 -1574
- package/src/model/parser/Base.ts +107 -0
- package/src/model/parser/DeploymentModelParser.ts +192 -0
- package/src/model/parser/DeploymentViewParser.ts +116 -0
- package/src/model/parser/FqnRefParser.ts +118 -0
- package/src/model/parser/GlobalsParser.ts +96 -0
- package/src/model/parser/ModelParser.ts +141 -0
- package/src/model/parser/PredicatesParser.ts +291 -0
- package/src/model/parser/SpecificationParser.ts +133 -0
- package/src/model/parser/ViewsParser.ts +428 -0
- package/src/module.ts +17 -18
- package/src/references/scope-provider.ts +13 -7
- package/src/utils/{deploymentRef.ts → fqnRef.ts} +27 -2
- package/src/validation/_shared.ts +0 -1
- package/src/validation/deployment-checks.ts +49 -62
- package/src/validation/index.ts +100 -9
- package/src/validation/view-predicates/expression-v2.ts +101 -0
- package/src/validation/view-predicates/index.ts +1 -1
- package/src/view-utils/assignNavigateTo.ts +1 -1
- package/src/view-utils/manual-layout.ts +25 -0
- package/dist/browser.cjs +0 -25
- package/dist/browser.d.cts +0 -23
- package/dist/browser.d.mts +0 -23
- package/dist/browser.mjs +0 -20
- package/dist/index.cjs +0 -53
- package/dist/index.d.cts +0 -34
- package/dist/index.d.mts +0 -34
- package/dist/index.mjs +0 -46
- package/dist/likec4lib.cjs +0 -1546
- package/dist/likec4lib.d.cts +0 -6
- package/dist/likec4lib.d.mts +0 -6
- package/dist/protocol.cjs +0 -25
- package/dist/protocol.d.cts +0 -48
- package/dist/protocol.d.mts +0 -48
- package/dist/protocol.mjs +0 -17
- package/dist/shared/language-server.CO_nmHiL.cjs +0 -7689
- package/dist/shared/language-server.Da6ey08o.d.cts +0 -1619
- package/dist/shared/language-server.De7S3e5Z.d.ts +0 -1619
- package/dist/shared/language-server.Dj4iDjtB.d.mts +0 -1619
- package/dist/shared/language-server.oO_9JoAG.mjs +0 -7666
- package/src/validation/view-predicates/deployments.ts +0 -56
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type AstNode } from 'langium';
|
|
2
|
+
import { AbstractFormatter } from 'langium/lsp';
|
|
3
|
+
export declare class LikeC4Formatter extends AbstractFormatter {
|
|
4
|
+
protected format(node: AstNode): void;
|
|
5
|
+
protected formatTags(node: AstNode): void;
|
|
6
|
+
protected formatRelation(node: AstNode): void;
|
|
7
|
+
protected removeIndentFromTopLevelStatements(node: AstNode): void;
|
|
8
|
+
protected indentContentInBraces(node: AstNode): void;
|
|
9
|
+
protected appendKeywordsWithSpace(node: AstNode): void;
|
|
10
|
+
protected formatView(node: AstNode): void;
|
|
11
|
+
protected formatLeafProperty(node: AstNode): void;
|
|
12
|
+
protected formatLinkProperty(node: AstNode): void;
|
|
13
|
+
protected formatNavigateToProperty(node: AstNode): void;
|
|
14
|
+
protected formatAutolayoutProperty(node: AstNode): void;
|
|
15
|
+
protected formatMetadataProperty(node: AstNode): void;
|
|
16
|
+
protected formatElementDeclaration(node: AstNode): void;
|
|
17
|
+
protected formatGlobals(node: AstNode): void;
|
|
18
|
+
protected formatSpecificationRule(node: AstNode): void;
|
|
19
|
+
protected formatWithPredicate(node: AstNode): void;
|
|
20
|
+
protected formatViewRuleGlobalStyle(node: AstNode): void;
|
|
21
|
+
protected formatViewRuleGroup(node: AstNode): void;
|
|
22
|
+
protected formatViewRuleStyle(node: AstNode): void;
|
|
23
|
+
protected formatWhereExpression(node: AstNode): void;
|
|
24
|
+
protected formatIncludeExcludeExpressions(node: AstNode): void;
|
|
25
|
+
private findPredicateExpressionRoot;
|
|
26
|
+
private on;
|
|
27
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { GrammarUtils } from "langium";
|
|
2
|
+
import { AbstractFormatter, Formatting } from "langium/lsp";
|
|
3
|
+
import { filter, isTruthy } from "remeda";
|
|
4
|
+
import * as ast from "../generated/ast.js";
|
|
5
|
+
import * as utils from "./utils.js";
|
|
6
|
+
const FormattingOptions = {
|
|
7
|
+
newLine: Formatting.newLine({ allowMore: true }),
|
|
8
|
+
oneSpace: Formatting.oneSpace(),
|
|
9
|
+
noSpace: Formatting.noSpace(),
|
|
10
|
+
indent: Formatting.indent({ allowMore: true }),
|
|
11
|
+
noIndent: Formatting.noIndent()
|
|
12
|
+
};
|
|
13
|
+
export class LikeC4Formatter extends AbstractFormatter {
|
|
14
|
+
format(node) {
|
|
15
|
+
this.removeIndentFromTopLevelStatements(node);
|
|
16
|
+
this.indentContentInBraces(node);
|
|
17
|
+
this.formatSpecificationRule(node);
|
|
18
|
+
this.formatGlobals(node);
|
|
19
|
+
this.formatElementDeclaration(node);
|
|
20
|
+
this.formatRelation(node);
|
|
21
|
+
this.formatMetadataProperty(node);
|
|
22
|
+
this.formatView(node);
|
|
23
|
+
this.formatViewRuleGroup(node);
|
|
24
|
+
this.formatViewRuleGlobalStyle(node);
|
|
25
|
+
this.formatIncludeExcludeExpressions(node);
|
|
26
|
+
this.formatWhereExpression(node);
|
|
27
|
+
this.formatAutolayoutProperty(node);
|
|
28
|
+
this.formatWithPredicate(node);
|
|
29
|
+
this.formatViewRuleStyle(node);
|
|
30
|
+
this.formatLeafProperty(node);
|
|
31
|
+
this.formatLinkProperty(node);
|
|
32
|
+
this.formatNavigateToProperty(node);
|
|
33
|
+
this.formatTags(node);
|
|
34
|
+
}
|
|
35
|
+
formatTags(node) {
|
|
36
|
+
this.on(node, ast.isTags, (n, f) => {
|
|
37
|
+
f.cst(GrammarUtils.findNodesForProperty(n.$cstNode, "values").slice(1)).prepend(FormattingOptions.oneSpace);
|
|
38
|
+
f.keywords(",").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
formatRelation(node) {
|
|
42
|
+
this.on(node, ast.isRelation, (n, f) => {
|
|
43
|
+
const sourceNodes = n?.source?.$cstNode ? [n?.source?.$cstNode] : [];
|
|
44
|
+
f.cst(sourceNodes).append(FormattingOptions.oneSpace);
|
|
45
|
+
f.keywords("]->").prepend(FormattingOptions.noSpace);
|
|
46
|
+
f.keywords("-[").append(FormattingOptions.noSpace);
|
|
47
|
+
f.nodes(...filter([
|
|
48
|
+
n.target,
|
|
49
|
+
n.tags
|
|
50
|
+
], isTruthy)).prepend(FormattingOptions.oneSpace);
|
|
51
|
+
f.properties("title", "technology").prepend(FormattingOptions.oneSpace);
|
|
52
|
+
});
|
|
53
|
+
this.on(node, ast.isDynamicViewStep, (n, f) => {
|
|
54
|
+
f.keywords("->", "<-").surround(FormattingOptions.oneSpace);
|
|
55
|
+
const kind = f.property("kind");
|
|
56
|
+
kind.nodes[0]?.text.startsWith(".") && kind.surround(FormattingOptions.oneSpace);
|
|
57
|
+
f.keywords("]->").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
|
|
58
|
+
f.keywords("-[").prepend(FormattingOptions.oneSpace).append(FormattingOptions.noSpace);
|
|
59
|
+
f.properties("title").prepend(FormattingOptions.oneSpace);
|
|
60
|
+
});
|
|
61
|
+
this.on(node, ast.isDirectedRelationExpression)?.property("target").prepend(FormattingOptions.oneSpace);
|
|
62
|
+
this.on(node, ast.isOutgoingRelationExpression, (n, f) => {
|
|
63
|
+
f.property("from").append(FormattingOptions.oneSpace);
|
|
64
|
+
f.keywords("]->").prepend(FormattingOptions.noSpace);
|
|
65
|
+
f.keywords("-[").append(FormattingOptions.noSpace);
|
|
66
|
+
});
|
|
67
|
+
this.on(node, ast.isIncomingRelationExpression)?.keywords("->").append(FormattingOptions.oneSpace);
|
|
68
|
+
this.on(node, ast.isInOutRelationExpression)?.keyword("->").prepend(FormattingOptions.oneSpace);
|
|
69
|
+
}
|
|
70
|
+
removeIndentFromTopLevelStatements(node) {
|
|
71
|
+
if (ast.isModel(node) || ast.isSpecificationRule(node) || ast.isModelViews(node) || ast.isLikeC4Lib(node) || ast.isGlobals(node)) {
|
|
72
|
+
const formatter = this.getNodeFormatter(node);
|
|
73
|
+
formatter.keywords("specification", "model", "views", "likec4lib", "global").prepend(FormattingOptions.noIndent);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
indentContentInBraces(node) {
|
|
77
|
+
if (ast.isLikeC4Lib(node) || ast.isSpecificationRule(node) || ast.isSpecificationElementKind(node) || ast.isSpecificationRelationshipKind(node) || ast.isGlobals(node) || ast.isGlobalStyle(node) || ast.isGlobalStyleGroup(node) || ast.isModel(node) || ast.isElementBody(node) || ast.isExtendElementBody(node) || ast.isRelationBody(node) || ast.isRelationStyleProperty(node) || ast.isMetadataBody(node) || ast.isModelViews(node) || ast.isElementViewBody(node) || ast.isDynamicViewBody(node) || ast.isViewRuleStyle(node) || ast.isViewRuleGroup(node) || ast.isCustomElementProperties(node) || ast.isCustomRelationProperties(node) || ast.isElementStyleProperty(node) || ast.isDynamicViewParallelSteps(node)) {
|
|
78
|
+
const formatter = this.getNodeFormatter(node);
|
|
79
|
+
const openBrace = formatter.keywords("{");
|
|
80
|
+
const closeBrace = formatter.keywords("}");
|
|
81
|
+
const interiorNodes = formatter.interior(openBrace, closeBrace);
|
|
82
|
+
let perviousNode = null;
|
|
83
|
+
for (const interiorNode of interiorNodes.nodes) {
|
|
84
|
+
if (!perviousNode || !utils.areOverlap(perviousNode, interiorNode)) {
|
|
85
|
+
formatter.cst([interiorNode]).prepend(FormattingOptions.indent);
|
|
86
|
+
}
|
|
87
|
+
perviousNode = interiorNode;
|
|
88
|
+
}
|
|
89
|
+
openBrace.prepend(FormattingOptions.noIndent).prepend(FormattingOptions.oneSpace);
|
|
90
|
+
closeBrace.prepend(FormattingOptions.noIndent).prepend(Formatting.newLine({ allowMore: true }));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
appendKeywordsWithSpace(node) {
|
|
94
|
+
this.on(node, ast.isElementKind)?.keywords("element").append(FormattingOptions.oneSpace);
|
|
95
|
+
}
|
|
96
|
+
formatView(node) {
|
|
97
|
+
this.on(node, ast.isElementView, (n, f) => {
|
|
98
|
+
if (n.extends || n.viewOf || n.name) {
|
|
99
|
+
f.keywords("view").append(FormattingOptions.oneSpace);
|
|
100
|
+
}
|
|
101
|
+
f.keywords("of", "extends").surround(FormattingOptions.oneSpace);
|
|
102
|
+
});
|
|
103
|
+
this.on(node, ast.isDynamicView)?.keywords("dynamic", "view").append(FormattingOptions.oneSpace);
|
|
104
|
+
}
|
|
105
|
+
formatLeafProperty(node) {
|
|
106
|
+
if (ast.isElementStringProperty(node) || ast.isRelationStringProperty(node) || ast.isViewStringProperty(node) || ast.isNotationProperty(node) || ast.isSpecificationElementStringProperty(node) || ast.isSpecificationRelationshipStringProperty(node) || ast.isColorProperty(node) || ast.isLineProperty(node) || ast.isArrowProperty(node) || ast.isIconProperty(node) || ast.isShapeProperty(node) || ast.isBorderProperty(node) || ast.isOpacityProperty(node)) {
|
|
107
|
+
const formatter = this.getNodeFormatter(node);
|
|
108
|
+
const colon = formatter.keyword(":");
|
|
109
|
+
const propertyName = formatter.keywords(
|
|
110
|
+
"title",
|
|
111
|
+
"description",
|
|
112
|
+
"technology",
|
|
113
|
+
"notation",
|
|
114
|
+
"color",
|
|
115
|
+
"line",
|
|
116
|
+
"head",
|
|
117
|
+
"tail",
|
|
118
|
+
"icon",
|
|
119
|
+
"shape",
|
|
120
|
+
"border",
|
|
121
|
+
"opacity"
|
|
122
|
+
);
|
|
123
|
+
if (colon.nodes.length === 0) {
|
|
124
|
+
propertyName.append(FormattingOptions.oneSpace);
|
|
125
|
+
} else {
|
|
126
|
+
colon.prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
|
|
127
|
+
}
|
|
128
|
+
formatter.keyword(";").prepend(FormattingOptions.noSpace).append(FormattingOptions.newLine);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
formatLinkProperty(node) {
|
|
132
|
+
this.on(node, ast.isLinkProperty, (n, f) => {
|
|
133
|
+
f.keyword("link").append(FormattingOptions.oneSpace);
|
|
134
|
+
f.property("value").append(FormattingOptions.oneSpace);
|
|
135
|
+
f.keyword(":").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
|
|
136
|
+
f.keyword(";").prepend(FormattingOptions.noSpace).append(FormattingOptions.newLine);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
formatNavigateToProperty(node) {
|
|
140
|
+
this.on(node, ast.isNavigateToProperty)?.property("key").append(FormattingOptions.oneSpace);
|
|
141
|
+
}
|
|
142
|
+
formatAutolayoutProperty(node) {
|
|
143
|
+
this.on(node, ast.isViewRuleAutoLayout, (n, f) => {
|
|
144
|
+
f.keyword("autoLayout").append(FormattingOptions.oneSpace);
|
|
145
|
+
f.property("rankSep").prepend(FormattingOptions.oneSpace);
|
|
146
|
+
f.property("nodeSep").prepend(FormattingOptions.oneSpace);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
formatMetadataProperty(node) {
|
|
150
|
+
this.on(node, ast.isMetadataAttribute, (n, f) => {
|
|
151
|
+
f.property("key").append(FormattingOptions.oneSpace);
|
|
152
|
+
f.keyword(":").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
|
|
153
|
+
f.keyword(";").prepend(FormattingOptions.noSpace).append(FormattingOptions.newLine);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
formatElementDeclaration(node) {
|
|
157
|
+
this.on(node, ast.isElement, (n, f) => {
|
|
158
|
+
const kind = GrammarUtils.findNodeForProperty(n.$cstNode, "kind");
|
|
159
|
+
const name = GrammarUtils.findNodeForProperty(n.$cstNode, "name");
|
|
160
|
+
if (name && kind) {
|
|
161
|
+
if (utils.compareRanges(name, kind) > 0) {
|
|
162
|
+
f.cst([kind]).append(FormattingOptions.oneSpace);
|
|
163
|
+
} else {
|
|
164
|
+
f.cst([name]).append(FormattingOptions.oneSpace);
|
|
165
|
+
f.cst([kind]).prepend(FormattingOptions.oneSpace);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
f.properties("props").prepend(FormattingOptions.oneSpace);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
formatGlobals(node) {
|
|
172
|
+
this.on(node, ast.isGlobalStyle, (n, f) => {
|
|
173
|
+
f.keyword("style").append(FormattingOptions.oneSpace);
|
|
174
|
+
f.property("id").append(FormattingOptions.oneSpace);
|
|
175
|
+
});
|
|
176
|
+
this.on(node, ast.isGlobalStyleGroup, (n, f) => {
|
|
177
|
+
f.keyword("styleGroup").append(FormattingOptions.oneSpace);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
formatSpecificationRule(node) {
|
|
181
|
+
if (ast.isSpecificationElementKind(node) || ast.isSpecificationRelationshipKind(node) || ast.isSpecificationTag(node)) {
|
|
182
|
+
const formatter = this.getNodeFormatter(node);
|
|
183
|
+
formatter.keywords("element", "relationship", "tag").append(FormattingOptions.oneSpace);
|
|
184
|
+
}
|
|
185
|
+
if (ast.isSpecificationColor(node)) {
|
|
186
|
+
const formatter = this.getNodeFormatter(node);
|
|
187
|
+
formatter.keyword("color").append(FormattingOptions.oneSpace);
|
|
188
|
+
formatter.property("name").append(FormattingOptions.oneSpace);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
formatWithPredicate(node) {
|
|
192
|
+
const formatter = this.getNodeFormatter(node);
|
|
193
|
+
if (ast.isElementPredicateWith(node) || ast.isRelationPredicateWith(node)) {
|
|
194
|
+
formatter.keyword("with").prepend(FormattingOptions.oneSpace);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
formatViewRuleGlobalStyle(node) {
|
|
198
|
+
this.on(node, ast.isViewRuleGlobalStyle, (n, f) => {
|
|
199
|
+
f.keywords("global", "style").append(FormattingOptions.oneSpace);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
formatViewRuleGroup(node) {
|
|
203
|
+
this.on(node, ast.isViewRuleGroup, (n, f) => {
|
|
204
|
+
f.keyword("group").append(FormattingOptions.oneSpace);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
formatViewRuleStyle(node) {
|
|
208
|
+
this.on(node, ast.isViewRuleStyle)?.keyword("style").append(FormattingOptions.oneSpace);
|
|
209
|
+
this.on(node, ast.isElementExpressionsIterator)?.keyword(",").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
|
|
210
|
+
}
|
|
211
|
+
formatWhereExpression(node) {
|
|
212
|
+
if (ast.isRelationPredicateOrWhere(node) || ast.isElementPredicateOrWhere(node)) {
|
|
213
|
+
const formatter = this.getNodeFormatter(node);
|
|
214
|
+
formatter.keyword("where").append(FormattingOptions.oneSpace);
|
|
215
|
+
}
|
|
216
|
+
if (ast.isWhereRelationExpression(node) || ast.isWhereElementExpression(node)) {
|
|
217
|
+
const formatter = this.getNodeFormatter(node);
|
|
218
|
+
formatter.property("operator").surround(FormattingOptions.oneSpace);
|
|
219
|
+
}
|
|
220
|
+
if (ast.isWhereElementNegation(node) || ast.isWhereRelationNegation(node)) {
|
|
221
|
+
const formatter = this.getNodeFormatter(node);
|
|
222
|
+
formatter.keyword("not").append(FormattingOptions.oneSpace);
|
|
223
|
+
}
|
|
224
|
+
if (ast.isWhereElement(node) || ast.isWhereElementTag(node) || ast.isWhereElementKind(node) || ast.isWhereRelation(node) || ast.isWhereRelationTag(node) || ast.isWhereRelationKind(node)) {
|
|
225
|
+
const formatter = this.getNodeFormatter(node);
|
|
226
|
+
formatter.property("operator").surround(FormattingOptions.oneSpace);
|
|
227
|
+
formatter.property("not").surround(FormattingOptions.oneSpace);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
formatIncludeExcludeExpressions(node) {
|
|
231
|
+
if (ast.isDynamicViewRule(node) || ast.isIncludePredicate(node) || ast.isExcludePredicate(node)) {
|
|
232
|
+
const formatter = this.getNodeFormatter(node);
|
|
233
|
+
if (!node.$cstNode || !utils.isMultiline(node.$cstNode)) {
|
|
234
|
+
formatter.keywords("include", "exclude").append(FormattingOptions.oneSpace);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (ast.isDynamicViewPredicateIterator(node) || ast.isPredicates(node) || ast.isPredicates(node)) {
|
|
238
|
+
const formatter = this.getNodeFormatter(node);
|
|
239
|
+
const parent = this.findPredicateExpressionRoot(node);
|
|
240
|
+
const isMultiline = parent?.$cstNode && utils.isMultiline(parent?.$cstNode);
|
|
241
|
+
if (isMultiline) {
|
|
242
|
+
formatter.property("value").prepend(FormattingOptions.indent);
|
|
243
|
+
}
|
|
244
|
+
formatter.keyword(",").prepend(FormattingOptions.noSpace).append(isMultiline ? FormattingOptions.newLine : FormattingOptions.oneSpace);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
findPredicateExpressionRoot(node) {
|
|
248
|
+
let parent = node.$container;
|
|
249
|
+
while (true) {
|
|
250
|
+
if (!parent || ast.isDynamicViewRule(parent) || ast.isIncludePredicate(parent) || ast.isExcludePredicate(parent)) {
|
|
251
|
+
return parent;
|
|
252
|
+
}
|
|
253
|
+
parent = parent.$container;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
on(node, predicate, format) {
|
|
257
|
+
const formatter = predicate(node) ? this.getNodeFormatter(node) : void 0;
|
|
258
|
+
format && formatter && format(node, formatter);
|
|
259
|
+
return formatter;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CstNode } from "langium";
|
|
2
|
+
import type { Position, Range } from "vscode-languageserver-types";
|
|
3
|
+
export declare function areOverlap(a: CstNode, b: CstNode): boolean;
|
|
4
|
+
export declare function compareRanges(a: CstNode, b: CstNode): number;
|
|
5
|
+
export declare function isInRagne(range: Range, pos: Position): boolean;
|
|
6
|
+
export declare function isMultiline(node: CstNode): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function areOverlap(a, b) {
|
|
2
|
+
;
|
|
3
|
+
[a, b] = compareRanges(a, b) > 0 ? [b, a] : [a, b];
|
|
4
|
+
return isInRagne(a.range, b.range.start);
|
|
5
|
+
}
|
|
6
|
+
export function compareRanges(a, b) {
|
|
7
|
+
const lineDiff = a.range.start.line - b.range.start.line;
|
|
8
|
+
return lineDiff !== 0 ? lineDiff : a.range.start.character - b.range.start.character;
|
|
9
|
+
}
|
|
10
|
+
export function isInRagne(range, pos) {
|
|
11
|
+
return !(pos.line < range.start.line || pos.line > range.end.line || pos.line == range.start.line && pos.character < range.start.character || pos.line == range.end.line && pos.character > range.end.character);
|
|
12
|
+
}
|
|
13
|
+
export function isMultiline(node) {
|
|
14
|
+
return node.range.start.line != node.range.end.line;
|
|
15
|
+
}
|