@likec4/language-server 0.37.1 → 0.41.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 (60) hide show
  1. package/contrib/likec4.monarch.ts +5 -5
  2. package/contrib/likec4.tmLanguage.json +1 -1
  3. package/dist/Rpc.d.ts +7 -0
  4. package/dist/Rpc.js +130 -0
  5. package/dist/ast.d.ts +20 -0
  6. package/dist/ast.js +169 -141
  7. package/dist/elementRef.js +31 -44
  8. package/dist/generated/ast.d.ts +48 -7
  9. package/dist/generated/ast.js +344 -315
  10. package/dist/generated/grammar.js +2 -3177
  11. package/dist/generated/module.js +13 -18
  12. package/dist/index.js +2 -3
  13. package/dist/logger.js +39 -42
  14. package/dist/lsp/CodeLensProvider.js +28 -32
  15. package/dist/lsp/DocumentLinkProvider.js +26 -33
  16. package/dist/lsp/DocumentSymbolProvider.js +165 -167
  17. package/dist/lsp/HoverProvider.js +35 -48
  18. package/dist/lsp/SemanticTokenProvider.js +160 -201
  19. package/dist/lsp/index.js +5 -6
  20. package/dist/model/fqn-computation.js +39 -40
  21. package/dist/model/fqn-index.js +117 -141
  22. package/dist/model/index.js +5 -6
  23. package/dist/model/model-builder.d.ts +10 -5
  24. package/dist/model/model-builder.js +247 -176
  25. package/dist/model/model-locator.d.ts +1 -1
  26. package/dist/model/model-locator.js +102 -100
  27. package/dist/model/model-parser.d.ts +2 -6
  28. package/dist/model/model-parser.js +284 -286
  29. package/dist/module.d.ts +4 -1
  30. package/dist/module.js +69 -60
  31. package/dist/protocol.d.ts +16 -19
  32. package/dist/protocol.js +14 -22
  33. package/dist/references/index.js +2 -3
  34. package/dist/references/scope-computation.js +72 -69
  35. package/dist/references/scope-provider.js +126 -116
  36. package/dist/shared/WorkspaceManager.d.ts +2 -3
  37. package/dist/shared/WorkspaceManager.js +13 -16
  38. package/dist/shared/index.js +1 -2
  39. package/dist/test/index.js +1 -2
  40. package/dist/test/testServices.js +73 -61
  41. package/dist/utils.d.ts +1 -0
  42. package/dist/utils.js +4 -3
  43. package/dist/validation/element.d.ts +1 -0
  44. package/dist/validation/element.js +31 -38
  45. package/dist/validation/index.js +37 -46
  46. package/dist/validation/relation.js +46 -46
  47. package/dist/validation/specification.d.ts +1 -0
  48. package/dist/validation/specification.js +33 -30
  49. package/dist/validation/view.js +16 -22
  50. package/dist/view-utils/assignNavigateTo.d.ts +3 -0
  51. package/dist/view-utils/assignNavigateTo.js +20 -0
  52. package/dist/view-utils/index.d.ts +4 -0
  53. package/dist/view-utils/index.js +3 -0
  54. package/dist/view-utils/resolve-extended-views.d.ts +7 -0
  55. package/dist/view-utils/resolve-extended-views.js +41 -0
  56. package/dist/view-utils/resolve-relative-paths.d.ts +3 -0
  57. package/dist/view-utils/resolve-relative-paths.js +76 -0
  58. package/package.json +33 -18
  59. package/dist/registerProtocolHandlers.d.ts +0 -3
  60. 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
