@likec4/language-server 1.8.0 → 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 (83) hide show
  1. package/contrib/likec4.tmLanguage.json +1 -1
  2. package/dist/browser.cjs +21 -0
  3. package/dist/browser.d.cts +22 -0
  4. package/dist/browser.d.mts +22 -0
  5. package/dist/browser.d.ts +22 -0
  6. package/dist/browser.mjs +19 -0
  7. package/dist/index.cjs +10 -0
  8. package/dist/index.d.cts +18 -0
  9. package/dist/index.d.mts +18 -0
  10. package/dist/index.d.ts +18 -0
  11. package/dist/index.mjs +1 -0
  12. package/dist/likec4lib.cjs +961 -0
  13. package/dist/likec4lib.d.cts +6 -0
  14. package/dist/likec4lib.d.mts +6 -0
  15. package/dist/likec4lib.d.ts +6 -0
  16. package/dist/likec4lib.mjs +957 -0
  17. package/dist/model-graph/index.cjs +10 -0
  18. package/dist/model-graph/index.d.cts +79 -0
  19. package/dist/model-graph/index.d.mts +79 -0
  20. package/dist/model-graph/index.d.ts +79 -0
  21. package/dist/model-graph/index.mjs +1 -0
  22. package/dist/node.cjs +18 -0
  23. package/dist/node.d.cts +20 -0
  24. package/dist/node.d.mts +20 -0
  25. package/dist/node.d.ts +20 -0
  26. package/dist/node.mjs +16 -0
  27. package/dist/protocol.cjs +25 -0
  28. package/dist/protocol.d.cts +43 -0
  29. package/dist/protocol.d.mts +43 -0
  30. package/dist/protocol.d.ts +43 -0
  31. package/dist/protocol.mjs +17 -0
  32. package/dist/shared/language-server.86lmJ8ZN.d.cts +1194 -0
  33. package/dist/shared/language-server.B1TZgyoH.cjs +5371 -0
  34. package/dist/shared/language-server.CCB4ESN5.mjs +1606 -0
  35. package/dist/shared/language-server.CFTY6j4e.d.mts +1194 -0
  36. package/dist/shared/language-server.D0bOlrCi.cjs +1619 -0
  37. package/dist/shared/language-server.Q-wtPShM.mjs +5360 -0
  38. package/dist/shared/language-server.RjhrBZS0.d.ts +1194 -0
  39. package/package.json +35 -20
  40. package/src/ast.ts +44 -32
  41. package/src/browser.ts +0 -3
  42. package/src/elementRef.ts +1 -1
  43. package/src/generated/ast.ts +105 -86
  44. package/src/generated/grammar.ts +1 -1
  45. package/src/generated-lib/icons.ts +1 -1
  46. package/src/like-c4.langium +30 -18
  47. package/src/likec4lib.ts +2 -3
  48. package/src/logger.ts +9 -1
  49. package/src/lsp/RenameProvider.ts +8 -0
  50. package/src/lsp/SemanticTokenProvider.ts +19 -1
  51. package/src/lsp/index.ts +1 -0
  52. package/src/model/fqn-computation.ts +33 -23
  53. package/src/model/fqn-index.ts +5 -20
  54. package/src/model/model-builder.ts +147 -90
  55. package/src/model/model-locator.ts +1 -1
  56. package/src/model/model-parser-where.ts +3 -2
  57. package/src/model/model-parser.ts +57 -19
  58. package/src/model-graph/LikeC4ModelGraph.ts +42 -21
  59. package/src/model-graph/compute-view/__test__/fixture.ts +16 -14
  60. package/src/model-graph/compute-view/compute.ts +9 -6
  61. package/src/model-graph/compute-view/predicates.ts +3 -3
  62. package/src/model-graph/dynamic-view/__test__/fixture.ts +1 -0
  63. package/src/model-graph/dynamic-view/compute.ts +2 -1
  64. package/src/model-graph/utils/elementExpressionToPredicate.ts +1 -1
  65. package/src/model-graph/utils/sortNodes.ts +2 -6
  66. package/src/module.ts +23 -3
  67. package/src/protocol.ts +4 -5
  68. package/src/references/scope-computation.ts +10 -1
  69. package/src/references/scope-provider.ts +22 -9
  70. package/src/shared/NodeKindProvider.ts +73 -34
  71. package/src/test/setup.ts +3 -8
  72. package/src/utils/graphlib.ts +11 -0
  73. package/src/validation/_shared.ts +24 -0
  74. package/src/validation/element.ts +9 -9
  75. package/src/validation/index.ts +2 -1
  76. package/src/validation/relation.ts +45 -39
  77. package/src/validation/specification.ts +15 -2
  78. package/src/validation/view.ts +7 -0
  79. package/src/view-utils/manual-layout.ts +1 -1
  80. package/src/view-utils/resolve-extended-views.ts +19 -10
  81. package/src/view-utils/resolve-relative-paths.ts +5 -7
  82. package/src/view-utils/view-hash.ts +1 -1
  83. package/src/reset.d.ts +0 -2
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.8.0",
4
+ "version": "1.9.0",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -21,30 +21,37 @@
21
21
  "directory": "packages/language-server"
