@likec4/language-server 0.5.0 → 0.6.1

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 (47) hide show
  1. package/contrib/likec4.monarch.ts +31 -0
  2. package/contrib/likec4.tmLanguage.json +73 -0
  3. package/dist/__test__/parser-smoke/01-Specification.d.ts +3 -0
  4. package/dist/__test__/parser-smoke/01-Specification.js +42 -0
  5. package/dist/__test__/parser-smoke/02-Model.d.ts +9 -0
  6. package/dist/__test__/parser-smoke/02-Model.js +110 -0
  7. package/dist/__test__/parser-smoke/03-ModelRelation.d.ts +6 -0
  8. package/dist/__test__/parser-smoke/03-ModelRelation.js +81 -0
  9. package/dist/__test__/parser-smoke/04-Scope.d.ts +2 -0
  10. package/dist/__test__/parser-smoke/04-Scope.js +38 -0
  11. package/dist/__test__/parser-smoke/05-StrictElementRef.d.ts +3 -0
  12. package/dist/__test__/parser-smoke/05-StrictElementRef.js +46 -0
  13. package/dist/__test__/parser-smoke/06-ElementRef.d.ts +2 -0
  14. package/dist/__test__/parser-smoke/06-ElementRef.js +59 -0
  15. package/dist/__test__/parser-smoke/07-Views.d.ts +10 -0
  16. package/dist/__test__/parser-smoke/07-Views.js +146 -0
  17. package/dist/__test__/parser-smoke/08-Structurizr.d.ts +1 -0
  18. package/dist/__test__/parser-smoke/08-Structurizr.js +22 -0
  19. package/dist/__test__/parser-smoke/index.d.ts +8 -0
  20. package/dist/__test__/parser-smoke/index.js +8 -0
  21. package/dist/__test__/parser-smoke-extendsElement.spec.d.ts +1 -0
  22. package/dist/__test__/parser-smoke-extendsElement.spec.js +36 -0
  23. package/dist/__test__/parser-smoke.spec.d.ts +1 -0
  24. package/dist/__test__/parser-smoke.spec.js +28 -0
  25. package/dist/ast.d.ts +1 -0
  26. package/dist/ast.js +16 -15
  27. package/dist/generated/ast.d.ts +16 -12
  28. package/dist/generated/ast.js +15 -5
  29. package/dist/generated/grammar.js +1534 -1379
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +0 -2
  32. package/dist/lsp/SemanticTokenProvider.js +32 -58
  33. package/dist/model/model-builder.js +13 -12
  34. package/dist/model/model-builder.spec.d.ts +1 -0
  35. package/dist/model/model-builder.spec.js +141 -0
  36. package/dist/protocol.d.ts +16 -12
  37. package/dist/protocol.js +2 -2
  38. package/dist/registerProtocolHandlers.js +24 -9
  39. package/dist/validation/element.spec.d.ts +1 -0
  40. package/dist/validation/element.spec.js +65 -0
  41. package/dist/validation/relation.spec.d.ts +1 -0
  42. package/dist/validation/relation.spec.js +93 -0
  43. package/dist/validation/specification.spec.d.ts +1 -0
  44. package/dist/validation/specification.spec.js +31 -0
  45. package/dist/validation/view.spec.d.ts +1 -0
  46. package/dist/validation/view.spec.js +20 -0
  47. package/package.json +22 -18
