@likec4/language-server 1.6.1 → 1.7.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 (51) hide show
  1. package/contrib/likec4.tmLanguage.json +1 -1
  2. package/package.json +23 -19
  3. package/src/Rpc.ts +1 -1
  4. package/src/ast.ts +34 -9
  5. package/src/{browser/index.ts → browser.ts} +4 -1
  6. package/src/generated/ast.ts +498 -152
  7. package/src/generated/grammar.ts +2 -2
  8. package/src/generated/module.ts +1 -1
  9. package/src/index.ts +1 -1
  10. package/src/like-c4.langium +116 -44
  11. package/src/logger.ts +76 -55
  12. package/src/lsp/DocumentLinkProvider.ts +1 -1
  13. package/src/lsp/DocumentSymbolProvider.ts +1 -1
  14. package/src/lsp/HoverProvider.ts +1 -1
  15. package/src/lsp/SemanticTokenProvider.ts +54 -26
  16. package/src/model/model-builder.ts +11 -8
  17. package/src/model/model-locator.ts +12 -25
  18. package/src/model/model-parser-where.ts +75 -0
  19. package/src/model/model-parser.ts +168 -68
  20. package/src/model-change/ModelChanges.ts +2 -3
  21. package/src/model-change/changeElementStyle.ts +4 -1
  22. package/src/model-change/changeViewLayout.ts +8 -8
  23. package/src/model-change/saveManualLayout.ts +4 -6
  24. package/src/model-graph/LikeC4ModelGraph.ts +50 -48
  25. package/src/model-graph/compute-view/__test__/fixture.ts +41 -16
  26. package/src/model-graph/compute-view/compute.ts +135 -69
  27. package/src/model-graph/compute-view/predicates.ts +232 -136
  28. package/src/model-graph/dynamic-view/__test__/fixture.ts +5 -1
  29. package/src/model-graph/dynamic-view/compute.ts +50 -41
  30. package/src/model-graph/utils/applyCustomElementProperties.ts +31 -29
  31. package/src/model-graph/utils/applyCustomRelationProperties.ts +52 -15
  32. package/src/model-graph/utils/elementExpressionToPredicate.ts +8 -3
  33. package/src/module.ts +4 -18
  34. package/src/{node/index.ts → node.ts} +1 -1
  35. package/src/protocol.ts +2 -2
  36. package/src/shared/NodeKindProvider.ts +4 -2
  37. package/src/test/setup.ts +13 -0
  38. package/src/test/testServices.ts +1 -1
  39. package/src/validation/dynamic-view-rule.ts +12 -12
  40. package/src/validation/index.ts +6 -6
  41. package/src/validation/relation.ts +1 -1
  42. package/src/validation/view-predicates/{custom-element-expr.ts → element-with.ts} +11 -10
  43. package/src/validation/view-predicates/expanded-element.ts +2 -10
  44. package/src/validation/view-predicates/incoming.ts +1 -1
  45. package/src/validation/view-predicates/index.ts +2 -2
  46. package/src/validation/view-predicates/outgoing.ts +1 -1
  47. package/src/validation/view-predicates/{custom-relation-expr.ts → relation-with.ts} +2 -2
  48. package/src/validation/view.ts +8 -9
  49. package/src/view-utils/manual-layout.ts +65 -72
  50. package/src/view-utils/resolve-relative-paths.ts +28 -17
  51. package/src/view-utils/view-hash.ts +33 -0
@@ -12,7 +12,7 @@
12
12
  },
13
13
  {
14
14
  "name": "keyword.control.likec4",
15
- "match": "\\b(BottomTop|LeftRight|RightLeft|TopBottom|amber|autoLayout|blue|border|browser|color|crow|cylinder|dashed|description|diamond|dot|dotted|dynamic|element|element\\.kind|element\\.tag|exclude|extend|extends|gray|green|head|icon|icons|include|indigo|it|likec4lib|line|link|mobile|model|muted|navigateTo|none|normal|odiamond|odot|of|onormal|opacity|open|person|primary|queue|rectangle|red|relationship|secondary|shape|sky|slate|solid|specification|storage|style|tag|tail|technology|this|title|vee|view|views|with)\\b"
15
+ "match": "\\b(BottomTop|LeftRight|RightLeft|TopBottom|amber|and|autoLayout|blue|border|browser|color|crow|cylinder|dashed|description|diamond|dot|dotted|dynamic|element|element\\.kind|element\\.tag|exclude|extend|extends|gray|green|head|icon|icons|include|indigo|is|it|kind|likec4lib|line|link|mobile|model|muted|navigateTo|none|normal|not|odiamond|odot|of|onormal|opacity|open|or|person|primary|queue|rectangle|red|relationship|secondary|shape|sky|slate|solid|specification|storage|style|tag|tail|technology|this|title|vee|view|views|where|with)\\b"
16
16
  },