22
22
  },
23
23
  "type": "module",
24
+ "sideEffects": false,
24
25
  "exports": {
25
26
  ".": {
26
27
  "types": "./dist/index.d.ts",
27
- "default": "./dist/index.js"
28
+ "import": "./dist/index.mjs",
29
+ "require": "./dist/index.cjs"
28
30
  },
29
31
  "./likec4lib": {
30
32
  "types": "./dist/likec4lib.d.ts",
31
- "default": "./dist/likec4lib.js"
33
+ "import": "./dist/likec4lib.mjs",
34
+ "require": "./dist/likec4lib.cjs"
32
35
  },
33
36
  "./browser": {
34
37
  "types": "./dist/browser.d.ts",
35
- "default": "./dist/browser.js"
38
+ "import": "./dist/browser.mjs",
39
+ "require": "./dist/browser.cjs"
36
40
  },
37
41
  "./protocol": {
38
42
  "types": "./dist/protocol.d.ts",
39
- "default": "./dist/protocol.js"
43
+ "import": "./dist/protocol.mjs",
44
+ "require": "./dist/protocol.cjs"
40
45
  },
41
46
  "./node": {
42
47
  "types": "./dist/node.d.ts",
43
- "default": "./dist/node.js"
48
+ "import": "./dist/node.mjs",
49
+ "require": "./dist/node.cjs"
44
50
  },
45
51
  "./model-graph": {
46
52
  "types": "./dist/model-graph/index.d.ts",
47
- "default": "./dist/model-graph/index.js"
53
+ "import": "./dist/model-graph/index.mjs",
54
+ "require": "./dist/model-graph/index.cjs"
48
55
  }
49
56
  },
50
57
  "publishConfig": {
@@ -53,32 +60,40 @@
53
60
  "exports": {
54
61
  ".": {
55
62
  "types": "./dist/index.d.ts",
56
- "default": "./dist/index.js"
63
+ "import": "./dist/index.mjs",
64
+ "require": "./dist/index.cjs"
57
65
  },
58
66
  "./likec4lib": {
59
67
  "types": "./dist/likec4lib.d.ts",
60
- "default": "./dist/likec4lib.js"
68
+ "import": "./dist/likec4lib.mjs",
69
+ "require": "./dist/likec4lib.cjs"
61
70
  },
62
71
  "./browser": {
63
72
  "types": "./dist/browser.d.ts",
64
- "default": "./dist/browser.js"
73
+ "import": "./dist/browser.mjs",
74
+ "require": "./dist/browser.cjs"
65
75
  },
66
76
  "./protocol": {
67
77
  "types": "./dist/protocol.d.ts",
68
- "default": "./dist/protocol.js"
78
+ "import": "./dist/protocol.mjs",
79
+ "require": "./dist/protocol.cjs"
69
80
  },
70
81
  "./node": {
71
82
  "types": "./dist/node.d.ts",
72
- "default": "./dist/node.js"
83
+ "import": "./dist/node.mjs",
84
+ "require": "./dist/node.cjs"
73
85
  },
74
86
  "./model-graph": {
75
87
  "types": "./dist/model-graph/index.d.ts",
76
- "default": "./dist/model-graph/index.js"
88
+ "import": "./dist/model-graph/index.mjs",
89
+ "require": "./dist/model-graph/index.cjs"
77
90
  }
78
91
  }
79
92
  },
