@likec4/language-server 1.8.1 → 1.9.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 (76) hide show
  1. package/dist/browser.cjs +21 -0
  2. package/dist/browser.d.cts +22 -0
  3. package/dist/browser.d.mts +22 -0
  4. package/dist/browser.d.ts +22 -0
  5. package/dist/browser.mjs +19 -0
  6. package/dist/index.cjs +10 -0
  7. package/dist/index.d.cts +18 -0
  8. package/dist/index.d.mts +18 -0
  9. package/dist/index.d.ts +18 -0
  10. package/dist/index.mjs +1 -0
  11. package/dist/likec4lib.cjs +961 -0
  12. package/dist/likec4lib.d.cts +6 -0
  13. package/dist/likec4lib.d.mts +6 -0
  14. package/dist/likec4lib.d.ts +6 -0
  15. package/dist/likec4lib.mjs +957 -0
  16. package/dist/model-graph/index.cjs +10 -0
  17. package/dist/model-graph/index.d.cts +79 -0
  18. package/dist/model-graph/index.d.mts +79 -0
  19. package/dist/model-graph/index.d.ts +79 -0
  20. package/dist/model-graph/index.mjs +1 -0
  21. package/dist/node.cjs +18 -0
  22. package/dist/node.d.cts +20 -0
  23. package/dist/node.d.mts +20 -0
  24. package/dist/node.d.ts +20 -0
  25. package/dist/node.mjs +16 -0
  26. package/dist/protocol.cjs +25 -0
  27. package/dist/protocol.d.cts +43 -0
  28. package/dist/protocol.d.mts +43 -0
  29. package/dist/protocol.d.ts +43 -0
  30. package/dist/protocol.mjs +17 -0
  31. package/dist/shared/language-server.86lmJ8ZN.d.cts +1194 -0
  32. package/dist/shared/language-server.B1TZgyoH.cjs +5371 -0
  33. package/dist/shared/language-server.CCB4ESN5.mjs +1606 -0
  34. package/dist/shared/language-server.CFTY6j4e.d.mts +1194 -0
  35. package/dist/shared/language-server.D0bOlrCi.cjs +1619 -0
  36. package/dist/shared/language-server.Q-wtPShM.mjs +5360 -0
  37. package/dist/shared/language-server.RjhrBZS0.d.ts +1194 -0
  38. package/package.json +35 -20
  39. package/src/ast.ts +40 -30
  40. package/src/browser.ts +0 -3
  41. package/src/elementRef.ts +1 -1
  42. package/src/generated/ast.ts +67 -3
  43. package/src/generated/grammar.ts +1 -1
  44. package/src/generated-lib/icons.ts +1 -1
  45. package/src/like-c4.langium +16 -2
  46. package/src/likec4lib.ts +2 -3
  47. package/src/logger.ts +9 -1
  48. package/src/lsp/RenameProvider.ts +8 -0
  49. package/src/lsp/SemanticTokenProvider.ts +19 -1
  50. package/src/lsp/index.ts +1 -0
  51. package/src/model/fqn-computation.ts +33 -23
  52. package/src/model/fqn-index.ts +5 -20
  53. package/src/model/model-builder.ts +147 -90
  54. package/src/model/model-locator.ts +1 -1
  55. package/src/model/model-parser-where.ts +3 -2
  56. package/src/model/model-parser.ts +57 -19
  57. package/src/model-graph/LikeC4ModelGraph.ts +42 -21
  58. package/src/model-graph/compute-view/__test__/fixture.ts +16 -14
  59. package/src/model-graph/compute-view/compute.ts +9 -6
  60. package/src/model-graph/compute-view/predicates.ts +3 -3
  61. package/src/model-graph/dynamic-view/__test__/fixture.ts +1 -0
  62. package/src/model-graph/dynamic-view/compute.ts +2 -1
  63. package/src/model-graph/utils/elementExpressionToPredicate.ts +1 -1
  64. package/src/model-graph/utils/sortNodes.ts +2 -6
  65. package/src/module.ts +23 -3
  66. package/src/protocol.ts +4 -5
  67. package/src/references/scope-computation.ts +10 -1
  68. package/src/references/scope-provider.ts +2 -1
  69. package/src/shared/NodeKindProvider.ts +73 -34
  70. package/src/test/setup.ts +3 -8
  71. package/src/utils/graphlib.ts +11 -0
  72. package/src/view-utils/manual-layout.ts +1 -1
  73. package/src/view-utils/resolve-extended-views.ts +19 -10
  74. package/src/view-utils/resolve-relative-paths.ts +5 -7
  75. package/src/view-utils/view-hash.ts +1 -1
  76. package/src/reset.d.ts +0 -2
@@ -1,9 +1,7 @@
1
- import graphlib from '@dagrejs/graphlib'
2
1
  import { isExtendsElementView, type LikeC4View } from '@likec4/core'
3
-
4
- // '@dagrejs/graphlib' is a CommonJS module
5
- // Here is a workaround to import it
6
- const { Graph, alg } = graphlib
2
+ import { logger } from '@likec4/log'
3
+ import { first, last, values } from 'remeda'
4
+ import { findCycles, Graph, isAcyclic, postorder } from '../utils/graphlib'
7
5
 
