@likec4/language-server 1.27.3 → 1.28.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 (111) hide show
  1. package/dist/LikeC4LanguageServices.js +6 -7
  2. package/dist/ast.d.ts +16 -9
  3. package/dist/ast.js +58 -79
  4. package/dist/bundled.mjs +2130 -2127
  5. package/dist/config/schema.d.ts +3 -3
  6. package/dist/config/schema.js +12 -5
  7. package/dist/documentation/documentation-provider.js +3 -1
  8. package/dist/formatting/LikeC4Formatter.d.ts +0 -2
  9. package/dist/formatting/LikeC4Formatter.js +24 -53
  10. package/dist/generated/ast.d.ts +128 -233
  11. package/dist/generated/ast.js +134 -306
  12. package/dist/generated/grammar.js +1 -1
  13. package/dist/lsp/CompletionProvider.d.ts +3 -0
  14. package/dist/lsp/CompletionProvider.js +128 -113
  15. package/dist/lsp/DocumentLinkProvider.js +6 -3
  16. package/dist/lsp/HoverProvider.js +3 -1
  17. package/dist/lsp/SemanticTokenProvider.js +33 -43
  18. package/dist/model/builder/MergedSpecification.d.ts +5 -3
  19. package/dist/model/builder/MergedSpecification.js +21 -7
  20. package/dist/model/builder/buildModel.d.ts +6 -1
  21. package/dist/model/builder/buildModel.js +20 -15
  22. package/dist/model/deployments-index.js +4 -2
  23. package/dist/model/fqn-index.d.ts +4 -2
  24. package/dist/model/fqn-index.js +28 -5
  25. package/dist/model/model-builder.d.ts +2 -2
  26. package/dist/model/model-builder.js +54 -16
  27. package/dist/model/model-locator.js +7 -4
  28. package/dist/model/model-parser.d.ts +215 -52
  29. package/dist/model/model-parser.js +6 -2
  30. package/dist/model/parser/Base.d.ts +11 -2
  31. package/dist/model/parser/Base.js +138 -3
  32. package/dist/model/parser/DeploymentModelParser.d.ts +19 -2
  33. package/dist/model/parser/DeploymentModelParser.js +19 -29
  34. package/dist/model/parser/DeploymentViewParser.d.ts +18 -2
  35. package/dist/model/parser/DeploymentViewParser.js +6 -24
  36. package/dist/model/parser/FqnRefParser.d.ts +18 -3
  37. package/dist/model/parser/FqnRefParser.js +264 -40
  38. package/dist/model/parser/GlobalsParser.d.ts +35 -18
  39. package/dist/model/parser/ImportsParser.d.ts +32 -0
  40. package/dist/model/parser/ImportsParser.js +26 -0
  41. package/dist/model/parser/ModelParser.d.ts +26 -2
  42. package/dist/model/parser/ModelParser.js +21 -41
  43. package/dist/model/parser/PredicatesParser.d.ts +35 -12
  44. package/dist/model/parser/PredicatesParser.js +20 -271
  45. package/dist/model/parser/SpecificationParser.d.ts +8 -0
  46. package/dist/model/parser/SpecificationParser.js +5 -9
  47. package/dist/model/parser/ViewsParser.d.ts +36 -19
  48. package/dist/model/parser/ViewsParser.js +15 -11
  49. package/dist/model-change/changeElementStyle.d.ts +2 -2
  50. package/dist/model-change/changeElementStyle.js +2 -1
  51. package/dist/references/name-provider.js +8 -2
  52. package/dist/references/scope-computation.d.ts +1 -1
  53. package/dist/references/scope-computation.js +33 -3
  54. package/dist/references/scope-provider.d.ts +7 -8
  55. package/dist/references/scope-provider.js +59 -41
  56. package/dist/shared/NodeKindProvider.js +4 -2
  57. package/dist/test/testServices.d.ts +2 -0
  58. package/dist/test/testServices.js +4 -1
  59. package/dist/utils/elementRef.d.ts +1 -1
  60. package/dist/utils/elementRef.js +6 -1
  61. package/dist/utils/fqnRef.d.ts +3 -0
  62. package/dist/utils/fqnRef.js +15 -4
  63. package/dist/utils/index.d.ts +1 -0
  64. package/dist/utils/index.js +9 -0
  65. package/dist/utils/projectId.d.ts +2 -1
  66. package/dist/utils/projectId.js +11 -1
  67. package/dist/validation/_shared.js +2 -2
  68. package/dist/validation/deployment-checks.js +24 -10
  69. package/dist/validation/element-ref.d.ts +4 -0
  70. package/dist/validation/element-ref.js +12 -0
  71. package/dist/validation/element.d.ts +1 -1
  72. package/dist/validation/element.js +1 -1
  73. package/dist/validation/imports.d.ts +5 -0
  74. package/dist/validation/imports.js +30 -0
  75. package/dist/validation/index.d.ts +1 -1
  76. package/dist/validation/index.js +47 -45
  77. package/dist/validation/relation.d.ts +2 -2
  78. package/dist/validation/relation.js +24 -27
  79. package/dist/validation/specification.d.ts +9 -9
  80. package/dist/validation/specification.js +9 -9
  81. package/dist/validation/view-predicates/{element-with.d.ts → fqn-expr-with.d.ts} +1 -1
  82. package/dist/validation/view-predicates/fqn-expr-with.js +42 -0
  83. package/dist/validation/view-predicates/fqn-ref-expr.d.ts +4 -0
  84. package/dist/validation/view-predicates/fqn-ref-expr.js +53 -0
  85. package/dist/validation/view-predicates/incoming.d.ts +1 -1
  86. package/dist/validation/view-predicates/incoming.js +2 -2
  87. package/dist/validation/view-predicates/index.d.ts +6 -6
  88. package/dist/validation/view-predicates/index.js +6 -6
  89. package/dist/validation/view-predicates/outgoing.d.ts +1 -1
  90. package/dist/validation/view-predicates/outgoing.js +8 -4
  91. package/dist/validation/view-predicates/{expanded-element.d.ts → relation-expr.d.ts} +1 -1
  92. package/dist/validation/view-predicates/relation-expr.js +39 -0
  93. package/dist/validation/view-predicates/relation-with.d.ts +1 -1
  94. package/dist/validation/view-predicates/relation-with.js +8 -5
  95. package/dist/workspace/AstNodeDescriptionProvider.d.ts +1 -1
  96. package/dist/workspace/AstNodeDescriptionProvider.js +2 -3
  97. package/dist/workspace/IndexManager.d.ts +1 -1
  98. package/dist/workspace/IndexManager.js +5 -4
  99. package/dist/workspace/LangiumDocuments.d.ts +1 -1
  100. package/dist/workspace/LangiumDocuments.js +3 -5
  101. package/dist/workspace/ProjectsManager.d.ts +25 -7
  102. package/dist/workspace/ProjectsManager.js +76 -32
  103. package/dist/workspace/WorkspaceManager.d.ts +4 -5
  104. package/dist/workspace/WorkspaceManager.js +53 -20
  105. package/package.json +12 -10
  106. package/dist/validation/dynamic-view-rule.d.ts +0 -4
  107. package/dist/validation/dynamic-view-rule.js +0 -17
  108. package/dist/validation/view-predicates/element-with.js +0 -31
  109. package/dist/validation/view-predicates/expanded-element.js +0 -12
  110. package/dist/validation/view-predicates/expression-v2.d.ts +0 -5
  111. package/dist/validation/view-predicates/expression-v2.js +0 -83