80
93
  "scripts": {
81
94
  "typecheck": "tsc --noEmit",
95
+ "prepack": "turbo run build",
96
+ "build": "unbuild",
82
97
  "pregenerate": "rm -f src/generated/*",
83
98
  "watch:langium": "langium generate --watch",
84
99
  "watch:ts": "tsc --watch",
@@ -92,11 +107,10 @@
92
107
  },
93
108
  "dependencies": {
94
109
  "@dagrejs/graphlib": "^2.2.4",
95
- "@likec4/core": "1.8.0",
96
- "@likec4/log": "1.8.0",
110
+ "@likec4/core": "1.9.0",
111
+ "@likec4/log": "1.9.0",
97
112
  "@msgpack/msgpack": "^3.0.0-beta2",
98
113
  "@smithy/util-base64": "^3.0.0",
99
- "@total-typescript/ts-reset": "^0.5.1",
100
114
  "fast-equals": "^5.0.1",
101
115
  "indent-string": "^5.0.0",
102
116
  "json5": "^2.2.3",
@@ -106,7 +120,7 @@
106
120
  "remeda": "^2.11.0",
107
121
  "string-hash": "^1.1.3",
108
122
  "strip-indent": "^4.0.0",
109
- "type-fest": "^4.21.0",
123
+ "type-fest": "^4.26.0",
110
124
  "ufo": "^1.5.4",
111
125
  "vscode-jsonrpc": "8.2.0",
112
126
  "vscode-languageserver": "9.0.1",
@@ -114,17 +128,18 @@
114
128
  "vscode-uri": "3.0.8"
115
129
  },
116
130
  "devDependencies": {
117
- "@likec4/icons": "1.8.0",
118
- "@likec4/tsconfig": "1.8.0",
131
+ "@likec4/icons": "1.9.0",
132
+ "@likec4/tsconfig": "1.9.0",
119
133
  "@types/node": "^20.16.1",
120
134
  "@types/object-hash": "^3.0.6",
121
135
  "@types/string-hash": "^1.1.3",
122
136
  "execa": "^9.3.1",
123
- "glob": "^11.0.0",
124
137
  "langium-cli": "3.1.1",
125
138
  "npm-run-all2": "^6.2.2",
126
139
  "tsx": "~4.9.3",
140
+ "turbo": "^2.1.1",
127
141
  "typescript": "^5.5.4",
142
+ "unbuild": "^3.0.0-rc.7",
128
143
  "vitest": "~2.0.5"
129
144
  },
130
145
  "packageManager": "yarn@4.3.1"
package/src/ast.ts CHANGED
@@ -1,15 +1,8 @@
1
- import {
2
- type c4,
3
- DefaultArrowType,
4
- DefaultLineStyle,
5
- DefaultRelationshipColor,
6
- nonexhaustive,
7
- NullableError,
8
- RelationRefError
9
- } from '@likec4/core'
1
+ import { DefaultArrowType, DefaultLineStyle, DefaultRelationshipColor, nonexhaustive } from '@likec4/core'
2
+ import type * as c4 from '@likec4/core'
10
3
  import type { AstNode, AstNodeDescription, DiagnosticInfo, LangiumDocument, MultiMap } from 'langium'
11
4
  import { DocumentState } from 'langium'
12
- import { clamp, isNullish, isTruthy } from 'remeda'
5
+ import { clamp, isDefined, isNullish, isTruthy } from 'remeda'
13
6
  import type { ConditionalPick, SetRequired, ValueOf } from 'type-fest'
14
7
  import type { Diagnostic } from 'vscode-languageserver-types'
15
8
  import { DiagnosticSeverity } from 'vscode-languageserver-types'