17
17
  {
18
18
  "name": "string.quoted.double.likec4",
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.6.1",
4
+ "version": "1.7.1",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -31,16 +31,16 @@
31
31
  "default": "./dist/likec4lib.js"
32
32
  },
33
33
  "./browser": {
34
- "types": "./dist/browser/index.d.ts",
35
- "default": "./dist/browser/index.js"
34
+ "types": "./dist/browser.d.ts",
35
+ "default": "./dist/browser.js"
36
36
  },
37
37
  "./protocol": {
38
38
  "types": "./dist/protocol.d.ts",
39
39
  "default": "./dist/protocol.js"
40
40
  },
41
41
  "./node": {
42
- "types": "./dist/node/index.d.ts",
43
- "default": "./dist/node/index.js"
42
+ "types": "./dist/node.d.ts",
43
+ "default": "./dist/node.js"
44
44
  },
45
45
  "./model-graph": {
46
46
  "types": "./dist/model-graph/index.d.ts",
@@ -60,16 +60,16 @@
60
60
  "default": "./dist/likec4lib.js"
61
61
  },
62
62
  "./browser": {
63
- "types": "./dist/browser/index.d.ts",
64
- "default": "./dist/browser/index.js"
63
+ "types": "./dist/browser.d.ts",
64
+ "default": "./dist/browser.js"
65
65
  },
66
66
  "./protocol": {
67
67
  "types": "./dist/protocol.d.ts",
68
68
  "default": "./dist/protocol.js"
69
69
  },
70
70
  "./node": {
71
- "types": "./dist/node/index.d.ts",
72
- "default": "./dist/node/index.js"
71
+ "types": "./dist/node.d.ts",
72
+ "default": "./dist/node.js"
73
73
  },
74
74
  "./model-graph": {
75
75
  "types": "./dist/model-graph/index.d.ts",
@@ -92,36 +92,40 @@
92
92
  },
93
93
  "dependencies": {
94
94
  "@dagrejs/graphlib": "^2.2.2",
95
- "@likec4/core": "1.6.1",
95
+ "@likec4/core": "1.7.1",
96
+ "@likec4/log": "1.7.1",
97
+ "@msgpack/msgpack": "^3.0.0-beta2",
98
+ "@smithy/util-base64": "^3.0.0",
96
99
  "@total-typescript/ts-reset": "^0.5.1",
97
100
  "fast-equals": "^5.0.1",
98
101
  "indent-string": "^5.0.0",
99
102
  "json5": "^2.2.3",
100
- "langium": "3.1.2",
103
+ "langium": "3.1.3",
101
104
  "object-hash": "^3.0.0",
102
105
  "p-debounce": "^4.0.0",
103
106
  "remeda": "^2.3.0",
104
107
  "string-hash": "^1.1.3",
105
108
  "strip-indent": "^4.0.0",
106
109
  "type-fest": "^4.21.0",
107
- "ufo": "^1.5.3",
110
+ "ufo": "^1.5.4",
111
+ "vscode-jsonrpc": "8.2.0",
108
112
  "vscode-languageserver": "9.0.1",
109
- "vscode-languageserver-protocol": "3.17.5",
113
+ "vscode-languageserver-types": "3.17.5",
110
114
  "vscode-uri": "3.0.8"
111
115
  },
112
116
  "devDependencies": {
113
- "@likec4/icons": "1.6.1",
114
- "@likec4/tsconfig": "1.6.1",
115
- "@types/node": "^20.14.10",
117
+ "@likec4/icons": "1.7.1",
118
+ "@likec4/tsconfig": "1.7.1",
119
+ "@types/node": "^20.14.13",
116
120
  "@types/object-hash": "^3.0.6",
117
121
  "@types/string-hash": "^1.1.3",
118
122
  "execa": "^9.3.0",
119
123
  "glob": "^11.0.0",
120
- "langium-cli": "3.1.0",
124
+ "langium-cli": "3.1.1",
121
125
  "npm-run-all2": "^6.2.2",
122
126
  "tsx": "~4.9.3",
123
- "typescript": "^5.5.3",
124
- "vitest": "~2.0.3"
127
+ "typescript": "^5.5.4",
128
+ "vitest": "~2.0.5"
125
129
  },
126
130
  "packageManager": "yarn@4.3.1"
127
131
  }
