@likec4/language-server 1.2.0 → 1.2.1
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/package.json +8 -10
- package/src/Rpc.ts +108 -0
- package/src/ast.ts +443 -0
- package/src/browser/index.ts +30 -0
- package/src/elementRef.ts +26 -0
- package/src/generated/ast.ts +1632 -0
- package/src/generated/grammar.ts +10 -0
- package/src/generated/module.ts +32 -0
- package/src/index.ts +4 -0
- package/src/like-c4.langium +395 -0
- package/src/logger.ts +54 -0
- package/src/lsp/CodeLensProvider.ts +51 -0
- package/src/lsp/DocumentHighlightProvider.ts +12 -0
- package/src/lsp/DocumentLinkProvider.test.ts +66 -0
- package/src/lsp/DocumentLinkProvider.ts +53 -0
- package/src/lsp/DocumentSymbolProvider.ts +201 -0
- package/src/lsp/HoverProvider.ts +58 -0
- package/{dist/lsp/SemanticTokenProvider.js → src/lsp/SemanticTokenProvider.ts} +57 -42
- package/src/lsp/index.ts +6 -0
- package/src/model/fqn-computation.ts +47 -0
- package/src/model/fqn-index.ts +161 -0
- package/src/model/index.ts +5 -0
- package/src/model/model-builder.ts +447 -0
- package/src/model/model-locator.ts +130 -0
- package/src/model/model-parser.ts +580 -0
- package/src/model-change/ModelChanges.ts +120 -0
- package/src/model-change/changeElementStyle.ts +176 -0
- package/src/model-change/changeViewLayout.ts +41 -0
- package/src/module.ts +197 -0
- package/src/node/index.ts +20 -0
- package/src/protocol.ts +87 -0
- package/src/references/index.ts +2 -0
- package/src/references/scope-computation.ts +142 -0
- package/src/references/scope-provider.ts +166 -0
- package/src/shared/NodeKindProvider.ts +67 -0
- package/src/shared/WorkspaceManager.ts +39 -0
- package/src/shared/WorkspaceSymbolProvider.ts +3 -0
- package/src/shared/index.ts +3 -0
- package/src/test/index.ts +1 -0
- package/src/test/testServices.ts +119 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/printDocs.ts +3 -0
- package/src/utils/stringHash.ts +6 -0
- package/{dist/validation/dynamic-view-rule.js → src/validation/dynamic-view-rule.ts} +14 -11
- package/src/validation/dynamic-view-step.ts +39 -0
- package/src/validation/element.ts +52 -0
- package/{dist/validation/index.js → src/validation/index.ts} +22 -18
- package/src/validation/property-checks.ts +17 -0
- package/src/validation/relation.ts +57 -0
- package/src/validation/specification.ts +118 -0
- package/src/validation/view-predicates/custom-element-expr.ts +21 -0
- package/{dist/validation/view-predicates/expanded-element.js → src/validation/view-predicates/expanded-element.ts} +18 -13
- package/src/validation/view-predicates/incoming.ts +19 -0
- package/src/validation/view-predicates/index.ts +4 -0
- package/src/validation/view-predicates/outgoing.ts +19 -0
- package/src/validation/view.ts +26 -0
- package/src/view-utils/assignNavigateTo.ts +30 -0
- package/src/view-utils/index.ts +3 -0
- package/src/view-utils/resolve-extended-views.ts +57 -0
- package/src/view-utils/resolve-relative-paths.ts +84 -0
- package/dist/Rpc.d.ts +0 -10
- package/dist/Rpc.js +0 -98
- package/dist/ast.d.ts +0 -149
- package/dist/ast.js +0 -271
- package/dist/browser/index.d.ts +0 -9
- package/dist/browser/index.js +0 -16
- package/dist/elementRef.d.ts +0 -12
- package/dist/elementRef.js +0 -15
- package/dist/generated/ast.d.ts +0 -615
- package/dist/generated/ast.js +0 -957
- package/dist/generated/grammar.d.ts +0 -7
- package/dist/generated/grammar.js +0 -3
- package/dist/generated/module.d.ts +0 -14
- package/dist/generated/module.js +0 -22
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -2
- package/dist/logger.d.ts +0 -12
- package/dist/logger.js +0 -51
- package/dist/lsp/CodeLensProvider.d.ts +0 -10
- package/dist/lsp/CodeLensProvider.js +0 -40
- package/dist/lsp/DocumentHighlightProvider.d.ts +0 -10
- package/dist/lsp/DocumentHighlightProvider.js +0 -10
- package/dist/lsp/DocumentLinkProvider.d.ts +0 -11
- package/dist/lsp/DocumentLinkProvider.js +0 -41
- package/dist/lsp/DocumentLinkProvider.test.d.ts +0 -2
- package/dist/lsp/DocumentLinkProvider.test.js +0 -54
- package/dist/lsp/DocumentSymbolProvider.d.ts +0 -22
- package/dist/lsp/DocumentSymbolProvider.js +0 -189
- package/dist/lsp/HoverProvider.d.ts +0 -10
- package/dist/lsp/HoverProvider.js +0 -36
- package/dist/lsp/SemanticTokenProvider.d.ts +0 -8
- package/dist/lsp/index.d.ts +0 -7
- package/dist/lsp/index.js +0 -6
- package/dist/model/fqn-computation.d.ts +0 -4
- package/dist/model/fqn-computation.js +0 -43
- package/dist/model/fqn-index.d.ts +0 -26
- package/dist/model/fqn-index.js +0 -114
- package/dist/model/index.d.ts +0 -6
- package/dist/model/index.js +0 -5
- package/dist/model/model-builder.d.ts +0 -20
- package/dist/model/model-builder.js +0 -365
- package/dist/model/model-locator.d.ts +0 -22
- package/dist/model/model-locator.js +0 -115
- package/dist/model/model-parser.d.ts +0 -29
- package/dist/model/model-parser.js +0 -520
- package/dist/model-change/ModelChanges.d.ts +0 -16
- package/dist/model-change/ModelChanges.js +0 -106
- package/dist/model-change/changeElementStyle.d.ts +0 -18
- package/dist/model-change/changeElementStyle.js +0 -141
- package/dist/model-change/changeViewLayout.d.ts +0 -13
- package/dist/model-change/changeViewLayout.js +0 -29
- package/dist/module.d.ts +0 -59
- package/dist/module.js +0 -121
- package/dist/node/index.d.ts +0 -6
- package/dist/node/index.js +0 -13
- package/dist/protocol.d.ts +0 -58
- package/dist/protocol.js +0 -14
- package/dist/references/index.d.ts +0 -3
- package/dist/references/index.js +0 -2
- package/dist/references/scope-computation.d.ts +0 -11
- package/dist/references/scope-computation.js +0 -111
- package/dist/references/scope-provider.d.ts +0 -18
- package/dist/references/scope-provider.js +0 -136
- package/dist/shared/NodeKindProvider.d.ts +0 -16
- package/dist/shared/NodeKindProvider.js +0 -60
- package/dist/shared/WorkspaceManager.d.ts +0 -17
- package/dist/shared/WorkspaceManager.js +0 -29
- package/dist/shared/WorkspaceSymbolProvider.d.ts +0 -4
- package/dist/shared/WorkspaceSymbolProvider.js +0 -3
- package/dist/shared/index.d.ts +0 -4
- package/dist/shared/index.js +0 -3
- package/dist/test/index.d.ts +0 -2
- package/dist/test/index.js +0 -1
- package/dist/test/testServices.d.ts +0 -23
- package/dist/test/testServices.js +0 -102
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -1
- package/dist/utils/printDocs.d.ts +0 -3
- package/dist/utils/printDocs.js +0 -1
- package/dist/utils/stringHash.d.ts +0 -2
- package/dist/utils/stringHash.js +0 -5
- package/dist/validation/dynamic-view-rule.d.ts +0 -5
- package/dist/validation/dynamic-view-step.d.ts +0 -5
- package/dist/validation/dynamic-view-step.js +0 -33
- package/dist/validation/element.d.ts +0 -6
- package/dist/validation/element.js +0 -38
- package/dist/validation/index.d.ts +0 -3
- package/dist/validation/property-checks.d.ts +0 -5
- package/dist/validation/property-checks.js +0 -11
- package/dist/validation/relation.d.ts +0 -5
- package/dist/validation/relation.js +0 -50
- package/dist/validation/specification.d.ts +0 -10
- package/dist/validation/specification.js +0 -97
- package/dist/validation/view-predicates/custom-element-expr.d.ts +0 -5
- package/dist/validation/view-predicates/custom-element-expr.js +0 -16
- package/dist/validation/view-predicates/expanded-element.d.ts +0 -5
- package/dist/validation/view-predicates/incoming.d.ts +0 -5
- package/dist/validation/view-predicates/incoming.js +0 -14
- package/dist/validation/view-predicates/index.d.ts +0 -5
- package/dist/validation/view-predicates/index.js +0 -4
- package/dist/validation/view-predicates/outgoing.d.ts +0 -5
- package/dist/validation/view-predicates/outgoing.js +0 -14
- package/dist/validation/view.d.ts +0 -5
- package/dist/validation/view.js +0 -16
- package/dist/view-utils/assignNavigateTo.d.ts +0 -3
- package/dist/view-utils/assignNavigateTo.js +0 -24
- package/dist/view-utils/index.d.ts +0 -4
- package/dist/view-utils/index.js +0 -3
- package/dist/view-utils/resolve-extended-views.d.ts +0 -7
- package/dist/view-utils/resolve-extended-views.js +0 -41
- package/dist/view-utils/resolve-relative-paths.d.ts +0 -3
- package/dist/view-utils/resolve-relative-paths.js +0 -75
- /package/{dist → src}/reset.d.ts +0 -0
package/dist/Rpc.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { debounce } from "remeda";
|
|
2
|
-
import { logError, logger } from "./logger.js";
|
|
3
|
-
import { nonexhaustive } from "@likec4/core";
|
|
4
|
-
import { Disposable, URI, UriUtils } from "langium";
|
|
5
|
-
import { isLikeC4LangiumDocument } from "./ast.js";
|
|
6
|
-
import {
|
|
7
|
-
buildDocuments,
|
|
8
|
-
changeView,
|
|
9
|
-
computeView,
|
|
10
|
-
fetchComputedModel,
|
|
11
|
-
fetchModel,
|
|
12
|
-
locate,
|
|
13
|
-
onDidChangeModel
|
|
14
|
-
} from "./protocol.js";
|
|
15
|
-
export class Rpc {
|
|
16
|
-
constructor(services) {
|
|
17
|
-
this.services = services;
|
|
18
|
-
}
|
|
19
|
-
disposables = [];
|
|
20
|
-
init() {
|
|
21
|
-
const modelBuilder = this.services.likec4.ModelBuilder;
|
|
22
|
-
const modelLocator = this.services.likec4.ModelLocator;
|
|
23
|
-
const modelEditor = this.services.likec4.ModelChanges;
|
|
24
|
-
const connection = this.services.shared.lsp.Connection;
|
|
25
|
-
if (!connection) {
|
|
26
|
-
logger.warn(`[ServerRpc] no connection, not initializing`);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
logger.info(`[ServerRpc] init`);
|
|
30
|
-
const LangiumDocuments = this.services.shared.workspace.LangiumDocuments;
|
|
31
|
-
const DocumentBuilder = this.services.shared.workspace.DocumentBuilder;
|
|
32
|
-
const notifyModelParsed = debounce(
|
|
33
|
-
() => void connection.sendNotification(onDidChangeModel, "").catch((e) => {
|
|
34
|
-
logger.error(`[ServerRpc] error sending onDidChangeModel: ${e}`);
|
|
35
|
-
return Promise.resolve();
|
|
36
|
-
}),
|
|
37
|
-
{
|
|
38
|
-
timing: "both",
|
|
39
|
-
waitMs: 350,
|
|
40
|
-
maxWaitMs: 1e3
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
this.disposables.push(
|
|
44
|
-
Disposable.create(() => {
|
|
45
|
-
notifyModelParsed.cancel();
|
|
46
|
-
}),
|
|
47
|
-
modelBuilder.onModelParsed(() => notifyModelParsed.call()),
|
|
48
|
-
connection.onRequest(fetchComputedModel, async (cancelToken) => {
|
|
49
|
-
const model = await modelBuilder.buildComputedModel(cancelToken);
|
|
50
|
-
return { model };
|
|
51
|
-
}),
|
|
52
|
-
connection.onRequest(fetchModel, async (cancelToken) => {
|
|
53
|
-
const model = await modelBuilder.buildModel(cancelToken);
|
|
54
|
-
return { model };
|
|
55
|
-
}),
|
|
56
|
-
connection.onRequest(computeView, async ({ viewId }, cancelToken) => {
|
|
57
|
-
const view = await modelBuilder.computeView(viewId, cancelToken);
|
|
58
|
-
return { view };
|
|
59
|
-
}),
|
|
60
|
-
connection.onRequest(buildDocuments, async ({ docs }, cancelToken) => {
|
|
61
|
-
const changed = docs.map((d) => URI.parse(d));
|
|
62
|
-
const notChanged = (uri) => changed.every((c) => !UriUtils.equals(c, uri));
|
|
63
|
-
const deleted = LangiumDocuments.all.filter((d) => isLikeC4LangiumDocument(d) && notChanged(d.uri)).map((d) => d.uri).toArray();
|
|
64
|
-
logger.debug(
|
|
65
|
-
`[ServerRpc] received request to build:
|
|
66
|
-
changed (total ${changed.length}):${docs.map((d) => "\n - " + d).join("")}
|
|
67
|
-
deleted (total ${deleted.length}):${deleted.map((d) => "\n - " + d.toString()).join("\n")}`
|
|
68
|
-
);
|
|
69
|
-
await DocumentBuilder.update(changed, deleted, cancelToken);
|
|
70
|
-
}),
|
|
71
|
-
connection.onRequest(locate, (params) => {
|
|
72
|
-
if ("element" in params) {
|
|
73
|
-
return modelLocator.locateElement(params.element, params.property ?? "name");
|
|
74
|
-
}
|
|
75
|
-
if ("relation" in params) {
|
|
76
|
-
return modelLocator.locateRelation(params.relation);
|
|
77
|
-
}
|
|
78
|
-
if ("view" in params) {
|
|
79
|
-
return modelLocator.locateView(params.view);
|
|
80
|
-
}
|
|
81
|
-
nonexhaustive(params);
|
|
82
|
-
}),
|
|
83
|
-
connection.onRequest(changeView, async (request, _cancelToken) => {
|
|
84
|
-
return await modelEditor.applyChange(request);
|
|
85
|
-
})
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
dispose() {
|
|
89
|
-
let item;
|
|
90
|
-
while (item = this.disposables.pop()) {
|
|
91
|
-
try {
|
|
92
|
-
item.dispose();
|
|
93
|
-
} catch (e) {
|
|
94
|
-
logError(e);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
package/dist/ast.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { type c4 } from '@likec4/core';
|
|
3
|
-
import type { AstNode, DiagnosticInfo, LangiumDocument, MultiMap } from 'langium';
|
|
4
|
-
import type { ConditionalPick, SetRequired, ValueOf } from 'type-fest';
|
|
5
|
-
import type { Diagnostic } from 'vscode-languageserver-protocol';
|
|
6
|
-
import type { LikeC4Grammar } from './generated/ast';
|
|
7
|
-
import * as ast from './generated/ast';
|
|
8
|
-
export { ast };
|
|
9
|
-
declare const idattr: unique symbol;
|
|
10
|
-
declare module './generated/ast' {
|
|
11
|
-
interface Element {
|
|
12
|
-
[idattr]?: c4.Fqn | undefined;
|
|
13
|
-
}
|
|
14
|
-
interface ElementView {
|
|
15
|
-
[idattr]?: c4.ViewID | undefined;
|
|
16
|
-
}
|
|
17
|
-
interface DynamicView {
|
|
18
|
-
[idattr]?: c4.ViewID | undefined;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
type ParsedElementStyle = {
|
|
22
|
-
shape?: c4.ElementShape;
|
|
23
|
-
icon?: c4.IconUrl;
|
|
24
|
-
color?: c4.ThemeColor;
|
|
25
|
-
border?: c4.BorderStyle;
|
|
26
|
-
opacity?: number;
|
|
27
|
-
};
|
|
28
|
-
export interface ParsedAstSpecification {
|
|
29
|
-
kinds: Record<c4.ElementKind, ParsedElementStyle>;
|
|
30
|
-
relationships: Record<c4.RelationshipKind, {
|
|
31
|
-
color?: c4.ThemeColor;
|
|
32
|
-
line?: c4.RelationshipLineType;
|
|
33
|
-
head?: c4.RelationshipArrowType;
|
|
34
|
-
tail?: c4.RelationshipArrowType;
|
|
35
|
-
}>;
|
|
36
|
-
}
|
|
37
|
-
export interface ParsedAstElement {
|
|
38
|
-
id: c4.Fqn;
|
|
39
|
-
astPath: string;
|
|
40
|
-
kind: c4.ElementKind;
|
|
41
|
-
title: string;
|
|
42
|
-
description?: string;
|
|
43
|
-
technology?: string;
|
|
44
|
-
tags?: c4.NonEmptyArray<c4.Tag>;
|
|
45
|
-
links?: c4.NonEmptyArray<string>;
|
|
46
|
-
style: ParsedElementStyle;
|
|
47
|
-
}
|
|
48
|
-
export interface ParsedAstRelation {
|
|
49
|
-
id: c4.RelationID;
|
|
50
|
-
astPath: string;
|
|
51
|
-
source: c4.Fqn;
|
|
52
|
-
target: c4.Fqn;
|
|
53
|
-
kind?: c4.RelationshipKind;
|
|
54
|
-
tags?: c4.NonEmptyArray<c4.Tag>;
|
|
55
|
-
title: string;
|
|
56
|
-
color?: c4.ThemeColor;
|
|
57
|
-
line?: c4.RelationshipLineType;
|
|
58
|
-
head?: c4.RelationshipArrowType;
|
|
59
|
-
tail?: c4.RelationshipArrowType;
|
|
60
|
-
links?: c4.NonEmptyArray<string>;
|
|
61
|
-
}
|
|
62
|
-
export interface ParsedAstElementView {
|
|
63
|
-
__: 'element';
|
|
64
|
-
id: c4.ViewID;
|
|
65
|
-
viewOf?: c4.Fqn;
|
|
66
|
-
extends?: c4.ViewID;
|
|
67
|
-
astPath: string;
|
|
68
|
-
title: string | null;
|
|
69
|
-
description: string | null;
|
|
70
|
-
tags: c4.NonEmptyArray<c4.Tag> | null;
|
|
71
|
-
links: c4.NonEmptyArray<string> | null;
|
|
72
|
-
rules: c4.ViewRule[];
|
|
73
|
-
}
|
|
74
|
-
export interface ParsedAstDynamicView {
|
|
75
|
-
__: 'dynamic';
|
|
76
|
-
id: c4.ViewID;
|
|
77
|
-
astPath: string;
|
|
78
|
-
title: string | null;
|
|
79
|
-
description: string | null;
|
|
80
|
-
tags: c4.NonEmptyArray<c4.Tag> | null;
|
|
81
|
-
links: c4.NonEmptyArray<string> | null;
|
|
82
|
-
steps: c4.DynamicViewStep[];
|
|
83
|
-
rules: Array<c4.DynamicViewRule>;
|
|
84
|
-
}
|
|
85
|
-
export type ParsedAstView = ParsedAstElementView | ParsedAstDynamicView;
|
|
86
|
-
export declare const ViewOps: {
|
|
87
|
-
writeId<T extends ast.LikeC4View>(node: T, id: c4.ViewID): T;
|
|
88
|
-
readId(node: ast.LikeC4View): c4.ViewID | undefined;
|
|
89
|
-
};
|
|
90
|
-
export declare const ElementOps: {
|
|
91
|
-
writeId(node: ast.Element, id: c4.Fqn | null): ast.Element;
|
|
92
|
-
readId(node: ast.Element): c4.Fqn | undefined;
|
|
93
|
-
};
|
|
94
|
-
export interface DocFqnIndexEntry {
|
|
95
|
-
name: string;
|
|
96
|
-
el: WeakRef<ast.Element>;
|
|
97
|
-
path: string;
|
|
98
|
-
}
|
|
99
|
-
export type LikeC4AstNode = ValueOf<ConditionalPick<ast.LikeC4AstType, AstNode>>;
|
|
100
|
-
type LikeC4DocumentDiagnostic = Diagnostic & DiagnosticInfo<LikeC4AstNode>;
|
|
101
|
-
export interface LikeC4DocumentProps {
|
|
102
|
-
diagnostics?: Array<LikeC4DocumentDiagnostic>;
|
|
103
|
-
c4Specification?: ParsedAstSpecification;
|
|
104
|
-
c4Elements?: ParsedAstElement[];
|
|
105
|
-
c4Relations?: ParsedAstRelation[];
|
|
106
|
-
c4Views?: ParsedAstView[];
|
|
107
|
-
c4fqns?: MultiMap<c4.Fqn, DocFqnIndexEntry>;
|
|
108
|
-
}
|
|
109
|
-
export interface LikeC4LangiumDocument extends Omit<LangiumDocument<LikeC4Grammar>, 'diagnostics'>, LikeC4DocumentProps {
|
|
110
|
-
}
|
|
111
|
-
export interface FqnIndexedDocument extends Omit<LangiumDocument<LikeC4Grammar>, 'diagnostics'>, SetRequired<LikeC4DocumentProps, 'c4fqns'> {
|
|
112
|
-
}
|
|
113
|
-
export interface ParsedLikeC4LangiumDocument extends Omit<LangiumDocument<LikeC4Grammar>, 'diagnostics'>, Required<LikeC4DocumentProps> {
|
|
114
|
-
}
|
|
115
|
-
export declare function cleanParsedModel(doc: LikeC4LangiumDocument): ParsedLikeC4LangiumDocument;
|
|
116
|
-
export declare function isFqnIndexedDocument(doc: LangiumDocument): doc is FqnIndexedDocument;
|
|
117
|
-
export declare function isLikeC4LangiumDocument(doc: LangiumDocument): doc is LikeC4LangiumDocument;
|
|
118
|
-
export declare function isParsedLikeC4LangiumDocument(doc: LangiumDocument): doc is ParsedLikeC4LangiumDocument;
|
|
119
|
-
type Guard<N extends AstNode> = (n: AstNode) => n is N;
|
|
120
|
-
type Guarded<G> = G extends Guard<infer N> ? N : never;
|
|
121
|
-
declare const isValidatableAstNode: (n: AstNode) => n is ast.DynamicViewRulePredicate | ast.ViewRuleAutoLayout | ast.ViewRuleStyle | ast.DescedantsExpr | ast.ElementKindExpr | ast.ElementRef | ast.ElementTagExpr | ast.ExpandElementExpr | ast.WildcardExpr | ast.ElementStringProperty | ast.LinkProperty | ast.StyleProperties | ast.DynamicView | ast.ElementView | ast.ExplicitRelation | ast.ImplicitRelation | ast.RelationStringProperty | ast.RelationStyleProperty | ast.ColorProperty | ast.BorderProperty | ast.IconProperty | ast.OpacityProperty | ast.ShapeProperty | ast.ViewStringProperty | ast.ExcludePredicate | ast.IncludePredicate | ast.CustomElementExpr | ast.InOutExpr | ast.IncomingExpr | ast.OutgoingExpr | ast.RelationExpr | ast.SpecificationRelationshipKind | ast.RelationBody | ast.ElementBody | ast.ExtendElementBody | ast.Model | ast.Element | ast.ExtendElement | ast.SpecificationRule | ast.CustomElementExprBody | ast.DynamicViewBody | ast.ElementViewBody | ast.ModelViews | ast.SpecificationElementKind | ast.DynamicViewStep | ast.Tags | ast.SpecificationTag;
|
|
122
|
-
type ValidatableAstNode = Guarded<typeof isValidatableAstNode>;
|
|
123
|
-
export declare function checksFromDiagnostics(doc: LikeC4LangiumDocument): {
|
|
124
|
-
isValid: (n: ValidatableAstNode) => boolean;
|
|
125
|
-
invalidNodes: WeakSet<ast.DynamicViewRulePredicate | ast.ViewRuleAutoLayout | ast.ViewRuleStyle | ast.DescedantsExpr | ast.ElementKindExpr | ast.ElementRef | ast.ElementTagExpr | ast.ExpandElementExpr | ast.WildcardExpr | ast.ElementStringProperty | ast.LinkProperty | ast.StyleProperties | ast.DynamicView | ast.ElementView | ast.ExplicitRelation | ast.ImplicitRelation | ast.RelationStringProperty | ast.RelationStyleProperty | ast.ColorProperty | ast.BorderProperty | ast.IconProperty | ast.OpacityProperty | ast.ShapeProperty | ast.ViewStringProperty | ast.ExcludePredicate | ast.IncludePredicate | ast.CustomElementExpr | ast.InOutExpr | ast.IncomingExpr | ast.OutgoingExpr | ast.RelationExpr | ast.SpecificationRelationshipKind | ast.RelationBody | ast.ElementBody | ast.ExtendElementBody | ast.Model | ast.Element | ast.ExtendElement | ast.SpecificationRule | ast.CustomElementExprBody | ast.DynamicViewBody | ast.ElementViewBody | ast.ModelViews | ast.SpecificationElementKind | ast.DynamicViewStep | ast.Tags | ast.SpecificationTag>;
|
|
126
|
-
};
|
|
127
|
-
export type ChecksFromDiagnostics = ReturnType<typeof checksFromDiagnostics>;
|
|
128
|
-
export declare function streamModel(doc: LikeC4LangiumDocument, isValid: ChecksFromDiagnostics['isValid']): Generator<ast.Relation | ast.Element, void, unknown>;
|
|
129
|
-
export declare function resolveRelationPoints(node: ast.Relation): {
|
|
130
|
-
source: ast.Element;
|
|
131
|
-
target: ast.Element;
|
|
132
|
-
};
|
|
133
|
-
export declare function parseAstOpacityProperty({ value }: ast.OpacityProperty): number;
|
|
134
|
-
export declare function toElementStyle(props?: Array<ast.StyleProperty>): ParsedElementStyle;
|
|
135
|
-
export declare function toRelationshipStyle(props?: ast.SpecificationRelationshipKind['props']): {
|
|
136
|
-
color?: c4.ThemeColor;
|
|
137
|
-
line?: c4.RelationshipLineType;
|
|
138
|
-
head?: c4.RelationshipArrowType;
|
|
139
|
-
tail?: c4.RelationshipArrowType;
|
|
140
|
-
};
|
|
141
|
-
export declare function toRelationshipStyleExcludeDefaults(props?: ast.SpecificationRelationshipKind['props']): {
|
|
142
|
-
tail?: c4.RelationshipArrowType;
|
|
143
|
-
head?: "crow" | "diamond" | "none" | "odiamond" | "onormal" | "open" | "vee";
|
|
144
|
-
line?: "dotted" | "solid";
|
|
145
|
-
color?: "amber" | "blue" | "green" | "indigo" | "muted" | "primary" | "red" | "secondary" | "sky" | "slate";
|
|
146
|
-
};
|
|
147
|
-
export declare function toAutoLayout(direction: ast.ViewLayoutDirection): c4.ViewRuleAutoLayout['autoLayout'];
|
|
148
|
-
export declare function toAstViewLayoutDirection(c4: c4.ViewRuleAutoLayout['autoLayout']): ast.ViewLayoutDirection;
|
|
149
|
-
//# sourceMappingURL=ast.d.ts.map
|
package/dist/ast.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DefaultArrowType,
|
|
3
|
-
DefaultLineStyle,
|
|
4
|
-
DefaultRelationshipColor,
|
|
5
|
-
nonexhaustive,
|
|
6
|
-
RelationRefError
|
|
7
|
-
} from "@likec4/core";
|
|
8
|
-
import { AstUtils, DocumentState } from "langium";
|
|
9
|
-
import { clamp, isNullish } from "remeda";
|
|
10
|
-
import { DiagnosticSeverity } from "vscode-languageserver-protocol";
|
|
11
|
-
import { elementRef } from "./elementRef.js";
|
|
12
|
-
import * as ast from "./generated/ast.js";
|
|
13
|
-
import { LikeC4LanguageMetaData } from "./generated/module.js";
|
|
14
|
-
export { ast };
|
|
15
|
-
const idattr = Symbol.for("idattr");
|
|
16
|
-
export const ViewOps = {
|
|
17
|
-
writeId(node, id) {
|
|
18
|
-
node[idattr] = id;
|
|
19
|
-
return node;
|
|
20
|
-
},
|
|
21
|
-
readId(node) {
|
|
22
|
-
return node[idattr];
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
export const ElementOps = {
|
|
26
|
-
writeId(node, id) {
|
|
27
|
-
if (isNullish(id)) {
|
|
28
|
-
node[idattr] = void 0;
|
|
29
|
-
} else {
|
|
30
|
-
node[idattr] = id;
|
|
31
|
-
}
|
|
32
|
-
return node;
|
|
33
|
-
},
|
|
34
|
-
readId(node) {
|
|
35
|
-
return node[idattr];
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
export function cleanParsedModel(doc) {
|
|
39
|
-
const props = {
|
|
40
|
-
c4Specification: {
|
|
41
|
-
kinds: {},
|
|
42
|
-
relationships: {}
|
|
43
|
-
},
|
|
44
|
-
c4Elements: [],
|
|
45
|
-
c4Relations: [],
|
|
46
|
-
c4Views: []
|
|
47
|
-
};
|
|
48
|
-
return Object.assign(doc, props);
|
|
49
|
-
}
|
|
50
|
-
export function isFqnIndexedDocument(doc) {
|
|
51
|
-
return isLikeC4LangiumDocument(doc) && doc.state >= DocumentState.IndexedContent && !!doc.c4fqns;
|
|
52
|
-
}
|
|
53
|
-
export function isLikeC4LangiumDocument(doc) {
|
|
54
|
-
return doc.textDocument.languageId === LikeC4LanguageMetaData.languageId;
|
|
55
|
-
}
|
|
56
|
-
export function isParsedLikeC4LangiumDocument(doc) {
|
|
57
|
-
return isLikeC4LangiumDocument(doc) && doc.state == DocumentState.Validated && !!doc.c4Specification && !!doc.c4Elements && !!doc.c4Relations && !!doc.c4Views && !!doc.c4fqns;
|
|
58
|
-
}
|
|
59
|
-
function validatableAstNodeGuards(predicates) {
|
|
60
|
-
return (n) => predicates.some((p) => p(n));
|
|
61
|
-
}
|
|
62
|
-
const isValidatableAstNode = validatableAstNodeGuards([
|
|
63
|
-
ast.isCustomElementExprBody,
|
|
64
|
-
ast.isViewRulePredicateExpr,
|
|
65
|
-
ast.isDynamicViewRulePredicate,
|
|
66
|
-
ast.isViewProperty,
|
|
67
|
-
ast.isStyleProperty,
|
|
68
|
-
ast.isTags,
|
|
69
|
-
ast.isViewRule,
|
|
70
|
-
ast.isDynamicViewRule,
|
|
71
|
-
ast.isDynamicViewStep,
|
|
72
|
-
ast.isElementViewBody,
|
|
73
|
-
ast.isDynamicViewBody,
|
|
74
|
-
ast.isLikeC4View,
|
|
75
|
-
ast.isRelationProperty,
|
|
76
|
-
ast.isRelationBody,
|
|
77
|
-
ast.isRelation,
|
|
78
|
-
ast.isElementProperty,
|
|
79
|
-
ast.isElementBody,
|
|
80
|
-
ast.isElement,
|
|
81
|
-
ast.isExtendElementBody,
|
|
82
|
-
ast.isExtendElement,
|
|
83
|
-
ast.isSpecificationElementKind,
|
|
84
|
-
ast.isSpecificationRelationshipKind,
|
|
85
|
-
ast.isSpecificationTag,
|
|
86
|
-
ast.isSpecificationRule,
|
|
87
|
-
ast.isModelViews,
|
|
88
|
-
ast.isModel
|
|
89
|
-
]);
|
|
90
|
-
export function checksFromDiagnostics(doc) {
|
|
91
|
-
const errors = doc.diagnostics?.filter((d) => d.severity === DiagnosticSeverity.Error) ?? [];
|
|
92
|
-
const invalidNodes = new WeakSet(
|
|
93
|
-
errors.flatMap((d) => {
|
|
94
|
-
return AstUtils.getContainerOfType(d.node, isValidatableAstNode) ?? [];
|
|
95
|
-
}) ?? []
|
|
96
|
-
);
|
|
97
|
-
const isValid = (n) => !invalidNodes.has(n);
|
|
98
|
-
return {
|
|
99
|
-
isValid,
|
|
100
|
-
invalidNodes
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
export function* streamModel(doc, isValid) {
|
|
104
|
-
const traverseStack = doc.parseResult.value.models.flatMap((m) => isValid(m) ? m.elements : []);
|
|
105
|
-
const relations = [];
|
|
106
|
-
let el;
|
|
107
|
-
while (el = traverseStack.shift()) {
|
|
108
|
-
if (!isValid(el)) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (ast.isRelation(el)) {
|
|
112
|
-
relations.push(el);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (ast.isExtendElement(el)) {
|
|
116
|
-
if (el.body && el.body.elements.length > 0) {
|
|
117
|
-
traverseStack.push(...el.body.elements);
|
|
118
|
-
}
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (el.body && el.body.elements.length > 0) {
|
|
122
|
-
for (const nested of el.body.elements) {
|
|
123
|
-
if (ast.isRelation(nested)) {
|
|
124
|
-
relations.push(nested);
|
|
125
|
-
} else {
|
|
126
|
-
traverseStack.push(nested);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
yield el;
|
|
131
|
-
}
|
|
132
|
-
for (const relation of relations) {
|
|
133
|
-
yield relation;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
export function resolveRelationPoints(node) {
|
|
137
|
-
const target = elementRef(node.target);
|
|
138
|
-
if (!target) {
|
|
139
|
-
throw new RelationRefError("Invalid reference to target");
|
|
140
|
-
}
|
|
141
|
-
if (ast.isExplicitRelation(node)) {
|
|
142
|
-
const source = elementRef(node.source);
|
|
143
|
-
if (!source) {
|
|
144
|
-
throw new RelationRefError("Invalid reference to source");
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
source,
|
|
148
|
-
target
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
source: node.$container.$container,
|
|
153
|
-
target
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
export function parseAstOpacityProperty({ value }) {
|
|
157
|
-
const opacity = parseFloat(value);
|
|
158
|
-
return isNaN(opacity) ? 100 : clamp(opacity, { min: 0, max: 100 });
|
|
159
|
-
}
|
|
160
|
-
export function toElementStyle(props) {
|
|
161
|
-
const result = {};
|
|
162
|
-
if (!props || props.length === 0) {
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
for (const prop of props) {
|
|
166
|
-
switch (true) {
|
|
167
|
-
case ast.isBorderProperty(prop): {
|
|
168
|
-
result.border = prop.value;
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
case ast.isColorProperty(prop): {
|
|
172
|
-
result.color = prop.value;
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
case ast.isShapeProperty(prop): {
|
|
176
|
-
result.shape = prop.value;
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
case ast.isIconProperty(prop): {
|
|
180
|
-
result.icon = prop.value;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
case ast.isOpacityProperty(prop): {
|
|
184
|
-
result.opacity = parseAstOpacityProperty(prop);
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
default:
|
|
188
|
-
nonexhaustive(prop.$type);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return result;
|
|
192
|
-
}
|
|
193
|
-
export function toRelationshipStyle(props) {
|
|
194
|
-
const result = {};
|
|
195
|
-
if (!props || props.length === 0) {
|
|
196
|
-
return result;
|
|
197
|
-
}
|
|
198
|
-
for (const prop of props) {
|
|
199
|
-
if (ast.isColorProperty(prop)) {
|
|
200
|
-
result.color = prop.value;
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
if (ast.isLineProperty(prop)) {
|
|
204
|
-
result.line = prop.value;
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
if (ast.isArrowProperty(prop)) {
|
|
208
|
-
switch (prop.key) {
|
|
209
|
-
case "head": {
|
|
210
|
-
result.head = prop.value;
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
case "tail": {
|
|
214
|
-
result.tail = prop.value;
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
default: {
|
|
218
|
-
nonexhaustive(prop);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
nonexhaustive(prop);
|
|
224
|
-
}
|
|
225
|
-
return result;
|
|
226
|
-
}
|
|
227
|
-
export function toRelationshipStyleExcludeDefaults(props) {
|
|
228
|
-
const { color, line, head, tail } = toRelationshipStyle(props);
|
|
229
|
-
return {
|
|
230
|
-
...color && color !== DefaultRelationshipColor ? { color } : {},
|
|
231
|
-
...line && line !== DefaultLineStyle ? { line } : {},
|
|
232
|
-
...head && head !== DefaultArrowType ? { head } : {},
|
|
233
|
-
...tail ? { tail } : {}
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
export function toAutoLayout(direction) {
|
|
237
|
-
switch (direction) {
|
|
238
|
-
case "TopBottom": {
|
|
239
|
-
return "TB";
|
|
240
|
-
}
|
|
241
|
-
case "BottomTop": {
|
|
242
|
-
return "BT";
|
|
243
|
-
}
|
|
244
|
-
case "LeftRight": {
|
|
245
|
-
return "LR";
|
|
246
|
-
}
|
|
247
|
-
case "RightLeft": {
|
|
248
|
-
return "RL";
|
|
249
|
-
}
|
|
250
|
-
default:
|
|
251
|
-
nonexhaustive(direction);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
export function toAstViewLayoutDirection(c4) {
|
|
255
|
-
switch (c4) {
|
|
256
|
-
case "TB": {
|
|
257
|
-
return "TopBottom";
|
|
258
|
-
}
|
|
259
|
-
case "BT": {
|
|
260
|
-
return "BottomTop";
|
|
261
|
-
}
|
|
262
|
-
case "LR": {
|
|
263
|
-
return "LeftRight";
|
|
264
|
-
}
|
|
265
|
-
case "RL": {
|
|
266
|
-
return "RightLeft";
|
|
267
|
-
}
|
|
268
|
-
default:
|
|
269
|
-
nonexhaustive(c4);
|
|
270
|
-
}
|
|
271
|
-
}
|
package/dist/browser/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BrowserMessageReader, BrowserMessageWriter } from 'vscode-languageserver/browser';
|
|
2
|
-
export declare function startLanguageServer(): {
|
|
3
|
-
connection: import("vscode-languageserver/browser").Connection;
|
|
4
|
-
messageReader: BrowserMessageReader;
|
|
5
|
-
messageWriter: BrowserMessageWriter;
|
|
6
|
-
shared: import("../module").LikeC4SharedServices;
|
|
7
|
-
likec4: import("../module").LikeC4Services;
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/browser/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { startLanguageServer as startLanguim } from "langium/lsp";
|
|
2
|
-
import { BrowserMessageReader, BrowserMessageWriter, createConnection } from "vscode-languageserver/browser";
|
|
3
|
-
import { createLanguageServices } from "../module.js";
|
|
4
|
-
export function startLanguageServer() {
|
|
5
|
-
const messageReader = new BrowserMessageReader(self);
|
|
6
|
-
const messageWriter = new BrowserMessageWriter(self);
|
|
7
|
-
const connection = createConnection(messageReader, messageWriter);
|
|
8
|
-
const services = createLanguageServices({ connection });
|
|
9
|
-
startLanguim(services.shared);
|
|
10
|
-
return {
|
|
11
|
-
...services,
|
|
12
|
-
connection,
|
|
13
|
-
messageReader,
|
|
14
|
-
messageWriter
|
|
15
|
-
};
|
|
16
|
-
}
|
package/dist/elementRef.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type c4 } from '@likec4/core';
|
|
2
|
-
import type { ast } from './ast';
|
|
3
|
-
/**
|
|
4
|
-
* Returns referenced AST Element
|
|
5
|
-
*/
|
|
6
|
-
export declare function elementRef(node: ast.ElementRef | ast.FqnElementRef): ast.Element | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Returns FQN of FqnElementRef
|
|
9
|
-
* a.b.c.d - for c node returns a.b.c
|
|
10
|
-
*/
|
|
11
|
-
export declare function getFqnElementRef(node: ast.FqnElementRef): c4.Fqn;
|
|
12
|
-
//# sourceMappingURL=elementRef.d.ts.map
|
package/dist/elementRef.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function elementRef(node) {
|
|
2
|
-
return node.el.ref;
|
|
3
|
-
}
|
|
4
|
-
export function getFqnElementRef(node) {
|
|
5
|
-
const name = [node.el.$refText];
|
|
6
|
-
let parent = node.parent;
|
|
7
|
-
while (parent) {
|
|
8
|
-
name.push(parent.el.$refText);
|
|
9
|
-
parent = parent.parent;
|
|
10
|
-
}
|
|
11
|
-
if (name.length === 1) {
|
|
12
|
-
return name[0];
|
|
13
|
-
}
|
|
14
|
-
return name.reverse().join(".");
|
|
15
|
-
}
|