@likec4/language-server 1.10.1 → 1.12.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 (60) hide show
  1. package/dist/browser.cjs +5 -1
  2. package/dist/browser.d.cts +7 -5
  3. package/dist/browser.d.mts +7 -5
  4. package/dist/browser.d.ts +7 -5
  5. package/dist/browser.mjs +3 -2
  6. package/dist/index.cjs +15 -2
  7. package/dist/index.d.cts +14 -11
  8. package/dist/index.d.mts +14 -11
  9. package/dist/index.d.ts +14 -11
  10. package/dist/index.mjs +17 -1
  11. package/dist/likec4lib.cjs +1538 -952
  12. package/dist/likec4lib.d.cts +1 -1
  13. package/dist/likec4lib.d.mts +1 -1
  14. package/dist/likec4lib.d.ts +1 -1
  15. package/dist/likec4lib.mjs +1538 -952
  16. package/dist/model-graph/index.cjs +1 -1
  17. package/dist/model-graph/index.mjs +1 -1
  18. package/dist/protocol.cjs +1 -1
  19. package/dist/protocol.d.cts +3 -1
  20. package/dist/protocol.d.mts +3 -1
  21. package/dist/protocol.d.ts +3 -1
  22. package/dist/protocol.mjs +1 -1
  23. package/dist/shared/{language-server.DJhoJBWh.cjs → language-server.3Bh0zvVS.cjs} +10 -2
  24. package/dist/shared/{language-server.CnVuAxDh.d.ts → language-server.BCDM5gt9.d.ts} +147 -137
  25. package/dist/shared/{language-server.DEK39RmI.d.mts → language-server.BN7V1vQA.d.mts} +147 -137
  26. package/dist/shared/language-server.BX2gtzo8.d.cts +1233 -0
  27. package/dist/shared/{language-server.BFBeyvV8.mjs → language-server.BbMFBkE-.mjs} +196 -140
  28. package/dist/shared/language-server.BiN_phWO.d.mts +1233 -0
  29. package/dist/shared/{language-server.CbqwHp7Q.mjs → language-server.BxxqS4Id.mjs} +10 -2
  30. package/dist/shared/{language-server.Bfc-5M8A.cjs → language-server.BzrAcTYK.cjs} +194 -137
  31. package/dist/shared/{language-server.BGy3FJPJ.d.cts → language-server.DtLmc4Fz.d.cts} +147 -137
  32. package/dist/shared/language-server.ljop0PBQ.d.ts +1233 -0
  33. package/package.json +34 -30
  34. package/src/Rpc.ts +10 -6
  35. package/src/ast.ts +24 -10
  36. package/src/browser.ts +5 -0
  37. package/src/formatting/LikeC4Formatter.ts +19 -7
  38. package/src/generated/ast.ts +9 -4
  39. package/src/generated/grammar.ts +1 -1
  40. package/src/generated-lib/icons.ts +1538 -952
  41. package/src/index.ts +23 -2
  42. package/src/like-c4.langium +8 -4
  43. package/src/likec4lib.ts +1 -1
  44. package/src/logger.ts +16 -16
  45. package/src/lsp/CompletionProvider.ts +48 -1
  46. package/src/model/model-builder.ts +12 -12
  47. package/src/model/model-parser.ts +2 -6
  48. package/src/model-graph/compute-view/compute.ts +5 -1
  49. package/src/model-graph/dynamic-view/compute.ts +5 -1
  50. package/src/model-graph/utils/applyCustomRelationProperties.ts +1 -1
  51. package/src/protocol.ts +5 -1
  52. package/src/shared/WorkspaceManager.ts +1 -1
  53. package/src/test/testServices.ts +1 -1
  54. package/src/view-utils/manual-layout.ts +5 -2
  55. package/dist/node.cjs +0 -18
  56. package/dist/node.d.cts +0 -19
  57. package/dist/node.d.mts +0 -19
  58. package/dist/node.d.ts +0 -19
  59. package/dist/node.mjs +0 -16
  60. package/src/node.ts +0 -20
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@likec4/language-server",
3
3
  "description": "LikeC4 Language Server",