@@ -1,210 +1,169 @@
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]
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.isRelation(node) && "kind" in node) {
22
+ keyword("-[");
23
+ acceptor({
24
+ node,
25
+ property: "kind",
26
+ type: SemanticTokenTypes.type,
27
+ modifier: [SemanticTokenModifiers.definition]
28
+ });
29
+ keyword("]->");
30
+ }
31
+ if (ast.isElementRef(node) || ast.isStrictElementRef(node)) {
32
+ acceptor({
33
+ node,
34
+ property: "el",
35
+ type: isElementRefHead(node) ? SemanticTokenTypes.variable : SemanticTokenTypes.property
36
+ });
37
+ }
38
+ if (ast.isElementViewRef(node)) {
39
+ acceptor({
40
+ node,
41
+ property: "view",
42
+ type: SemanticTokenTypes.variable
43
+ });
44
+ }
45
+ if (ast.isWildcardExpression(node)) {
46
+ acceptor({
47
+ node,
48
+ property: "isWildcard",
49
+ type: SemanticTokenTypes.variable
50
+ });
51
+ }
52
+ if (ast.isElementKindExpression(node) || ast.isElementTagExpression(node)) {
53
+ keyword("element");
54
+ if (ast.isElementKindExpression(node)) {
55
+ keyword("kind");
56
+ acceptor({
57
+ node,
58
+ property: "kind",
59
+ type: SemanticTokenTypes.type,
60
+ modifier: [SemanticTokenModifiers.definition]
12
61
  });
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
- }
184
- }
185
- highlightAstElement(node, acceptor) {
62
+ }
63
+ if (ast.isElementTagExpression(node)) {
64
+ keyword("tag");
186
65
  acceptor({
187
- node,
188
- property: 'name',
189
- type: SemanticTokenTypes.variable,
190
- modifier: [SemanticTokenModifiers.declaration]
66
+ node,
67
+ property: "tag",
68
+ type: SemanticTokenTypes.type,
69
+ modifier: [SemanticTokenModifiers.definition]
191
70
  });
71
+ }
72
+ }
73
+ if (ast.isRelation(node)) {
74
+ if ("title" in node) {
192
75
  acceptor({
193
- node,
194
- property: 'kind',
195
- type: SemanticTokenTypes.keyword,
196
- modifier: []
76
+ node,
77
+ property: "title",
78
+ type: SemanticTokenTypes.string
197
79
  });
80
+ }
81
+ }
82
+ if (ast.isElementKind(node)) {
83
+ acceptor({
84
+ node,
85
+ property: "name",
86
+ type: SemanticTokenTypes.type,
87
+ modifier: [SemanticTokenModifiers.definition]
88
+ });
89
+ }
90
+ if (ast.isTags(node)) {
91
+ acceptor({
92
+ node,
93
+ property: "value",
94
+ type: SemanticTokenTypes.type,
95
+ modifier: [SemanticTokenModifiers.definition]
96
+ });
97
+ }
98
+ if (ast.isTag(node)) {
99
+ acceptor({
100
+ node,
101
+ property: "name",
102
+ type: SemanticTokenTypes.type,
103
+ modifier: [SemanticTokenModifiers.definition]
104
+ });
105
+ }
106
+ if (ast.isRelationshipKind(node)) {
107
+ acceptor({
108
+ node,
109
+ property: "name",
110
+ type: SemanticTokenTypes.type,
111
+ modifier: [SemanticTokenModifiers.definition]
112
+ });
113
+ }
114
+ if (ast.isColorProperty(node) || ast.isShapeProperty(node) || ast.isArrowProperty(node) || ast.isLineProperty(node)) {
115
+ acceptor({
116
+ node,
117
+ property: "key",
118
+ type: SemanticTokenTypes.keyword
119
+ });
120
+ acceptor({
121
+ node,
122
+ property: "value",
123
+ type: SemanticTokenTypes.enum
124
+ });
125
+ }
126
+ if (ast.isLinkProperty(node) || ast.isIconProperty(node)) {
127
+ acceptor({
128
+ node,
129
+ property: "key",
130
+ type: SemanticTokenTypes.keyword
131
+ });
132
+ acceptor({
133
+ node,
134
+ property: "value",
135
+ type: SemanticTokenTypes.string
136
+ });
137
+ }
138
+ if (ast.isElement(node)) {
139
+ this.highlightAstElement(node, acceptor);
140
+ }
141
+ if (ast.isView(node)) {
142
+ this.highlightView(node, acceptor);
198
143
  }
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
- }
144
+ }
145
+ highlightAstElement(node, acceptor) {
146
+ acceptor({
147
+ node,
148
+ property: "name",
149
+ type: SemanticTokenTypes.variable,
150
+ modifier: [SemanticTokenModifiers.declaration]
151
+ });
152
+ acceptor({
153
+ node,
154
+ property: "kind",
155
+ type: SemanticTokenTypes.keyword,
156
+ modifier: []
157
+ });
158
+ }
159
+ highlightView(node, acceptor) {
160
+ if (node.name) {
161
+ acceptor({
162
+ node,
163
+ property: "name",
164
+ type: SemanticTokenTypes.variable,
165
+ modifier: [SemanticTokenModifiers.declaration]
166
+ });
208
167
  }
168
+ }
209
169
  }
210
- //# sourceMappingURL=SemanticTokenProvider.js.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,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