@likec4/language-server 1.11.0 → 1.12.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.
Files changed (38) hide show
  1. package/dist/browser.cjs +1 -1
  2. package/dist/browser.d.cts +2 -2
  3. package/dist/browser.d.mts +2 -2
  4. package/dist/browser.d.ts +2 -2
  5. package/dist/browser.mjs +2 -2
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.cts +2 -2
  8. package/dist/index.d.mts +2 -2
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.mjs +2 -2
  11. package/dist/likec4lib.cjs +589 -0
  12. package/dist/likec4lib.mjs +589 -0
  13. package/dist/model-graph/index.cjs +1 -1
  14. package/dist/model-graph/index.mjs +1 -1
  15. package/dist/shared/{language-server.DJhoJBWh.cjs → language-server.3Bh0zvVS.cjs} +10 -2
  16. package/dist/shared/{language-server.Cyw-bCtc.d.ts → language-server.B8Ce0R_D.d.ts} +5 -2
  17. package/dist/shared/language-server.BCDM5gt9.d.ts +1233 -0
  18. package/dist/shared/{language-server.C8lV6gDw.cjs → language-server.BH0brgLf.cjs} +98 -34
  19. package/dist/shared/language-server.BN7V1vQA.d.mts +1233 -0
  20. package/dist/shared/{language-server.CCOotWDz.mjs → language-server.BYjS7OIz.mjs} +100 -36
  21. package/dist/shared/{language-server.CbqwHp7Q.mjs → language-server.BxxqS4Id.mjs} +10 -2
  22. package/dist/shared/{language-server.DGjTE7xL.d.mts → language-server.CzkWpuWT.d.mts} +5 -2
  23. package/dist/shared/{language-server.Ol32Kygo.d.cts → language-server.DJAHXekh.d.cts} +5 -2
  24. package/dist/shared/language-server.DtLmc4Fz.d.cts +1233 -0
  25. package/package.json +11 -11
  26. package/src/ast.ts +23 -9
  27. package/src/formatting/LikeC4Formatter.ts +29 -12
  28. package/src/generated/ast.ts +9 -4
  29. package/src/generated/grammar.ts +1 -1
  30. package/src/generated-lib/icons.ts +589 -0
  31. package/src/like-c4.langium +8 -4
  32. package/src/lsp/CompletionProvider.ts +48 -1
  33. package/src/model/model-parser.ts +2 -6
  34. package/src/model-change/changeViewLayout.ts +15 -9
  35. package/src/model-graph/compute-view/compute.ts +5 -1
  36. package/src/model-graph/dynamic-view/compute.ts +5 -1
  37. package/src/test/testServices.ts +1 -1
  38. package/src/view-utils/manual-layout.ts +5 -2
@@ -1,5 +1,6 @@
1
- import { type AutoLayoutDirection, invariant } from '@likec4/core'
1
+ import { invariant, type ViewRuleAutoLayout } from '@likec4/core'
2
2
  import { GrammarUtils } from 'langium'
3
+ import { isDefined } from 'remeda'
3
4
  import { TextEdit } from 'vscode-languageserver-types'
4
5
  import { ast, type ParsedAstView, type ParsedLikeC4LangiumDocument, toAstViewLayoutDirection } from '../ast'
5
6
  import type { LikeC4Services } from '../module'
@@ -10,7 +11,7 @@ type ChangeViewLayoutArg = {
10
11
  view: ParsedAstView
11
12
  doc: ParsedLikeC4LangiumDocument
12
13
  viewAst: ast.LikeC4View
13
- layout: AutoLayoutDirection
14
+ layout: ViewRuleAutoLayout
14
15
  }
15
16
 