4
- "version": "1.10.1",
4
+ "version": "1.12.0",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -24,9 +24,16 @@
24
24
  "sideEffects": false,
25
25
  "exports": {
26
26
  ".": {
27
- "types": "./dist/index.d.ts",
28
- "import": "./dist/index.mjs",
29
- "require": "./dist/index.cjs"
27
+ "browser": {
28
+ "types": "./dist/browser.d.ts",
29
+ "import": "./dist/browser.mjs",
30
+ "require": "./dist/browser.cjs"
31
+ },
32
+ "default": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.mjs",
35
+ "require": "./dist/index.cjs"
36
+ }
30
37
  },
31
38
  "./likec4lib": {
32
39
  "types": "./dist/likec4lib.d.ts",
@@ -43,11 +50,6 @@
43
50
  "import": "./dist/protocol.mjs",
44
51
  "require": "./dist/protocol.cjs"
45
52
  },
46
- "./node": {
47
- "types": "./dist/node.d.ts",
48
- "import": "./dist/node.mjs",
49
- "require": "./dist/node.cjs"
50
- },
51
53
  "./model-graph": {
52
54
  "types": "./dist/model-graph/index.d.ts",
53
55
  "import": "./dist/model-graph/index.mjs",
@@ -59,9 +61,16 @@
59
61
  "access": "public",
60
62
  "exports": {
61
63
  ".": {
62
- "types": "./dist/index.d.ts",
63
- "import": "./dist/index.mjs",
64
- "require": "./dist/index.cjs"
64
+ "browser": {
65
+ "types": "./dist/browser.d.ts",
66
+ "import": "./dist/browser.mjs",
67
+ "require": "./dist/browser.cjs"
68
+ },
69
+ "default": {
70
+ "types": "./dist/index.d.ts",
71
+ "import": "./dist/index.mjs",
72
+ "require": "./dist/index.cjs"
73
+ }
65
74
  },
66
75
  "./likec4lib": {
67
76
  "types": "./dist/likec4lib.d.ts",
@@ -78,11 +87,6 @@
78
87
  "import": "./dist/protocol.mjs",
79
88
  "require": "./dist/protocol.cjs"
80
89
  },
81
- "./node": {
82
- "types": "./dist/node.d.ts",
83
- "import": "./dist/node.mjs",
84
- "require": "./dist/node.cjs"
85
- },
86
90
  "./model-graph": {
87
91
  "types": "./dist/model-graph/index.d.ts",
88
92
  "import": "./dist/model-graph/index.mjs",
@@ -100,7 +104,7 @@
100
104
  "generate": "langium generate && tsx scripts/generate-icons.ts",
101
105
  "dev": "run-p 'watch:*'",
102
106
  "lint": "run -T eslint src/ --fix",
103
- "clean": "run -T rimraf dist contrib",
107
+ "clean": "rm -r -f dist contrib",
104
108
  "test": "vitest run --no-isolate",
105
109
  "test-dbg": "vitest run --no-isolate -t formating",
106
110
  "vitest:ui": "vitest --no-isolate --ui",
@@ -108,8 +112,8 @@
108
112
  },
109
113
  "dependencies": {
110
114
  "@dagrejs/graphlib": "^2.2.4",
111
- "@likec4/core": "1.10.1",
112
- "@likec4/log": "1.10.1",
115
+ "@likec4/core": "1.12.0",
116
+ "@likec4/log": "1.12.0",
113
117
  "@msgpack/msgpack": "^3.0.0-beta2",
114
118
  "@smithy/util-base64": "^3.0.0",
115
119
  "fast-equals": "^5.0.1",
@@ -118,10 +122,10 @@
118
122
  "langium": "3.2.0",
119
123
  "object-hash": "^3.0.0",
120
124
  "p-debounce": "^4.0.0",
121
- "remeda": "^2.11.0",
125
+ "remeda": "^2.14.0",
122
126
  "string-hash": "^1.1.3",
123
127
  "strip-indent": "^4.0.0",
124
- "type-fest": "^4.26.1",
128
+ "type-fest": "4.26.1",
125
129
  "ufo": "^1.5.4",
126
130
  "vscode-jsonrpc": "8.2.0",
127
131
  "vscode-languageserver": "9.0.1",
@@ -129,20 +133,20 @@
129
133
  "vscode-uri": "3.0.8"
130
134
  },
131
135
  "devDependencies": {
132
- "@likec4/icons": "1.10.1",
133
- "@likec4/tsconfig": "1.10.1",
134
- "@types/node": "^20.16.1",
136
+ "@likec4/icons": "1.12.0",
137
+ "@likec4/tsconfig": "1.12.0",
138
+ "@types/node": "^20.16.5",
135
139
  "@types/object-hash": "^3.0.6",
136
140
  "@types/string-hash": "^1.1.3",
137
- "@vitest/coverage-v8": "^2.1.0",
141
+ "@vitest/coverage-v8": "^2.1.2",
138
142
  "execa": "^9.3.1",
139
143
  "langium-cli": "3.2.0",
140
144
  "npm-run-all2": "^6.2.2",
141
145
  "tsx": "~4.9.3",
142
- "turbo": "^2.1.1",
146
+ "turbo": "^2.1.2",
143
147
  "typescript": "^5.6.2",
144
- "unbuild": "^3.0.0-rc.7",
145
- "vitest": "^2.1.0"
148
+ "unbuild": "^3.0.0-rc.8",
149
+ "vitest": "^2.1.2"
146
150
  },
147
- "packageManager": "yarn@4.4.1"
151
+ "packageManager": "yarn@4.5.0"
148
152
  }
package/src/Rpc.ts CHANGED
@@ -35,15 +35,16 @@ export class Rpc implements Disposable {
35
35
  const DocumentBuilder = this.services.shared.workspace.DocumentBuilder
36
36
 
37
37
  const notifyModelParsed = debounce(
38
- () =>
39
- void connection.sendNotification(onDidChangeModel, '').catch(e => {
38
+ () => {
39
+ connection.sendNotification(onDidChangeModel, '').catch(e => {
40
40
  logger.error(`[ServerRpc] error sending onDidChangeModel: ${e}`)
41
41
  return Promise.resolve()
42
- }),
42
+ })
43
+ },
43
44
  {
44
45
  timing: 'both',
45
- waitMs: 350,
46
- maxWaitMs: 1000
46
+ waitMs: 300,
47
+ maxWaitMs: 600
47
48
  }
48
49
  )
49
50
 
@@ -54,7 +55,10 @@ export class Rpc implements Disposable {
54
55
  notifyModelParsed.cancel()
55
56
  }),
56
57
  modelBuilder.onModelParsed(() => notifyModelParsed.call()),
57
- connection.onRequest(fetchComputedModel, async cancelToken => {
58
+ connection.onRequest(fetchComputedModel, async ({ cleanCaches }, cancelToken) => {
59
+ if (cleanCaches) {
60
+ this.services.WorkspaceCache.clear()
61
+ }
58
62
  const model = await modelBuilder.buildComputedModel(cancelToken)
59
63
  return { model }
60
64
  }),
package/src/ast.ts CHANGED
@@ -288,7 +288,7 @@ export type ChecksFromDiagnostics = ReturnType<typeof checksFromDiagnostics>
288
288
  export type IsValidFn = ChecksFromDiagnostics['isValid']
289
289
 
290
290
  export function* streamModel(doc: LikeC4LangiumDocument, isValid: IsValidFn) {
291
- const traverseStack = doc.parseResult.value.models.flatMap(m => (isValid(m) ? m.elements : []))
291
+ const traverseStack = doc.parseResult.value.models.flatMap(m => m.elements)
292
292
  const relations = [] as ast.Relation[]
293
293
  let el
294
294
  while ((el = traverseStack.shift())) {
@@ -455,27 +455,41 @@ export function toColor(astNode: ast.ColorProperty): c4.Color | undefined {
455
455
  }
456
456
 
457
457
  export function toAutoLayout(
458
- direction: ast.ViewLayoutDirection
459
- ): c4.ViewRuleAutoLayout['autoLayout'] {
460
- switch (direction) {
458
+ rule: ast.ViewRuleAutoLayout
459
+ ): c4.ViewRuleAutoLayout {
460
+ const rankSep = rule.rankSep
461
+ const nodeSep = rule.nodeSep
462
+
463
+ let direction: c4.ViewRuleAutoLayout['direction'];
464
+ switch (rule.direction) {
461
465
  case 'TopBottom': {
462
- return 'TB'
466
+ direction = 'TB'
467
+ break
463
468
  }
464
469
  case 'BottomTop': {
465
- return 'BT'
470
+ direction = 'BT'
471
+ break
466
472
  }
467
473
  case 'LeftRight': {
468
- return 'LR'
474
+ direction = 'LR'
475
+ break
469
476
  }
470
477
  case 'RightLeft': {
471
- return 'RL'
478
+ direction = 'RL'
479
+ break
472
480
  }
473
481
  default:
474
- nonexhaustive(direction)
482
+ nonexhaustive(rule.direction)
483
+ }
484
+
485
+ return {
486
+ direction,
487
+ ...(nodeSep && { nodeSep }),
488
+ ...(rankSep && { rankSep })
475
489
  }
476
490
  }
477
491
 
478
- export function toAstViewLayoutDirection(c4: c4.ViewRuleAutoLayout['autoLayout']): ast.ViewLayoutDirection {
492
+ export function toAstViewLayoutDirection(c4: c4.ViewRuleAutoLayout['direction']): ast.ViewLayoutDirection {
479
493
  switch (c4) {
480
494
  case 'TB': {
481
495
  return 'TopBottom'
package/src/browser.ts CHANGED
@@ -2,6 +2,11 @@ import { startLanguageServer as startLanguim } from 'langium/lsp'
2
2
  import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser'
3
3
  import { createLanguageServices } from './module'
4
4
 
5
+ export { setLogLevel } from './logger'
6
+ export type * from './model'
7
+ export type * from './module'
8
+ export { createCustomLanguageServices, createLanguageServices, LikeC4Module } from './module'
9
+
5
10
  // This is an example copied as is from here:
6
11
  // https://github.com/microsoft/vscode-extension-samples/blob/main/lsp-web-extension-sample/server/src/browserServerMain.ts
7
12
  // the only addition is the following line:
@@ -56,10 +56,18 @@ export class LikeC4Formatter extends AbstractFormatter {
56
56
  })
57
57
 
58
58
  this.on(node, ast.isDynamicViewStep, (n, f) => {
59
- f.properties('source').append(FormattingOptions.oneSpace)
60
- f.keywords(']->').prepend(FormattingOptions.noSpace)
61
- f.keywords('-[').append(FormattingOptions.noSpace)
62
- f.properties('target', 'title').prepend(FormattingOptions.oneSpace)
59
+ f.keywords('->', '<-').surround(FormattingOptions.oneSpace)
60
+
61
+ const kind = f.property('kind')
62
+ kind.nodes[0]?.text.startsWith('.') && kind.surround(FormattingOptions.oneSpace)
63
+ f.keywords(']->')
64
+ .prepend(FormattingOptions.noSpace)
65
+ .append(FormattingOptions.oneSpace)
66
+ f.keywords('-[')
67
+ .prepend(FormattingOptions.oneSpace)
68
+ .append(FormattingOptions.noSpace)
69
+
70
+ f.properties('title').prepend(FormattingOptions.oneSpace)
63
71
  })
64
72
 
65
73
  this.on(node, ast.isDirectedRelationExpression)
@@ -110,6 +118,7 @@ export class LikeC4Formatter extends AbstractFormatter {
110
118
  || ast.isCustomElementProperties(node)
111
119
  || ast.isCustomRelationProperties(node)
112
120
  || ast.isElementStyleProperty(node)
121
+ || ast.isDynamicViewParallelSteps(node)
113
122
  ) {
114
123
  const formatter = this.getNodeFormatter(node)
115
124
  const openBrace = formatter.keywords('{')
@@ -216,8 +225,11 @@ export class LikeC4Formatter extends AbstractFormatter {
216
225
  }
217
226
 
218
227
  protected formatAutolayoutProperty(node: AstNode) {
219
- this.on(node, ast.isViewRuleAutoLayout)
220
- ?.keyword('autoLayout').append(FormattingOptions.oneSpace)
228
+ this.on(node, ast.isViewRuleAutoLayout, (n, f) => {
229
+ f.keyword('autoLayout').append(FormattingOptions.oneSpace)
230
+ f.property('rankSep').prepend(FormattingOptions.oneSpace)
231
+ f.property('nodeSep').prepend(FormattingOptions.oneSpace)
232
+ })
221
233
  }
222
234
 
223
235
  protected formatMetadataProperty(node: AstNode) {
@@ -287,7 +299,7 @@ export class LikeC4Formatter extends AbstractFormatter {
287
299
  this.on(node, ast.isViewRuleStyle)
288
300
  ?.keyword('style').append(FormattingOptions.oneSpace)
289
301
 
290
- this.on(node, ast.isElementExpressionsIterator)
302
+ this.on(node, ast.isElementExpressionsIterator)
291
303
  ?.keyword(',')
292
304
  .prepend(FormattingOptions.noSpace)
293
305
  .append(FormattingOptions.oneSpace)
@@ -12,7 +12,7 @@ export const LikeC4Terminals = {
12
12
  LINE_COMMENT: /\/\/[^\n\r]*/,
13
13
  WS: /[\t ]+/,
14
14
  NL: /[\r\n]+/,
15
- LIB_ICON: /(aws|gcp|tech):[-\w]*/,
15
+ LIB_ICON: /(aws|azure|gcp|tech):[-\w]*/,
16
16
  URI_WITH_SCHEMA: /\w+:\/\/\S+/,
17
17
  URI_RELATIVE: /\.{0,2}\/[^\/]\S+/,
18
18
  DotUnderscore: /\b\._/,
@@ -25,7 +25,8 @@ export const LikeC4Terminals = {
25
25
  Percent: /\b\d+%/,
26
26
  String: /"[^"]*"|'[^']*'/,
27
27
  IdTerminal: /[_]*[a-zA-Z][-\w]*/,
28
- Hex: /[a-zA-Z0-9]+/,
28
+ Number: /\b\d+\b/,
29
+ Hex: /\b[a-zA-Z0-9]+\b/,
29
30
  };
30
31
 
31
32
  export type LikeC4TerminalNames = keyof typeof LikeC4Terminals;
@@ -205,7 +206,7 @@ export function isElementShape(item: unknown): item is ElementShape {
205
206
  export type IconId = string;
206
207
 
207
208
  export function isIconId(item: unknown): item is IconId {
208
- return (typeof item === 'string' && (/(aws|gcp|tech):[-\w]*/.test(item)));
209
+ return (typeof item === 'string' && (/(aws|azure|gcp|tech):[-\w]*/.test(item)));
209
210
  }
210
211
 
211
212
  export type Id = 'element' | 'model' | ArrowType | ElementShape | LineOptions | ThemeColor | string;
@@ -1347,6 +1348,8 @@ export interface ViewRuleAutoLayout extends AstNode {
1347
1348
  readonly $container: DynamicViewBody | ElementViewBody;
1348
1349
  readonly $type: 'ViewRuleAutoLayout';
1349
1350
  direction: ViewLayoutDirection;
1351
+ nodeSep?: number;
1352
+ rankSep?: number;
1350
1353
  }
1351
1354
 
1352
1355
  export const ViewRuleAutoLayout = 'ViewRuleAutoLayout';
@@ -2441,7 +2444,9 @@ export class LikeC4AstReflection extends AbstractAstReflection {
2441
2444
  return {
2442
2445
  name: ViewRuleAutoLayout,
2443
2446
  properties: [
2444
- { name: 'direction' }
2447
+ { name: 'direction' },
2448
+ { name: 'nodeSep' },
2449
+ { name: 'rankSep' }
2445
2450
  ]
2446
2451
  };
2447
2452
  }