@likec4/language-server 1.14.0 → 1.15.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.
Files changed (43) hide show
  1. package/contrib/likec4.tmLanguage.json +1 -1
  2. package/dist/browser.cjs +1 -1
  3. package/dist/browser.d.cts +2 -2
  4. package/dist/browser.d.mts +2 -2
  5. package/dist/browser.d.ts +2 -2
  6. package/dist/browser.mjs +2 -2
  7. package/dist/index.cjs +1 -1
  8. package/dist/index.d.cts +2 -2
  9. package/dist/index.d.mts +2 -2
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.mjs +2 -2
  12. package/dist/likec4lib.cjs +0 -1
  13. package/dist/likec4lib.mjs +0 -1
  14. package/dist/model-graph/index.cjs +1 -1
  15. package/dist/model-graph/index.mjs +1 -1
  16. package/dist/shared/{language-server.CbDa016p.cjs → language-server.80ITEDo5.cjs} +272 -64
  17. package/dist/shared/{language-server.CITj0XN3.cjs → language-server.BUtiWTKg.cjs} +188 -30
  18. package/dist/shared/{language-server.DFLaUdYu.mjs → language-server.DXC9g4_f.mjs} +274 -66
  19. package/dist/shared/{language-server.CO6aEDQm.d.mts → language-server.DfMwkd2l.d.mts} +46 -15
  20. package/dist/shared/{language-server.Cqyh6-9S.d.cts → language-server.U2piOAVt.d.cts} +46 -15
  21. package/dist/shared/{language-server.BI99piRy.d.ts → language-server.j-ShR6as.d.ts} +46 -15
  22. package/dist/shared/{language-server.DZYziEuF.mjs → language-server.zY53FGJE.mjs} +189 -31
  23. package/package.json +9 -9
  24. package/src/ast.ts +1 -0
  25. package/src/generated/ast.ts +103 -19
  26. package/src/generated/grammar.ts +1 -1
  27. package/src/generated-lib/icons.ts +0 -1
  28. package/src/like-c4.langium +32 -9
  29. package/src/lsp/CompletionProvider.ts +70 -2
  30. package/src/model/model-builder.ts +0 -1
  31. package/src/model/model-parser.ts +71 -20
  32. package/src/model-graph/compute-view/__test__/fixture.ts +45 -4
  33. package/src/model-graph/compute-view/compute.ts +223 -40
  34. package/src/model-graph/compute-view/predicates.ts +12 -6
  35. package/src/model-graph/utils/applyCustomElementProperties.ts +18 -4
  36. package/src/model-graph/utils/applyCustomRelationProperties.ts +2 -1
  37. package/src/model-graph/utils/applyViewRuleStyles.ts +30 -25
  38. package/src/model-graph/utils/buildComputeNodes.ts +69 -17
  39. package/src/model-graph/utils/elementExpressionToPredicate.ts +3 -1
  40. package/src/model-graph/utils/sortNodes.ts +11 -7
  41. package/src/references/scope-computation.ts +3 -2
  42. package/src/validation/index.ts +2 -2
  43. package/src/validation/specification.ts +4 -4
@@ -4,7 +4,9 @@ import { isNullish } from 'remeda'
4
4
 
5
5
  type Predicate<T> = (x: T) => boolean
6
6
 
