@likec4/language-server 0.37.1 → 0.40.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.
Files changed (75) hide show
  1. package/dist/Rpc.d.ts +6 -0
  2. package/dist/Rpc.js +130 -0
  3. package/dist/ast.d.ts +0 -97
  4. package/dist/ast.js +127 -143
  5. package/dist/elementRef.d.ts +1 -2
  6. package/dist/elementRef.js +31 -44
  7. package/dist/generated/ast.d.ts +4 -5
  8. package/dist/generated/ast.js +310 -315
  9. package/dist/generated/grammar.d.ts +0 -2
  10. package/dist/generated/grammar.js +2 -3177
  11. package/dist/generated/module.d.ts +1 -6
  12. package/dist/generated/module.js +13 -18
  13. package/dist/index.d.ts +0 -1
  14. package/dist/index.js +2 -3
  15. package/dist/logger.d.ts +0 -1
  16. package/dist/logger.js +39 -42
  17. package/dist/lsp/CodeLensProvider.d.ts +0 -1
  18. package/dist/lsp/CodeLensProvider.js +28 -32
  19. package/dist/lsp/DocumentLinkProvider.d.ts +0 -1
  20. package/dist/lsp/DocumentLinkProvider.js +26 -33
  21. package/dist/lsp/DocumentSymbolProvider.d.ts +0 -1
  22. package/dist/lsp/DocumentSymbolProvider.js +165 -167
  23. package/dist/lsp/HoverProvider.d.ts +0 -1
  24. package/dist/lsp/HoverProvider.js +35 -48
  25. package/dist/lsp/SemanticTokenProvider.d.ts +0 -1
  26. package/dist/lsp/SemanticTokenProvider.js +153 -201
  27. package/dist/lsp/index.d.ts +0 -1
  28. package/dist/lsp/index.js +5 -6
  29. package/dist/model/fqn-computation.d.ts +0 -1
  30. package/dist/model/fqn-computation.js +39 -40
  31. package/dist/model/fqn-index.d.ts +0 -1
  32. package/dist/model/fqn-index.js +112 -142
  33. package/dist/model/index.d.ts +0 -1
  34. package/dist/model/index.js +5 -6
  35. package/dist/model/model-builder.d.ts +10 -6
  36. package/dist/model/model-builder.js +242 -177
  37. package/dist/model/model-locator.d.ts +1 -2
  38. package/dist/model/model-locator.js +102 -100
  39. package/dist/model/model-parser.d.ts +2 -7
  40. package/dist/model/model-parser.js +296 -287
  41. package/dist/module.d.ts +4 -2
  42. package/dist/module.js +69 -60
  43. package/dist/protocol.d.ts +16 -20
  44. package/dist/protocol.js +14 -22
  45. package/dist/references/index.d.ts +0 -1
  46. package/dist/references/index.js +2 -3
  47. package/dist/references/scope-computation.d.ts +2 -3
  48. package/dist/references/scope-computation.js +68 -70
  49. package/dist/references/scope-provider.d.ts +1 -2
  50. package/dist/references/scope-provider.js +126 -116
  51. package/dist/shared/WorkspaceManager.d.ts +2 -4
  52. package/dist/shared/WorkspaceManager.js +13 -16
  53. package/dist/shared/index.d.ts +0 -1
  54. package/dist/shared/index.js +1 -2
  55. package/dist/test/index.d.ts +0 -1
  56. package/dist/test/index.js +1 -2
  57. package/dist/test/testServices.d.ts +6 -7
  58. package/dist/test/testServices.js +64 -61
  59. package/dist/utils.d.ts +1 -1
  60. package/dist/utils.js +4 -3
  61. package/dist/validation/element.d.ts +0 -2
  62. package/dist/validation/element.js +28 -39
  63. package/dist/validation/index.d.ts +0 -1
  64. package/dist/validation/index.js +36 -46
  65. package/dist/validation/relation.d.ts +0 -2
  66. package/dist/validation/relation.js +43 -47
  67. package/dist/validation/specification.d.ts +0 -2
  68. package/dist/validation/specification.js +21 -30
  69. package/dist/validation/view.d.ts +0 -2
  70. package/dist/validation/view.js +16 -22
  71. package/package.json +20 -13
  72. package/contrib/likec4.monarch.ts +0 -48
  73. package/contrib/likec4.tmLanguage.json +0 -73
  74. package/dist/registerProtocolHandlers.d.ts +0 -3
  75. package/dist/registerProtocolHandlers.js +0 -112
