@likec4/language-server 0.31.0 → 0.33.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/dist/logger.d.ts CHANGED
@@ -6,4 +6,5 @@ export declare const logger: {
6
6
  error(message: string | Error | unknown): void;
7
7
  trace(message: string): void;
8
8
  };
9
+ export type Logger = typeof logger;
9
10
  //# sourceMappingURL=logger.d.ts.map
@@ -80,7 +80,7 @@ export class LikeC4DocumentSymbolProvider {
80
80
  return [];
81
81
  return [
82
82
  {
83
- kind: SymbolKind.Class,
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.Class,
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.Class,
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 (ast.isRelation(node) ||
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.isAStyleProperty(node)) {
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
- // ViewProperty | ElementStringProperty | RelationStringProperty | LinkProperty
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 { failExpectedNever, AsFqn } from '@likec4/core';
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
- failExpectedNever(el);
38
+ nonexhaustive(el);
38
39
  }
39
40
  }
40
41
  //# sourceMappingURL=fqn-computation.js.map
@@ -51,18 +51,18 @@ export class FqnIndex {
51
51
  }
52
52
  directChildrenOf(parent) {
53
53
  return new StreamImpl(() => {
54
- const children = new MultiMap(this.entries()
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.size === 0) {
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, type LikeC4LangiumDocument } from '../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
- shape: kind.shape,
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
- const styleProps = toElementStyle(style?.props);
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
- failExpectedNever(el);
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 = (astNode.body && this.convertTags(astNode.body));
205
- const styleProps = astNode.body?.props.find(ast.isElementStyleProperties)?.props;
206
- const { color, shape } = toElementStyle(styleProps);
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 ?? astNode.name,
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
- ...(shape && shape !== DefaultElementShape ? { shape } : {}),
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(el) {
365
- const tags = el.tags?.value.map(tagRef => tagRef.ref?.name);
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.31.0",
4
+ "version": "0.33.0",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -23,26 +23,9 @@
23
23
  "main": "./dist/index.js",
24
24
  "module": "./dist/index.js",
25
25
  "types": "./dist/index.d.ts",
26
- "exports": {
27
- ".": {
28
- "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js",
30
- "require": "./dist/index.js"
31
- }
32
- },
33
26
  "publishConfig": {
34
27
  "registry": "https://registry.npmjs.org",
35
- "access": "public",
36
- "main": "./dist/index.js",
37
- "module": "./dist/index.js",
38
- "types": "./dist/index.d.ts",
39
- "exports": {
40
- ".": {
41
- "types": "./dist/index.d.ts",
42
- "import": "./dist/index.js",
43
- "require": "./dist/index.js"
44
- }
45
- }
28
+ "access": "public"
46
29
  },
47
30
  "scripts": {
48
31
  "turbo-build": "run -T turbo run build --filter='language-server'",
@@ -55,11 +38,11 @@
55
38
  "dev": "run-p 'watch:*'",
56
39
  "lint": "run -T eslint src/ --fix",
57
40
  "clean": "run -T rimraf dist contrib",
58
- "test": "run -T vitest run",
59
- "test:watch": "run -T vitest"
41
+ "test": "vitest run",
42
+ "test:watch": "vitest"
60
43
  },
61
44
  "dependencies": {
62
- "@likec4/core": "0.31.0",
45
+ "@likec4/core": "0.33.0",
63
46
  "langium": "^1.2.1",
64
47
  "nanoid": "^4.0.2",
65
48
  "object-hash": "^3.0.0",
@@ -74,6 +57,7 @@
74
57
  "@types/object-hash": "^3.0.2",
75
58
  "langium-cli": "^1.2.1",
76
59
  "npm-run-all": "^4.1.5",
77
- "typescript": "^5.1.6"
60
+ "typescript": "^5.1.6",
61
+ "vitest": "^0.34.1"
78
62
  }
79
63
  }