@@ -1,8 +1,8 @@
1
1
  import * as v from 'valibot';
2
2
  export declare const ProjectConfig: v.ObjectSchema<{
3
- readonly name: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.DescriptionAction<string, "Project name, must be unique in the workspace">]>;
4
- readonly contactPerson: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>, v.DescriptionAction<string, "A person who has been involved in creating or maintaining this project">]>, undefined>;
5
- readonly exclude: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.StringSchema<undefined>, undefined>, v.DescriptionAction<string[], "List of file patterns to exclude from the project, default is [\"node_modules\"]">]>, undefined>;
3
+ readonly name: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>, v.DescriptionAction<string, "Project name, must be unique in the workspace">]>;
4
+ readonly contactPerson: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>, v.DescriptionAction<string, "A person who has been involved in creating or maintaining this project">]>, undefined>;
5
+ readonly exclude: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.StringSchema<undefined>, undefined>, v.DescriptionAction<string[], "List of file patterns to exclude from the project, default is [\"**/node_modules/**/*\"]">]>, undefined>;
6
6
  }, undefined>;
7
7
  export type ProjectConfig = v.InferOutput<typeof ProjectConfig>;
8
8
  export declare function parseConfigJson(config: string): ProjectConfig;
@@ -1,22 +1,29 @@
1
1
  import JSON5 from "json5";
