@likec4/language-server 1.8.0 → 1.8.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.
@@ -12,7 +12,7 @@
12
12
  },
13
13
  {
14
14
  "name": "keyword.control.likec4",
15
- "match": "\\b(BottomTop|LeftRight|RightLeft|TopBottom|amber|and|autoLayout|blue|border|browser|color|crow|cylinder|dashed|description|diamond|dot|dotted|dynamic|element|element\\.kind|element\\.tag|exclude|extend|extends|gray|green|head|icon|icons|include|indigo|is|it|kind|likec4lib|line|link|metadata|mobile|model|muted|navigateTo|none|normal|not|notation|odiamond|odot|of|onormal|opacity|open|or|person|primary|queue|rectangle|red|relationship|secondary|shape|sky|slate|solid|specification|storage|style|tag|tail|technology|this|title|vee|view|views|where|with)\\b"
15
+ "match": "\\b(BottomTop|LeftRight|RightLeft|TopBottom|amber|and|autoLayout|blue|border|browser|color|crow|cylinder|dashed|description|diamond|dot|dotted|dynamic|element|element\\.kind|element\\.tag|exclude|extend|extends|gray|green|head|icon|icons|include|indigo|is|kind|likec4lib|line|link|metadata|mobile|model|muted|navigateTo|none|normal|not|notation|odiamond|odot|of|onormal|opacity|open|or|person|primary|queue|rectangle|red|relationship|secondary|shape|sky|slate|solid|specification|storage|style|tag|tail|technology|title|vee|view|views|where|with)\\b"
16
16
  },
17
17
  {
18
18
  "name": "string.quoted.double.likec4",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@likec4/language-server",
3
3
  "description": "LikeC4 Language Server",
4
- "version": "1.8.0",
4
+ "version": "1.8.1",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -92,8 +92,8 @@
92
92
  },
93
93
  "dependencies": {
94
94
  "@dagrejs/graphlib": "^2.2.4",
95
- "@likec4/core": "1.8.0",
96
- "@likec4/log": "1.8.0",
95
+ "@likec4/core": "1.8.1",
96
+ "@likec4/log": "1.8.1",
97
97
  "@msgpack/msgpack": "^3.0.0-beta2",
98
98
  "@smithy/util-base64": "^3.0.0",
99
99
  "@total-typescript/ts-reset": "^0.5.1",
@@ -114,8 +114,8 @@
114
114
  "vscode-uri": "3.0.8"
115
115
  },