16
17
  export function changeViewLayout(_services: LikeC4Services, {
@@ -22,20 +23,25 @@ export function changeViewLayout(_services: LikeC4Services, {
22
23
  invariant(viewAst.body, `View ${view.id} has no body`)
23
24
  const viewCstNode = viewAst.$cstNode
24
25
  invariant(viewCstNode, 'viewCstNode')
25
- const newlayout = toAstViewLayoutDirection(layout)
26
+ const newdirection = toAstViewLayoutDirection(layout.direction)
26
27
  const existingRule = viewAst.body.rules.findLast(ast.isViewRuleAutoLayout) as ast.ViewRuleAutoLayout | undefined
27
28
 
28
- if (existingRule && existingRule.$cstNode) {
29
- const directionCstNode = findNodeForProperty(existingRule.$cstNode, 'direction')
30
- if (directionCstNode) {
31
- return TextEdit.replace(directionCstNode.range, newlayout)
29
+ let newRule = `autoLayout ${newdirection}`
30
+
31
+ if (isDefined(layout.rankSep)) {
32
+ newRule += ` ${layout.rankSep}`
33
+ if (isDefined(layout.nodeSep)) {
34
+ newRule += ` ${layout.nodeSep}`
32
35
  }
33
- return TextEdit.replace(existingRule.$cstNode.range, `autoLayout ${newlayout}`)
36
+ }
37
+
38
+ if (existingRule && existingRule.$cstNode) {
39
+ return TextEdit.replace(existingRule.$cstNode.range, newRule)
34
40
  }
35
41
 
36
42
  const insertPos = findNodeForKeyword(viewAst.body.$cstNode, '}')?.range.start
37
43
  invariant(insertPos, 'Closing brace not found')
38
- const insert = ` autoLayout ${newlayout}\n` + ' '.repeat(insertPos.character)
44
+ const insert = `\t${newRule}\n\t`
39
45
 
40
46
  return TextEdit.insert(insertPos, insert)
41
47
  }
@@ -175,7 +175,11 @@ export class ComputeCtx {
175
175
 
176
176
  return calcViewLayoutHash({
177
177
  ...view,
178
- autoLayout: autoLayoutRule?.autoLayout ?? 'TB',
178
+ autoLayout: {
179
+ direction: autoLayoutRule?.direction ?? 'TB',
180
+ ...(autoLayoutRule?.nodeSep && { nodeSep: autoLayoutRule.nodeSep }),
181
+ ...(autoLayoutRule?.rankSep && { rankSep: autoLayoutRule.rankSep }),
182
+ },
179
183
  nodes: map(nodes, omit(['notation'])),
180
184
  edges: applyCustomRelationProperties(rules, nodes, sortedEdges),
181
185
  ...(elementNotations.length > 0 && {
@@ -200,7 +200,11 @@ export class DynamicViewComputeCtx {
200
200
 
201
201
  return calcViewLayoutHash({
202
202
  ...view,
203
- autoLayout: autoLayoutRule?.autoLayout ?? 'LR',
203
+ autoLayout: {
204
+ direction: autoLayoutRule?.direction ?? 'LR',
205
+ ...(autoLayoutRule?.nodeSep && { nodeSep: autoLayoutRule.nodeSep }),
206
+ ...(autoLayoutRule?.rankSep && { rankSep: autoLayoutRule.rankSep }),
207
+ },
204
208
  nodes: map(nodes, omit(['notation'])),
205
209
  edges,
206
210
  ...(elementNotations.length > 0 && {
@@ -72,7 +72,7 @@ export function createTestServices(workspace = 'file:///test/workspace') {
72
72
  const format = async (input: string | LikeC4LangiumDocument, uri?: string) => {
73
73
  const document = typeof input === 'string' ? await parse(input, uri) : input
74
74
  await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
75
- await documentBuilder.build([document], { validation: false })
75
+ await documentBuilder.build([document], { validation: true })
76
76
  })
77
77
 
78
78
  const edits = await services.lsp.Formatter?.formatDocument(
@@ -1,4 +1,4 @@
1
- import type { ViewManualLayout } from '@likec4/core'
1
+ import { isAutoLayoutDirection, type ViewManualLayout } from '@likec4/core'
2
2
  import { decode, encode } from '@msgpack/msgpack'
3
3
  import { fromBase64, toBase64 } from '@smithy/util-base64'
4
4
  import { mapValues } from 'remeda'
@@ -28,10 +28,13 @@ function pack({
28
28
  function unpack({
29
29
  nodes,
30
30
  edges,
31
+ autoLayout,
31
32
  ...rest
32
33
  }: ReturnType<typeof pack>): ViewManualLayout {
33
34
  return {
34
35
  ...rest,
36
+ /// Try to parse the old format for backward compatibility
37
+ autoLayout: isAutoLayoutDirection(autoLayout) ? { direction: autoLayout } : autoLayout,
35
38
  nodes: mapValues(nodes, ({ b, c, ...n }) => ({
36
39
  x: b[0],
37
40
  y: b[1],
@@ -50,12 +53,12 @@ function unpack({
50
53
  }
51
54
  }
52
55
 
56
+ const MAX_LINE_LENGTH = 500
53
57
  export function serializeToComment(layout: ViewManualLayout) {
54
58
  const bytes = encode(pack(layout))
55
59
  const base64 = toBase64(bytes)
56
60
  const lines = [] as string[]
57
61
  let offset = 0
58
- const MAX_LINE_LENGTH = 200
59
62
  while (offset < base64.length) {
60
63
  lines.push(' * ' + base64.slice(offset, Math.min(offset + MAX_LINE_LENGTH, base64.length)))
61
64
  offset += MAX_LINE_LENGTH