@@ -37,13 +30,14 @@ declare module './generated/ast' {
37
30
  type ParsedElementStyle = {
38
31
  shape?: c4.ElementShape
39
32
  icon?: c4.IconUrl
40
- color?: c4.ThemeColor
33
+ color?: c4.Color
41
34
  border?: c4.BorderStyle
42
35
  opacity?: number
43
36
  }
44
37
 
45
38
  export interface ParsedAstSpecification {
46
- kinds: Record<c4.ElementKind, {
39
+ tags: Set<c4.Tag>
40
+ elements: Record<c4.ElementKind, {
47
41
  technology?: string
48
42
  notation?: string
49
43
  style: ParsedElementStyle
@@ -53,12 +47,18 @@ export interface ParsedAstSpecification {
53
47
  {
54
48
  technology?: string
55
49
  notation?: string
56
- color?: c4.ThemeColor
50
+ color?: c4.Color
57
51
  line?: c4.RelationshipLineType
58
52
  head?: c4.RelationshipArrowType
59
53
  tail?: c4.RelationshipArrowType
60
54
  }
61
55
  >
56
+ colors: Record<
57
+ c4.CustomColor,
58
+ {
59
+ color: c4.HexColorLiteral
60
+ }
61
+ >
62
62
  }
63
63
 
64
64
  export interface ParsedAstElement {
@@ -84,7 +84,7 @@ export interface ParsedAstRelation {
84
84
  title: string
85
85
  description?: string
86
86
  technology?: string
87
- color?: c4.ThemeColor
87
+ color?: c4.Color
88
88
  line?: c4.RelationshipLineType
89
89
  head?: c4.RelationshipArrowType
90
90
  tail?: c4.RelationshipArrowType
@@ -182,8 +182,10 @@ export interface ParsedLikeC4LangiumDocument
182
182
  export function cleanParsedModel(doc: LikeC4LangiumDocument) {
183
183
  const props: Required<Omit<LikeC4DocumentProps, 'c4fqnIndex' | 'diagnostics'>> = {
184
184
  c4Specification: {
185
- kinds: {},
186
- relationships: {}
185
+ tags: new Set(),
186
+ elements: {},
187
+ relationships: {},
188
+ colors: {}
187
189
  },
188
190
  c4Elements: [],
189
191
  c4Relations: [],
@@ -248,6 +250,7 @@ const isValidatableAstNode = validatableAstNodeGuards([
248
250
  ast.isSpecificationElementKind,
249
251
  ast.isSpecificationRelationshipKind,
250
252
  ast.isSpecificationTag,
253
+ ast.isSpecificationColor,
251
254
  ast.isSpecificationRule,
252
255
  ast.isModelViews,
253
256
  ast.isModel
@@ -280,8 +283,9 @@ export function checksFromDiagnostics(doc: LikeC4LangiumDocument) {
280
283
  }
281
284
  }
282
285
  export type ChecksFromDiagnostics = ReturnType<typeof checksFromDiagnostics>
286
+ export type IsValidFn = ChecksFromDiagnostics['isValid']
283
287
 
284
- export function* streamModel(doc: LikeC4LangiumDocument, isValid: ChecksFromDiagnostics['isValid']) {
288
+ export function* streamModel(doc: LikeC4LangiumDocument, isValid: IsValidFn) {
285
289
  const traverseStack = doc.parseResult.value.models.flatMap(m => (isValid(m) ? m.elements : []))
286
290
  const relations = [] as ast.Relation[]
287
291
  let el
@@ -300,13 +304,7 @@ export function* streamModel(doc: LikeC4LangiumDocument, isValid: ChecksFromDiag
300
304
  continue
301
305
  }
302
306
  if (el.body && el.body.elements.length > 0) {
303
- for (const nested of el.body.elements) {
304
- if (ast.isRelation(nested)) {
305
- relations.push(nested)
306
- } else {
307
- traverseStack.push(nested)
308
- }
309
- }
307
+ traverseStack.push(...el.body.elements)
310
308
  }
311
309
  yield el
312
310
  }
@@ -321,18 +319,21 @@ export function resolveRelationPoints(node: ast.Relation): {
321
319
  } {
322
320
  const target = elementRef(node.target)
323
321
  if (!target) {
324
- throw new RelationRefError('Invalid reference to target')
322
+ throw new Error('RelationRefError: Invalid reference to target')
325
323
  }
326
- if (ast.isExplicitRelation(node)) {
324
+ if (isDefined(node.source)) {
327
325
  const source = elementRef(node.source)
328
326
  if (!source) {
329
- throw new RelationRefError('Invalid reference to source')
327
+ throw new Error('RelationRefError: Invalid reference to source')
330
328
  }
331
329
  return {
332
330
  source,
333
331
  target
334
332
  }
335
333
  }
334
+ if (!ast.isElementBody(node.$container)) {
335
+ throw new Error('RelationRefError: Invalid container for sourceless relation')
336
+ }
336
337
  return {
337
338
  source: node.$container.$container,
338
339
  target
@@ -344,12 +345,15 @@ export function parseAstOpacityProperty({ value }: ast.OpacityProperty): number
344
345
  return isNaN(opacity) ? 100 : clamp(opacity, { min: 0, max: 100 })
345
346
  }
346
347
 
347
- export function toElementStyle(props?: Array<ast.StyleProperty>) {
348
+ export function toElementStyle(props: Array<ast.StyleProperty> | undefined, isValid: IsValidFn) {
348
349
  const result = {} as ParsedElementStyle
349
350
  if (!props || props.length === 0) {
350
351
  return result
351
352
  }
352
353
  for (const prop of props) {
354
+ if (!isValid(prop)) {
355
+ continue
356
+ }
353
357
  switch (true) {
354
358
  case ast.isBorderProperty(prop): {
355
359
  if (isTruthy(prop.value)) {
@@ -358,8 +362,9 @@ export function toElementStyle(props?: Array<ast.StyleProperty>) {
358
362
  break
359
363
  }
360
364
  case ast.isColorProperty(prop): {
361
- if (isTruthy(prop.value)) {
362
- result.color = prop.value
365
+ const color = toColor(prop)
366
+ if (isTruthy(color)) {
367
+ result.color = color
363
368
  }
364
369
  break
365
370
  }
@@ -390,7 +395,7 @@ export function toElementStyle(props?: Array<ast.StyleProperty>) {
390
395
 
391
396
  export function toRelationshipStyle(props?: ast.RelationshipStyleProperty[]) {
392
397
  const result = {} as {
393
- color?: c4.ThemeColor
398
+ color?: c4.Color
394
399
  line?: c4.RelationshipLineType
395
400
  head?: c4.RelationshipArrowType
396
401
  tail?: c4.RelationshipArrowType
@@ -400,7 +405,10 @@ export function toRelationshipStyle(props?: ast.RelationshipStyleProperty[]) {
400
405
  }
401
406
  for (const prop of props) {
402
407
  if (ast.isColorProperty(prop)) {
403
- result.color = prop.value
408
+ const color = toColor(prop)
409
+ if (isTruthy(color)) {
410
+ result.color = color
411
+ }
404
412
  continue
405
413
  }
406
414
  if (ast.isLineProperty(prop)) {
@@ -440,6 +448,10 @@ export function toRelationshipStyleExcludeDefaults(
440
448
  }
441
449
  }
442
450
 
451
+ export function toColor(astNode: ast.ColorProperty): c4.Color | undefined {
452
+ return astNode?.themeColor ?? (astNode?.customColor?.$refText as (c4.HexColorLiteral | undefined))
453
+ }
454
+
443
455
  export function toAutoLayout(
444
456
  direction: ast.ViewLayoutDirection
445
457
  ): c4.ViewRuleAutoLayout['autoLayout'] {
package/src/browser.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { startLanguageServer as startLanguim } from 'langium/lsp'
2
2
  import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser'
3
- import { logToLspConnection } from './logger'
4
3
  import { createLanguageServices } from './module'
5
4
 
6
5
  // This is an example copied as is from here:
@@ -22,8 +21,6 @@ export function startLanguageServer() {
22
21
  // Start the language server with the shared services
23
22
  startLanguim(services.shared)
24
23
 
25
- logToLspConnection(connection)
26
-
27
24
  return {
28
25
  ...services,
29
26
  connection,
package/src/elementRef.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type c4 } from '@likec4/core'
1
+ import type * as c4 from '@likec4/core'
2
2
  import type { ast } from './ast'
3
3
  /**
4
4
  * Returns referenced AST Element