@@ -1,55 +1,42 @@
1
- import { AstNodeHoverProvider } from 'langium';
2
- import stripIndent from 'strip-indent';
3
- import { ast } from '../ast';
1
+ import { AstNodeHoverProvider } from "langium";
2
+ import stripIndent from "strip-indent";
3
+ import { ast } from "../ast.js";
4
4
  export class LikeC4HoverProvider extends AstNodeHoverProvider {
5
- locator;
6
- constructor(services) {
7
- super(services);
8
- this.locator = services.likec4.ModelLocator;
9
- }
10
- getAstNodeHoverContent(node) {
11
- if (ast.isTag(node)) {
12
- return {
13
- contents: {
14
- kind: 'markdown',
15
- value: stripIndent(`
5
+ locator;
6
+ constructor(services) {
7
+ super(services);
8
+ this.locator = services.likec4.ModelLocator;
9
+ }
10
+ getAstNodeHoverContent(node) {
11
+ if (ast.isTag(node)) {
12
+ return {
13
+ contents: {
14
+ kind: "markdown",
15
+ value: stripIndent(`
16
16
  tag: \`${node.name}\`
17
17
  `)
18
- }
19
- };
20
- }
21
- // if (ast.isElementKind(node)) {
22
- // const spec = this.specIndex.get(node.name as ElementKind)
23
- // return {
24
- // contents: {
25
- // kind: 'markdown',
26
- // value: stripIndent(`
27
- // kind: **${spec.id}**
28
- // shape: ${spec.style.shape}
29
- // `)
30
- // }
31
- // }
32
- // }
33
- if (ast.isElement(node)) {
34
- const el = this.locator.getParsedElement(node);
35
- if (!el) {
36
- return;
37
- }
38
- const lines = [el.id, `${el.kind}: **${el.title}**`];
39
- if (el.tags && el.tags.length > 0) {
40
- lines.push(' \n', el.tags.map(t => '#' + t).join(', '));
41
- }
42
- if (el.description) {
43
- lines.push(' \n', el.description);
44
- }
45
- return {
46
- contents: {
47
- kind: 'markdown',
48
- value: lines.join(' \n')
49
- }
50
- };
51
18
  }
19
+ };
20
+ }
21
+ if (ast.isElement(node)) {
22
+ const el = this.locator.getParsedElement(node);
23
+ if (!el) {
52
24
  return;
25
+ }
26
+ const lines = [el.id, `${el.kind}: **${el.title}**`];
27
+ if (el.tags && el.tags.length > 0) {
28
+ lines.push(" \n", el.tags.map((t) => "#" + t).join(", "));
29
+ }
30
+ if (el.description) {
31
+ lines.push(" \n", el.description);
32
+ }
33
+ return {
34
+ contents: {
35
+ kind: "markdown",
36
+ value: lines.join(" \n")
37
+ }
38
+ };
53
39
  }
40
+ return;
41
+ }
54
42
  }
55
- //# sourceMappingURL=HoverProvider.js.map
@@ -4,4 +4,3 @@ export declare class LikeC4SemanticTokenProvider extends AbstractSemanticTokenPr
4
4
  private highlightAstElement;
5
5
  private highlightView;
6
6
  }
7
- //# sourceMappingURL=SemanticTokenProvider.d.ts.map
@@ -1,210 +1,162 @@
1
- import { AbstractSemanticTokenProvider } from 'langium';
2
- import { SemanticTokenModifiers, SemanticTokenTypes } from 'vscode-languageserver-protocol';
3
- import { ast } from '../ast';
4
- import { isElementRefHead } from '../elementRef';
1
+ import { AbstractSemanticTokenProvider } from "langium";
2
+ import { SemanticTokenModifiers, SemanticTokenTypes } from "vscode-languageserver-protocol";
3
+ import { ast } from "../ast.js";
4
+ import { isElementRefHead } from "../elementRef.js";
5
5
  export class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