@@ -0,0 +1,22 @@
1
+ const model = `
2
+ specification {
3
+ element person
4
+ element group
5
+ element softwareSystem
6
+ element container
7
+ element component
8
+ }
9
+ `;
10
+ export const valid_08_Structurizr = model +
11
+ `
12
+ model {
13
+ u = person "User"
14
+ s = softwareSystem "Software System" {
15
+ webapp = container "Web Application" "" "Spring Boot"
16
+ database = container "Database" "" "Relational database schema"
17
+ }
18
+
19
+ u -> webapp "Uses"
20
+ webapp -> database "Reads from and writes to"
21
+ }
22
+ `;
@@ -0,0 +1,8 @@
1
+ export * from './01-Specification';
2
+ export * from './02-Model';
3
+ export * from './03-ModelRelation';
4
+ export * from './04-Scope';
5
+ export * from './05-StrictElementRef';
6
+ export * from './06-ElementRef';
7
+ export * from './07-Views';
8
+ export * from './08-Structurizr';
@@ -0,0 +1,8 @@
1
+ export * from './01-Specification';
2
+ export * from './02-Model';
3
+ export * from './03-ModelRelation';
4
+ export * from './04-Scope';
5
+ export * from './05-StrictElementRef';
6
+ export * from './06-ElementRef';
7
+ export * from './07-Views';
8
+ export * from './08-Structurizr';
@@ -0,0 +1,36 @@
1
+ import { expect, test } from 'vitest';
2
+ import { createTestServices } from '../test';
3
+ const document1 = `
4
+ specification {
5
+ element component
6
+ }
7
+ model {
8
+ component system {
9
+ sub = component {
10
+ component sub1
11
+ }
12
+ }
13
+ }
14
+ `;
15
+ const document2 = `
16
+ model {
17
+ extend system.sub {
18
+ component sub2 {
19
+ -> sub1
20
+ }
21
+ }
22
+ }
23
+ `;
24
+ const document3 = `
25
+ model {
26
+ system.sub1 -> system.sub2
27
+ }
28
+ `;
29
+ test('parser smoke: ExtendsElement Scope', async () => {
30
+ const { parse, validateAll } = createTestServices();
31
+ await parse(document1);
32
+ await parse(document2);
33
+ await parse(document3);
34
+ const { errors } = await validateAll();
35
+ expect(errors).toEqual([]);
36
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { toPairs } from 'rambdax';
2
+ import { describe, vi, it } from 'vitest';
3
+ import { createTestServices } from '../test';
4
+ import * as testfiles from './parser-smoke';
5
+ vi.mock('../logger', () => ({
6
+ logger: {
7
+ log: vi.fn(),
8
+ error: vi.fn(),
9
+ warn: vi.fn(),
10
+ info: vi.fn(),
11
+ debug: vi.fn()
12
+ }
13
+ }));
14
+ describe('parser smoke', () => {
15
+ toPairs(testfiles).forEach(([name, document]) => {
16
+ it.concurrent(name, async ({ expect }) => {
17
+ const { validate } = createTestServices();
18
+ const { diagnostics } = await validate(document);
19
+ const errors = diagnostics.map(d => d.message);
20
+ if (name.startsWith('invalid_')) {
21
+ expect(errors).not.toEqual([]);
22
+ }
23
+ else {
24
+ expect(errors).toEqual([]);
25
+ }
26
+ });
27
+ });
28
+ });
package/dist/ast.d.ts CHANGED
@@ -70,3 +70,4 @@ export declare function toElementStyle(props?: ast.AStyleProperty[]): {
70
70
  color?: c4.ThemeColor;
71
71
  shape?: c4.ElementShape;
72
72
  };
73
+ export declare function toAutoLayout(direction: ast.ViewRuleLayoutDirection): c4.ViewRuleAutoLayout['autoLayout'];
package/dist/ast.js CHANGED
@@ -115,18 +115,19 @@ export function toElementStyle(props) {
115
115
  }
116
116
  return result;
117
117
  }
118
- // const result: c4.ElementStyle = {}
119
- // const shapeProperty = props.find(ast.isElementShapeStyleProperty)
120
- // if (shapeProperty) {
121
- // result.shape = shapeProperty.value
122
- // }
123
- // // const colorPropValue = props.find(isColorStyleProperty)?.value
124
- // // if (isElementStyleColor(colorPropValue)) {
125
- // // result.color = colorPropValue
126
- // // }
127
- // // const iconProp = props.find(isIconStyleProperty)
128
- // // if (iconProp) {
129
- // // result.icon = iconProp.value
130
- // // }
131
- // return result
132
- // }
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
+ }
@@ -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;
@@ -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
  }