@likec4/language-server 1.7.4 → 1.8.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.
@@ -0,0 +1,63 @@
1
+ import type { ComputedNode, ElementNotation } from '@likec4/core'
2
+ import { entries, flatMap, groupBy, map, mapValues, pipe, piped, prop, sortBy, unique } from 'remeda'
3
+
4
+ /**
5
+ * Build element notations from computed nodes:
6
+ * 1. Group by notation
7
+ * 2. Group by shape
8
+ * 3. Group by color
9
+ * 4. For each group get unique kinds
10
+ * 5. Unwind the groups
11
+ */
12
+ export function buildElementNotations(nodes: ComputedNode[]): ElementNotation[] {
13
+ return pipe(
14
+ nodes,
15
+ groupBy(prop('notation')),
16
+ mapValues(
17
+ piped(
18
+ groupBy(prop('shape')),
19
+ mapValues(
20
+ piped(
21
+ groupBy(prop('color')),
22
+ mapValues(
23
+ piped(
24
+ map(prop('kind')),
25
+ unique()
26
+ )
27
+ ),
28
+ entries(),
29
+ map(([color, kinds]) => ({
30
+ kinds,
31
+ color
32
+ }))
33
+ )
34
+ ),
35
+ entries(),
36
+ flatMap(([shape, colors]) =>
37
+ colors.map(({ color, kinds }) => ({
38
+ shape,
39
+ color,
40
+ kinds
41
+ }))
42
+ )
43
+ )
44
+ ),
45
+ entries(),
46
+ flatMap(([title, shapes]) =>
47
+ shapes.map(({ shape, color, kinds }) => ({
48
+ title,
49
+ shape,
50
+ color,
51
+ kinds
52
+ }))
53
+ ),
54
+ sortBy(
55
+ prop('title'),
56
+ prop('shape'),
57
+ [
58
+ n => n.kinds.length,
59
+ 'desc'
60
+ ]
61
+ )
62
+ )
63
+ }
@@ -82,15 +82,15 @@ export class LikeC4ScopeComputation extends DefaultScopeComputation {
82
82
  docExports: AstNodeDescription[],
83
83
  document: LikeC4LangiumDocument
84
84
  ) {
85
- if (isNullish(likec4lib) || likec4lib.length === 0) {
85
+ if (isNullish(likec4lib)) {
86
86
  return
87
87
  }
88
- for (const iconAst of likec4lib.flatMap(l => l.icons)) {
89
- try {
88
+ try {
89
+ for (const iconAst of likec4lib.flatMap(l => l.icons)) {
90
90
  docExports.push(this.descriptions.createDescription(iconAst, iconAst.name, document))
91
- } catch (e) {
92
- logError(e)
93
91
  }
92
+ } catch (e) {
93
+ logError(e)
94
94
  }
95
95
  }
96
96
 
@@ -9,10 +9,6 @@ export const dynamicViewRulePredicate = (
9
9
  return (predicate, accept) => {
10
10
  const expr = elementExpressionFromPredicate(predicate.value)
11
11
  switch (true) {
12
- case ast.isElementRef(expr):
13
- case ast.isElementDescedantsExpression(expr):
14
- case ast.isExpandElementExpression(expr):
15
- return
16
12
  case ast.isElementKindExpression(expr):
17
13
  case ast.isElementTagExpression(expr):
18
14
  case ast.isWildcardExpression(expr): {
@@ -21,8 +17,6 @@ export const dynamicViewRulePredicate = (
21
17
  })
22
18
  return
23
19
  }
24
- default:
25
- nonexhaustive(expr)
26
20
  }
27
21
  }
28
22
  }
@@ -28,7 +28,7 @@ export const iconPropertyRuleChecks = (
28
28
  })
29
29
  }
30
30
  if (
31
- ast.isStyleProperties(container) && ast.isElementBody(container.$container)
31
+ ast.isElementStyleProperty(container) && ast.isElementBody(container.$container)
32
32
  && container.$container.props.some(p => ast.isIconProperty(p))
33
33
  ) {
34
34
  accept('warning', `Redundant as icon defined on element`, {
@@ -1,6 +1,6 @@
1
1
  import type { ComputedView } from '@likec4/core/types'
2
2
  import objectHash from 'object-hash'
3
- import { isString, pick } from 'remeda'
3
+ import { isTruthy, map, mapToObj, pick, pipe } from 'remeda'
4
4
  import type { SetOptional } from 'type-fest'
5
5
 
6
6
  export function calcViewLayoutHash<V extends ComputedView>(view: SetOptional<V, 'hash'>): V {
@@ -8,26 +8,20 @@ export function calcViewLayoutHash<V extends ComputedView>(view: SetOptional<V,
8
8
  id: view.id,
9
9
  __: view.__ ?? 'element',
10
10
  autoLayout: view.autoLayout,
11
- nodes: view.nodes
12
- .map(pick(['id', 'title', 'description', 'technology', 'shape', 'icon', 'children']))
13
- .toSorted((a, b) => a.id.localeCompare(b.id)),
14
- edges: view.edges
15
- .map(pick(['id', 'source', 'target', 'label', 'description', 'technology', 'dir', 'head', 'tail', 'line']))
16
- .toSorted((a, b) => a.id.localeCompare(b.id))
11
+ nodes: pipe(
12
+ view.nodes,
13
+ map(pick(['id', 'title', 'description', 'technology', 'shape', 'icon', 'children'])),
14
+ mapToObj(({ id, icon, ...node }) => [id, { ...node, icon: isTruthy(icon) ? 'Y' : 'N' }])
15
+ ),
16
+ edges: pipe(
17
+ view.edges,
18
+ map(pick(['source', 'target', 'label', 'description', 'technology', 'dir', 'head', 'tail', 'line'])),
19
+ mapToObj(({ source, target, ...edge }) => [`${source}:${target}`, edge])
20
+ )
17
21
  }
18
22
  view.hash = objectHash(tohash, {
19
23
  ignoreUnknown: true,
20
- respectType: false,
21
- replacer(value) {
22
- if (!isString(value)) {
23
- return value
24
- }
25
- value = value.trim()
26
- if (value.match('^(aws|tech|gcp|https|http)')) {
27
- value = 'U' // hide urls
28
- }
29
- return value
30
- }
24
+ respectType: false
31
25
  })
32
26
  return view as V
33
27
  }