2
2
  import * as v from "valibot";
3
+ const nonEmptyString = v.pipe(v.string(), v.nonEmpty());
3
4
  export const ProjectConfig = v.object({
4
5
  name: v.pipe(
5
- v.string(),
6
- v.nonEmpty(),
6
+ nonEmptyString,
7
+ // TODO: check if this is needed
8
+ // v.excludes('.', 'Project name cannot contain "."'),
7
9
  v.description("Project name, must be unique in the workspace")
8
10
  ),
9
11
  contactPerson: v.optional(
10
12
  v.pipe(
11
- v.string(),
12
- v.nonEmpty(),
13
+ nonEmptyString,
13
14
  v.description("A person who has been involved in creating or maintaining this project")
14
15
  )
15
16
  ),
17
+ // imports: v.optional(
18
+ // v.pipe(
19
+ // v.record(v.string(), nonEmptyString),
20
+ // v.description('Imported projects'),
21
+ // ),
22
+ // ),
16
23
  exclude: v.optional(
17
24
  v.pipe(
18
25
  v.array(v.string()),
19
- v.description('List of file patterns to exclude from the project, default is ["node_modules"]')
26
+ v.description('List of file patterns to exclude from the project, default is ["**/node_modules/**/*"]')
20
27
  )
21
28
  )
22
29
  });
@@ -1,3 +1,4 @@
1
+ import { FqnRef } from "@likec4/core";
1
2
  import { AstUtils } from "langium";
2
3
  import { ast } from "../ast.js";
3
4
  import { logWarnError } from "../logger.js";