116
116
  "devDependencies": {
117
- "@likec4/icons": "1.8.0",
118
- "@likec4/tsconfig": "1.8.0",
117
+ "@likec4/icons": "1.8.1",
118
+ "@likec4/tsconfig": "1.8.1",
119
119
  "@types/node": "^20.16.1",
120
120
  "@types/object-hash": "^3.0.6",
121
121
  "@types/string-hash": "^1.1.3",
package/src/ast.ts CHANGED
@@ -4,12 +4,11 @@ import {
4
4
  DefaultLineStyle,
5
5
  DefaultRelationshipColor,
6
6
  nonexhaustive,
7
- NullableError,
8
7
  RelationRefError
9
8
  } from '@likec4/core'
10
9
  import type { AstNode, AstNodeDescription, DiagnosticInfo, LangiumDocument, MultiMap } from 'langium'
11
10
  import { DocumentState } from 'langium'
12
- import { clamp, isNullish, isTruthy } from 'remeda'
11
+ import { clamp, isDefined, isNullish, isTruthy } from 'remeda'
13
12
  import type { ConditionalPick, SetRequired, ValueOf } from 'type-fest'
14
13
  import type { Diagnostic } from 'vscode-languageserver-types'
15
14
  import { DiagnosticSeverity } from 'vscode-languageserver-types'
@@ -323,7 +322,7 @@ export function resolveRelationPoints(node: ast.Relation): {
323
322
  if (!target) {
324
323
  throw new RelationRefError('Invalid reference to target')
325
324
  }
326
- if (ast.isExplicitRelation(node)) {
325
+ if (isDefined(node.source)) {
327
326
  const source = elementRef(node.source)
328
327
  if (!source) {
329
328
  throw new RelationRefError('Invalid reference to source')
@@ -333,6 +332,9 @@ export function resolveRelationPoints(node: ast.Relation): {
333
332
  target
334
333
  }
335
334
  }
335
+ if (!ast.isElementBody(node.$container)) {
336
+ throw new RelationRefError('Invalid container for sourceless relation')
337
+ }
336
338
  return {
337
339
  source: node.$container.$container,
338
340
  target
@@ -132,14 +132,6 @@ export function isPredicate(item: unknown): item is Predicate {
132
132
  return reflection.isInstance(item, Predicate);
133
133
  }
134
134
 
135
- export type Relation = ExplicitRelation | ImplicitRelation;
136
-
137
- export const Relation = 'Relation';
138
-
139
- export function isRelation(item: unknown): item is Relation {
140
- return reflection.isInstance(item, Relation);
141
- }
142
-
143
135
  export type RelationExpression = DirectedRelationExpression | InOutRelationExpression | IncomingRelationExpression | OutgoingRelationExpression;
144
136
 
145
137
  export const RelationExpression = 'RelationExpression';
@@ -552,7 +544,7 @@ export function isElementPredicateWith(item: unknown): item is ElementPredicateW
552
544
  }
553
545
 
554
546
  export interface ElementRef extends AstNode {
555
- readonly $container: DirectedRelationExpression | DynamicViewPredicateIterator | DynamicViewStep | ElementDescedantsExpression | ElementExpressionsIterator | ElementPredicateWhere | ElementPredicateWith | ElementRef | ElementView | ExpandElementExpression | ExplicitRelation | ImplicitRelation | IncomingRelationExpression | OutgoingRelationExpression | Predicates;
547
+ readonly $container: DirectedRelationExpression | DynamicViewPredicateIterator | DynamicViewStep | ElementDescedantsExpression | ElementExpressionsIterator | ElementPredicateWhere | ElementPredicateWith | ElementRef | ElementView | ExpandElementExpression | IncomingRelationExpression | OutgoingRelationExpression | Predicates | Relation;
556
548
  readonly $type: 'ElementRef';
557
549
  el: Reference<Element>;
558
550
  parent?: ElementRef;
@@ -668,24 +660,6 @@ export function isExpandElementExpression(item: unknown): item is ExpandElementE
668
660
  return reflection.isInstance(item, ExpandElementExpression);
669
661
  }
670
662
 
671
- export interface ExplicitRelation extends AstNode {
672
- readonly $container: ElementBody | ExtendElementBody | Model;
673
- readonly $type: 'ExplicitRelation';
674
- body?: RelationBody;
675
- kind?: Reference<RelationshipKind>;
676
- source: ElementRef;
677
- tags?: Tags;
678
- target: ElementRef;
679
- technology?: string;
680
- title?: string;
681
- }
682
-
683
- export const ExplicitRelation = 'ExplicitRelation';
684
-
685
- export function isExplicitRelation(item: unknown): item is ExplicitRelation {
686
- return reflection.isInstance(item, ExplicitRelation);
687
- }
688
-
689
663
  export interface ExtendElement extends AstNode {
690
664
  readonly $container: Model;
691
665
  readonly $type: 'ExtendElement';
@@ -702,7 +676,7 @@ export function isExtendElement(item: unknown): item is ExtendElement {
702
676
  export interface ExtendElementBody extends AstNode {
703
677
  readonly $container: ExtendElement;
704
678
  readonly $type: 'ExtendElementBody';
705
- elements: Array<Element | ExplicitRelation>;
679
+ elements: Array<Element | Relation>;
706
680
  }
707
681
 
708
682
  export const ExtendElementBody = 'ExtendElementBody';
@@ -738,23 +712,6 @@ export function isIconProperty(item: unknown): item is IconProperty {
738
712
  return reflection.isInstance(item, IconProperty);
739
713
  }
740
714
 
741
- export interface ImplicitRelation extends AstNode {
742
- readonly $container: ElementBody;
743
- readonly $type: 'ImplicitRelation';
744
- body?: RelationBody;
745
- kind?: Reference<RelationshipKind>;
746
- tags?: Tags;
747
- target: ElementRef;
748
- technology?: string;
749
- title?: string;
750
- }
751
-
752
- export const ImplicitRelation = 'ImplicitRelation';
753
-
754
- export function isImplicitRelation(item: unknown): item is ImplicitRelation {
755
- return reflection.isInstance(item, ImplicitRelation);
756
- }
757
-
758
715
  export interface IncludePredicate extends AstNode {
759
716
  readonly $container: ElementViewBody;
760
717
  readonly $type: 'IncludePredicate';
@@ -884,7 +841,7 @@ export function isMetadataBody(item: unknown): item is MetadataBody {
884
841
  export interface Model extends AstNode {
885
842
  readonly $container: LikeC4Grammar;
886
843
  readonly $type: 'Model';
887
- elements: Array<Element | ExplicitRelation | ExtendElement>;
844
+ elements: Array<Element | ExtendElement | Relation>;
888
845
  name: 'model';
889
846
  }
890
847
 
@@ -973,8 +930,26 @@ export function isPredicates(item: unknown): item is Predicates {
973
930
  return reflection.isInstance(item, Predicates);
974
931
  }
975
932
 
933
+ export interface Relation extends AstNode {
934
+ readonly $container: ElementBody | ExtendElementBody | Model;
935
+ readonly $type: 'Relation';
936
+ body?: RelationBody;
937
+ kind?: Reference<RelationshipKind>;
938
+ source?: ElementRef;
939
+ tags?: Tags;
940
+ target: ElementRef;
941
+ technology?: string;
942
+ title?: string;
943
+ }
944
+
945
+ export const Relation = 'Relation';
946
+
947
+ export function isRelation(item: unknown): item is Relation {
948
+ return reflection.isInstance(item, Relation);
949
+ }
950
+
976
951
  export interface RelationBody extends AstNode {
977
- readonly $container: ExplicitRelation | ImplicitRelation;
952
+ readonly $container: Relation;
978
953
  readonly $type: 'RelationBody';
979
954
  props: Array<RelationProperty>;
980
955
  tags?: Tags;
@@ -1155,7 +1130,7 @@ export function isTag(item: unknown): item is Tag {
1155
1130
  }
1156
1131
 
1157
1132
  export interface Tags extends AstNode {
1158
- readonly $container: DynamicViewBody | ElementBody | ElementViewBody | ExplicitRelation | ImplicitRelation | RelationBody | Tags;
1133
+ readonly $container: DynamicViewBody | ElementBody | ElementViewBody | Relation | RelationBody | Tags;
1159
1134
  readonly $type: 'Tags';
1160
1135
  prev?: Tags;
1161
1136
  values: Array<Reference<Tag>>;
@@ -1357,12 +1332,10 @@ export type LikeC4AstType = {
1357
1332
  ElementViewRef: ElementViewRef
1358
1333
  ExcludePredicate: ExcludePredicate
1359
1334
  ExpandElementExpression: ExpandElementExpression
1360
- ExplicitRelation: ExplicitRelation
1361
1335
  ExtendElement: ExtendElement
1362
1336
  ExtendElementBody: ExtendElementBody
1363
1337
  FqnElementRef: FqnElementRef
1364
1338
  IconProperty: IconProperty
1365
- ImplicitRelation: ImplicitRelation
1366
1339
  InOutRelationExpression: InOutRelationExpression
1367
1340
  IncludePredicate: IncludePredicate
1368
1341
  IncomingRelationExpression: IncomingRelationExpression
@@ -1433,7 +1406,7 @@ export type LikeC4AstType = {
1433
1406
  export class LikeC4AstReflection extends AbstractAstReflection {
1434
1407
 
1435
1408
  getAllTypes(): string[] {
1436
- return [ArrowProperty, BorderProperty, ColorProperty, CustomElementProperties, CustomRelationProperties, DirectedRelationExpression, DynamicView, DynamicViewBody, DynamicViewIncludePredicate, DynamicViewPredicateIterator, DynamicViewRule, DynamicViewStep, Element, ElementBody, ElementDescedantsExpression, ElementExpression, ElementExpressionsIterator, ElementKind, ElementKindExpression, ElementPredicate, ElementPredicateOrWhere, ElementPredicateWhere, ElementPredicateWith, ElementProperty, ElementRef, ElementStringProperty, ElementStyleProperty, ElementTagExpression, ElementView, ElementViewBody, ElementViewRef, ExcludePredicate, ExpandElementExpression, ExplicitRelation, ExtendElement, ExtendElementBody, FqnElementRef, IconProperty, ImplicitRelation, InOutRelationExpression, IncludePredicate, IncomingRelationExpression, LibIcon, LikeC4Grammar, LikeC4Lib, LikeC4View, LineProperty, LinkProperty, MetadataAttribute, MetadataBody, MetadataProperty, Model, ModelViews, NavigateToProperty, NotationProperty, OpacityProperty, OutgoingRelationExpression, Predicate, Predicates, Relation, RelationBody, RelationExpression, RelationPredicate, RelationPredicateOrWhere, RelationPredicateWhere, RelationPredicateWith, RelationProperty, RelationStringProperty, RelationStyleProperty, RelationshipKind, RelationshipStyleProperty, ShapeProperty, SpecificationElementKind, SpecificationElementStringProperty, SpecificationRelationshipKind, SpecificationRelationshipStringProperty, SpecificationRule, SpecificationTag, StringProperty, StyleProperty, Tag, Tags, ViewProperty, ViewRef, ViewRule, ViewRuleAutoLayout, ViewRulePredicate, ViewRuleStyle, ViewStringProperty, WhereBinaryExpression, WhereElement, WhereElementExpression, WhereElementKind, WhereElementNegation, WhereElementTag, WhereExpression, WhereKindEqual, WhereRelation, WhereRelationExpression, WhereRelationKind, WhereRelationNegation, WhereRelationTag, WhereTagEqual, WildcardExpression];
1409
+ return [ArrowProperty, BorderProperty, ColorProperty, CustomElementProperties, CustomRelationProperties, DirectedRelationExpression, DynamicView, DynamicViewBody, DynamicViewIncludePredicate, DynamicViewPredicateIterator, DynamicViewRule, DynamicViewStep, Element, ElementBody, ElementDescedantsExpression, ElementExpression, ElementExpressionsIterator, ElementKind, ElementKindExpression, ElementPredicate, ElementPredicateOrWhere, ElementPredicateWhere, ElementPredicateWith, ElementProperty, ElementRef, ElementStringProperty, ElementStyleProperty, ElementTagExpression, ElementView, ElementViewBody, ElementViewRef, ExcludePredicate, ExpandElementExpression, ExtendElement, ExtendElementBody, FqnElementRef, IconProperty, InOutRelationExpression, IncludePredicate, IncomingRelationExpression, LibIcon, LikeC4Grammar, LikeC4Lib, LikeC4View, LineProperty, LinkProperty, MetadataAttribute, MetadataBody, MetadataProperty, Model, ModelViews, NavigateToProperty, NotationProperty, OpacityProperty, OutgoingRelationExpression, Predicate, Predicates, Relation, RelationBody, RelationExpression, RelationPredicate, RelationPredicateOrWhere, RelationPredicateWhere, RelationPredicateWith, RelationProperty, RelationStringProperty, RelationStyleProperty, RelationshipKind, RelationshipStyleProperty, ShapeProperty, SpecificationElementKind, SpecificationElementStringProperty, SpecificationRelationshipKind, SpecificationRelationshipStringProperty, SpecificationRule, SpecificationTag, StringProperty, StyleProperty, Tag, Tags, ViewProperty, ViewRef, ViewRule, ViewRuleAutoLayout, ViewRulePredicate, ViewRuleStyle, ViewStringProperty, WhereBinaryExpression, WhereElement, WhereElementExpression, WhereElementKind, WhereElementNegation, WhereElementTag, WhereExpression, WhereKindEqual, WhereRelation, WhereRelationExpression, WhereRelationKind, WhereRelationNegation, WhereRelationTag, WhereTagEqual, WildcardExpression];
1437
1410
  }
1438
1411
 
1439
1412
  protected override computeIsSubtype(subtype: string, supertype: string): boolean {
@@ -1493,10 +1466,6 @@ export class LikeC4AstReflection extends AbstractAstReflection {
1493
1466
  case IncludePredicate: {
1494
1467
  return this.isSubtype(ViewRulePredicate, supertype);
1495
1468
  }
1496
- case ExplicitRelation:
1497
- case ImplicitRelation: {
1498
- return this.isSubtype(Relation, supertype);
1499
- }
1500
1469
  case IconProperty: {
1501
1470
  return this.isSubtype(ElementProperty, supertype) || this.isSubtype(StyleProperty, supertype);
1502
1471
  }
@@ -1576,9 +1545,8 @@ export class LikeC4AstReflection extends AbstractAstReflection {
1576
1545
  const referenceId = `${refInfo.container.$type}:${refInfo.property}`;
1577
1546
  switch (referenceId) {
1578
1547
  case 'DynamicViewStep:kind':
1579
- case 'ExplicitRelation:kind':
1580
- case 'ImplicitRelation:kind':
1581
1548
  case 'OutgoingRelationExpression:kind':
1549
+ case 'Relation:kind':
1582
1550
  case 'WhereRelationKind:value': {
1583
1551
  return RelationshipKind;
1584
1552
  }
@@ -1870,20 +1838,6 @@ export class LikeC4AstReflection extends AbstractAstReflection {
1870
1838
  ]
1871
1839
  };
1872
1840
  }
1873
- case ExplicitRelation: {
1874
- return {
1875
- name: ExplicitRelation,
1876
- properties: [
1877
- { name: 'body' },
1878
- { name: 'kind' },
1879
- { name: 'source' },
1880
- { name: 'tags' },
1881
- { name: 'target' },
1882
- { name: 'technology' },
1883
- { name: 'title' }
1884
- ]
1885
- };
1886
- }
1887
1841
  case ExtendElement: {
1888
1842
  return {
1889
1843
  name: ExtendElement,
@@ -1920,19 +1874,6 @@ export class LikeC4AstReflection extends AbstractAstReflection {
1920
1874
  ]
1921
1875
  };
1922
1876
  }
1923
- case ImplicitRelation: {
1924
- return {
1925
- name: ImplicitRelation,
1926
- properties: [
1927
- { name: 'body' },
1928
- { name: 'kind' },
1929
- { name: 'tags' },
1930
- { name: 'target' },
1931
- { name: 'technology' },
1932
- { name: 'title' }
1933
- ]
1934
- };
1935
- }
1936
1877
  case IncludePredicate: {
1937
1878
  return {
1938
1879
  name: IncludePredicate,
@@ -2084,6 +2025,20 @@ export class LikeC4AstReflection extends AbstractAstReflection {
2084
2025
  ]
2085
2026
  };
2086
2027
  }
2028
+ case Relation: {
2029
+ return {
2030
+ name: Relation,
2031
+ properties: [
2032
+ { name: 'body' },
2033
+ { name: 'kind' },
2034
+ { name: 'source' },
2035
+ { name: 'tags' },
2036
+ { name: 'target' },
2037
+ { name: 'technology' },
2038
+ { name: 'title' }
2039
+ ]
2040
+ };
2041
+ }
2087
2042
  case RelationBody: {
2088
2043
  return {
2089
2044
  name: RelationBody,