@likec4/language-server 1.41.0 → 1.42.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 (85) hide show
  1. package/browser/package.json +4 -0
  2. package/browser-worker/package.json +4 -0
  3. package/dist/LikeC4LanguageServices.d.ts +1 -1
  4. package/dist/LikeC4LanguageServices.mjs +3 -2
  5. package/dist/Rpc.mjs +30 -24
  6. package/dist/ast.d.ts +1 -7
  7. package/dist/ast.mjs +0 -10
  8. package/dist/bundled.mjs +4125 -3660
  9. package/dist/documentation/documentation-provider.mjs +1 -1
  10. package/dist/filesystem/FileSystemWatcher.d.ts +2 -2
  11. package/dist/filesystem/LikeC4FileSystem.mjs +10 -4
  12. package/dist/filesystem/index.d.ts +1 -1
  13. package/dist/formatting/LikeC4Formatter.mjs +41 -10
  14. package/dist/formatting/utils.d.ts +3 -3
  15. package/dist/formatting/utils.mjs +1 -1
  16. package/dist/generated/ast.d.ts +35 -16
  17. package/dist/generated/ast.mjs +69 -26
  18. package/dist/generated/grammar.mjs +1 -1
  19. package/dist/lsp/CompletionProvider.mjs +1 -1
  20. package/dist/lsp/DocumentLinkProvider.d.ts +1 -1
  21. package/dist/lsp/DocumentLinkProvider.mjs +1 -1
  22. package/dist/lsp/DocumentSymbolProvider.mjs +1 -1
  23. package/dist/mcp/NoopLikeC4MCPServer.d.ts +1 -1
  24. package/dist/mcp/NoopLikeC4MCPServer.mjs +1 -1
  25. package/dist/mcp/server/StdioLikeC4MCPServer.mjs +4 -1
  26. package/dist/mcp/server/StreamableLikeC4MCPServer.mjs +3 -3
  27. package/dist/mcp/server/WithMCPServer.mjs +2 -2
  28. package/dist/mcp/tools/_common.mjs +2 -2
  29. package/dist/model/builder/MergedSpecification.d.ts +3 -3
  30. package/dist/model/builder/MergedSpecification.mjs +13 -39
  31. package/dist/model/builder/buildModel.mjs +14 -17
  32. package/dist/model/model-builder.d.ts +1 -1
  33. package/dist/model/model-builder.mjs +12 -9
  34. package/dist/model/model-locator.d.ts +5 -0
  35. package/dist/model/model-locator.mjs +40 -3
  36. package/dist/model/model-parser-where.mjs +1 -2
  37. package/dist/model/model-parser.d.ts +19 -2
  38. package/dist/model/parser/Base.mjs +8 -8
  39. package/dist/model/parser/DeploymentModelParser.d.ts +1 -0
  40. package/dist/model/parser/DeploymentModelParser.mjs +7 -7
  41. package/dist/model/parser/DeploymentViewParser.d.ts +1 -0
  42. package/dist/model/parser/FqnRefParser.d.ts +2 -0
  43. package/dist/model/parser/FqnRefParser.mjs +16 -11
  44. package/dist/model/parser/GlobalsParser.d.ts +8 -2
  45. package/dist/model/parser/ModelParser.d.ts +1 -0
  46. package/dist/model/parser/ModelParser.mjs +16 -11
  47. package/dist/model/parser/PredicatesParser.d.ts +1 -0
  48. package/dist/model/parser/SpecificationParser.mjs +4 -4
  49. package/dist/model/parser/ViewsParser.d.ts +12 -2
  50. package/dist/model/parser/ViewsParser.mjs +123 -31
  51. package/dist/model-change/ModelChanges.d.ts +1 -1
  52. package/dist/module.mjs +3 -2
  53. package/dist/protocol.d.ts +28 -4
  54. package/dist/references/scope-computation.mjs +2 -3
  55. package/dist/references/scope-provider.d.ts +2 -2
  56. package/dist/references/scope-provider.mjs +8 -15
  57. package/dist/test/testServices.d.ts +2 -0
  58. package/dist/test/testServices.mjs +10 -11
  59. package/dist/utils/disposable.mjs +2 -2
  60. package/dist/utils/index.mjs +1 -1
  61. package/dist/validation/_shared.d.ts +1 -1
  62. package/dist/validation/deployment-checks.d.ts +1 -1
  63. package/dist/validation/deployment-checks.mjs +4 -1
  64. package/dist/validation/dynamic-view.d.ts +3 -2
  65. package/dist/validation/dynamic-view.mjs +21 -2
  66. package/dist/validation/element-ref.d.ts +2 -2
  67. package/dist/validation/element-ref.mjs +1 -1
  68. package/dist/validation/imports.d.ts +0 -1
  69. package/dist/validation/imports.mjs +0 -5
  70. package/dist/validation/index.d.ts +1 -1
  71. package/dist/validation/index.mjs +19 -13
  72. package/dist/validation/view-predicates/relation-with.d.ts +1 -1
  73. package/dist/validation/view.d.ts +1 -1
  74. package/dist/view-utils/index.d.ts +0 -1
  75. package/dist/view-utils/index.mjs +0 -1
  76. package/dist/views/likec4-views.d.ts +6 -0
  77. package/dist/views/likec4-views.mjs +31 -18
  78. package/dist/workspace/ProjectsManager.d.ts +23 -31
  79. package/dist/workspace/ProjectsManager.mjs +78 -89
  80. package/dist/workspace/WorkspaceManager.mjs +1 -1
  81. package/likec4lib/package.json +4 -0
  82. package/package.json +24 -28
  83. package/protocol/package.json +4 -0
  84. package/dist/view-utils/resolve-relative-paths.d.ts +0 -2
  85. package/dist/view-utils/resolve-relative-paths.mjs +0 -78