package/src/Rpc.ts CHANGED
@@ -27,7 +27,7 @@ export class Rpc implements Disposable {
27
27
  const modelEditor = this.services.likec4.ModelChanges
28
28
  const connection = this.services.shared.lsp.Connection
29
29
  if (!connection) {
30
- logger.warn(`[ServerRpc] no connection, not initializing`)
30
+ logger.info(`[ServerRpc] no connection, not initializing`)
31
31
  return
32
32
  }
33
33
  logger.info(`[ServerRpc] init`)
package/src/ast.ts CHANGED
@@ -7,11 +7,11 @@ import {
7
7
  RelationRefError
8
8
  } from '@likec4/core'
9
9
  import type { AstNode, AstNodeDescription, DiagnosticInfo, LangiumDocument, MultiMap } from 'langium'
10
- import { AstUtils, DocumentState } from 'langium'
10
+ import { DocumentState } from 'langium'
11
11
  import { clamp, isNullish, isTruthy } from 'remeda'
12
12
  import type { ConditionalPick, SetRequired, ValueOf } from 'type-fest'
13
- import type { Diagnostic } from 'vscode-languageserver-protocol'
14
- import { DiagnosticSeverity } from 'vscode-languageserver-protocol'
13
+ import type { Diagnostic } from 'vscode-languageserver-types'
14
+ import { DiagnosticSeverity } from 'vscode-languageserver-types'
15
15
  import { elementRef } from './elementRef'
16
16
  import type { LikeC4Grammar } from './generated/ast'
17
17
  import * as ast from './generated/ast'
@@ -74,6 +74,8 @@ export interface ParsedAstRelation {
74
74
  kind?: c4.RelationshipKind
75
75
  tags?: c4.NonEmptyArray<c4.Tag>
76
76
  title: string
77
+ description?: string
78
+ technology?: string
77
79
  color?: c4.ThemeColor
78
80
  line?: c4.RelationshipLineType
79
81
  head?: c4.RelationshipArrowType
@@ -207,12 +209,11 @@ function validatableAstNodeGuards<const Predicates extends Guard<AstNode>[]>(
207
209
  return (n: AstNode): n is Guarded<Predicates[number]> => predicates.some(p => p(n))
208
210
  }
209
211
  const isValidatableAstNode = validatableAstNodeGuards([
210
- ast.isDynamicViewRulePredicateIterator,
211
- ast.isCustomElementExpression,
212
- ast.isCustomRelationExpression,
212
+ ast.isDynamicViewPredicateIterator,
213
+ ast.isElementPredicateWith,
214
+ ast.isRelationPredicateWith,
213
215
  ast.isElementExpression,
214
216
  ast.isRelationExpression,
215
- ast.isDynamicViewRulePredicate,
216
217
  ast.isDynamicViewStep,
217
218
  ast.isViewProperty,
218
219
  ast.isStyleProperty,
@@ -239,12 +240,23 @@ const isValidatableAstNode = validatableAstNodeGuards([
239
240
  ])
240
241
  type ValidatableAstNode = Guarded<typeof isValidatableAstNode>
241
242
 
243
+ const findInvalidContainer = (node: LikeC4AstNode): ValidatableAstNode | undefined => {
244
+ let nd = node as LikeC4AstNode['$container']
245
+ while (nd) {
246
+ if (isValidatableAstNode(nd)) {
247
+ return nd
248
+ }
249
+ nd = nd.$container
250
+ }
251
+ return
252
+ }
253
+
242
254
  export function checksFromDiagnostics(doc: LikeC4LangiumDocument) {
243
255
  const errors = doc.diagnostics?.filter(d => d.severity === DiagnosticSeverity.Error) ?? []
244
256
  const invalidNodes = new WeakSet(
245
257
  errors.flatMap(d => {
246
- return AstUtils.getContainerOfType(d.node, isValidatableAstNode) ?? []
247
- }) ?? []
258
+ return findInvalidContainer(d.node) ?? []
259
+ })
248
260
  )
249
261
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
262
  const isValid = (n: ValidatableAstNode) => !invalidNodes.has(n)
@@ -447,3 +459,16 @@ export function toAstViewLayoutDirection(c4: c4.ViewRuleAutoLayout['autoLayout']
447
459
  nonexhaustive(c4)
448
460
  }
449
461
  }
462
+
463
+ export function elementExpressionFromPredicate(predicate: ast.ElementPredicate): ast.ElementExpression {
464
+ if (ast.isElementExpression(predicate)) {
465
+ return predicate
466
+ }
467
+ if (ast.isElementPredicateWhere(predicate)) {
468
+ return predicate.subject
469
+ }
470
+ if (ast.isElementPredicateWith(predicate)) {
471
+ return elementExpressionFromPredicate(predicate.subject)
472
+ }
473
+ nonexhaustive(predicate)
474
+ }
@@ -1,6 +1,7 @@
1
1
  import { startLanguageServer as startLanguim } from 'langium/lsp'
2
2
  import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser'
3
- import { createLanguageServices } from '../module'
3
+ import { logToLspConnection } from './logger'
4
+ import { createLanguageServices } from './module'
4
5
 
5
6
  // This is an example copied as is from here:
6
7
  // https://github.com/microsoft/vscode-extension-samples/blob/main/lsp-web-extension-sample/server/src/browserServerMain.ts
@@ -21,6 +22,8 @@ export function startLanguageServer() {
21
22
  // Start the language server with the shared services
22
23
  startLanguim(services.shared)
23
24
 
25
+ logToLspConnection(connection)
26
+
24
27
  return {
25
28
  ...services,
26
29
  connection,