@likec4/language-server 0.4.0 → 0.6.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/ast.d.ts CHANGED
@@ -69,3 +69,4 @@ export declare function toElementStyle(props?: ast.AStyleProperty[]): {
69
69
  color?: c4.ThemeColor;
70
70
  shape?: c4.ElementShape;
71
71
  };
72
+ export declare function toAutoLayout(direction: ast.ViewRuleLayoutDirection): c4.ViewRuleAutoLayout['autoLayout'];
package/dist/ast.js CHANGED
@@ -11,7 +11,7 @@ export function c4hash({ c4Specification, c4Elements, c4Relations, c4Views }) {
11
11
  c4Relations,
12
12
  c4Views
13
13
  }, {
14
- respectType: false,
14
+ respectType: false
15
15
  });
16
16
  }
17
17
  const idattr = Symbol.for('idattr');
@@ -39,9 +39,9 @@ export function cleanParsedModel(doc) {
39
39
  doc.c4Specification = {
40
40
  kinds: {}
41
41
  };
42
- const elements = doc.c4Elements = [];
43
- const relations = doc.c4Relations = [];
44
- const views = doc.c4Views = [];
42
+ const elements = (doc.c4Elements = []);
43
+ const relations = (doc.c4Relations = []);
44
+ const views = (doc.c4Views = []);
45
45
  return {
46
46
  elements,
47
47
  relations,
@@ -53,21 +53,22 @@ export function isLikeC4LangiumDocument(doc) {
53
53
  return doc.textDocument.languageId === LikeC4LanguageMetaData.languageId;
54
54
  }
55
55
  export function isParsedLikeC4LangiumDocument(doc) {
56
- return isLikeC4LangiumDocument(doc) && ['c4Specification', 'c4Elements', 'c4Relations', 'c4Views'].every(key => key in doc);
56
+ return (isLikeC4LangiumDocument(doc) &&
57
+ ['c4Specification', 'c4Elements', 'c4Relations', 'c4Views'].every(key => key in doc));
57
58
  }
58
59
  export const isValidDocument = (doc) => {
59
60
  if (!isLikeC4LangiumDocument(doc))
60
61
  return false;
61
62
  const { state, parseResult, diagnostics } = doc;
62
- return (state === DocumentState.Validated
63
- && parseResult.lexerErrors.length === 0
64
- && (!diagnostics || diagnostics.every(d => d.severity !== 1)));
63
+ return (state === DocumentState.Validated &&
64
+ parseResult.lexerErrors.length === 0 &&
65
+ (!diagnostics || diagnostics.every(d => d.severity !== 1)));
65
66
  };
66
67
  export function* streamModel(doc) {
67
68
  const elements = doc.parseResult.value.model?.elements ?? [];
68
69
  const traverseStack = [...elements];
69
70
  let el;
70
- while (el = traverseStack.shift()) {
71
+ while ((el = traverseStack.shift())) {
71
72
  if (ast.isExtendElement(el)) {
72
73
  traverseStack.push(...el.body.elements);
73
74
  continue;
@@ -114,18 +115,19 @@ export function toElementStyle(props) {
114
115
  }
115
116
  return result;
116
117
  }
117
- // const result: c4.ElementStyle = {}
118
- // const shapeProperty = props.find(ast.isElementShapeStyleProperty)
119
- // if (shapeProperty) {
120
- // result.shape = shapeProperty.value
121
- // }
122
- // // const colorPropValue = props.find(isColorStyleProperty)?.value
123
- // // if (isElementStyleColor(colorPropValue)) {
124
- // // result.color = colorPropValue
125
- // // }
126
- // // const iconProp = props.find(isIconStyleProperty)
127
- // // if (iconProp) {
128
- // // result.icon = iconProp.value
129
- // // }
130
- // return result
131
- // }
118
+ export function toAutoLayout(direction) {
119
+ switch (direction) {
120
+ case 'TopBottom': {
121
+ return 'TB';
122
+ }
123
+ case 'BottomTop': {
124
+ return 'BT';
125
+ }
126
+ case 'LeftRight': {
127
+ return 'LR';
128
+ }
129
+ case 'RightLeft': {
130
+ return 'RL';
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,4 @@
1
+ export declare const specification: {
2
+ uri: string;
3
+ document: string;
4
+ };
@@ -0,0 +1,8 @@
1
+ export const specification = {
2
+ uri: 'builtin:///specification.likec4',
3
+ document: `
4
+ specification {
5
+ element element
6
+ }
7
+ `.trimStart()
8
+ };
@@ -3,6 +3,9 @@
3
3
  * DO NOT EDIT MANUALLY!
4
4
  ******************************************************************************/
5
5
  import { AstNode, AbstractAstReflection, Reference, ReferenceInfo, TypeMetaData } from 'langium';
6
+ export type AnyStringProperty = ElementStringProperty | RelationStringProperty | ViewProperty;
7
+ export declare const AnyStringProperty = "AnyStringProperty";
8
+ export declare function isAnyStringProperty(item: unknown): item is AnyStringProperty;
6
9
  export type AStyleProperty = ColorProperty | ShapeProperty;
7
10
  export declare const AStyleProperty = "AStyleProperty";
8
11
  export declare function isAStyleProperty(item: unknown): item is AStyleProperty;
@@ -16,7 +19,7 @@ export type ElementShape = 'browser' | 'cylinder' | 'person' | 'queue' | 'rectan
16
19
  export type Expression = ElementExpression | InOutExpression | IncomingExpression | OutgoingExpression | RelationExpression;
17
20
  export declare const Expression = "Expression";
18
21
  export declare function isExpression(item: unknown): item is Expression;
19
- export type Name = 'model' | ElementShape | ThemeColor | string;
22
+ export type Name = 'element' | 'model' | ElementShape | ThemeColor | string;
20
23
  export type ThemeColor = 'muted' | 'primary' | 'secondary';
21
24
  export type View = ElementView;
22
25
  export declare const View = "View";
@@ -24,7 +27,7 @@ export declare function isView(item: unknown): item is View;
24
27
  export type ViewRule = ViewRuleAutoLayout | ViewRuleExpression | ViewRuleStyle;
25
28
  export declare const ViewRule = "ViewRule";
26
29
  export declare function isViewRule(item: unknown): item is ViewRule;
27
- export type ViewRuleLayoutDirection = 'BT' | 'LR' | 'RL' | 'TB';
30
+ export type ViewRuleLayoutDirection = 'BottomTop' | 'LeftRight' | 'RightLeft' | 'TopBottom';
28
31
  export interface ColorProperty extends AstNode {
29
32
  readonly $container: ElementStyleProperty | SpecificationElementKindStyle | ViewRuleStyle;
30
33
  readonly $type: 'ColorProperty';
@@ -76,7 +79,7 @@ export interface ElementRefExpression extends AstNode {
76
79
  export declare const ElementRefExpression = "ElementRefExpression";
77
80
  export declare function isElementRefExpression(item: unknown): item is ElementRefExpression;
78
81
  export interface ElementStringProperty extends AstNode {
79
- readonly $container: ElementBody;
82
+ readonly $container: ElementBody | ElementView | RelationBody;
80
83
  readonly $type: 'ElementStringProperty';
81
84
  key: 'description' | 'technology' | 'title';
82
85
  value: string;
@@ -84,7 +87,7 @@ export interface ElementStringProperty extends AstNode {
84
87
  export declare const ElementStringProperty = "ElementStringProperty";
85
88
  export declare function isElementStringProperty(item: unknown): item is ElementStringProperty;
86
89
  export interface ElementStyleProperty extends AstNode {
87
- readonly $container: ElementBody;
90
+ readonly $container: ElementBody | ElementView | RelationBody;
88
91
  readonly $type: 'ElementStyleProperty';
89
92
  key: 'style';
90
93
  props: Array<ColorProperty | ShapeProperty>;
@@ -96,7 +99,7 @@ export interface ElementView extends AstNode {
96
99
  readonly $type: 'ElementView';
97
100
  name?: Name;
98
101
  properties: Array<ViewProperty>;
99
- rules: Array<ViewRule>;
102
+ rules: Array<ViewRuleAutoLayout | ViewRuleExpression | ViewRuleStyle>;
100
103
  viewOf?: ElementRef;
101
104
  }
102
105
  export declare const ElementView = "ElementView";
@@ -173,7 +176,7 @@ export declare function isRelation(item: unknown): item is Relation;
173
176
  export interface RelationBody extends AstNode {
174
177
  readonly $container: Relation | RelationWithSource;
175
178
  readonly $type: 'RelationBody';
176
- props: Array<RelationProperty>;
179
+ props: Array<RelationStringProperty>;
177
180
  tags?: Tags;
178
181
  }
179
182
  export declare const RelationBody = "RelationBody";
@@ -186,14 +189,14 @@ export interface RelationExpression extends AstNode {
186
189
  }
187
190
  export declare const RelationExpression = "RelationExpression";
188
191
  export declare function isRelationExpression(item: unknown): item is RelationExpression;
189
- export interface RelationProperty extends AstNode {
190
- readonly $container: RelationBody;
191
- readonly $type: 'RelationProperty';
192
+ export interface RelationStringProperty extends AstNode {
193
+ readonly $container: ElementBody | ElementView | RelationBody;
194
+ readonly $type: 'RelationStringProperty';
192
195
  key: 'title';
193
196
  value: string;
194
197
  }
195
- export declare const RelationProperty = "RelationProperty";
196
- export declare function isRelationProperty(item: unknown): item is RelationProperty;
198
+ export declare const RelationStringProperty = "RelationStringProperty";
199
+ export declare function isRelationStringProperty(item: unknown): item is RelationStringProperty;
197
200
  export interface ShapeProperty extends AstNode {
198
201
  readonly $container: ElementStyleProperty | SpecificationElementKindStyle | ViewRuleStyle;
199
202
  readonly $type: 'ShapeProperty';
@@ -256,7 +259,7 @@ export interface Tags extends AstNode {
256
259
  export declare const Tags = "Tags";
257
260
  export declare function isTags(item: unknown): item is Tags;
258
261
  export interface ViewProperty extends AstNode {
259
- readonly $container: ElementView;
262
+ readonly $container: ElementBody | ElementView | RelationBody;
260
263
  readonly $type: 'ViewProperty';
261
264
  key: 'description' | 'title';
262
265
  value: string;
@@ -305,6 +308,7 @@ export declare const RelationWithSource = "RelationWithSource";
305
308
  export declare function isRelationWithSource(item: unknown): item is RelationWithSource;
306
309
  export interface LikeC4AstType {
307
310
  AStyleProperty: AStyleProperty;
311
+ AnyStringProperty: AnyStringProperty;
308
312
  ColorProperty: ColorProperty;
309
313
  Element: Element;
310
314
  ElementBody: ElementBody;
@@ -328,7 +332,7 @@ export interface LikeC4AstType {
328
332
  Relation: Relation;
329
333
  RelationBody: RelationBody;
330
334
  RelationExpression: RelationExpression;
331
- RelationProperty: RelationProperty;
335
+ RelationStringProperty: RelationStringProperty;
332
336
  RelationWithSource: RelationWithSource;
333
337
  ShapeProperty: ShapeProperty;
334
338
  SpecificationElementKind: SpecificationElementKind;
@@ -4,6 +4,10 @@
4
4
  ******************************************************************************/
5
5
  /* eslint-disable */
6
6
  import { AbstractAstReflection } from 'langium';
7
+ export const AnyStringProperty = 'AnyStringProperty';
8
+ export function isAnyStringProperty(item) {
9
+ return reflection.isInstance(item, AnyStringProperty);
10
+ }
7
11
  export const AStyleProperty = 'AStyleProperty';
8
12
  export function isAStyleProperty(item) {
9
13
  return reflection.isInstance(item, AStyleProperty);
@@ -108,9 +112,9 @@ export const RelationExpression = 'RelationExpression';
108
112
  export function isRelationExpression(item) {
109
113
  return reflection.isInstance(item, RelationExpression);
110
114
  }
111
- export const RelationProperty = 'RelationProperty';
112
- export function isRelationProperty(item) {
113
- return reflection.isInstance(item, RelationProperty);
115
+ export const RelationStringProperty = 'RelationStringProperty';
116
+ export function isRelationStringProperty(item) {
117
+ return reflection.isInstance(item, RelationStringProperty);
114
118
  }
115
119
  export const ShapeProperty = 'ShapeProperty';
116
120
  export function isShapeProperty(item) {
@@ -170,7 +174,7 @@ export function isRelationWithSource(item) {
170
174
  }
171
175
  export class LikeC4AstReflection extends AbstractAstReflection {
172
176
  getAllTypes() {
173
- return ['AStyleProperty', 'ColorProperty', 'Element', 'ElementBody', 'ElementExpression', 'ElementKind', 'ElementProperty', 'ElementRef', 'ElementRefExpression', 'ElementStringProperty', 'ElementStyleProperty', 'ElementView', 'Expression', 'ExtendElement', 'ExtendElementBody', 'InOutExpression', 'IncomingExpression', 'LikeC4Document', 'Model', 'ModelViews', 'OutgoingExpression', 'Relation', 'RelationBody', 'RelationExpression', 'RelationProperty', 'RelationWithSource', 'ShapeProperty', 'SpecificationElementKind', 'SpecificationElementKindStyle', 'SpecificationRule', 'SpecificationTag', 'StrictElementRef', 'Tag', 'Tags', 'View', 'ViewProperty', 'ViewRule', 'ViewRuleAutoLayout', 'ViewRuleExpression', 'ViewRuleStyle', 'WildcardExpression'];
177
+ return ['AStyleProperty', 'AnyStringProperty', 'ColorProperty', 'Element', 'ElementBody', 'ElementExpression', 'ElementKind', 'ElementProperty', 'ElementRef', 'ElementRefExpression', 'ElementStringProperty', 'ElementStyleProperty', 'ElementView', 'Expression', 'ExtendElement', 'ExtendElementBody', 'InOutExpression', 'IncomingExpression', 'LikeC4Document', 'Model', 'ModelViews', 'OutgoingExpression', 'Relation', 'RelationBody', 'RelationExpression', 'RelationStringProperty', 'RelationWithSource', 'ShapeProperty', 'SpecificationElementKind', 'SpecificationElementKindStyle', 'SpecificationRule', 'SpecificationTag', 'StrictElementRef', 'Tag', 'Tags', 'View', 'ViewProperty', 'ViewRule', 'ViewRuleAutoLayout', 'ViewRuleExpression', 'ViewRuleStyle', 'WildcardExpression'];
174
178
  }
175
179
  computeIsSubtype(subtype, supertype) {
176
180
  switch (subtype) {
@@ -189,13 +193,19 @@ export class LikeC4AstReflection extends AbstractAstReflection {
189
193
  case WildcardExpression: {
190
194
  return this.isSubtype(ElementExpression, supertype);
191
195
  }
192
- case ElementStringProperty:
196
+ case ElementStringProperty: {
197
+ return this.isSubtype(AnyStringProperty, supertype) || this.isSubtype(ElementProperty, supertype);
198
+ }
193
199
  case ElementStyleProperty: {
194
200
  return this.isSubtype(ElementProperty, supertype);
195
201
  }
196
202
  case ElementView: {
197
203
  return this.isSubtype(View, supertype);
198
204
  }
205
+ case RelationStringProperty:
206
+ case ViewProperty: {
207
+ return this.isSubtype(AnyStringProperty, supertype);
208
+ }
199
209
  case RelationWithSource: {
200
210
  return this.isSubtype(Relation, supertype);
201
211
  }