@@ -22,7 +23,8 @@ export class LikeC4DocumentationProvider {
22
23
  if (ast.isDeployedInstance(node)) {
23
24
  const doc = AstUtils.getDocument(node);
24
25
  const instance = this.parser.forDocument(doc).parseDeployedInstance(node);
25
- const el = this.locator.getParsedElement(instance.element);
26
+ const [projectId, fqn] = FqnRef.isImportRef(instance.element) ? [instance.element.project, instance.element.model] : [doc.likec4ProjectId, instance.element.model];
27
+ const el = projectId ? this.locator.getParsedElement(fqn, projectId) : this.locator.getParsedElement(fqn);
26
28
  const lines = [instance.id, `_instance of_ ${instance.element}`];
27
29
  if (el) {
28
30
  lines.push(" ", `**${el.title}**`);
@@ -25,12 +25,10 @@ export declare class LikeC4Formatter extends AbstractFormatter {
25
25
  protected formatViewRuleGroup(node: AstNode): void;
26
26
  protected formatViewRuleStyle(node: AstNode): void;
27
27
  protected formatWhereExpression(node: AstNode): void;
28
- protected formatWhereExpressionV2(node: AstNode): void;
29
28
  protected formatWhereRelationExpression(node: AstNode): void;
30
29
  protected formatWhereElementExpression(node: AstNode): void;
31
30
  protected formatIncludeExcludeExpressions(node: AstNode): void;
32
31
  protected formatRelationExpression(node: AstNode): void;
33
- protected formatDeploymentViewRulePredicateExpressions(node: AstNode): void;
34
32
  private findPredicateExpressionRoot;
35
33
  private on;
36
34
  }
@@ -27,9 +27,7 @@ export class LikeC4Formatter extends AbstractFormatter {
27
27
  this.formatViewRuleGlobalStyle(node);
28
28
  this.formatViewRuleGlobalPredicate(node);
29
29
  this.formatIncludeExcludeExpressions(node);
30
- this.formatDeploymentViewRulePredicateExpressions(node);
31
30
  this.formatWhereExpression(node);
32
- this.formatWhereExpressionV2(node);
33
31
  this.formatWhereRelationExpression(node);
34
32
  this.formatWhereElementExpression(node);
35
33
  this.formatRelationExpression(node);
@@ -61,17 +59,21 @@ export class LikeC4Formatter extends AbstractFormatter {
61
59
  });
62
60
  }
63
61
  formatRelation(node) {
64
- this.on(node, ast.isRelation, (n, f) => {
65
- const sourceNodes = n?.source?.$cstNode ? [n?.source?.$cstNode] : [];
66
- f.cst(sourceNodes).append(FormattingOptions.oneSpace);
67
- f.keywords("]->").prepend(FormattingOptions.noSpace);
68
- f.keywords("-[").append(FormattingOptions.noSpace);
69
- f.nodes(...filter([
70
- n.target,
71
- n.tags
72
- ], isTruthy)).prepend(FormattingOptions.oneSpace);
73
- f.properties("title", "technology").prepend(FormattingOptions.oneSpace);
74
- });
62
+ this.on(
63
+ node,
64
+ (n) => ast.isRelation(n) || ast.isDeploymentRelation(n),
65
+ (n, f) => {
66
+ const sourceNodes = n?.source?.$cstNode ? [n?.source?.$cstNode] : [];
67
+ f.cst(sourceNodes).append(FormattingOptions.oneSpace);
68
+ f.keywords("]->").prepend(FormattingOptions.noSpace);
69
+ f.keywords("-[").append(FormattingOptions.noSpace);
70
+ f.nodes(...filter([
71
+ n.target,
72
+ n.tags
73
+ ], isTruthy)).prepend(FormattingOptions.oneSpace);
74
+ f.properties("title", "technology").prepend(FormattingOptions.oneSpace);
75
+ }
76
+ );
75
77
  this.on(node, ast.isDynamicViewStep, (n, f) => {
76
78
  f.keywords("->", "<-").surround(FormattingOptions.oneSpace);
77
79
  const kind = f.property("kind");
@@ -80,19 +82,11 @@ export class LikeC4Formatter extends AbstractFormatter {
80
82
  f.keywords("-[").prepend(FormattingOptions.oneSpace).append(FormattingOptions.noSpace);
81
83
  f.properties("title").prepend(FormattingOptions.oneSpace);
82
84
  });
83
- this.on(node, ast.isDirectedRelationExpression)?.property("target").prepend(FormattingOptions.oneSpace);
84
- this.on(node, ast.isOutgoingRelationExpression, (n, f) => {
85
- f.property("from").append(FormattingOptions.oneSpace);
86
- f.keywords("]->").prepend(FormattingOptions.noSpace);
87
- f.keywords("-[").append(FormattingOptions.noSpace);
88
- });
89
- this.on(node, ast.isIncomingRelationExpression)?.keywords("->").append(FormattingOptions.oneSpace);
90
- this.on(node, ast.isInOutRelationExpression)?.keyword("->").prepend(FormattingOptions.oneSpace);
91
85
  }
92
86
  removeIndentFromTopLevelStatements(node) {
93
- if (ast.isModel(node) || ast.isSpecificationRule(node) || ast.isModelViews(node) || ast.isLikeC4Lib(node) || ast.isGlobals(node) || ast.isModelDeployments(node)) {
87
+ if (ast.isLikeC4Grammar(node.$container)) {
94
88
  const formatter = this.getNodeFormatter(node);
95
- formatter.keywords("specification", "model", "views", "likec4lib", "global", "deployments").prepend(FormattingOptions.noIndent);
89
+ formatter.keywords("specification", "model", "views", "likec4lib", "global", "deployments", "import").prepend(FormattingOptions.noIndent);
96
90
  }
97
91
  }
98
92
  indentContentInBraces(node) {
@@ -222,8 +216,8 @@ export class LikeC4Formatter extends AbstractFormatter {
222
216
  }
223
217
  }
224
218
  formatWithPredicate(node) {
225
- const formatter = this.getNodeFormatter(node);
226
- if (ast.isElementPredicateWith(node) || ast.isRelationPredicateWith(node)) {
219
+ if (ast.isFqnExprWith(node) || ast.isRelationExprWith(node)) {
220
+ const formatter = this.getNodeFormatter(node);
227
221
  formatter.keyword("with").prepend(FormattingOptions.oneSpace);
228
222
  }
229
223
  }
@@ -271,17 +265,11 @@ export class LikeC4Formatter extends AbstractFormatter {
271
265
  formatViewRuleStyle(node) {
272
266
  this.on(node, ast.isViewRuleStyle)?.keyword("style").append(FormattingOptions.oneSpace);
273
267
  this.on(node, ast.isDeploymentViewRuleStyle)?.keyword("style").append(FormattingOptions.oneSpace);
274
- this.on(node, ast.isElementExpressionsIterator)?.keyword(",").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
268
+ this.on(node, ast.isExpressions)?.keyword(",").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
275
269
  this.on(node, ast.isFqnExpressions)?.keyword(",").prepend(FormattingOptions.noSpace).append(FormattingOptions.oneSpace);
276
270
  }
277
271
  formatWhereExpression(node) {
278
- if (ast.isRelationPredicateOrWhere(node) || ast.isElementPredicateOrWhere(node)) {
279
- const formatter = this.getNodeFormatter(node);
280
- formatter.keyword("where").append(FormattingOptions.oneSpace);
281
- }
282
- }
283
- formatWhereExpressionV2(node) {
284
- if (ast.isRelationPredicateOrWhereV2(node) || ast.isElementPredicateOrWhereV2(node)) {
272
+ if (ast.isRelationExprWhere(node) || ast.isFqnExprWhere(node)) {
285
273
  const formatter = this.getNodeFormatter(node);
286
274
  formatter.keyword("where").append(FormattingOptions.oneSpace);
287
275
  }
@@ -313,13 +301,13 @@ export class LikeC4Formatter extends AbstractFormatter {
313
301
  }
314
302
  }
315
303
  formatIncludeExcludeExpressions(node) {
316
- if (ast.isDynamicViewRule(node) || ast.isIncludePredicate(node) || ast.isExcludePredicate(node) || ast.isDeploymentViewRulePredicate(node)) {
304
+ if (ast.isDynamicViewRule(node) || ast.isViewRulePredicate(node) || ast.isDeploymentViewRulePredicate(node)) {
317
305
  const formatter = this.getNodeFormatter(node);
318
306
  if (!node.$cstNode || !utils.isMultiline(node.$cstNode)) {
319
307
  formatter.keywords("include", "exclude").append(FormattingOptions.oneSpace);
320
308
  }
321
309
  }
322
- if (ast.isDynamicViewPredicateIterator(node) || ast.isPredicates(node) || ast.isPredicates(node)) {
310
+ if (ast.isExpressions(node)) {
323
311
  const formatter = this.getNodeFormatter(node);
324
312
  const parent = this.findPredicateExpressionRoot(node);
325
313
  const isMultiline = parent?.$cstNode && utils.isMultiline(parent?.$cstNode);
@@ -347,27 +335,10 @@ export class LikeC4Formatter extends AbstractFormatter {
347
335
  f.property("target").prepend(FormattingOptions.oneSpace);
348
336
  });
349
337
  }
350
- formatDeploymentViewRulePredicateExpressions(node) {
351
- if (ast.isDynamicViewRule(node) || ast.isIncludePredicate(node) || ast.isExcludePredicate(node) || ast.isDeploymentViewRulePredicate(node)) {
352
- const formatter = this.getNodeFormatter(node);
353
- if (!node.$cstNode || !utils.isMultiline(node.$cstNode)) {
354
- formatter.keywords("include", "exclude").append(FormattingOptions.oneSpace);
355
- }
356
- }
357
- if (ast.isDeploymentViewRulePredicateExpression(node)) {
358
- const formatter = this.getNodeFormatter(node);
359
- const parent = this.findPredicateExpressionRoot(node);
360
- const isMultiline = parent?.$cstNode && utils.isMultiline(parent?.$cstNode);
361
- if (isMultiline) {
362
- formatter.property("value").prepend(FormattingOptions.indent);
363
- }
364
- formatter.keyword(",").prepend(FormattingOptions.noSpace).append(isMultiline ? FormattingOptions.newLine : FormattingOptions.oneSpace);
365
- }
366
- }
367
338
  findPredicateExpressionRoot(node) {
368
339
  let parent = node.$container;
369
340
  while (true) {
370
- if (!parent || ast.isDynamicViewRule(parent) || ast.isIncludePredicate(parent) || ast.isExcludePredicate(parent) || ast.isDeploymentViewRulePredicate(parent)) {
341
+ if (!parent || ast.isDynamicViewRule(parent) || ast.isViewRulePredicate(parent) || ast.isDeploymentViewRulePredicate(parent)) {
371
342
  return parent;
372
343
  }
373
344
  parent = parent.$container;