@@ -0,0 +1,4 @@
1
+ {
2
+ "types": "../dist/browser.d.ts",
3
+ "module": "../dist/browser.mjs"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "types": "../dist/browser-worker.d.ts",
3
+ "module": "../dist/browser-worker.mjs"
4
+ }
@@ -70,10 +70,10 @@ export interface LikeC4LanguageServices {
70
70
  */
71
71
  export declare class DefaultLikeC4LanguageServices implements LikeC4LanguageServices {
72
72
  private services;
73
- readonly views: LikeC4Views;
74
73
  readonly builder: LikeC4ModelBuilder;
75
74
  readonly projectsManager: ProjectsManager;
76
75
  constructor(services: LikeC4Services);
76
+ get views(): LikeC4Views;
77
77
  get workspaceUri(): URI;
78
78
  projects(): NonEmptyArray<{
79
79
  id: ProjectId;
@@ -13,13 +13,14 @@ const logger = mainLogger.getChild("LanguageServices");
13
13
  export class DefaultLikeC4LanguageServices {
14
14
  constructor(services) {
15
15
  this.services = services;
16
- this.views = services.likec4.Views;
17
16
  this.builder = services.likec4.ModelBuilder;
18
17
  this.projectsManager = services.shared.workspace.ProjectsManager;
19
18
  }
20
- views;
21
19
  builder;
22
20
  projectsManager;
21
+ get views() {
22
+ return this.services.likec4.Views;
23
+ }
23
24
  get workspaceUri() {
24
25
  return this.services.shared.workspace.WorkspaceManager.workspaceUri;
25
26
  }
package/dist/Rpc.mjs CHANGED
@@ -2,6 +2,7 @@ import { filter, flatMap, funnel, indexBy, keys, map, mapValues, pipe, sort } fr
2
2
  import { logger as rootLogger } from "./logger.mjs";
3
3
  import { serializableLikeC4ProjectConfig } from "@likec4/config";
4
4
  import {
5
+ invariant,
5
6
  nonexhaustive
6
7
  } from "@likec4/core";
7
8
  import { LikeC4Model } from "@likec4/core/model";
@@ -33,17 +34,14 @@ export class Rpc extends ADisposable {
33
34
  this.services = services;
34
35
  }
35
36
  init() {
36
- const modelBuilder = this.services.likec4.ModelBuilder;
37
- const modelLocator = this.services.likec4.ModelLocator;
38
- const modelEditor = this.services.likec4.ModelChanges;
39
- const views = this.services.likec4.Views;
40
37
  const connection = this.services.shared.lsp.Connection;
41
- const projects = this.services.shared.workspace.ProjectsManager;
42
38
  if (!connection) {
43
39
  logger.info(`[ServerRpc] no connection, not initializing`);
44
40
  return;
45
41
  }
46
42
  logger.info(`[ServerRpc] init`);
43
+ const likec4Services = this.services.likec4;
44
+ const projects = this.services.shared.workspace.ProjectsManager;
47
45
  const LangiumDocuments = this.services.shared.workspace.LangiumDocuments;
48
46
  const DocumentBuilder = this.services.shared.workspace.DocumentBuilder;
49
47
  const notifyModelParsed = funnel(
@@ -63,7 +61,7 @@ export class Rpc extends ADisposable {
63
61
  );
64
62
  let isFirstBuild = true;
65
63
  this.onDispose(
66
- modelBuilder.onModelParsed(() => notifyModelParsed.call()),
64
+ likec4Services.ModelBuilder.onModelParsed(() => notifyModelParsed.call()),
67
65
  connection.onRequest(FetchComputedModel.req, async ({ projectId, cleanCaches }, cancelToken) => {
68
66
  logger.debug`received request ${"fetchComputedModel"} for project ${projectId}`;
69
67
  if (cleanCaches) {
@@ -71,22 +69,22 @@ export class Rpc extends ADisposable {
71
69
  const uris = docs.toArray().map((d) => d.uri);
72
70
  await DocumentBuilder.update(uris, [], cancelToken);
73
71
  }
74
- const likec4model = await modelBuilder.buildLikeC4Model(projectId, cancelToken);
72
+ const likec4model = await likec4Services.ModelBuilder.buildLikeC4Model(projectId, cancelToken);
75
73
  if (likec4model !== LikeC4Model.EMPTY) {
76
74
  return { model: likec4model.$model };
77
75
  }
78
76
  return { model: null };
79
77
  }),
80
78
  connection.onRequest(ComputeView.req, async ({ viewId, projectId }, cancelToken) => {
81
- const view = await modelBuilder.computeView(viewId, projectId, cancelToken);
79
+ const view = await likec4Services.ModelBuilder.computeView(viewId, projectId, cancelToken);
82
80
  return { view };
83
81
  }),
84
82
  connection.onRequest(FetchLayoutedModel.req, async ({ projectId }, cancelToken) => {
85
- const model = await modelBuilder.parseModel(projectId, cancelToken);
83
+ const model = await likec4Services.ModelBuilder.parseModel(projectId, cancelToken);
86
84
  if (model === null) {
87
85
  return { model: null };
88
86
  }
89
- const diagrams = await views.diagrams(projectId, cancelToken);
87
+ const diagrams = await likec4Services.Views.diagrams(projectId, cancelToken);
90
88
  return {
91
89
  model: {
92
90
  ...model.$data,
@@ -97,11 +95,11 @@ export class Rpc extends ADisposable {
97
95
  }),
98
96
  connection.onRequest(LayoutView.req, async ({ viewId, projectId }, cancelToken) => {
99
97
  logger.debug`received request ${"layoutView"} of ${viewId} from project ${projectId}`;
100
- const result = await views.layoutView(viewId, projectId, cancelToken);
98
+ const result = await likec4Services.Views.layoutView(viewId, projectId, cancelToken);
101
99
  return { result };
102
100
  }),
103
101
  connection.onRequest(ValidateLayout.Req, async ({ projectId }, cancelToken) => {
104
- const layouts = await views.layoutAllViews(projectId, cancelToken);
102
+ const layouts = await likec4Services.Views.layoutAllViews(projectId, cancelToken);
105
103
  const result = reportLayoutDrift(layouts.map((l) => l.diagram));
106
104
  return { result };
107
105
  }),
@@ -122,9 +120,9 @@ export class Rpc extends ADisposable {
122
120
  })
123
121
  };
124
122
  }),
125
- connection.onRequest(ReloadProjects.req, async (cancelToken) => {
123
+ connection.onRequest(ReloadProjects.req, async () => {
126
124
  logger.debug`received request ${"ReloadProjects"}`;
127
- await projects.reloadProjects(cancelToken);
125
+ await projects.reloadProjects();
128
126
  return;
129
127
  }),
130
128
  connection.onRequest(RegisterProject.req, async (params) => {
@@ -135,7 +133,7 @@ export class Rpc extends ADisposable {
135
133
  connection.onRequest(FetchViewsFromAllProjects.req, async (cancelToken) => {
136
134
  logger.debug`received request ${"FetchViewsFromAllProjects"}`;
137
135
  const promises = projects.all.map(async (projectId) => {
138
- const computedViews = await views.computedViews(projectId, cancelToken);
136
+ const computedViews = await likec4Services.Views.computedViews(projectId, cancelToken);
139
137
  return pipe(
140
138
  computedViews,
141
139
  map((v) => ({
@@ -196,25 +194,31 @@ export class Rpc extends ADisposable {
196
194
  connection.onRequest(Locate.Req, (params) => {
197
195
  switch (true) {
198
196
  case "element" in params:
199
- return modelLocator.locateElement(params.element, params.projectId);
197
+ return likec4Services.ModelLocator.locateElement(params.element, params.projectId);
200
198
  case "relation" in params:
201
- return modelLocator.locateRelation(params.relation, params.projectId);
199
+ return likec4Services.ModelLocator.locateRelation(params.relation, params.projectId);
200
+ case "astPath" in params:
201
+ return likec4Services.ModelLocator.locateDynamicViewStep({
202
+ view: params.view,
203
+ astPath: params.astPath,
204
+ projectId: params.projectId
205
+ });
202
206
  case "view" in params:
203
- return modelLocator.locateView(params.view, params.projectId);
207
+ return likec4Services.ModelLocator.locateView(params.view, params.projectId);
204
208
  case "deployment" in params:
205
- return modelLocator.locateDeploymentElement(params.deployment, params.projectId);
209
+ return likec4Services.ModelLocator.locateDeploymentElement(params.deployment, params.projectId);
206
210
  default:
207
211
  nonexhaustive(params);
208
212
  }
209
213
  }),
210
214
  connection.onRequest(ChangeView.Req, async (request, _cancelToken) => {
211
215
  logger.debug`received request ${"changeView"} of ${request.viewId} from project ${request.projectId}`;
212
- return await modelEditor.applyChange(request);
216
+ return await likec4Services.ModelChanges.applyChange(request);
213
217
  }),
214
218
  connection.onRequest(FetchTelemetryMetrics.req, async (cancelToken) => {
215
219
  const projectsIds = [...projects.all];
216
220
  const promises = projectsIds.map(async (projectId) => {
217
- const model = await modelBuilder.buildLikeC4Model(projectId, cancelToken);
221
+ const model = await likec4Services.ModelBuilder.buildLikeC4Model(projectId, cancelToken);
218
222
  if (model === LikeC4Model.EMPTY) {
219
223
  return Promise.reject(new Error(`Model is empty`));
220
224
  }
@@ -251,7 +255,7 @@ export class Rpc extends ADisposable {
251
255
  };
252
256
  }),
253
257
  connection.onRequest(GetDocumentTags.req, async ({ documentUri }, cancelToken) => {
254
- const tags = await modelLocator.locateDocumentTags(URI.parse(documentUri), cancelToken);
258
+ const tags = await likec4Services.ModelLocator.locateDocumentTags(URI.parse(documentUri), cancelToken);
255
259
  return {
256
260
  tags
257
261
  };
@@ -265,12 +269,14 @@ export class Rpc extends ADisposable {
265
269
  diagrams,
266
270
  filter((d) => !!d.hasLayoutDrift),
267
271
  map((d) => {
272
+ const loc = likec4Services.ModelLocator.locateView(d.id);
273
+ invariant(loc, `View ${d.id} not found`);
268
274
  return {
269
- uri: modelLocator.locateView(d.id).uri,
275
+ uri: loc.uri,
270
276
  viewId: d.id,
271
277
  severity: DiagnosticSeverity.Warning,
272
278
  message: `Layout drift detected for view '${d.id}'`,
273
- range: modelLocator.locateView(d.id).range
279
+ range: loc.range
274
280
  };
275
281
  })
276
282
  );
package/dist/ast.d.ts CHANGED
@@ -140,7 +140,7 @@ export interface ParsedAstDynamicView {
140
140
  description: c4.MarkdownOrString | null;
141
141
  tags: c4.NonEmptyArray<c4.Tag> | null;
142
142
  links: c4.NonEmptyArray<c4.Link> | null;
143
- steps: c4.DynamicViewStepOrParallel[];
143
+ steps: c4.DynamicViewStep[];
144
144
  rules: Array<c4.DynamicViewRule>;
145
145
  variant: c4.DynamicViewDisplayVariant | undefined;
146
146
  manualLayout?: c4.ViewManualLayout;
@@ -203,12 +203,6 @@ export declare function toRelationshipStyle(props: ast.RelationshipStyleProperty
203
203
  head?: c4.RelationshipArrowType;
204
204
  tail?: c4.RelationshipArrowType;
205
205
  };
206
- export declare function toRelationshipStyleExcludeDefaults(props: ast.SpecificationRelationshipKind['props'] | undefined, isValid: IsValidFn): {
207
- tail?: any;
208
- head?: any;
209
- line?: any;
210
- color?: any;
211
- };
212
206
  export declare function toColor(astNode: ast.ColorProperty): c4.Color | undefined;
213
207
  export declare function toAutoLayout(rule: ast.ViewRuleAutoLayout): c4.ViewRuleAutoLayout;
214
208
  export declare function toAstViewLayoutDirection(c4: c4.ViewRuleAutoLayout['direction']): ast.ViewLayoutDirection;
package/dist/ast.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import { DefaultArrowType, DefaultLineStyle, DefaultRelationshipColor } from "@likec4/core";
2
1
  import { nonexhaustive } from "@likec4/core/utils";
3
2
  import { AstUtils, DocumentState } from "langium";
4
3
  import { clamp, isNullish, isTruthy } from "remeda";
@@ -110,15 +109,6 @@ export function toRelationshipStyle(props, isValid) {
110
109
  }
111
110
  return result;
112
111
  }
113
- export function toRelationshipStyleExcludeDefaults(props, isValid) {
114
- const { color, line, head, tail } = toRelationshipStyle(props?.filter(ast.isRelationshipStyleProperty), isValid);
115
- return {
116
- ...color && color !== DefaultRelationshipColor ? { color } : {},
117
- ...line && line !== DefaultLineStyle ? { line } : {},
118
- ...head && head !== DefaultArrowType ? { head } : {},
119
- ...tail ? { tail } : {}
120
- };
121
- }
122
112
  export function toColor(astNode) {
123
113
  return astNode?.themeColor ?? astNode?.customColor?.$refText;
124
114
  }