7
- export function elementExprToPredicate(target: Expr.ElementPredicateExpression): Predicate<Element> {
7
+ export function elementExprToPredicate<T extends Pick<Element, 'id' | 'kind' | 'tags'>>(
8
+ target: Expr.ElementPredicateExpression
9
+ ): Predicate<T> {
8
10
  if (Expr.isElementWhere(target)) {
9
11
  const predicate = elementExprToPredicate(target.where.expr)
10
12
  const where = whereOperatorAsPredicate(target.where.condition)
@@ -8,7 +8,7 @@ import {
8
8
  invariant,
9
9
  nonNullable
10
10
  } from '@likec4/core'
11
- import { difference, filter, map, pipe, sort } from 'remeda'
11
+ import { difference, filter, map, pipe, sort, tap } from 'remeda'
12
12
  import { Graph, postorder } from '../../utils/graphlib'
13
13
 
14
14
  // side effect
@@ -27,9 +27,16 @@ export function sortNodes({
27
27
  nodes: ComputedNode[]
28
28
  edges: ComputedEdge[]
29
29
  }): ComputedNode[] {
30
- if (edges.length === 0) {
30
+ if (nodes.length < 2) {
31
31
  return nodes
32
32
  }
33
+ if (edges.length === 0) {
34
+ return pipe(
35
+ nodes,
36
+ sort(compareByFqnHierarchically),
37
+ tap(sortChildren)
38
+ )
39
+ }
33
40
 
34
41
  const g = new Graph({
35
42
  compound: false,
@@ -55,9 +62,6 @@ export function sortNodes({
55
62
  for (const n of nodes) {
56
63
  g.setNode(n.id, n.id)
57
64
  if (n.children.length > 0) {
58
- // n.children.forEach(c => {
59
- // g.setEdge(n.id, c, undefined, `${n.id}:${c}`)
60
- // })
61
65
  n.inEdges.forEach(e => {
62
66
  const edge = getEdge(e)
63
67
  // if this edge from leaf to the child of this node
@@ -83,15 +87,15 @@ export function sortNodes({
83
87
  if (sources.length === 0) {
84
88
  sources = pipe(
85
89
  nodes,
86
- sort(compareByFqnHierarchically),
87
90
  filter(n => n.inEdges.length === 0 || n.parent === null),
91
+ sort(compareByFqnHierarchically),
88
92
  map(n => n.id)
89
93
  )
90
94
  }
91
95
  const orderedIds = postorder(g, sources).reverse() as Fqn[]
92
96
  const sorted = orderedIds.map(getNode)
93
97
  if (sorted.length < nodes.length) {
94
- const unsorted = difference(nodes, sorted)
98
+ const unsorted = difference(nodes, sorted).sort(compareByFqnHierarchically)
95
99
  sorted.push(...unsorted)
96
100
  }
97
101
 
@@ -71,8 +71,9 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
71
71
  }
72
72
  for (const globalStyleAst of globals.flatMap(g => g.styles)) {
73
73
  try {
74
- if (isTruthy(globalStyleAst.name)) {
75
- docExports.push(this.descriptions.createDescription(globalStyleAst, globalStyleAst.name, document))
74
+ const id = globalStyleAst.id
75
+ if (isTruthy(id.name)) {
76
+ docExports.push(this.descriptions.createDescription(id, id.name, document))
76
77
  }
77
78
  } catch (e) {
78
79
  logError(e)
@@ -9,7 +9,7 @@ import { relationBodyChecks, relationChecks } from './relation'
9
9
  import {
10
10
  elementKindChecks,
11
11
  globalsChecks,
12
- globalStyleChecks,
12
+ globalStyleIdChecks,
13
13
  modelRuleChecks,
14
14
  relationshipChecks,
15
15
  specificationRuleChecks,
@@ -34,7 +34,7 @@ export function registerValidationChecks(services: LikeC4Services) {
34
34
  SpecificationRule: specificationRuleChecks(services),
35
35
  Model: modelRuleChecks(services),
36
36
  Globals: globalsChecks(services),
37
- GlobalStyle: globalStyleChecks(services),
37
+ GlobalStyleId: globalStyleIdChecks(services),
38
38
  DynamicViewStep: dynamicViewStep(services),
39
39
  LikeC4View: viewChecks(services),
40
40
  Element: elementChecks(services),
@@ -130,18 +130,18 @@ export const relationshipChecks = (
130
130
  }
131
131
  }
132
132
 
133
- export const globalStyleChecks = (
133
+ export const globalStyleIdChecks = (
134
134
  services: LikeC4Services
135
- ): ValidationCheck<ast.GlobalStyle> => {
135
+ ): ValidationCheck<ast.GlobalStyleId> => {
136
136
  const index = services.shared.workspace.IndexManager
137
137
  return (node, accept) => {
138
138
  const sameName = index
139
- .allElements(ast.GlobalStyle)
139
+ .allElements(ast.GlobalStyleId)
140
140
  .filter(s => s.name === node.name)
141
141
  .limit(2)
142
142
  .count()
143
143
  if (sameName > 1) {
144
- accept('error', `Duplicate GlobalStyle name '${node.name}'`, {
144
+ accept('error', `Duplicate GlobalStyleId name '${node.name}'`, {
145
145
  node: node,
146
146
  property: 'name'
147
147
  })