@likec4/language-server 1.47.0 → 1.48.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/LICENSE +1 -1
- package/browser/package.json +2 -2
- package/browser-worker/package.json +2 -2
- package/bundled/package.json +4 -0
- package/dist/LikeC4LanguageServices.d.mts +4 -0
- package/dist/LikeC4LanguageServices.mjs +3 -0
- package/dist/_chunks/ConfigurableLayouter.mjs +1956 -0
- package/dist/_chunks/LikeC4LanguageServices.d.mts +1978 -0
- package/dist/_chunks/LikeC4LanguageServices.mjs +725 -0
- package/dist/_chunks/ast.d.mts +1444 -0
- package/dist/_chunks/ast.mjs +2375 -0
- package/dist/_chunks/ast2.mjs +176 -0
- package/dist/_chunks/common-exports.mjs +0 -0
- package/dist/_chunks/filesystem.mjs +58 -0
- package/dist/_chunks/grammar.mjs +8 -0
- package/dist/_chunks/icons.mjs +5211 -0
- package/dist/_chunks/libs/@hono/node-server.mjs +436 -0
- package/dist/_chunks/libs/@msgpack/msgpack.mjs +805 -0
- package/dist/_chunks/libs/eventemitter3.mjs +243 -0
- package/dist/_chunks/libs/fast-equals.mjs +446 -0
- package/dist/_chunks/libs/hono.mjs +1829 -0
- package/dist/_chunks/libs/p-queue.mjs +449 -0
- package/dist/_chunks/libs/parse-ms.mjs +36 -0
- package/dist/_chunks/libs/picomatch.mjs +1673 -0
- package/dist/_chunks/libs/pretty-ms.mjs +80 -0
- package/dist/_chunks/libs/remeda.mjs +482 -0
- package/dist/_chunks/libs/strip-indent.mjs +15 -0
- package/dist/_chunks/libs/ufo.mjs +166 -0
- package/dist/_chunks/likec4lib.mjs +9 -0
- package/dist/_chunks/mcp.mjs +33 -0
- package/dist/_chunks/module.mjs +28 -0
- package/dist/_chunks/module2.mjs +6576 -0
- package/dist/_chunks/protocol.d.mts +311 -0
- package/dist/_chunks/protocol.mjs +78 -0
- package/dist/_chunks/rolldown-runtime.mjs +42 -0
- package/dist/ast.d.mts +4 -0
- package/dist/ast.mjs +4 -0
- package/dist/browser-worker.d.mts +1 -0
- package/dist/browser-worker.mjs +6 -0
- package/dist/browser.d.mts +11 -0
- package/dist/browser.mjs +27 -0
- package/dist/bundled.d.mts +28 -0
- package/dist/bundled.mjs +51 -4853
- package/dist/common-exports.d.mts +4 -0
- package/dist/common-exports.mjs +5 -0
- package/dist/filesystem/index.d.mts +4 -0
- package/dist/filesystem/index.mjs +3 -0
- package/dist/generated/ast.d.mts +2 -0
- package/dist/generated/ast.mjs +3 -0
- package/dist/generated/grammar.d.mts +6 -0
- package/dist/generated/grammar.mjs +3 -0
- package/dist/generated/module.d.mts +14 -0
- package/dist/generated/module.mjs +3 -0
- package/dist/generated-lib/icons.d.mts +4 -0
- package/dist/generated-lib/icons.mjs +3 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +48 -0
- package/dist/likec4lib.d.mts +9 -0
- package/dist/likec4lib.mjs +4 -0
- package/dist/mcp/index.d.mts +4 -0
- package/dist/mcp/index.mjs +3 -0
- package/dist/module.d.mts +4 -0
- package/dist/module.mjs +3 -0
- package/dist/protocol.d.mts +2 -0
- package/dist/protocol.mjs +3 -0
- package/likec4lib/package.json +2 -2
- package/package.json +106 -63
- package/protocol/package.json +2 -2
- package/dist/LikeC4LanguageServices.d.ts +0 -115
- package/dist/LikeC4LanguageServices.js +0 -164
- package/dist/Rpc.d.ts +0 -9
- package/dist/Rpc.js +0 -276
- package/dist/ast.d.ts +0 -226
- package/dist/ast.js +0 -264
- package/dist/browser-worker.d.ts +0 -1
- package/dist/browser-worker.js +0 -4
- package/dist/browser.d.ts +0 -10
- package/dist/browser.js +0 -34
- package/dist/bundled.d.ts +0 -8
- package/dist/bundled.js +0 -44
- package/dist/documentation/documentation-provider.d.ts +0 -8
- package/dist/documentation/documentation-provider.js +0 -51
- package/dist/documentation/index.d.ts +0 -1
- package/dist/documentation/index.js +0 -1
- package/dist/empty.d.ts +0 -2
- package/dist/empty.js +0 -2
- package/dist/filesystem/ChokidarWatcher.d.ts +0 -19
- package/dist/filesystem/ChokidarWatcher.js +0 -133
- package/dist/filesystem/FileSystemWatcher.d.ts +0 -19
- package/dist/filesystem/FileSystemWatcher.js +0 -14
- package/dist/filesystem/LikeC4FileSystem.d.ts +0 -3
- package/dist/filesystem/LikeC4FileSystem.js +0 -140
- package/dist/filesystem/index.d.ts +0 -55
- package/dist/filesystem/index.js +0 -29
- package/dist/formatting/LikeC4Formatter.d.ts +0 -59
- package/dist/formatting/LikeC4Formatter.js +0 -637
- package/dist/formatting/utils.d.ts +0 -6
- package/dist/formatting/utils.js +0 -18
- package/dist/generated/ast.d.ts +0 -1411
- package/dist/generated/ast.js +0 -2207
- package/dist/generated/grammar.d.ts +0 -6
- package/dist/generated/grammar.js +0 -7
- package/dist/generated/module.d.ts +0 -14
- package/dist/generated/module.js +0 -27
- package/dist/generated-lib/icons.d.ts +0 -1
- package/dist/generated-lib/icons.js +0 -18
- package/dist/index.d.ts +0 -37
- package/dist/index.js +0 -54
- package/dist/likec4lib.d.ts +0 -6
- package/dist/likec4lib.js +0 -7
- package/dist/logger.d.ts +0 -17
- package/dist/logger.js +0 -81
- package/dist/lsp/CodeActionProvider.d.ts +0 -14
- package/dist/lsp/CodeActionProvider.js +0 -33
- package/dist/lsp/CodeLensProvider.d.ts +0 -9
- package/dist/lsp/CodeLensProvider.js +0 -44
- package/dist/lsp/CompletionProvider.d.ts +0 -13
- package/dist/lsp/CompletionProvider.js +0 -238
- package/dist/lsp/DocumentHighlightProvider.d.ts +0 -9
- package/dist/lsp/DocumentHighlightProvider.js +0 -10
- package/dist/lsp/DocumentLinkProvider.d.ts +0 -11
- package/dist/lsp/DocumentLinkProvider.js +0 -58
- package/dist/lsp/DocumentSymbolProvider.d.ts +0 -33
- package/dist/lsp/DocumentSymbolProvider.js +0 -317
- package/dist/lsp/HoverProvider.d.ts +0 -10
- package/dist/lsp/HoverProvider.js +0 -106
- package/dist/lsp/RenameProvider.d.ts +0 -5
- package/dist/lsp/RenameProvider.js +0 -6
- package/dist/lsp/SemanticTokenProvider.d.ts +0 -19
- package/dist/lsp/SemanticTokenProvider.js +0 -305
- package/dist/lsp/index.d.ts +0 -8
- package/dist/lsp/index.js +0 -9
- package/dist/mcp/MCPServerFactory.d.ts +0 -8
- package/dist/mcp/MCPServerFactory.js +0 -73
- package/dist/mcp/NoopLikeC4MCPServer.d.ts +0 -9
- package/dist/mcp/NoopLikeC4MCPServer.js +0 -17
- package/dist/mcp/interfaces.d.ts +0 -13
- package/dist/mcp/interfaces.js +0 -4
- package/dist/mcp/server/StdioLikeC4MCPServer.d.ts +0 -16
- package/dist/mcp/server/StdioLikeC4MCPServer.js +0 -51
- package/dist/mcp/server/StreamableLikeC4MCPServer.d.ts +0 -16
- package/dist/mcp/server/StreamableLikeC4MCPServer.js +0 -121
- package/dist/mcp/server/WithMCPServer.d.ts +0 -4
- package/dist/mcp/server/WithMCPServer.js +0 -54
- package/dist/mcp/tools/_common.d.ts +0 -88
- package/dist/mcp/tools/_common.js +0 -49
- package/dist/mcp/tools/find-relationships.d.ts +0 -202
- package/dist/mcp/tools/find-relationships.js +0 -150
- package/dist/mcp/tools/list-projects.d.ts +0 -194
- package/dist/mcp/tools/list-projects.js +0 -62
- package/dist/mcp/tools/open-view.d.ts +0 -200
- package/dist/mcp/tools/open-view.js +0 -52
- package/dist/mcp/tools/read-deployment.d.ts +0 -200
- package/dist/mcp/tools/read-deployment.js +0 -150
- package/dist/mcp/tools/read-element.d.ts +0 -200
- package/dist/mcp/tools/read-element.js +0 -218
- package/dist/mcp/tools/read-project-summary.d.ts +0 -198
- package/dist/mcp/tools/read-project-summary.js +0 -176
- package/dist/mcp/tools/read-view.d.ts +0 -200
- package/dist/mcp/tools/read-view.js +0 -203
- package/dist/mcp/tools/search-element.d.ts +0 -198
- package/dist/mcp/tools/search-element.js +0 -177
- package/dist/mcp/utils.d.ts +0 -18
- package/dist/mcp/utils.js +0 -48
- package/dist/model/builder/MergedExtends.d.ts +0 -13
- package/dist/model/builder/MergedExtends.js +0 -74
- package/dist/model/builder/MergedSpecification.d.ts +0 -32
- package/dist/model/builder/MergedSpecification.js +0 -175
- package/dist/model/builder/buildModel.d.ts +0 -16
- package/dist/model/builder/buildModel.js +0 -245
- package/dist/model/deployments-index.d.ts +0 -10
- package/dist/model/deployments-index.js +0 -102
- package/dist/model/fqn-index.d.ts +0 -61
- package/dist/model/fqn-index.js +0 -253
- package/dist/model/index.d.ts +0 -6
- package/dist/model/index.js +0 -6
- package/dist/model/model-builder.d.ts +0 -54
- package/dist/model/model-builder.js +0 -233
- package/dist/model/model-locator.d.ts +0 -39
- package/dist/model/model-locator.js +0 -240
- package/dist/model/model-parser-where.d.ts +0 -4
- package/dist/model/model-parser-where.js +0 -81
- package/dist/model/model-parser.d.ts +0 -645
- package/dist/model/model-parser.js +0 -133
- package/dist/model/parser/Base.d.ts +0 -69
- package/dist/model/parser/Base.js +0 -382
- package/dist/model/parser/DeploymentModelParser.d.ts +0 -71
- package/dist/model/parser/DeploymentModelParser.js +0 -176
- package/dist/model/parser/DeploymentViewParser.d.ts +0 -75
- package/dist/model/parser/DeploymentViewParser.js +0 -86
- package/dist/model/parser/FqnRefParser.d.ts +0 -66
- package/dist/model/parser/FqnRefParser.js +0 -382
- package/dist/model/parser/GlobalsParser.d.ts +0 -109
- package/dist/model/parser/GlobalsParser.js +0 -84
- package/dist/model/parser/ImportsParser.d.ts +0 -46
- package/dist/model/parser/ImportsParser.js +0 -24
- package/dist/model/parser/ModelParser.d.ts +0 -71
- package/dist/model/parser/ModelParser.js +0 -209
- package/dist/model/parser/PredicatesParser.d.ts +0 -75
- package/dist/model/parser/PredicatesParser.js +0 -45
- package/dist/model/parser/SpecificationParser.d.ts +0 -53
- package/dist/model/parser/SpecificationParser.js +0 -113
- package/dist/model/parser/ValueConverter.d.ts +0 -4
- package/dist/model/parser/ValueConverter.js +0 -12
- package/dist/model/parser/ViewsParser.d.ts +0 -112
- package/dist/model/parser/ViewsParser.js +0 -492
- package/dist/model-change/ModelChanges.d.ts +0 -18
- package/dist/model-change/ModelChanges.js +0 -129
- package/dist/model-change/changeElementStyle.d.ts +0 -16
- package/dist/model-change/changeElementStyle.js +0 -134
- package/dist/model-change/changeViewLayout.d.ts +0 -12
- package/dist/model-change/changeViewLayout.js +0 -28
- package/dist/model-change/removeManualLayoutV1.d.ts +0 -7
- package/dist/model-change/removeManualLayoutV1.js +0 -27
- package/dist/module.d.ts +0 -92
- package/dist/module.js +0 -143
- package/dist/protocol.d.ts +0 -289
- package/dist/protocol.js +0 -123
- package/dist/references/index.d.ts +0 -3
- package/dist/references/index.js +0 -3
- package/dist/references/name-provider.d.ts +0 -9
- package/dist/references/name-provider.js +0 -37
- package/dist/references/scope-computation.d.ts +0 -20
- package/dist/references/scope-computation.js +0 -288
- package/dist/references/scope-provider.d.ts +0 -40
- package/dist/references/scope-provider.js +0 -239
- package/dist/shared/NodeKindProvider.d.ts +0 -15
- package/dist/shared/NodeKindProvider.js +0 -57
- package/dist/shared/WorkspaceSymbolProvider.d.ts +0 -3
- package/dist/shared/WorkspaceSymbolProvider.js +0 -3
- package/dist/shared/index.d.ts +0 -2
- package/dist/shared/index.js +0 -2
- package/dist/test/index.d.ts +0 -1
- package/dist/test/index.js +0 -1
- package/dist/test/testServices.d.ts +0 -64
- package/dist/test/testServices.js +0 -210
- package/dist/utils/disposable.d.ts +0 -8
- package/dist/utils/disposable.js +0 -26
- package/dist/utils/elementRef.d.ts +0 -11
- package/dist/utils/elementRef.js +0 -33
- package/dist/utils/fqnRef.d.ts +0 -11
- package/dist/utils/fqnRef.js +0 -63
- package/dist/utils/index.d.ts +0 -11
- package/dist/utils/index.js +0 -35
- package/dist/utils/printDocs.d.ts +0 -2
- package/dist/utils/printDocs.js +0 -1
- package/dist/utils/projectId.d.ts +0 -4
- package/dist/utils/projectId.js +0 -16
- package/dist/utils/stringHash.d.ts +0 -1
- package/dist/utils/stringHash.js +0 -5
- package/dist/validation/DocumentValidator.d.ts +0 -11
- package/dist/validation/DocumentValidator.js +0 -17
- package/dist/validation/_shared.d.ts +0 -3
- package/dist/validation/_shared.js +0 -26
- package/dist/validation/deployment-checks.d.ts +0 -7
- package/dist/validation/deployment-checks.js +0 -140
- package/dist/validation/dynamic-view.d.ts +0 -6
- package/dist/validation/dynamic-view.js +0 -67
- package/dist/validation/element-ref.d.ts +0 -4
- package/dist/validation/element-ref.js +0 -12
- package/dist/validation/element.d.ts +0 -4
- package/dist/validation/element.js +0 -49
- package/dist/validation/imports.d.ts +0 -4
- package/dist/validation/imports.js +0 -46
- package/dist/validation/index.d.ts +0 -15
- package/dist/validation/index.js +0 -167
- package/dist/validation/property-checks.d.ts +0 -7
- package/dist/validation/property-checks.js +0 -108
- package/dist/validation/relation.d.ts +0 -6
- package/dist/validation/relation.js +0 -141
- package/dist/validation/specification.d.ts +0 -12
- package/dist/validation/specification.js +0 -190
- package/dist/validation/view-checks.d.ts +0 -4
- package/dist/validation/view-checks.js +0 -46
- package/dist/validation/view-predicates/fqn-expr-with.d.ts +0 -4
- package/dist/validation/view-predicates/fqn-expr-with.js +0 -43
- package/dist/validation/view-predicates/fqn-ref-expr.d.ts +0 -4
- package/dist/validation/view-predicates/fqn-ref-expr.js +0 -51
- package/dist/validation/view-predicates/incoming.d.ts +0 -4
- package/dist/validation/view-predicates/incoming.js +0 -16
- package/dist/validation/view-predicates/index.d.ts +0 -6
- package/dist/validation/view-predicates/index.js +0 -6
- package/dist/validation/view-predicates/outgoing.d.ts +0 -4
- package/dist/validation/view-predicates/outgoing.js +0 -20
- package/dist/validation/view-predicates/relation-expr.d.ts +0 -4
- package/dist/validation/view-predicates/relation-expr.js +0 -46
- package/dist/validation/view-predicates/relation-with.d.ts +0 -4
- package/dist/validation/view-predicates/relation-with.js +0 -16
- package/dist/validation/view.d.ts +0 -4
- package/dist/validation/view.js +0 -42
- package/dist/view-utils/assignNavigateTo.d.ts +0 -2
- package/dist/view-utils/assignNavigateTo.js +0 -27
- package/dist/view-utils/index.d.ts +0 -2
- package/dist/view-utils/index.js +0 -2
- package/dist/view-utils/manual-layout.d.ts +0 -13
- package/dist/view-utils/manual-layout.js +0 -149
- package/dist/views/ConfigurableLayouter.d.ts +0 -7
- package/dist/views/ConfigurableLayouter.js +0 -51
- package/dist/views/LikeC4ManualLayouts.d.ts +0 -42
- package/dist/views/LikeC4ManualLayouts.js +0 -209
- package/dist/views/LikeC4Views.d.ts +0 -89
- package/dist/views/LikeC4Views.js +0 -216
- package/dist/views/index.d.ts +0 -4
- package/dist/views/index.js +0 -11
- package/dist/workspace/AstNodeDescriptionProvider.d.ts +0 -7
- package/dist/workspace/AstNodeDescriptionProvider.js +0 -18
- package/dist/workspace/IndexManager.d.ts +0 -10
- package/dist/workspace/IndexManager.js +0 -26
- package/dist/workspace/LangiumDocuments.d.ts +0 -29
- package/dist/workspace/LangiumDocuments.js +0 -104
- package/dist/workspace/ProjectsManager.d.ts +0 -134
- package/dist/workspace/ProjectsManager.js +0 -610
- package/dist/workspace/WorkspaceManager.d.ts +0 -31
- package/dist/workspace/WorkspaceManager.js +0 -132
- package/dist/workspace/index.d.ts +0 -5
- package/dist/workspace/index.js +0 -5
|
@@ -1,637 +0,0 @@
|
|
|
1
|
-
import { nonexhaustive } from '@likec4/core';
|
|
2
|
-
import { GrammarUtils, } from 'langium';
|
|
3
|
-
import { AbstractFormatter, Formatting, FormattingRegion } from 'langium/lsp';
|
|
4
|
-
import { filter, isTruthy } from 'remeda';
|
|
5
|
-
import * as ast from '../generated/ast';
|
|
6
|
-
import * as utils from './utils';
|
|
7
|
-
import { isMultiline } from './utils';
|
|
8
|
-
const FormattingOptions = {
|
|
9
|
-
newLine: Formatting.newLine({ allowMore: true }),
|
|
10
|
-
oneSpace: Formatting.oneSpace(),
|
|
11
|
-
noSpace: Formatting.noSpace(),
|
|
12
|
-
indent: Formatting.indent({ allowMore: true }),
|
|
13
|
-
noIndent: Formatting.noIndent(),
|
|
14
|
-
};
|
|
15
|
-
export class LikeC4Formatter extends AbstractFormatter {
|
|
16
|
-
options = {
|
|
17
|
-
quoteStyle: 'auto',
|
|
18
|
-
};
|
|
19
|
-
extendedFormattingCommands = [];
|
|
20
|
-
constructor(services) {
|
|
21
|
-
super();
|
|
22
|
-
services.shared.workspace.ConfigurationProvider.onConfigurationSectionUpdate(update => this.onConfigurationUpdate(update.configuration.formatting));
|
|
23
|
-
}
|
|
24
|
-
doDocumentFormat(document, options, range) {
|
|
25
|
-
this.extendedFormattingCommands = [];
|
|
26
|
-
const edits = super.doDocumentFormat(document, options, range);
|
|
27
|
-
this.doExtendedFormatting(edits);
|
|
28
|
-
return edits;
|
|
29
|
-
}
|
|
30
|
-
format(node) {
|
|
31
|
-
this.removeIndentFromTopLevelStatements(node);
|
|
32
|
-
this.indentContentInBraces(node);
|
|
33
|
-
this.normalizeQuotes(node);
|
|
34
|
-
// Imports
|
|
35
|
-
this.formatImports(node);
|
|
36
|
-
// Specification
|
|
37
|
-
this.formatSpecificationRule(node);
|
|
38
|
-
// Globals
|
|
39
|
-
this.formatGlobals(node);
|
|
40
|
-
// Models
|
|
41
|
-
this.formatElementDeclaration(node);
|
|
42
|
-
this.formatExtendElement(node);
|
|
43
|
-
this.formatRelation(node);
|
|
44
|
-
this.formatMetadataProperty(node);
|
|
45
|
-
// Deployment
|
|
46
|
-
this.formatDeploymentNodeDeclaration(node);
|
|
47
|
-
this.formatDeployedInstance(node);
|
|
48
|
-
this.formatDeploymentRelation(node);
|
|
49
|
-
this.formatExtendDeployment(node);
|
|
50
|
-
// Views
|
|
51
|
-
this.formatView(node);
|
|
52
|
-
this.formatViewRuleGroup(node);
|
|
53
|
-
this.formatViewRuleGlobalStyle(node);
|
|
54
|
-
this.formatViewRuleGlobalPredicate(node);
|
|
55
|
-
this.formatIncludeExcludeExpressions(node);
|
|
56
|
-
this.formatWhereExpression(node);
|
|
57
|
-
this.formatWhereRelationExpression(node);
|
|
58
|
-
this.formatWhereElementExpression(node);
|
|
59
|
-
this.formatRelationExpression(node);
|
|
60
|
-
this.formatAutolayoutProperty(node);
|
|
61
|
-
this.formatWithPredicate(node);
|
|
62
|
-
// Common
|
|
63
|
-
this.formatViewRuleStyle(node);
|
|
64
|
-
this.formatLeafProperty(node);
|
|
65
|
-
this.formatLinkProperty(node);
|
|
66
|
-
this.formatNavigateToProperty(node);
|
|
67
|
-
this.formatTags(node);
|
|
68
|
-
}
|
|
69
|
-
formatTags(node) {
|
|
70
|
-
this.on(node, ast.isTags, (n, f) => {
|
|
71
|
-
const tags = GrammarUtils.findNodesForProperty(n.$cstNode, 'values')
|
|
72
|
-
.filter(isTruthy)
|
|
73
|
-
.slice(1);
|
|
74
|
-
f.cst(tags)
|
|
75
|
-
.prepend(FormattingOptions.oneSpace);
|
|
76
|
-
f.keywords(',')
|
|
77
|
-
.prepend(FormattingOptions.noSpace)
|
|
78
|
-
.append(FormattingOptions.oneSpace);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
formatDeploymentRelation(node) {
|
|
82
|
-
this.on(node, ast.isDeploymentRelation, (n, f) => {
|
|
83
|
-
const sourceNodes = n?.source?.$cstNode ? [n?.source?.$cstNode] : [];
|
|
84
|
-
f.cst(sourceNodes).append(FormattingOptions.oneSpace);
|
|
85
|
-
f.keywords(']->').prepend(FormattingOptions.noSpace);
|
|
86
|
-
f.keywords('-[').append(FormattingOptions.noSpace);
|
|
87
|
-
f.nodes(...filter([
|
|
88
|
-
n.target,
|
|
89
|
-
n.tags,
|
|
90
|
-
], isTruthy)).prepend(FormattingOptions.oneSpace);
|
|
91
|
-
f.properties('title', 'description', 'technology').prepend(FormattingOptions.oneSpace);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
formatExtendDeployment(node) {
|
|
95
|
-
this.on(node, ast.isExtendDeployment, (n, f) => {
|
|
96
|
-
f.keywords('extend').append(FormattingOptions.oneSpace);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
formatRelation(node) {
|
|
100
|
-
this.on(node, (n) => ast.isRelation(n) || ast.isDeploymentRelation(n), (n, f) => {
|
|
101
|
-
const sourceNodes = n?.source?.$cstNode ? [n?.source?.$cstNode] : [];
|
|
102
|
-
f.cst(sourceNodes).append(FormattingOptions.oneSpace);
|
|
103
|
-
f.keywords(']->').prepend(FormattingOptions.noSpace);
|
|
104
|
-
f.keywords('-[').append(FormattingOptions.noSpace);
|
|
105
|
-
f.nodes(...filter([
|
|
106
|
-
n.target,
|
|
107
|
-
n.tags,
|
|
108
|
-
], isTruthy)).prepend(FormattingOptions.oneSpace);
|
|
109
|
-
f.properties('title', 'description', 'technology').prepend(FormattingOptions.oneSpace);
|
|
110
|
-
});
|
|
111
|
-
this.on(node, ast.isDynamicViewStep, (n, f) => {
|
|
112
|
-
f.keywords('->', '<-').surround(FormattingOptions.oneSpace);
|
|
113
|
-
f.property('dotKind')
|
|
114
|
-
.prepend(FormattingOptions.oneSpace)
|
|
115
|
-
.append(FormattingOptions.oneSpace);
|
|
116
|
-
f.keywords(']->')
|
|
117
|
-
.prepend(FormattingOptions.noSpace)
|
|
118
|
-
.append(FormattingOptions.oneSpace);
|
|
119
|
-
f.keywords('-[')
|
|
120
|
-
.prepend(FormattingOptions.oneSpace)
|
|
121
|
-
.append(FormattingOptions.noSpace);
|
|
122
|
-
f.properties('title').prepend(FormattingOptions.oneSpace);
|
|
123
|
-
const wrapToNextLine =
|
|
124
|
-
// Dynamic step chain with multiline source
|
|
125
|
-
(ast.isDynamicStepChain(n) && isMultiline(n.$cstNode))
|
|
126
|
-
// This is the beginning of the series
|
|
127
|
-
|| (ast.isDynamicStepSingle(n) && ast.isDynamicStepChain(n.$container) && isMultiline(n.$container.$cstNode));
|
|
128
|
-
if (!wrapToNextLine) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
f.property('dotKind')
|
|
132
|
-
.prepend(Formatting.indent({ allowLess: false, allowMore: true, priority: 2 }));
|
|
133
|
-
f.keywords('->', '-[')
|
|
134
|
-
.prepend(Formatting.indent({ allowLess: false, allowMore: true, priority: 2 }));
|
|
135
|
-
if (n.custom?.$cstNode && isMultiline(n.custom.$cstNode)) {
|
|
136
|
-
f.property('custom')
|
|
137
|
-
.prepend({
|
|
138
|
-
options: {
|
|
139
|
-
allowLess: false,
|
|
140
|
-
allowMore: true,
|
|
141
|
-
priority: 2,
|
|
142
|
-
},
|
|
143
|
-
moves: [{
|
|
144
|
-
tabs: 1,
|
|
145
|
-
}],
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
removeIndentFromTopLevelStatements(node) {
|
|
151
|
-
if (ast.isLikeC4Grammar(node.$container)) {
|
|
152
|
-
const formatter = this.getNodeFormatter(node);
|
|
153
|
-
formatter.keywords('specification', 'model', 'views', 'likec4lib', 'global', 'deployments', 'import')
|
|
154
|
-
.prepend(FormattingOptions.noIndent);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
indentContentInBraces(node) {
|
|
158
|
-
if (ast.isLikeC4Lib(node)
|
|
159
|
-
|| ast.isSpecificationRule(node)
|
|
160
|
-
|| ast.isSpecificationElementKind(node)
|
|
161
|
-
|| ast.isSpecificationRelationshipKind(node)
|
|
162
|
-
|| ast.isSpecificationDeploymentNodeKind(node)
|
|
163
|
-
|| ast.isGlobals(node)
|
|
164
|
-
|| ast.isGlobalStyle(node)
|
|
165
|
-
|| ast.isGlobalStyleGroup(node)
|
|
166
|
-
|| ast.isGlobalPredicateGroup(node)
|
|
167
|
-
|| ast.isGlobalDynamicPredicateGroup(node)
|
|
168
|
-
|| ast.isGlobalStyleGroup(node)
|
|
169
|
-
|| ast.isModel(node)
|
|
170
|
-
|| ast.isElementBody(node)
|
|
171
|
-
|| ast.isExtendElementBody(node)
|
|
172
|
-
|| ast.isRelationBody(node)
|
|
173
|
-
|| ast.isRelationStyleProperty(node)
|
|
174
|
-
|| ast.isMetadataBody(node)
|
|
175
|
-
|| ast.isModelViews(node)
|
|
176
|
-
|| ast.isElementViewBody(node)
|
|
177
|
-
|| ast.isDynamicViewBody(node)
|
|
178
|
-
|| ast.isDeploymentViewBody(node)
|
|
179
|
-
|| ast.isViewRuleStyle(node)
|
|
180
|
-
|| ast.isViewRuleGroup(node)
|
|
181
|
-
|| ast.isCustomElementProperties(node)
|
|
182
|
-
|| ast.isCustomRelationProperties(node)
|
|
183
|
-
|| ast.isElementStyleProperty(node)
|
|
184
|
-
|| ast.isDynamicViewParallelSteps(node)
|
|
185
|
-
|| ast.isModelDeployments(node)
|
|
186
|
-
|| ast.isDeploymentNodeBody(node)
|
|
187
|
-
|| ast.isDeploymentRelationBody(node)
|
|
188
|
-
|| ast.isDeployedInstanceBody(node)
|
|
189
|
-
|| ast.isExtendDeploymentBody(node)) {
|
|
190
|
-
const formatter = this.getNodeFormatter(node);
|
|
191
|
-
const openBrace = formatter.keywords('{');
|
|
192
|
-
openBrace
|
|
193
|
-
.prepend(FormattingOptions.noIndent)
|
|
194
|
-
.prepend(FormattingOptions.oneSpace);
|
|
195
|
-
const multiline = isMultiline(node.$cstNode);
|
|
196
|
-
const closeBrace = formatter.keywords('}');
|
|
197
|
-
const interiorNodes = formatter.interior(openBrace, closeBrace);
|
|
198
|
-
// Workaround for tags as they are parsed as overlapping regions.
|
|
199
|
-
// E.g. '#tag1, #tag2' will be parsed as two nodes: '#tag1' and '#tag1, #tag2'
|
|
200
|
-
let previousNode = null;
|
|
201
|
-
for (const interiorNode of interiorNodes.nodes) {
|
|
202
|
-
if (!multiline) {
|
|
203
|
-
formatter.cst([interiorNode])
|
|
204
|
-
.surround(FormattingOptions.oneSpace);
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
if (!previousNode || !utils.areOverlap(previousNode, interiorNode)) {
|
|
208
|
-
formatter.cst([interiorNode])
|
|
209
|
-
.prepend(Formatting.newLine({ allowMore: true }))
|
|
210
|
-
.prepend(FormattingOptions.indent);
|
|
211
|
-
}
|
|
212
|
-
previousNode = interiorNode;
|
|
213
|
-
}
|
|
214
|
-
if (multiline) {
|
|
215
|
-
closeBrace
|
|
216
|
-
.prepend(FormattingOptions.noIndent)
|
|
217
|
-
.prepend(Formatting.newLine({ allowMore: true }));
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
closeBrace
|
|
221
|
-
.prepend(Formatting.oneSpace({ allowLess: true }));
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
appendKeywordsWithSpace(node) {
|
|
226
|
-
this.on(node, ast.isElementKind)
|
|
227
|
-
?.keywords('element').append(FormattingOptions.oneSpace);
|
|
228
|
-
}
|
|
229
|
-
formatView(node) {
|
|
230
|
-
this.on(node, ast.isElementView, (n, f) => {
|
|
231
|
-
if (n.extends || n.viewOf || n.name) {
|
|
232
|
-
f.keywords('view').append(FormattingOptions.oneSpace);
|
|
233
|
-
}
|
|
234
|
-
f.keywords('of', 'extends').surround(FormattingOptions.oneSpace);
|
|
235
|
-
});
|
|
236
|
-
this.on(node, ast.isDynamicView)
|
|
237
|
-
?.keywords('dynamic', 'view').append(FormattingOptions.oneSpace);
|
|
238
|
-
this.on(node, ast.isDeploymentView)
|
|
239
|
-
?.keywords('deployment', 'view').append(FormattingOptions.oneSpace);
|
|
240
|
-
}
|
|
241
|
-
formatLeafProperty(node) {
|
|
242
|
-
if (ast.isElementStringProperty(node)
|
|
243
|
-
|| ast.isRelationStringProperty(node)
|
|
244
|
-
|| ast.isViewStringProperty(node)
|
|
245
|
-
|| ast.isNotationProperty(node)
|
|
246
|
-
|| ast.isNotesProperty(node)
|
|
247
|
-
|| ast.isSpecificationElementStringProperty(node)
|
|
248
|
-
|| ast.isSpecificationRelationshipStringProperty(node)
|
|
249
|
-
|| ast.isColorProperty(node)
|
|
250
|
-
|| ast.isLineProperty(node)
|
|
251
|
-
|| ast.isArrowProperty(node)
|
|
252
|
-
|| ast.isIconProperty(node)
|
|
253
|
-
|| ast.isShapeProperty(node)
|
|
254
|
-
|| ast.isBorderProperty(node)
|
|
255
|
-
|| ast.isOpacityProperty(node)
|
|
256
|
-
|| ast.isMultipleProperty(node)
|
|
257
|
-
|| ast.isShapeSizeProperty(node)
|
|
258
|
-
|| ast.isPaddingSizeProperty(node)
|
|
259
|
-
|| ast.isTextSizeProperty(node)) {
|
|
260
|
-
const formatter = this.getNodeFormatter(node);
|
|
261
|
-
const colon = formatter.keyword(':');
|
|
262
|
-
const propertyName = formatter.keywords('title', 'description', 'technology', 'summary', 'notation', 'notes', 'color', 'line', 'head', 'tail', 'icon', 'shape', 'border', 'opacity', 'multiple', 'size', 'padding', 'textSize');
|
|
263
|
-
if (colon.nodes.length === 0) {
|
|
264
|
-
propertyName
|
|
265
|
-
.append(FormattingOptions.oneSpace);
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
colon
|
|
269
|
-
.prepend(FormattingOptions.noSpace)
|
|
270
|
-
.append(FormattingOptions.oneSpace);
|
|
271
|
-
}
|
|
272
|
-
formatter.keyword(';')
|
|
273
|
-
.prepend(FormattingOptions.noSpace)
|
|
274
|
-
.append(FormattingOptions.newLine);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
formatLinkProperty(node) {
|
|
278
|
-
this.on(node, ast.isLinkProperty, (n, f) => {
|
|
279
|
-
f.keyword('link').append(FormattingOptions.oneSpace);
|
|
280
|
-
f.property('value').append(FormattingOptions.oneSpace);
|
|
281
|
-
f.keyword(':')
|
|
282
|
-
.prepend(FormattingOptions.noSpace)
|
|
283
|
-
.append(FormattingOptions.oneSpace);
|
|
284
|
-
f.keyword(';')
|
|
285
|
-
.prepend(FormattingOptions.noSpace)
|
|
286
|
-
.append(FormattingOptions.newLine);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
formatNavigateToProperty(node) {
|
|
290
|
-
this.on(node, ast.isNavigateToProperty)
|
|
291
|
-
?.property('key').append(FormattingOptions.oneSpace);
|
|
292
|
-
}
|
|
293
|
-
formatAutolayoutProperty(node) {
|
|
294
|
-
this.on(node, ast.isViewRuleAutoLayout, (n, f) => {
|
|
295
|
-
f.keyword('autoLayout').append(FormattingOptions.oneSpace);
|
|
296
|
-
f.property('rankSep').prepend(FormattingOptions.oneSpace);
|
|
297
|
-
f.property('nodeSep').prepend(FormattingOptions.oneSpace);
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
formatMetadataProperty(node) {
|
|
301
|
-
this.on(node, ast.isMetadataAttribute, (n, f) => {
|
|
302
|
-
f.property('key').append(FormattingOptions.oneSpace);
|
|
303
|
-
f.keyword(':')
|
|
304
|
-
.prepend(FormattingOptions.noSpace)
|
|
305
|
-
.append(FormattingOptions.oneSpace);
|
|
306
|
-
f.keyword(';')
|
|
307
|
-
.prepend(FormattingOptions.noSpace)
|
|
308
|
-
.append(FormattingOptions.newLine);
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
formatElementDeclaration(node) {
|
|
312
|
-
this.on(node, ast.isElement, (n, f) => {
|
|
313
|
-
const kind = GrammarUtils.findNodeForProperty(n.$cstNode, 'kind');
|
|
314
|
-
const name = GrammarUtils.findNodeForProperty(n.$cstNode, 'name');
|
|
315
|
-
if (name && kind) {
|
|
316
|
-
// system sys1
|
|
317
|
-
if (utils.compareRanges(name, kind) > 0) {
|
|
318
|
-
f.cst([kind]).append(FormattingOptions.oneSpace);
|
|
319
|
-
}
|
|
320
|
-
// sys1 = system
|
|
321
|
-
else {
|
|
322
|
-
f.cst([name]).append(FormattingOptions.oneSpace);
|
|
323
|
-
f.cst([kind]).prepend(FormattingOptions.oneSpace);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
f.properties('props').prepend(FormattingOptions.oneSpace);
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
formatExtendElement(node) {
|
|
330
|
-
this.on(node, ast.isExtendElement, (n, f) => {
|
|
331
|
-
f.keywords('extend').append(FormattingOptions.oneSpace);
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
formatGlobals(node) {
|
|
335
|
-
this.on(node, ast.isGlobalStyle, (n, f) => {
|
|
336
|
-
f.keyword('style').append(FormattingOptions.oneSpace);
|
|
337
|
-
f.property('id').append(FormattingOptions.oneSpace);
|
|
338
|
-
});
|
|
339
|
-
this.on(node, ast.isGlobalStyleGroup, (n, f) => {
|
|
340
|
-
f.keyword('styleGroup').append(FormattingOptions.oneSpace);
|
|
341
|
-
});
|
|
342
|
-
this.on(node, ast.isGlobalPredicateGroup, (n, f) => {
|
|
343
|
-
f.keyword('predicateGroup').append(FormattingOptions.oneSpace);
|
|
344
|
-
});
|
|
345
|
-
this.on(node, ast.isGlobalDynamicPredicateGroup, (n, f) => {
|
|
346
|
-
f.keyword('dynamicPredicateGroup').append(FormattingOptions.oneSpace);
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
formatImports(node) {
|
|
350
|
-
this.on(node, ast.isImportsFromPoject, (n, f) => {
|
|
351
|
-
f.keyword('import').append(FormattingOptions.oneSpace);
|
|
352
|
-
f.keywords('{', '}', 'from').surround(FormattingOptions.oneSpace);
|
|
353
|
-
});
|
|
354
|
-
this.on(node, ast.isImported, (n, f) => {
|
|
355
|
-
f.keywords(',')
|
|
356
|
-
.prepend(FormattingOptions.noSpace)
|
|
357
|
-
.append(FormattingOptions.oneSpace);
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
formatSpecificationRule(node) {
|
|
361
|
-
if (ast.isSpecificationElementKind(node)
|
|
362
|
-
|| ast.isSpecificationRelationshipKind(node)
|
|
363
|
-
|| ast.isSpecificationTag(node)
|
|
364
|
-
|| ast.isSpecificationDeploymentNodeKind(node)) {
|
|
365
|
-
const formatter = this.getNodeFormatter(node);
|
|
366
|
-
formatter.keywords('element', 'relationship', 'tag', 'deploymentNode')
|
|
367
|
-
.append(FormattingOptions.oneSpace);
|
|
368
|
-
}
|
|
369
|
-
if (ast.isSpecificationColor(node)) {
|
|
370
|
-
const formatter = this.getNodeFormatter(node);
|
|
371
|
-
formatter.keyword('color').append(FormattingOptions.oneSpace);
|
|
372
|
-
formatter.property('name').append(FormattingOptions.oneSpace);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
formatWithPredicate(node) {
|
|
376
|
-
if (ast.isFqnExprWith(node)
|
|
377
|
-
|| ast.isRelationExprWith(node)) {
|
|
378
|
-
const formatter = this.getNodeFormatter(node);
|
|
379
|
-
formatter.keyword('with').prepend(FormattingOptions.oneSpace);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
formatDeploymentNodeDeclaration(node) {
|
|
383
|
-
this.on(node, ast.isDeploymentNode, (n, f) => {
|
|
384
|
-
const kind = GrammarUtils.findNodeForProperty(n.$cstNode, 'kind');
|
|
385
|
-
const name = GrammarUtils.findNodeForProperty(n.$cstNode, 'name');
|
|
386
|
-
if (name && kind) {
|
|
387
|
-
// system sys1
|
|
388
|
-
if (utils.compareRanges(name, kind) > 0) {
|
|
389
|
-
f.cst([kind]).append(FormattingOptions.oneSpace);
|
|
390
|
-
}
|
|
391
|
-
// sys1 = system
|
|
392
|
-
else {
|
|
393
|
-
f.cst([name]).append(FormattingOptions.oneSpace);
|
|
394
|
-
f.cst([kind]).prepend(FormattingOptions.oneSpace);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
f.properties('title').prepend(FormattingOptions.oneSpace);
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
formatDeployedInstance(node) {
|
|
401
|
-
this.on(node, ast.isDeployedInstance, (n, f) => {
|
|
402
|
-
const eqNode = n.$cstNode?.content.find(c => c.text === '=');
|
|
403
|
-
if (eqNode) {
|
|
404
|
-
f.cst([eqNode]).surround(FormattingOptions.oneSpace);
|
|
405
|
-
}
|
|
406
|
-
f.keyword('instanceOf').append(FormattingOptions.oneSpace);
|
|
407
|
-
f.property('title').prepend(FormattingOptions.oneSpace);
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
formatViewRuleGlobalStyle(node) {
|
|
411
|
-
this.on(node, ast.isViewRuleGlobalStyle, (n, f) => {
|
|
412
|
-
f.keywords('global', 'style').append(FormattingOptions.oneSpace);
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
formatViewRuleGlobalPredicate(node) {
|
|
416
|
-
const formatter = this.getNodeFormatter(node);
|
|
417
|
-
if (ast.isViewRuleGlobalPredicateRef(node)
|
|
418
|
-
|| ast.isDynamicViewGlobalPredicateRef(node)) {
|
|
419
|
-
formatter.keywords('global', 'predicate').append(FormattingOptions.oneSpace);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
formatViewRuleGroup(node) {
|
|
423
|
-
this.on(node, ast.isViewRuleGroup, (n, f) => {
|
|
424
|
-
f.keyword('group').append(FormattingOptions.oneSpace);
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
formatViewRuleStyle(node) {
|
|
428
|
-
this.on(node, ast.isViewRuleStyle)
|
|
429
|
-
?.keyword('style').append(FormattingOptions.oneSpace);
|
|
430
|
-
this.on(node, ast.isDeploymentViewRuleStyle)
|
|
431
|
-
?.keyword('style').append(FormattingOptions.oneSpace);
|
|
432
|
-
this.on(node, ast.isExpressions)
|
|
433
|
-
?.keyword(',')
|
|
434
|
-
.prepend(FormattingOptions.noSpace)
|
|
435
|
-
.append(FormattingOptions.oneSpace);
|
|
436
|
-
this.on(node, ast.isFqnExpressions)
|
|
437
|
-
?.keyword(',')
|
|
438
|
-
.prepend(FormattingOptions.noSpace)
|
|
439
|
-
.append(FormattingOptions.oneSpace);
|
|
440
|
-
}
|
|
441
|
-
formatWhereExpression(node) {
|
|
442
|
-
if (ast.isRelationExprWhere(node)
|
|
443
|
-
|| ast.isFqnExprWhere(node)) {
|
|
444
|
-
const formatter = this.getNodeFormatter(node);
|
|
445
|
-
formatter.keyword('where').append(FormattingOptions.oneSpace);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
formatWhereRelationExpression(node) {
|
|
449
|
-
this.on(node, ast.isWhereRelationExpression, (n, f) => {
|
|
450
|
-
f.property('operator').surround(FormattingOptions.oneSpace);
|
|
451
|
-
});
|
|
452
|
-
this.on(node, ast.isWhereRelationNegation, (n, f) => {
|
|
453
|
-
f.keyword('not').append(FormattingOptions.oneSpace);
|
|
454
|
-
});
|
|
455
|
-
if (ast.isWhereRelation(node)
|
|
456
|
-
|| ast.isWhereRelationTag(node)
|
|
457
|
-
|| ast.isWhereRelationKind(node)) {
|
|
458
|
-
const formatter = this.getNodeFormatter(node);
|
|
459
|
-
formatter.property('operator').surround(FormattingOptions.oneSpace);
|
|
460
|
-
formatter.property('not').surround(FormattingOptions.oneSpace);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
formatWhereElementExpression(node) {
|
|
464
|
-
this.on(node, ast.isWhereElementExpression, (n, f) => {
|
|
465
|
-
f.property('operator').surround(FormattingOptions.oneSpace);
|
|
466
|
-
});
|
|
467
|
-
this.on(node, ast.isWhereElementNegation, (n, f) => {
|
|
468
|
-
f.keyword('not').append(FormattingOptions.oneSpace);
|
|
469
|
-
});
|
|
470
|
-
if (ast.isWhereElement(node)
|
|
471
|
-
|| ast.isWhereElementTag(node)
|
|
472
|
-
|| ast.isWhereElementKind(node)) {
|
|
473
|
-
const formatter = this.getNodeFormatter(node);
|
|
474
|
-
formatter.property('operator').surround(FormattingOptions.oneSpace);
|
|
475
|
-
formatter.property('not').surround(FormattingOptions.oneSpace);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
formatIncludeExcludeExpressions(node) {
|
|
479
|
-
if (ast.isDynamicViewRule(node)
|
|
480
|
-
|| ast.isViewRulePredicate(node)
|
|
481
|
-
|| ast.isDeploymentViewRulePredicate(node)) {
|
|
482
|
-
const formatter = this.getNodeFormatter(node);
|
|
483
|
-
if (!node.$cstNode || !utils.isMultiline(node.$cstNode)) {
|
|
484
|
-
formatter.keywords('include', 'exclude')
|
|
485
|
-
.append(FormattingOptions.oneSpace);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
if (ast.isExpressions(node)) {
|
|
489
|
-
const formatter = this.getNodeFormatter(node);
|
|
490
|
-
const parent = this.findPredicateExpressionRoot(node);
|
|
491
|
-
const isMultiline = parent?.$cstNode && utils.isMultiline(parent?.$cstNode);
|
|
492
|
-
if (isMultiline) {
|
|
493
|
-
formatter.property('value').prepend(FormattingOptions.indent);
|
|
494
|
-
}
|
|
495
|
-
formatter.keyword(',')
|
|
496
|
-
.prepend(FormattingOptions.noSpace)
|
|
497
|
-
.append(isMultiline ? FormattingOptions.newLine : FormattingOptions.oneSpace);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
formatRelationExpression(node) {
|
|
501
|
-
this.on(node, ast.isIncomingRelationExpr, (n, f) => {
|
|
502
|
-
f.keyword('->').append(FormattingOptions.oneSpace);
|
|
503
|
-
});
|
|
504
|
-
this.on(node, ast.isInOutRelationExpr, (n, f) => {
|
|
505
|
-
f.keyword('->').prepend(FormattingOptions.oneSpace);
|
|
506
|
-
});
|
|
507
|
-
this.on(node, ast.isOutgoingRelationExpr, (n, f) => {
|
|
508
|
-
f.keywords('->', '<->').prepend(FormattingOptions.oneSpace);
|
|
509
|
-
f.keywords('-[')
|
|
510
|
-
.prepend(FormattingOptions.oneSpace)
|
|
511
|
-
.append(FormattingOptions.noSpace);
|
|
512
|
-
f.keywords(']->')
|
|
513
|
-
.prepend(FormattingOptions.noSpace)
|
|
514
|
-
.append(FormattingOptions.oneSpace);
|
|
515
|
-
f.property('dotKind')
|
|
516
|
-
.prepend(FormattingOptions.oneSpace)
|
|
517
|
-
.append(FormattingOptions.oneSpace);
|
|
518
|
-
});
|
|
519
|
-
this.on(node, ast.isDirectedRelationExpr, (n, f) => {
|
|
520
|
-
f.property('target').prepend(FormattingOptions.oneSpace);
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
findPredicateExpressionRoot(node) {
|
|
524
|
-
let parent = node.$container;
|
|
525
|
-
while (true) {
|
|
526
|
-
if (!parent
|
|
527
|
-
|| ast.isDynamicViewRule(parent)
|
|
528
|
-
|| ast.isViewRulePredicate(parent)
|
|
529
|
-
|| ast.isDeploymentViewRulePredicate(parent)) {
|
|
530
|
-
return parent;
|
|
531
|
-
}
|
|
532
|
-
parent = parent.$container;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
on(node, predicate, format) {
|
|
536
|
-
const formatter = predicate(node) ? this.getNodeFormatter(node) : undefined;
|
|
537
|
-
format && formatter && format(node, formatter);
|
|
538
|
-
return formatter;
|
|
539
|
-
}
|
|
540
|
-
doExtendedFormatting(edits) {
|
|
541
|
-
const quotesNormalizer = this.quotesNormalizerFactory(this.extendedFormattingCommands);
|
|
542
|
-
for (let command of this.extendedFormattingCommands) {
|
|
543
|
-
switch (command.type) {
|
|
544
|
-
case 'normalizeQuotes':
|
|
545
|
-
quotesNormalizer(command, edits);
|
|
546
|
-
break;
|
|
547
|
-
default:
|
|
548
|
-
nonexhaustive(command.type);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
normalizeQuotes(node) {
|
|
553
|
-
if (this.options.quoteStyle === 'ignore') {
|
|
554
|
-
return;
|
|
555
|
-
}
|
|
556
|
-
let region = null;
|
|
557
|
-
region = region ?? this.on(node, ast.isStringProperty)
|
|
558
|
-
?.property('value');
|
|
559
|
-
region = region ?? this.on(node, ast.isElement)
|
|
560
|
-
?.properties('props');
|
|
561
|
-
region = region ?? this.on(node, ast.isImportsFromPoject)
|
|
562
|
-
?.properties('project');
|
|
563
|
-
region = region ?? this.on(node, ast.isRelation)
|
|
564
|
-
?.properties('title', 'technology');
|
|
565
|
-
region = region ?? this.on(node, ast.isViewRuleGroup)
|
|
566
|
-
?.properties('title');
|
|
567
|
-
region = region ?? this.on(node, ast.isDynamicViewStep)
|
|
568
|
-
?.properties('title');
|
|
569
|
-
region = region ?? this.on(node, ast.isDeploymentNode)
|
|
570
|
-
?.properties('title');
|
|
571
|
-
region = region ?? this.on(node, ast.isDeployedInstance)
|
|
572
|
-
?.properties('title');
|
|
573
|
-
region = region ?? this.on(node, ast.isDeploymentRelation)
|
|
574
|
-
?.properties('title', 'technology');
|
|
575
|
-
region = region ?? this.on(node, ast.isLinkProperty)
|
|
576
|
-
?.properties('title');
|
|
577
|
-
if (region) {
|
|
578
|
-
this.extendedFormattingCommands.push({ type: 'normalizeQuotes', region });
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
quotesNormalizerFactory(commands) {
|
|
582
|
-
const quoteStyle = this.options.quoteStyle != 'auto'
|
|
583
|
-
? this.options.quoteStyle
|
|
584
|
-
: this.getAutoQuoteStyle(commands);
|
|
585
|
-
return (command, edits) => {
|
|
586
|
-
const quotesToReplace = quoteStyle === 'single' ? '"' : '\'';
|
|
587
|
-
const quotesToInsert = quoteStyle === 'single' ? '\'' : '"';
|
|
588
|
-
const markdownFence = quotesToInsert.repeat(3);
|
|
589
|
-
const plainFence = quotesToInsert;
|
|
590
|
-
const newEdits = command.region.nodes.map(node => {
|
|
591
|
-
const fence = node.text.startsWith(`"""`) || node.text.startsWith(`'''`)
|
|
592
|
-
? markdownFence
|
|
593
|
-
: plainFence;
|
|
594
|
-
return {
|
|
595
|
-
range: node.range,
|
|
596
|
-
newText: fence +
|
|
597
|
-
this.escapeQuotesInternalQuotes(node.text.slice(fence.length, -fence.length), quotesToReplace, quotesToInsert) +
|
|
598
|
-
fence,
|
|
599
|
-
};
|
|
600
|
-
});
|
|
601
|
-
edits.push(...newEdits);
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
escapeQuotesInternalQuotes(text, quotesToReplace, quoteToInsert) {
|
|
605
|
-
let result = '';
|
|
606
|
-
let start = 0;
|
|
607
|
-
while (start >= 0) {
|
|
608
|
-
let pos = text.indexOf(quoteToInsert, start);
|
|
609
|
-
if (pos < 0) {
|
|
610
|
-
result += text.slice(start);
|
|
611
|
-
break;
|
|
612
|
-
}
|
|
613
|
-
result += text.slice(start, pos);
|
|
614
|
-
start = pos + 1;
|
|
615
|
-
let escaped = false;
|
|
616
|
-
while (pos > 0 && text[pos - 1] == '\\') {
|
|
617
|
-
escaped = !escaped;
|
|
618
|
-
pos--;
|
|
619
|
-
}
|
|
620
|
-
result += escaped ? quoteToInsert : `\\${quoteToInsert}`;
|
|
621
|
-
}
|
|
622
|
-
return result;
|
|
623
|
-
}
|
|
624
|
-
getAutoQuoteStyle(commands) {
|
|
625
|
-
const nodes = commands.flatMap(x => x.region.nodes);
|
|
626
|
-
const doubleQuotesCount = nodes.filter(x => x.text[0] == '"').length;
|
|
627
|
-
return doubleQuotesCount * 2 >= nodes.length ? 'double' : 'single';
|
|
628
|
-
}
|
|
629
|
-
onConfigurationUpdate(options) {
|
|
630
|
-
this.options = {
|
|
631
|
-
...this.options,
|
|
632
|
-
...options ?? {
|
|
633
|
-
quoteStyle: 'auto',
|
|
634
|
-
},
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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 | undefined): boolean;
|
package/dist/formatting/utils.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
12
|
-
|| pos.line > range.end.line
|
|
13
|
-
|| pos.line == range.start.line && pos.character < range.start.character
|
|
14
|
-
|| pos.line == range.end.line && pos.character > range.end.character);
|
|
15
|
-
}
|
|
16
|
-
export function isMultiline(node) {
|
|
17
|
-
return !!node && node.range.start.line != node.range.end.line;
|
|
18
|
-
}
|