8
6
  /**
9
7
  * Resolve rules of extended views
@@ -18,21 +16,31 @@ export function resolveRulesExtendedViews<V extends Record<any, LikeC4View>>(
18
16
  multigraph: false,
19
17
  compound: false
20
18
  })
21
- for (const view of Object.values(unresolvedViews)) {
19
+ for (const view of values(unresolvedViews)) {
22
20
  g.setNode(view.id)
23
21
  if (isExtendsElementView(view)) {
24
22
  // view -> parent
25
23
  g.setEdge(view.id, view.extends)
26
24
  }
27
25
  }
26
+ if (g.edgeCount() === 0) {
27
+ return unresolvedViews
28
+ }
28
29
 
29
30
  // Remove circular dependencies
30
- const cycles = alg.findCycles(g)
31
- if (cycles.length > 0) {
32
- cycles.flat().forEach(id => g.removeNode(id))
31
+ while (!isAcyclic(g)) {
32
+ const firstCycle = first(findCycles(g))
33
+ if (!firstCycle) {
34
+ break
35
+ }
36
+ const cycledNode = last(firstCycle)
37
+ if (!cycledNode) {
38
+ break
39
+ }
40
+ g.removeNode(cycledNode)
33
41
  }
34
42
 
35
- const ordered = alg.postorder(g, g.sources())
43
+ const ordered = postorder(g, g.sources())
36
44
 
37
45
  return ordered.reduce((acc, id) => {
38
46
  const view = unresolvedViews[id]
@@ -42,6 +50,7 @@ export function resolveRulesExtendedViews<V extends Record<any, LikeC4View>>(
42
50
  if (isExtendsElementView(view)) {
43
51
  const extendsFrom = acc[view.extends]
44
52
  if (!extendsFrom) {
53
+ logger.debug(`View "${view.id}" extends from "${view.extends}" which does not exist`)
45
54
  return acc
46
55
  }
47
56
  return Object.assign(acc, {
@@ -1,6 +1,7 @@
1
1
  import type { LikeC4View } from '@likec4/core'
2
2
  import { invariant } from '@likec4/core'
3
3
  import { filter, hasAtLeast, isTruthy, map, pipe, unique, zip } from 'remeda'
4
+ import { parsePath } from 'ufo'
4
5
 
5
6
  function commonAncestorPath(views: LikeC4View[], sep = '/') {
6
7
  const uniqURIs = pipe(
@@ -11,20 +12,20 @@ function commonAncestorPath(views: LikeC4View[], sep = '/') {
11
12
  )
12
13
  if (uniqURIs.length === 0) return ''
13
14
  if (hasAtLeast(uniqURIs, 1) && uniqURIs.length === 1) {
14
- const parts = new URL(uniqURIs[0]).pathname.split(sep)
15
+ const parts = parsePath(uniqURIs[0]).pathname.split(sep)
15
16
  if (parts.length <= 1) return sep
16
17
  parts.pop() // remove filename
17
18
  return parts.join(sep) + sep
18
19
  }
19
20
  invariant(hasAtLeast(uniqURIs, 2), 'Expected at least 2 unique URIs')
20
21
  const [baseUri, ...tail] = uniqURIs
21
- const parts = new URL(baseUri).pathname.split(sep)
22
+ const parts = parsePath(baseUri).pathname.split(sep)
22
23
  let endOfPrefix = parts.length
23
24
  for (const uri of tail) {
24
25
  if (uri === baseUri) {
25
26
  continue
26
27
  }
27
- const compare = new URL(uri).pathname.split(sep)
28
+ const compare = parsePath(uri).pathname.split(sep)
28
29
  for (let i = 0; i < endOfPrefix; i++) {
29
30
  if (compare[i] !== parts[i]) {
30
31
  endOfPrefix = i
@@ -50,7 +51,7 @@ export function resolveRelativePaths(views: LikeC4View[]): LikeC4View[] {
50
51
  parts: []
51
52
  }
52
53
  }
53
- let path = new URL(view.docUri).pathname
54
+ let path = parsePath(view.docUri).pathname
54
55
  if (commonPrefix.length > 0) {
55
56
  invariant(
56
57
  path.startsWith(commonPrefix),
@@ -71,9 +72,6 @@ export function resolveRelativePaths(views: LikeC4View[]): LikeC4View[] {
71
72
  if (a.parts.length === 0) {
72
73
  return 0
73
74
  }
74
- if (a.parts.length === 1 && hasAtLeast(a.parts, 1) && hasAtLeast(b.parts, 1)) {
75
- return a.parts[0].localeCompare(b.parts[0])
76
- }
77
75
  for (const [_a, _b] of zip(a.parts, b.parts)) {
78
76
  const compare = _a.localeCompare(_b)
79
77
  if (compare !== 0) {
@@ -1,4 +1,4 @@
1
- import type { ComputedView } from '@likec4/core/types'
1
+ import type { ComputedView } from '@likec4/core'
2
2
  import objectHash from 'object-hash'
3
3
  import { isTruthy, map, mapToObj, pick, pipe } from 'remeda'
4
4
  import type { SetOptional } from 'type-fest'
package/src/reset.d.ts DELETED
@@ -1,2 +0,0 @@
1
- // Do not add any other lines of code to this file!
2
- import '@total-typescript/ts-reset'