@likec4/language-server 1.4.0 → 1.5.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.
- package/README.md +1 -1
- package/contrib/likec4.tmLanguage.json +1 -1
- package/package.json +13 -13
- package/src/Rpc.ts +23 -1
- package/src/ast.ts +11 -12
- package/src/generated/ast.ts +101 -31
- package/src/generated/grammar.ts +1 -1
- package/src/like-c4.langium +58 -33
- package/src/lsp/SemanticTokenProvider.ts +12 -14
- package/src/model/fqn-computation.ts +29 -7
- package/src/model/fqn-index.ts +18 -31
- package/src/model/model-builder.ts +13 -9
- package/src/model/model-locator.ts +7 -7
- package/src/model/model-parser.ts +63 -18
- package/src/model-change/changeElementStyle.ts +2 -2
- package/src/model-graph/compute-view/__test__/fixture.ts +51 -23
- package/src/model-graph/compute-view/compute.ts +47 -16
- package/src/model-graph/compute-view/predicates.ts +6 -1
- package/src/model-graph/dynamic-view/compute.ts +2 -2
- package/src/model-graph/utils/{applyElementCustomProperties.ts → applyCustomElementProperties.ts} +5 -3
- package/src/model-graph/utils/applyCustomRelationProperties.ts +50 -0
- package/src/model-graph/utils/applyViewRuleStyles.ts +11 -34
- package/src/model-graph/utils/elementExpressionToPredicate.ts +32 -0
- package/src/references/scope-provider.ts +3 -23
- package/src/validation/dynamic-view-rule.ts +5 -7
- package/src/validation/element.ts +8 -4
- package/src/validation/index.ts +2 -0
- package/src/validation/view-predicates/custom-element-expr.ts +17 -6
- package/src/validation/view-predicates/custom-relation-expr.ts +15 -0
- package/src/validation/view-predicates/index.ts +1 -0
- package/src/view-utils/assignNavigateTo.ts +2 -2
- package/src/view-utils/manual-layout.ts +4 -2
- package/src/view-utils/resolve-extended-views.ts +2 -2
- package/src/view-utils/resolve-relative-paths.ts +3 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nonexhaustive } from '@likec4/core'
|
|
1
2
|
import type { ValidationCheck } from 'langium'
|
|
2
3
|
import { ast } from '../../ast'
|
|
3
4
|
import type { LikeC4Services } from '../../module'
|
|
@@ -7,15 +8,25 @@ export const customElementExprChecks = (
|
|
|
7
8
|
): ValidationCheck<ast.CustomElementExpr> => {
|
|
8
9
|
return (el, accept) => {
|
|
9
10
|
if (ast.isExcludePredicate(el.$container)) {
|
|
10
|
-
accept('error', 'Invalid inside "exclude"', {
|
|
11
|
+
accept('error', 'Invalid usage inside "exclude"', {
|
|
11
12
|
node: el
|
|
12
13
|
})
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
switch (true) {
|
|
16
|
+
case ast.isElementRef(el.target):
|
|
17
|
+
return
|
|
18
|
+
case ast.isExpandElementExpr(el.target):
|
|
19
|
+
case ast.isElementKindExpr(el.target):
|
|
20
|
+
case ast.isElementTagExpr(el.target):
|
|
21
|
+
case ast.isWildcardExpr(el.target):
|
|
22
|
+
case ast.isDescedantsExpr(el.target):
|
|
23
|
+
accept('error', 'Invalid target (expect reference to specific element)', {
|
|
24
|
+
node: el,
|
|
25
|
+
property: 'target'
|
|
26
|
+
})
|
|
27
|
+
return
|
|
28
|
+
default:
|
|
29
|
+
nonexhaustive(el.target)
|
|
19
30
|
}
|
|
20
31
|
}
|
|
21
32
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ValidationCheck } from 'langium'
|
|
2
|
+
import { ast } from '../../ast'
|
|
3
|
+
import type { LikeC4Services } from '../../module'
|
|
4
|
+
|
|
5
|
+
export const customRelationExprChecks = (
|
|
6
|
+
_services: LikeC4Services
|
|
7
|
+
): ValidationCheck<ast.CustomRelationExpr> => {
|
|
8
|
+
return (el, accept) => {
|
|
9
|
+
if (ast.isExcludePredicate(el.$container)) {
|
|
10
|
+
accept('error', 'Invalid usage inside "exclude"', {
|
|
11
|
+
node: el
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type ComputedView, type Fqn, isComputedElementView, type ViewID } from '@likec4/core'
|
|
2
|
-
import { find } from 'remeda'
|
|
2
|
+
import { find, isNullish } from 'remeda'
|
|
3
3
|
|
|
4
4
|
export function assignNavigateTo<R extends Iterable<ComputedView>>(views: R): R {
|
|
5
5
|
const allElementViews = new Map<Fqn, ViewID[]>()
|
|
6
6
|
|
|
7
7
|
for (const v of views) {
|
|
8
|
-
if (isComputedElementView(v) && v.viewOf &&
|
|
8
|
+
if (isComputedElementView(v) && v.viewOf && isNullish(v.extends)) {
|
|
9
9
|
const viewsOf = allElementViews.get(v.viewOf) ?? []
|
|
10
10
|
viewsOf.push(v.id)
|
|
11
11
|
allElementViews.set(v.viewOf, viewsOf)
|
|
@@ -29,8 +29,10 @@ export namespace CompactViewManualLayout {
|
|
|
29
29
|
export function pack(layout: ViewManualLayout): CompactViewManualLayout {
|
|
30
30
|
return [
|
|
31
31
|
1,
|
|
32
|
-
entries
|
|
33
|
-
entries
|
|
32
|
+
entries(layout.nodes).map(([id, { x, y, width, height }]) => [id as Fqn, x, y, width, height]),
|
|
33
|
+
entries(layout.edges).map((
|
|
34
|
+
[id, { controlPoints }]
|
|
35
|
+
) => [id as EdgeId, controlPoints.flatMap(({ x, y }) => [x, y])])
|
|
34
36
|
]
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import graphlib from '@dagrejs/graphlib'
|
|
2
|
-
import { isExtendsElementView, type
|
|
2
|
+
import { isExtendsElementView, type LikeC4View } from '@likec4/core'
|
|
3
3
|
|
|
4
4
|
// '@dagrejs/graphlib' is a CommonJS module
|
|
5
5
|
// Here is a workaround to import it
|
|
@@ -10,7 +10,7 @@ const { Graph, alg } = graphlib
|
|
|
10
10
|
* (Removes invalid views)
|
|
11
11
|
*/
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
export function resolveRulesExtendedViews<V extends Record<any,
|
|
13
|
+
export function resolveRulesExtendedViews<V extends Record<any, LikeC4View>>(
|
|
14
14
|
unresolvedViews: V
|
|
15
15
|
): V {
|
|
16
16
|
const g = new Graph({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LikeC4View } from '@likec4/core'
|
|
2
2
|
import { invariant } from '@likec4/core'
|
|
3
3
|
import { hasAtLeast, unique, zip } from 'remeda'
|
|
4
4
|
|
|
5
|
-
function commonAncestorPath(views:
|
|
5
|
+
function commonAncestorPath(views: LikeC4View[], sep = '/') {
|
|
6
6
|
if (views.length <= 1) return ''
|
|
7
7
|
const uniqURIs = unique(views.flatMap(({ docUri }) => (docUri ? [docUri] : [])))
|
|
8
8
|
if (uniqURIs.length === 0) return ''
|
|
@@ -30,7 +30,7 @@ function commonAncestorPath(views: View[], sep = '/') {
|
|
|
30
30
|
return prefix.endsWith(sep) ? prefix : prefix + sep
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export function resolveRelativePaths(views:
|
|
33
|
+
export function resolveRelativePaths(views: LikeC4View[]): LikeC4View[] {
|
|
34
34
|
const commonPrefix = commonAncestorPath(views)
|
|
35
35
|
return (
|
|
36
36
|
views
|