6
- highlightElement(node, acceptor) {
7
- const keyword = (keyword, _index) => acceptor({
8
- node,
9
- keyword,
10
- type: SemanticTokenTypes.keyword,
11
- modifier: [SemanticTokenModifiers.defaultLibrary]
12
- });
13
- if ('arr' in node) {
14
- acceptor({
15
- node,
16
- property: 'arr',
17
- type: SemanticTokenTypes.keyword,
18
- modifier: [SemanticTokenModifiers.defaultLibrary]
19
- });
20
- }
21
- if (ast.isElementRef(node) || ast.isStrictElementRef(node)) {
22
- acceptor({
23
- node,
24
- property: 'el',
25
- type: isElementRefHead(node) ? SemanticTokenTypes.variable : SemanticTokenTypes.property
26
- });
27
- return;
28
- }
29
- if (ast.isElementViewRef(node)) {
30
- acceptor({
31
- node,
32
- property: 'view',
33
- type: SemanticTokenTypes.variable
34
- });
35
- return;
36
- }
37
- if (ast.isWildcardExpression(node)) {
38
- acceptor({
39
- node,
40
- property: 'isWildcard',
41
- type: SemanticTokenTypes.variable
42
- });
43
- return;
44
- }
45
- // if (
46
- // ast.isRelation(node) ||
47
- // ast.isRelationExpression(node) ||
48
- // ast.isIncomingExpression(node) ||
49
- // ast.isInOutExpression(node) ||
50
- // ast.isOutgoingExpression(node)
51
- // ) {
52
- // acceptor({
53
- // node,
54
- // property: 'arr',
55
- // type: SemanticTokenTypes.keyword,
56
- // modifier: [SemanticTokenModifiers.defaultLibrary]
57
- // })
58
- // }
59
- if (ast.isElementKindExpression(node) || ast.isElementTagExpression(node)) {
60
- keyword('element');
61
- if (ast.isElementKindExpression(node)) {
62
- keyword('kind');
63
- acceptor({
64
- node,
65
- property: 'kind',
66
- type: SemanticTokenTypes.type,
67
- modifier: [SemanticTokenModifiers.definition]
68
- });
69
- return;
70
- }
71
- if (ast.isElementTagExpression(node)) {
72
- keyword('tag');
73
- acceptor({
74
- node,
75
- property: 'tag',
76
- type: SemanticTokenTypes.type,
77
- modifier: [SemanticTokenModifiers.definition]
78
- });
79
- return;
80
- }
81
- }
82
- if (ast.isRelation(node)) {
83
- if ('title' in node) {
84
- acceptor({
85
- node,
86
- property: 'title',
87
- type: SemanticTokenTypes.string
88
- });
89
- }
90
- return;
91
- }
92
- if (ast.isElementKind(node)) {
93
- acceptor({
94
- node,
95
- property: 'name',
96
- type: SemanticTokenTypes.type,
97
- modifier: [SemanticTokenModifiers.definition]
98
- });
99
- return;
100
- }
101
- if (ast.isTags(node)) {
102
- acceptor({
103
- node,
104
- property: 'value',
105
- type: SemanticTokenTypes.type,
106
- modifier: [SemanticTokenModifiers.definition]
107
- });
108
- return;
109
- }
110
- if (ast.isTag(node)) {
111
- acceptor({
112
- node,
113
- property: 'name',
114
- type: SemanticTokenTypes.type,
115
- modifier: [SemanticTokenModifiers.definition]
116
- });
117
- return;
118
- }
119
- if (ast.isColorProperty(node) || ast.isShapeProperty(node)) {
120
- acceptor({
121
- node,
122
- property: 'key',
123
- type: SemanticTokenTypes.keyword
124
- });
125
- acceptor({
126
- node,
127
- property: 'value',
128
- type: SemanticTokenTypes.enum
129
- });
130
- return;
131
- }
132
- if (ast.isLinkProperty(node) || ast.isIconProperty(node)) {
133
- acceptor({
134
- node,
135
- property: 'key',
136
- type: SemanticTokenTypes.keyword
137
- });
138
- acceptor({
139
- node,
140
- property: 'value',
141
- type: SemanticTokenTypes.string
142
- });
143
- return;
144
- }
145
- // ViewProperty | ElementStringProperty | RelationStringProperty | LinkProperty
146
- // if (
147
- // ast.isViewProperty(node) ||
148
- // ast.isElementStringProperty(node) ||
149
- // ast.isRelationStringProperty(node) ||
150
- // ast.isLinkProperty(node) ||
151
- // ast.isIconProperty(node)
152
- // ) {
153
- // acceptor({
154
- // node,
155
- // property: 'key',
156
- // type: SemanticTokenTypes.keyword
157
- // // type: SemanticTokenTypes.property,
158
- // // modifier: [
159
- // // SemanticTokenModifiers.readonly,
160
- // // SemanticTokenModifiers.declaration
161
- // // ]
162
- // })
163
- // acceptor({
164
- // node,
165
- // property: 'value',
166
- // type: SemanticTokenTypes.string
167
- // })
168
- // return
169
- // }
170
- // if (ast.isModel(node)) {
171
- // keyword('model')
172
- // return
173
- // }
174
- // if (ast.isModelViews(node)) {
175
- // keyword('views')
176
- // return
177
- // }
178
- if (ast.isElement(node)) {
179
- return this.highlightAstElement(node, acceptor);
180
- }
181
- if (ast.isView(node)) {
182
- return this.highlightView(node, acceptor);
183
- }
6
+ highlightElement(node, acceptor) {
7
+ const keyword = (keyword2, _index) => acceptor({
8
+ node,
9
+ keyword: keyword2,
10
+ type: SemanticTokenTypes.keyword,
11
+ modifier: [SemanticTokenModifiers.defaultLibrary]
12
+ });
13
+ if ("arr" in node) {
14
+ acceptor({
15
+ node,
16
+ property: "arr",
17
+ type: SemanticTokenTypes.keyword,
18
+ modifier: [SemanticTokenModifiers.defaultLibrary]
19
+ });
20
+ }
21
+ if (ast.isElementRef(node) || ast.isStrictElementRef(node)) {
22
+ acceptor({
23
+ node,
24
+ property: "el",
25
+ type: isElementRefHead(node) ? SemanticTokenTypes.variable : SemanticTokenTypes.property
26
+ });
27
+ return;
28
+ }
29
+ if (ast.isElementViewRef(node)) {
30
+ acceptor({
31
+ node,
32
+ property: "view",
33
+ type: SemanticTokenTypes.variable
34
+ });
35
+ return;
36
+ }
37
+ if (ast.isWildcardExpression(node)) {
38
+ acceptor({
39
+ node,
40
+ property: "isWildcard",
41
+ type: SemanticTokenTypes.variable
42
+ });
43
+ return;
184
44
  }
185
- highlightAstElement(node, acceptor) {
45
+ if (ast.isElementKindExpression(node) || ast.isElementTagExpression(node)) {
46
+ keyword("element");
47
+ if (ast.isElementKindExpression(node)) {
48
+ keyword("kind");
186
49
  acceptor({
187
- node,
188
- property: 'name',
189
- type: SemanticTokenTypes.variable,
190
- modifier: [SemanticTokenModifiers.declaration]
50
+ node,
51
+ property: "kind",
52
+ type: SemanticTokenTypes.type,
53
+ modifier: [SemanticTokenModifiers.definition]
191
54
  });
55
+ return;
56
+ }
57
+ if (ast.isElementTagExpression(node)) {
58
+ keyword("tag");
59
+ acceptor({
60
+ node,
61
+ property: "tag",
62
+ type: SemanticTokenTypes.type,
63
+ modifier: [SemanticTokenModifiers.definition]
64
+ });
65
+ return;
66
+ }
67
+ }
68
+ if (ast.isRelation(node)) {
69
+ if ("title" in node) {
192
70
  acceptor({
193
- node,
194
- property: 'kind',
195
- type: SemanticTokenTypes.keyword,
196
- modifier: []
71
+ node,
72
+ property: "title",
73
+ type: SemanticTokenTypes.string
197
74
  });
75
+ }
76
+ return;
77
+ }
78
+ if (ast.isElementKind(node)) {
79
+ acceptor({
80
+ node,
81
+ property: "name",
82
+ type: SemanticTokenTypes.type,
83
+ modifier: [SemanticTokenModifiers.definition]
84
+ });
85
+ return;
86
+ }
87
+ if (ast.isTags(node)) {
88
+ acceptor({
89
+ node,
90
+ property: "value",
91
+ type: SemanticTokenTypes.type,
92
+ modifier: [SemanticTokenModifiers.definition]
93
+ });
94
+ return;
95
+ }
96
+ if (ast.isTag(node)) {
97
+ acceptor({
98
+ node,
99
+ property: "name",
100
+ type: SemanticTokenTypes.type,
101
+ modifier: [SemanticTokenModifiers.definition]
102
+ });
103
+ return;
104
+ }
105
+ if (ast.isColorProperty(node) || ast.isShapeProperty(node)) {
106
+ acceptor({
107
+ node,
108
+ property: "key",
109
+ type: SemanticTokenTypes.keyword
110
+ });
111
+ acceptor({
112
+ node,
113
+ property: "value",
114
+ type: SemanticTokenTypes.enum
115
+ });
116
+ return;
117
+ }
118
+ if (ast.isLinkProperty(node) || ast.isIconProperty(node)) {
119
+ acceptor({
120
+ node,
121
+ property: "key",
122
+ type: SemanticTokenTypes.keyword
123
+ });
124
+ acceptor({
125
+ node,
126
+ property: "value",
127
+ type: SemanticTokenTypes.string
128
+ });
129
+ return;
130
+ }
131
+ if (ast.isElement(node)) {
132
+ return this.highlightAstElement(node, acceptor);
133
+ }
134
+ if (ast.isView(node)) {
135
+ return this.highlightView(node, acceptor);
198
136
  }
199
- highlightView(node, acceptor) {
200
- if (node.name) {
201
- acceptor({
202
- node,
203
- property: 'name',
204
- type: SemanticTokenTypes.variable,
205
- modifier: [SemanticTokenModifiers.declaration]
206
- });
207
- }
137
+ }
138
+ highlightAstElement(node, acceptor) {
139
+ acceptor({
140
+ node,
141
+ property: "name",
142
+ type: SemanticTokenTypes.variable,
143
+ modifier: [SemanticTokenModifiers.declaration]
144
+ });
145
+ acceptor({
146
+ node,
147
+ property: "kind",
148
+ type: SemanticTokenTypes.keyword,
149
+ modifier: []
150
+ });
151
+ }
152
+ highlightView(node, acceptor) {
153
+ if (node.name) {
154
+ acceptor({
155
+ node,
156
+ property: "name",
157
+ type: SemanticTokenTypes.variable,
158
+ modifier: [SemanticTokenModifiers.declaration]
159
+ });
208
160
  }
161
+ }
209
162
  }
210
- //# sourceMappingURL=SemanticTokenProvider.js.map
@@ -3,4 +3,3 @@ export * from './DocumentLinkProvider';
3
3
  export * from './DocumentSymbolProvider';
4
4
  export * from './HoverProvider';
5
5
  export * from './SemanticTokenProvider';
6
- //# sourceMappingURL=index.d.ts.map
package/dist/lsp/index.js CHANGED
@@ -1,6 +1,5 @@
1
- export * from './CodeLensProvider';
2
- export * from './DocumentLinkProvider';
3
- export * from './DocumentSymbolProvider';
4
- export * from './HoverProvider';
5
- export * from './SemanticTokenProvider';
6
- //# sourceMappingURL=index.js.map
1
+ export * from "./CodeLensProvider.js";
2
+ export * from "./DocumentLinkProvider.js";
3
+ export * from "./DocumentSymbolProvider.js";
4
+ export * from "./HoverProvider.js";
5
+ export * from "./SemanticTokenProvider.js";
@@ -1,4 +1,3 @@
1
1
  import { type LikeC4LangiumDocument } from '../ast';
2
2
  import type { LikeC4Services } from '../module';
3
3
  export declare function computeDocumentFqn(document: LikeC4LangiumDocument, services: LikeC4Services): void;
4
- //# sourceMappingURL=fqn-computation.d.ts.map
@@ -1,44 +1,43 @@
1
- import { AsFqn, nonexhaustive } from '@likec4/core';
2
- import { MultiMap } from 'langium';
3
- import { isEmpty, isNil } from 'remeda';
4
- import { ElementOps, ast } from '../ast';
5
- import { fqnElementRef } from '../elementRef';
1
+ import { AsFqn, nonexhaustive } from "@likec4/core";
2
+ import { MultiMap } from "langium";
3
+ import { isEmpty, isNil } from "remeda";
4
+ import { ElementOps, ast } from "../ast.js";
5
+ import { fqnElementRef } from "../elementRef.js";
6
6
  export function computeDocumentFqn(document, services) {
7
- const c4fqns = (document.c4fqns = new MultiMap());
8
- const { model } = document.parseResult.value;
9
- if (!model?.elements) {
10
- return;
7
+ const c4fqns = document.c4fqns = new MultiMap();
8
+ const { model } = document.parseResult.value;
9
+ if (!model?.elements) {
10
+ return;
11
+ }
12
+ const locator = services.workspace.AstNodeLocator;
13
+ const traverseStack = model.elements.map((el) => [el, null]);
14
+ let pair;
15
+ while (pair = traverseStack.shift()) {
16
+ const [el, parent] = pair;
17
+ if (ast.isRelation(el)) {
18
+ continue;
11
19
  }
12
- const locator = services.workspace.AstNodeLocator;
13
- const traverseStack = model.elements.map(el => [el, null]);
14
- let pair;
15
- while ((pair = traverseStack.shift())) {
16
- const [el, parent] = pair;
17
- if (ast.isRelation(el)) {
18
- continue;
19
- }
20
- if (ast.isExtendElement(el)) {
21
- if (!isNil(el.body) && !isEmpty(el.body.elements)) {
22
- const fqn = fqnElementRef(el.element);
23
- el.body.elements.forEach(child => traverseStack.push([child, fqn]));
24
- }
25
- continue;
26
- }
27
- if (ast.isElement(el)) {
28
- const fqn = AsFqn(el.name, parent);
29
- const path = locator.getAstNodePath(el);
30
- c4fqns.add(fqn, {
31
- el: new WeakRef(el),
32
- path,
33
- name: el.name
34
- });
35
- ElementOps.writeId(el, fqn);
36
- if (!isNil(el.body) && !isEmpty(el.body.elements)) {
37
- el.body.elements.forEach(child => traverseStack.push([child, fqn]));
38
- }
39
- continue;
40
- }
41
- nonexhaustive(el);
20
+ if (ast.isExtendElement(el)) {
21
+ if (!isNil(el.body) && !isEmpty(el.body.elements)) {
22
+ const fqn = fqnElementRef(el.element);
23
+ el.body.elements.forEach((child) => traverseStack.push([child, fqn]));
24
+ }
25
+ continue;
42
26
  }
27
+ if (ast.isElement(el)) {
28
+ const fqn = AsFqn(el.name, parent);
29
+ const path = locator.getAstNodePath(el);
30
+ c4fqns.add(fqn, {
31
+ el: new WeakRef(el),
32
+ path,
33
+ name: el.name
34
+ });
35
+ ElementOps.writeId(el, fqn);
36
+ if (!isNil(el.body) && !isEmpty(el.body.elements)) {
37
+ el.body.elements.forEach((child) => traverseStack.push([child, fqn]));
38
+ }
39
+ continue;
40
+ }
41
+ nonexhaustive(el);
42
+ }
43
43
  }
44
- //# sourceMappingURL=fqn-computation.js.map
@@ -27,4 +27,3 @@ export declare class FqnIndex {
27
27
  */
28
28
  uniqueDescedants(parent: Fqn): Stream<FqnIndexEntry>;
29
29
  }
30
- //# sourceMappingURL=fqn-index.d.ts.map