@likec4/language-server 0.31.0 → 0.32.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/README.md +2 -0
- package/contrib/likec4.monarch.ts +1 -1
- package/contrib/likec4.tmLanguage.json +1 -1
- package/dist/ast.d.ts +11 -3
- package/dist/ast.js +30 -9
- package/dist/generated/ast.d.ts +25 -28
- package/dist/generated/ast.js +12 -28
- package/dist/generated/grammar.js +231 -172
- package/dist/logger.d.ts +1 -0
- package/dist/lsp/DocumentSymbolProvider.js +3 -3
- package/dist/lsp/SemanticTokenProvider.js +42 -21
- package/dist/model/fqn-computation.js +3 -2
- package/dist/model/fqn-index.js +4 -4
- package/dist/model/model-builder.d.ts +2 -1
- package/dist/model/model-builder.js +15 -20
- package/package.json +6 -5
package/dist/logger.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export class LikeC4DocumentSymbolProvider {
|
|
|
80
80
|
return [];
|
|
81
81
|
return [
|
|
82
82
|
{
|
|
83
|
-
kind: SymbolKind.
|
|
83
|
+
kind: SymbolKind.Namespace,
|
|
84
84
|
name: astSpec.name,
|
|
85
85
|
range: cstModel.range,
|
|
86
86
|
selectionRange: specKeywordNode.range,
|
|
@@ -97,7 +97,7 @@ export class LikeC4DocumentSymbolProvider {
|
|
|
97
97
|
return [];
|
|
98
98
|
return [
|
|
99
99
|
{
|
|
100
|
-
kind: SymbolKind.
|
|
100
|
+
kind: SymbolKind.Namespace,
|
|
101
101
|
name: astModel.name,
|
|
102
102
|
range: cstModel.range,
|
|
103
103
|
selectionRange: nameNode.range,
|
|
@@ -166,7 +166,7 @@ export class LikeC4DocumentSymbolProvider {
|
|
|
166
166
|
return [];
|
|
167
167
|
return [
|
|
168
168
|
{
|
|
169
|
-
kind: SymbolKind.
|
|
169
|
+
kind: SymbolKind.Namespace,
|
|
170
170
|
name: astViews.name,
|
|
171
171
|
range: cst.range,
|
|
172
172
|
selectionRange: nameNode.range,
|
|
@@ -26,11 +26,7 @@ export class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
|
|
|
26
26
|
});
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
if (
|
|
30
|
-
ast.isRelationExpression(node) ||
|
|
31
|
-
ast.isIncomingExpression(node) ||
|
|
32
|
-
ast.isInOutExpression(node) ||
|
|
33
|
-
ast.isOutgoingExpression(node)) {
|
|
29
|
+
if ('arr' in node) {
|
|
34
30
|
acceptor({
|
|
35
31
|
node,
|
|
36
32
|
property: 'arr',
|
|
@@ -38,6 +34,20 @@ export class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
|
|
|
38
34
|
modifier: [SemanticTokenModifiers.defaultLibrary]
|
|
39
35
|
});
|
|
40
36
|
}
|
|
37
|
+
// if (
|
|
38
|
+
// ast.isRelation(node) ||
|
|
39
|
+
// ast.isRelationExpression(node) ||
|
|
40
|
+
// ast.isIncomingExpression(node) ||
|
|
41
|
+
// ast.isInOutExpression(node) ||
|
|
42
|
+
// ast.isOutgoingExpression(node)
|
|
43
|
+
// ) {
|
|
44
|
+
// acceptor({
|
|
45
|
+
// node,
|
|
46
|
+
// property: 'arr',
|
|
47
|
+
// type: SemanticTokenTypes.keyword,
|
|
48
|
+
// modifier: [SemanticTokenModifiers.defaultLibrary]
|
|
49
|
+
// })
|
|
50
|
+
// }
|
|
41
51
|
if (ast.isElementKindExpression(node) || ast.isElementTagExpression(node)) {
|
|
42
52
|
keyword('element');
|
|
43
53
|
if (ast.isElementKindExpression(node)) {
|
|
@@ -98,16 +108,11 @@ export class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
|
|
|
98
108
|
});
|
|
99
109
|
return;
|
|
100
110
|
}
|
|
101
|
-
if (ast.
|
|
111
|
+
if (ast.isColorProperty(node) || ast.isShapeProperty(node)) {
|
|
102
112
|
acceptor({
|
|
103
113
|
node,
|
|
104
114
|
property: 'key',
|
|
105
115
|
type: SemanticTokenTypes.keyword
|
|
106
|
-
// type: SemanticTokenTypes.property,
|
|
107
|
-
// modifier: [
|
|
108
|
-
// SemanticTokenModifiers.readonly,
|
|
109
|
-
// SemanticTokenModifiers.declaration
|
|
110
|
-
// ]
|
|
111
116
|
});
|
|
112
117
|
acceptor({
|
|
113
118
|
node,
|
|
@@ -116,20 +121,11 @@ export class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
|
|
|
116
121
|
});
|
|
117
122
|
return;
|
|
118
123
|
}
|
|
119
|
-
|
|
120
|
-
if (ast.isViewProperty(node) ||
|
|
121
|
-
ast.isElementStringProperty(node) ||
|
|
122
|
-
ast.isRelationStringProperty(node) ||
|
|
123
|
-
ast.isLinkProperty(node)) {
|
|
124
|
+
if (ast.isLinkProperty(node) || ast.isIconProperty(node)) {
|
|
124
125
|
acceptor({
|
|
125
126
|
node,
|
|
126
127
|
property: 'key',
|
|
127
128
|
type: SemanticTokenTypes.keyword
|
|
128
|
-
// type: SemanticTokenTypes.property,
|
|
129
|
-
// modifier: [
|
|
130
|
-
// SemanticTokenModifiers.readonly,
|
|
131
|
-
// SemanticTokenModifiers.declaration
|
|
132
|
-
// ]
|
|
133
129
|
});
|
|
134
130
|
acceptor({
|
|
135
131
|
node,
|
|
@@ -138,6 +134,31 @@ export class LikeC4SemanticTokenProvider extends AbstractSemanticTokenProvider {
|
|
|
138
134
|
});
|
|
139
135
|
return;
|
|
140
136
|
}
|
|
137
|
+
// ViewProperty | ElementStringProperty | RelationStringProperty | LinkProperty
|
|
138
|
+
// if (
|
|
139
|
+
// ast.isViewProperty(node) ||
|
|
140
|
+
// ast.isElementStringProperty(node) ||
|
|
141
|
+
// ast.isRelationStringProperty(node) ||
|
|
142
|
+
// ast.isLinkProperty(node) ||
|
|
143
|
+
// ast.isIconProperty(node)
|
|
144
|
+
// ) {
|
|
145
|
+
// acceptor({
|
|
146
|
+
// node,
|
|
147
|
+
// property: 'key',
|
|
148
|
+
// type: SemanticTokenTypes.keyword
|
|
149
|
+
// // type: SemanticTokenTypes.property,
|
|
150
|
+
// // modifier: [
|
|
151
|
+
// // SemanticTokenModifiers.readonly,
|
|
152
|
+
// // SemanticTokenModifiers.declaration
|
|
153
|
+
// // ]
|
|
154
|
+
// })
|
|
155
|
+
// acceptor({
|
|
156
|
+
// node,
|
|
157
|
+
// property: 'value',
|
|
158
|
+
// type: SemanticTokenTypes.string
|
|
159
|
+
// })
|
|
160
|
+
// return
|
|
161
|
+
// }
|
|
141
162
|
// if (ast.isModel(node)) {
|
|
142
163
|
// keyword('model')
|
|
143
164
|
// return
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nonexhaustive } from '@likec4/core/errors';
|
|
2
|
+
import { AsFqn } from '@likec4/core/types';
|
|
2
3
|
import { MultiMap } from 'langium';
|
|
3
4
|
import { isEmpty, isNil } from 'remeda';
|
|
4
5
|
import { ElementOps, ast } from '../ast';
|
|
@@ -34,7 +35,7 @@ export function computeDocumentFqn(document, services) {
|
|
|
34
35
|
}
|
|
35
36
|
continue;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
nonexhaustive(el);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
//# sourceMappingURL=fqn-computation.js.map
|
package/dist/model/fqn-index.js
CHANGED
|
@@ -51,18 +51,18 @@ export class FqnIndex {
|
|
|
51
51
|
}
|
|
52
52
|
directChildrenOf(parent) {
|
|
53
53
|
return new StreamImpl(() => {
|
|
54
|
-
const children =
|
|
54
|
+
const children = this.entries()
|
|
55
55
|
.filter(e => parentFqn(e.fqn) === parent)
|
|
56
56
|
.map((e) => {
|
|
57
57
|
const name = nameFromFqn(e.fqn);
|
|
58
58
|
const entry = { ...e, name };
|
|
59
59
|
return [name, entry];
|
|
60
60
|
})
|
|
61
|
-
.toArray()
|
|
62
|
-
if (children.
|
|
61
|
+
.toArray();
|
|
62
|
+
if (children.length === 0) {
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
|
-
return children
|
|
65
|
+
return new MultiMap(children)
|
|
66
66
|
.entriesGroupedByKey()
|
|
67
67
|
.flatMap(([_name, descrs]) => (descrs.length === 1 ? descrs : []))
|
|
68
68
|
.iterator();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as c4 from '@likec4/core/types';
|
|
2
|
-
import { ast
|
|
2
|
+
import { ast } from '../ast';
|
|
3
|
+
import type { LikeC4LangiumDocument } from '../ast';
|
|
3
4
|
import type { LikeC4Services } from '../module';
|
|
4
5
|
export declare class LikeC4ModelBuilder {
|
|
5
6
|
private services;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { ModelIndex, assignNavigateTo, computeView, invariant } from '@likec4/core';
|
|
2
|
-
import { DefaultElementShape, DefaultThemeColor } from '@likec4/core/types';
|
|
3
|
-
import { compareByFqnHierarchically, isNonEmptyArray, parentFqn } from '@likec4/core/utils';
|
|
1
|
+
import { ModelIndex, assignNavigateTo, compareByFqnHierarchically, computeView, invariant, isNonEmptyArray, nonexhaustive, parentFqn } from '@likec4/core';
|
|
4
2
|
import { DocumentState, getDocument } from 'langium';
|
|
5
3
|
import objectHash from 'object-hash';
|
|
6
4
|
import { clone } from 'rambdax';
|
|
7
5
|
import * as R from 'remeda';
|
|
8
6
|
import stripIndent from 'strip-indent';
|
|
9
|
-
import { ElementViewOps, ast, cleanParsedModel, isLikeC4LangiumDocument, isValidLikeC4LangiumDocument, resolveRelationPoints, streamModel, toAutoLayout, toElementStyle } from '../ast';
|
|
7
|
+
import { ElementViewOps, ast, cleanParsedModel, isLikeC4LangiumDocument, isValidLikeC4LangiumDocument, resolveRelationPoints, streamModel, toAutoLayout, toElementStyle, toElementStyleExcludeDefaults } from '../ast';
|
|
10
8
|
import { elementRef, strictElementRefFqn } from '../elementRef';
|
|
11
9
|
import { logger } from '../logger';
|
|
12
10
|
import { Rpc } from '../protocol';
|
|
@@ -71,8 +69,7 @@ export class LikeC4ModelBuilder {
|
|
|
71
69
|
const kind = c4Specification.kinds[parsed.kind];
|
|
72
70
|
if (kind) {
|
|
73
71
|
return {
|
|
74
|
-
|
|
75
|
-
color: kind.color,
|
|
72
|
+
...kind,
|
|
76
73
|
description: null,
|
|
77
74
|
technology: null,
|
|
78
75
|
tags: tags ?? null,
|
|
@@ -148,11 +145,7 @@ export class LikeC4ModelBuilder {
|
|
|
148
145
|
if (specs) {
|
|
149
146
|
for (const { kind, style } of specs) {
|
|
150
147
|
try {
|
|
151
|
-
|
|
152
|
-
specification.kinds[kind.name] = {
|
|
153
|
-
color: styleProps.color ?? DefaultThemeColor,
|
|
154
|
-
shape: styleProps.shape ?? DefaultElementShape
|
|
155
|
-
};
|
|
148
|
+
specification.kinds[kind.name] = toElementStyleExcludeDefaults(style?.props);
|
|
156
149
|
}
|
|
157
150
|
catch (e) {
|
|
158
151
|
logger.warn(e);
|
|
@@ -178,7 +171,7 @@ export class LikeC4ModelBuilder {
|
|
|
178
171
|
}
|
|
179
172
|
continue;
|
|
180
173
|
}
|
|
181
|
-
|
|
174
|
+
nonexhaustive(el);
|
|
182
175
|
}
|
|
183
176
|
const docviews = doc.parseResult.value.views?.views;
|
|
184
177
|
if (docviews) {
|
|
@@ -201,9 +194,9 @@ export class LikeC4ModelBuilder {
|
|
|
201
194
|
const id = this.resolveFqn(astNode);
|
|
202
195
|
invariant(astNode.kind.ref, 'Element kind is not resolved: ' + astNode.name);
|
|
203
196
|
const kind = astNode.kind.ref.name;
|
|
204
|
-
const tags =
|
|
205
|
-
const
|
|
206
|
-
const
|
|
197
|
+
const tags = this.convertTags(astNode.body);
|
|
198
|
+
const stylePropsAst = astNode.body?.props.find(ast.isStyleProperties)?.props;
|
|
199
|
+
const styleProps = toElementStyleExcludeDefaults(stylePropsAst);
|
|
207
200
|
const astPath = this.getAstNodePath(astNode);
|
|
208
201
|
let [title, description, technology] = astNode.props;
|
|
209
202
|
const bodyProps = astNode.body?.props.filter((p) => ast.isElementStringProperty(p)) ?? [];
|
|
@@ -215,13 +208,12 @@ export class LikeC4ModelBuilder {
|
|
|
215
208
|
id,
|
|
216
209
|
kind,
|
|
217
210
|
astPath,
|
|
218
|
-
title: title
|
|
211
|
+
title: title ? stripIndent(title).trim() : astNode.name,
|
|
219
212
|
...(tags && { tags }),
|
|
220
213
|
...(links && isNonEmptyArray(links) && { links }),
|
|
221
214
|
...(technology && { technology }),
|
|
222
215
|
...(description && { description: stripIndent(description).trim() }),
|
|
223
|
-
...
|
|
224
|
-
...(color && color !== DefaultThemeColor ? { color } : {})
|
|
216
|
+
...styleProps
|
|
225
217
|
};
|
|
226
218
|
}
|
|
227
219
|
parseRelation(astNode) {
|
|
@@ -361,8 +353,11 @@ export class LikeC4ModelBuilder {
|
|
|
361
353
|
getAstNodePath(node) {
|
|
362
354
|
return this.services.workspace.AstNodeLocator.getAstNodePath(node);
|
|
363
355
|
}
|
|
364
|
-
convertTags(
|
|
365
|
-
|
|
356
|
+
convertTags(withTags) {
|
|
357
|
+
if (!withTags) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
const tags = withTags.tags?.value.flatMap(({ ref }) => (ref ? ref.name : []));
|
|
366
361
|
return tags && isNonEmptyArray(tags) ? tags : null;
|
|
367
362
|
}
|
|
368
363
|
scheduledCb = null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/language-server",
|
|
3
3
|
"description": "LikeC4 Language Server",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.32.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
7
7
|
"homepage": "https://likec4.dev",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
"dev": "run-p 'watch:*'",
|
|
56
56
|
"lint": "run -T eslint src/ --fix",
|
|
57
57
|
"clean": "run -T rimraf dist contrib",
|
|
58
|
-
"test": "
|
|
59
|
-
"test:watch": "
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:watch": "vitest"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@likec4/core": "0.
|
|
62
|
+
"@likec4/core": "0.32.0",
|
|
63
63
|
"langium": "^1.2.1",
|
|
64
64
|
"nanoid": "^4.0.2",
|
|
65
65
|
"object-hash": "^3.0.0",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"@types/object-hash": "^3.0.2",
|
|
75
75
|
"langium-cli": "^1.2.1",
|
|
76
76
|
"npm-run-all": "^4.1.5",
|
|
77
|
-
"typescript": "^5.1.6"
|
|
77
|
+
"typescript": "^5.1.6",
|
|
78
|
+
"vitest": "^0.34.1"
|
|
78
79
|
}
|
|
79
80
|
}
|