@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 CHANGED
@@ -1,3 +1,5 @@
1
1
  # LikeC4 Language Server
2
2
 
3
+ [docs](https://likec4.dev/docs/) | [example](https://likec4.dev/examples/bigbank/likec4/)
4
+
3
5
  Language Server Protocol (LSP) based on [languim](https://github.com/languim/languim) library.
@@ -1,7 +1,7 @@
1
1
  // Monarch syntax highlighting for the likec4 language.
2
2
  export default {
3
3
  keywords: [
4
- 'BottomTop','LeftRight','RightLeft','TopBottom','amber','autoLayout','blue','browser','color','cylinder','description','element','exclude','extend','gray','green','include','indigo','it','kind','link','mobile','model','muted','of','person','primary','queue','rectangle','red','secondary','shape','sky','slate','specification','storage','style','tag','technology','this','title','view','views'
4
+ 'BottomTop','LeftRight','RightLeft','TopBottom','amber','autoLayout','blue','browser','color','cylinder','description','element','exclude','extend','gray','green','icon','include','indigo','it','kind','link','mobile','model','muted','of','person','primary','queue','rectangle','red','secondary','shape','sky','slate','specification','storage','style','tag','technology','this','title','view','views'
5
5
  ],
6
6
  operators: [
7
7
  '*','.*'
@@ -12,7 +12,7 @@
12
12
  },
13
13
  {
14
14
  "name": "keyword.control.likec4",
15
- "match": "\\b(BottomTop|LeftRight|RightLeft|TopBottom|amber|autoLayout|blue|browser|color|cylinder|description|element|exclude|extend|gray|green|include|indigo|it|kind|link|mobile|model|muted|of|person|primary|queue|rectangle|red|secondary|shape|sky|slate|specification|storage|style|tag|technology|this|title|view|views)\\b"
15
+ "match": "\\b(BottomTop|LeftRight|RightLeft|TopBottom|amber|autoLayout|blue|browser|color|cylinder|description|element|exclude|extend|gray|green|icon|include|indigo|it|kind|link|mobile|model|muted|of|person|primary|queue|rectangle|red|secondary|shape|sky|slate|specification|storage|style|tag|technology|this|title|view|views)\\b"
16
16
  },
17
17
  {
18
18
  "name": "string.quoted.double.likec4",
package/dist/ast.d.ts CHANGED
@@ -5,8 +5,9 @@ import * as ast from './generated/ast';
5
5
  export { ast };
6
6
  export interface ParsedAstSpecification {
7
7
  kinds: Record<c4.ElementKind, {
8
- shape: c4.ElementShape;
9
- color: c4.ThemeColor;
8
+ shape?: c4.ElementShape;
9
+ color?: c4.ThemeColor;
10
+ icon?: c4.IconUrl;
10
11
  }>;
11
12
  }
12
13
  export interface ParsedAstElement {
@@ -16,6 +17,7 @@ export interface ParsedAstElement {
16
17
  title: string;
17
18
  description?: string;
18
19
  technology?: string;
20
+ icon?: c4.IconUrl;
19
21
  tags?: c4.NonEmptyArray<c4.Tag>;
20
22
  links?: c4.NonEmptyArray<string>;
21
23
  shape?: c4.ElementShape;
@@ -67,9 +69,15 @@ export declare function resolveRelationPoints(node: ast.Relation): {
67
69
  source: ast.Element;
68
70
  target: ast.Element;
69
71
  };
70
- export declare function toElementStyle(props?: ast.AStyleProperty[]): {
72
+ export declare function toElementStyle(props?: ast.StyleProperties['props']): {
71
73
  color?: c4.ThemeColor;
72
74
  shape?: c4.ElementShape;
75
+ icon?: c4.IconUrl;
76
+ };
77
+ export declare function toElementStyleExcludeDefaults(props?: ast.StyleProperties['props']): {
78
+ shape?: c4.ElementShape;
79
+ color?: c4.ThemeColor;
80
+ icon?: c4.IconUrl;
73
81
  };
74
82
  export declare function toAutoLayout(direction: ast.ViewRuleLayoutDirection): c4.ViewRuleAutoLayout['autoLayout'];
75
83
  //# sourceMappingURL=ast.d.ts.map
package/dist/ast.js CHANGED
@@ -1,6 +1,5 @@
1
- import { RelationRefError } from '@likec4/core';
1
+ import { DefaultElementShape, DefaultThemeColor, RelationRefError, nonexhaustive } from '@likec4/core';
2
2
  import { DocumentState } from 'langium/lib/workspace';
3
- // import objectHash from 'object-hash'
4
3
  import { elementRef } from './elementRef';
5
4
  import * as ast from './generated/ast';
6
5
  import { LikeC4LanguageMetaData } from './generated/module';
@@ -55,7 +54,11 @@ export function isLikeC4LangiumDocument(doc) {
55
54
  }
56
55
  export function isParsedLikeC4LangiumDocument(doc) {
57
56
  return (isLikeC4LangiumDocument(doc) &&
58
- ['c4Specification', 'c4Elements', 'c4Relations', 'c4Views'].every(key => key in doc));
57
+ doc.state >= DocumentState.Validated &&
58
+ 'c4Specification' in doc &&
59
+ 'c4Elements' in doc &&
60
+ 'c4Relations' in doc &&
61
+ 'c4Views' in doc);
59
62
  }
60
63
  export const isValidLikeC4LangiumDocument = (doc) => {
61
64
  if (!isParsedLikeC4LangiumDocument(doc))
@@ -122,16 +125,34 @@ export function resolveRelationPoints(node) {
122
125
  }
123
126
  export function toElementStyle(props) {
124
127
  const result = {};
125
- const color = props?.find(ast.isColorProperty)?.value;
126
- if (color) {
127
- result.color = color;
128
+ if (!props || props.length === 0) {
129
+ return result;
128
130
  }
129
- const shape = props?.find(ast.isShapeProperty)?.value;
130
- if (shape) {
131
- result.shape = shape;
131
+ for (const prop of props) {
132
+ if (ast.isColorProperty(prop)) {
133
+ result.color = prop.value;
134
+ continue;
135
+ }
136
+ if (ast.isShapeProperty(prop)) {
137
+ result.shape = prop.value;
138
+ continue;
139
+ }
140
+ if (ast.isIconProperty(prop)) {
141
+ result.icon = prop.value;
142
+ continue;
143
+ }
144
+ nonexhaustive(prop);
132
145
  }
133
146
  return result;
134
147
  }
148
+ export function toElementStyleExcludeDefaults(props) {
149
+ const { color, shape, ...rest } = toElementStyle(props);
150
+ return {
151
+ ...rest,
152
+ ...(color && color !== DefaultThemeColor ? { color } : {}),
153
+ ...(shape && shape !== DefaultElementShape ? { shape } : {})
154
+ };
155
+ }
135
156
  export function toAutoLayout(direction) {
136
157
  switch (direction) {
137
158
  case 'TopBottom': {
@@ -4,13 +4,10 @@
4
4
  ******************************************************************************/
5
5
  import type { AstNode, Reference, ReferenceInfo, TypeMetaData } from 'langium';
6
6
  import { AbstractAstReflection } from 'langium';
7
- export type AStyleProperty = ColorProperty | ShapeProperty;
8
- export declare const AStyleProperty = "AStyleProperty";
9
- export declare function isAStyleProperty(item: unknown): item is AStyleProperty;
10
7
  export type ElementExpression = ElementKindExpression | ElementRefExpression | ElementTagExpression | WildcardExpression;
11
8
  export declare const ElementExpression = "ElementExpression";
12
9
  export declare function isElementExpression(item: unknown): item is ElementExpression;
13
- export type ElementProperty = ElementStringProperty | ElementStyleProperties;
10
+ export type ElementProperty = ElementStringProperty | StyleProperties;
14
11
  export declare const ElementProperty = "ElementProperty";
15
12
  export declare function isElementProperty(item: unknown): item is ElementProperty;
16
13
  export type ElementShape = 'browser' | 'cylinder' | 'mobile' | 'person' | 'queue' | 'rectangle' | 'storage';
@@ -35,7 +32,7 @@ export declare function isViewRule(item: unknown): item is ViewRule;
35
32
  export type ViewRuleLayoutDirection = 'BottomTop' | 'LeftRight' | 'RightLeft' | 'TopBottom';
36
33
  export declare function isViewRuleLayoutDirection(item: unknown): item is ViewRuleLayoutDirection;
37
34
  export interface ColorProperty extends AstNode {
38
- readonly $container: ElementStyleProperties | SpecificationStyleProperties | ViewRuleStyle;
35
+ readonly $container: StyleProperties | ViewRuleStyle;
39
36
  readonly $type: 'ColorProperty';
40
37
  key: 'color';
41
38
  value: ThemeColor;
@@ -93,21 +90,13 @@ export interface ElementRefExpression extends AstNode {
93
90
  export declare const ElementRefExpression = "ElementRefExpression";
94
91
  export declare function isElementRefExpression(item: unknown): item is ElementRefExpression;
95
92
  export interface ElementStringProperty extends AstNode {
96
- readonly $container: ElementBody;
93
+ readonly $container: ElementBody | SpecificationElementKind | SpecificationTag;
97
94
  readonly $type: 'ElementStringProperty';
98
95
  key: 'description' | 'technology' | 'title';
99
96
  value: string;
100
97
  }
101
98
  export declare const ElementStringProperty = "ElementStringProperty";
102
99
  export declare function isElementStringProperty(item: unknown): item is ElementStringProperty;
103
- export interface ElementStyleProperties extends AstNode {
104
- readonly $container: ElementBody;
105
- readonly $type: 'ElementStyleProperties';
106
- key: 'style';
107
- props: Array<ColorProperty | ShapeProperty>;
108
- }
109
- export declare const ElementStyleProperties = "ElementStyleProperties";
110
- export declare function isElementStyleProperties(item: unknown): item is ElementStyleProperties;
111
100
  export interface ElementTagExpression extends AstNode {
112
101
  readonly $container: InOutExpression | IncomingExpression | OutgoingExpression | RelationExpression | ViewRuleExpression | ViewRuleStyle;
113
102
  readonly $type: 'ElementTagExpression';
@@ -142,6 +131,14 @@ export interface ExtendElementBody extends AstNode {
142
131
  }
143
132
  export declare const ExtendElementBody = "ExtendElementBody";
144
133
  export declare function isExtendElementBody(item: unknown): item is ExtendElementBody;
134
+ export interface IconProperty extends AstNode {
135
+ readonly $container: StyleProperties | ViewRuleStyle;
136
+ readonly $type: 'IconProperty';
137
+ key: 'icon';
138
+ value: Uri;
139
+ }
140
+ export declare const IconProperty = "IconProperty";
141
+ export declare function isIconProperty(item: unknown): item is IconProperty;
145
142
  export interface IncomingExpression extends AstNode {
146
143
  readonly $container: InOutExpression | IncomingExpression | OutgoingExpression | RelationExpression | ViewRuleExpression | ViewRuleStyle;
147
144
  readonly $type: 'IncomingExpression';
@@ -235,7 +232,7 @@ export interface RelationStringProperty extends AstNode {
235
232
  export declare const RelationStringProperty = "RelationStringProperty";
236
233
  export declare function isRelationStringProperty(item: unknown): item is RelationStringProperty;
237
234
  export interface ShapeProperty extends AstNode {
238
- readonly $container: ElementStyleProperties | SpecificationStyleProperties | ViewRuleStyle;
235
+ readonly $container: StyleProperties | ViewRuleStyle;
239
236
  readonly $type: 'ShapeProperty';
240
237
  key: 'shape';
241
238
  value: ElementShape;
@@ -246,7 +243,7 @@ export interface SpecificationElementKind extends AstNode {
246
243
  readonly $container: SpecificationRule;
247
244
  readonly $type: 'SpecificationElementKind';
248
245
  kind: ElementKind;
249
- style?: SpecificationStyleProperties;
246
+ style?: StyleProperties;
250
247
  }
251
248
  export declare const SpecificationElementKind = "SpecificationElementKind";
252
249
  export declare function isSpecificationElementKind(item: unknown): item is SpecificationElementKind;
@@ -258,17 +255,10 @@ export interface SpecificationRule extends AstNode {
258
255
  }
259
256
  export declare const SpecificationRule = "SpecificationRule";
260
257
  export declare function isSpecificationRule(item: unknown): item is SpecificationRule;
261
- export interface SpecificationStyleProperties extends AstNode {
262
- readonly $container: SpecificationElementKind | SpecificationTag;
263
- readonly $type: 'SpecificationStyleProperties';
264
- props: Array<ColorProperty | ShapeProperty>;
265
- }
266
- export declare const SpecificationStyleProperties = "SpecificationStyleProperties";
267
- export declare function isSpecificationStyleProperties(item: unknown): item is SpecificationStyleProperties;
268
258
  export interface SpecificationTag extends AstNode {
269
259
  readonly $container: SpecificationRule;
270
260
  readonly $type: 'SpecificationTag';
271
- style?: SpecificationStyleProperties;
261
+ style?: StyleProperties;
272
262
  tag: Tag;
273
263
  }
274
264
  export declare const SpecificationTag = "SpecificationTag";
@@ -281,6 +271,14 @@ export interface StrictElementRef extends AstNode {
281
271
  }
282
272
  export declare const StrictElementRef = "StrictElementRef";
283
273
  export declare function isStrictElementRef(item: unknown): item is StrictElementRef;
274
+ export interface StyleProperties extends AstNode {
275
+ readonly $container: ElementBody | SpecificationElementKind | SpecificationTag;
276
+ readonly $type: 'StyleProperties';
277
+ key: 'style';
278
+ props: Array<ColorProperty | IconProperty | ShapeProperty>;
279
+ }
280
+ export declare const StyleProperties = "StyleProperties";
281
+ export declare function isStyleProperties(item: unknown): item is StyleProperties;
284
282
  export interface Tag extends AstNode {
285
283
  readonly $container: SpecificationTag;
286
284
  readonly $type: 'Tag';
@@ -321,7 +319,7 @@ export declare function isViewRuleExpression(item: unknown): item is ViewRuleExp
321
319
  export interface ViewRuleStyle extends AstNode {
322
320
  readonly $container: ElementView;
323
321
  readonly $type: 'ViewRuleStyle';
324
- props: Array<ColorProperty | ShapeProperty>;
322
+ props: Array<ColorProperty | IconProperty | ShapeProperty>;
325
323
  targets: Array<ElementExpression>;
326
324
  }
327
325
  export declare const ViewRuleStyle = "ViewRuleStyle";
@@ -334,7 +332,6 @@ export interface WildcardExpression extends AstNode {
334
332
  export declare const WildcardExpression = "WildcardExpression";
335
333
  export declare function isWildcardExpression(item: unknown): item is WildcardExpression;
336
334
  export type LikeC4AstType = {
337
- AStyleProperty: AStyleProperty;
338
335
  ColorProperty: ColorProperty;
339
336
  Element: Element;
340
337
  ElementBody: ElementBody;
@@ -345,12 +342,12 @@ export type LikeC4AstType = {
345
342
  ElementRef: ElementRef;
346
343
  ElementRefExpression: ElementRefExpression;
347
344
  ElementStringProperty: ElementStringProperty;
348
- ElementStyleProperties: ElementStyleProperties;
349
345
  ElementTagExpression: ElementTagExpression;
350
346
  ElementView: ElementView;
351
347
  Expression: Expression;
352
348
  ExtendElement: ExtendElement;
353
349
  ExtendElementBody: ExtendElementBody;
350
+ IconProperty: IconProperty;
354
351
  InOutExpression: InOutExpression;
355
352
  IncomingExpression: IncomingExpression;
356
353
  LikeC4Document: LikeC4Document;
@@ -365,9 +362,9 @@ export type LikeC4AstType = {
365
362
  ShapeProperty: ShapeProperty;
366
363
  SpecificationElementKind: SpecificationElementKind;
367
364
  SpecificationRule: SpecificationRule;
368
- SpecificationStyleProperties: SpecificationStyleProperties;
369
365
  SpecificationTag: SpecificationTag;
370
366
  StrictElementRef: StrictElementRef;
367
+ StyleProperties: StyleProperties;
371
368
  Tag: Tag;
372
369
  Tags: Tags;
373
370
  View: View;
@@ -3,10 +3,6 @@
3
3
  * DO NOT EDIT MANUALLY!
4
4
  ******************************************************************************/
5
5
  import { AbstractAstReflection } from 'langium';
6
- export const AStyleProperty = 'AStyleProperty';
7
- export function isAStyleProperty(item) {
8
- return reflection.isInstance(item, AStyleProperty);
9
- }
10
6
  export const ElementExpression = 'ElementExpression';
11
7
  export function isElementExpression(item) {
12
8
  return reflection.isInstance(item, ElementExpression);
@@ -77,10 +73,6 @@ export const ElementStringProperty = 'ElementStringProperty';
77
73
  export function isElementStringProperty(item) {
78
74
  return reflection.isInstance(item, ElementStringProperty);
79
75
  }
80
- export const ElementStyleProperties = 'ElementStyleProperties';
81
- export function isElementStyleProperties(item) {
82
- return reflection.isInstance(item, ElementStyleProperties);
83
- }
84
76
  export const ElementTagExpression = 'ElementTagExpression';
85
77
  export function isElementTagExpression(item) {
86
78
  return reflection.isInstance(item, ElementTagExpression);
@@ -97,6 +89,10 @@ export const ExtendElementBody = 'ExtendElementBody';
97
89
  export function isExtendElementBody(item) {
98
90
  return reflection.isInstance(item, ExtendElementBody);
99
91
  }
92
+ export const IconProperty = 'IconProperty';
93
+ export function isIconProperty(item) {
94
+ return reflection.isInstance(item, IconProperty);
95
+ }
100
96
  export const IncomingExpression = 'IncomingExpression';
101
97
  export function isIncomingExpression(item) {
102
98
  return reflection.isInstance(item, IncomingExpression);
@@ -153,10 +149,6 @@ export const SpecificationRule = 'SpecificationRule';
153
149
  export function isSpecificationRule(item) {
154
150
  return reflection.isInstance(item, SpecificationRule);
155
151
  }
156
- export const SpecificationStyleProperties = 'SpecificationStyleProperties';
157
- export function isSpecificationStyleProperties(item) {
158
- return reflection.isInstance(item, SpecificationStyleProperties);
159
- }
160
152
  export const SpecificationTag = 'SpecificationTag';
161
153
  export function isSpecificationTag(item) {
162
154
  return reflection.isInstance(item, SpecificationTag);
@@ -165,6 +157,10 @@ export const StrictElementRef = 'StrictElementRef';
165
157
  export function isStrictElementRef(item) {
166
158
  return reflection.isInstance(item, StrictElementRef);
167
159
  }
160
+ export const StyleProperties = 'StyleProperties';
161
+ export function isStyleProperties(item) {
162
+ return reflection.isInstance(item, StyleProperties);
163
+ }
168
164
  export const Tag = 'Tag';
169
165
  export function isTag(item) {
170
166
  return reflection.isInstance(item, Tag);
@@ -195,14 +191,10 @@ export function isWildcardExpression(item) {
195
191
  }
196
192
  export class LikeC4AstReflection extends AbstractAstReflection {
197
193
  getAllTypes() {
198
- return ['AStyleProperty', 'ColorProperty', 'Element', 'ElementBody', 'ElementExpression', 'ElementKind', 'ElementKindExpression', 'ElementProperty', 'ElementRef', 'ElementRefExpression', 'ElementStringProperty', 'ElementStyleProperties', 'ElementTagExpression', 'ElementView', 'Expression', 'ExtendElement', 'ExtendElementBody', 'InOutExpression', 'IncomingExpression', 'LikeC4Document', 'LinkProperty', 'Model', 'ModelViews', 'OutgoingExpression', 'Relation', 'RelationBody', 'RelationExpression', 'RelationStringProperty', 'ShapeProperty', 'SpecificationElementKind', 'SpecificationRule', 'SpecificationStyleProperties', 'SpecificationTag', 'StrictElementRef', 'Tag', 'Tags', 'View', 'ViewProperty', 'ViewRule', 'ViewRuleAutoLayout', 'ViewRuleExpression', 'ViewRuleStyle', 'WildcardExpression'];
194
+ return ['ColorProperty', 'Element', 'ElementBody', 'ElementExpression', 'ElementKind', 'ElementKindExpression', 'ElementProperty', 'ElementRef', 'ElementRefExpression', 'ElementStringProperty', 'ElementTagExpression', 'ElementView', 'Expression', 'ExtendElement', 'ExtendElementBody', 'IconProperty', 'InOutExpression', 'IncomingExpression', 'LikeC4Document', 'LinkProperty', 'Model', 'ModelViews', 'OutgoingExpression', 'Relation', 'RelationBody', 'RelationExpression', 'RelationStringProperty', 'ShapeProperty', 'SpecificationElementKind', 'SpecificationRule', 'SpecificationTag', 'StrictElementRef', 'StyleProperties', 'Tag', 'Tags', 'View', 'ViewProperty', 'ViewRule', 'ViewRuleAutoLayout', 'ViewRuleExpression', 'ViewRuleStyle', 'WildcardExpression'];
199
195
  }
200
196
  computeIsSubtype(subtype, supertype) {
201
197
  switch (subtype) {
202
- case ColorProperty:
203
- case ShapeProperty: {
204
- return this.isSubtype(AStyleProperty, supertype);
205
- }
206
198
  case ElementExpression:
207
199
  case IncomingExpression:
208
200
  case InOutExpression:
@@ -217,7 +209,7 @@ export class LikeC4AstReflection extends AbstractAstReflection {
217
209
  return this.isSubtype(ElementExpression, supertype);
218
210
  }
219
211
  case ElementStringProperty:
220
- case ElementStyleProperties: {
212
+ case StyleProperties: {
221
213
  return this.isSubtype(ElementProperty, supertype);
222
214
  }
223
215
  case ElementView: {
@@ -288,14 +280,6 @@ export class LikeC4AstReflection extends AbstractAstReflection {
288
280
  ]
289
281
  };
290
282
  }
291
- case 'ElementStyleProperties': {
292
- return {
293
- name: 'ElementStyleProperties',
294
- mandatory: [
295
- { name: 'props', type: 'array' }
296
- ]
297
- };
298
- }
299
283
  case 'ElementTagExpression': {
300
284
  return {
301
285
  name: 'ElementTagExpression',
@@ -353,9 +337,9 @@ export class LikeC4AstReflection extends AbstractAstReflection {
353
337
  ]
354
338
  };
355
339
  }
356
- case 'SpecificationStyleProperties': {
340
+ case 'StyleProperties': {
357
341
  return {
358
- name: 'SpecificationStyleProperties',
342
+ name: 'StyleProperties',
359
343
  mandatory: [
360
344
  { name: 'props', type: 'array' }
361
345
  ]