@likec4/language-server 1.24.0 → 1.25.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.
package/dist/Rpc.js CHANGED
@@ -1,22 +1,23 @@
1
- import { filter, funnel, map, pipe } from "remeda";
2
- import { logger } from "./logger.js";
1
+ import { filter, funnel, indexBy, map, pipe } from "remeda";
2
+ import { logger as rootLogger } from "./logger.js";
3
3
  import { LikeC4Model, nonexhaustive } from "@likec4/core";
4
4
  import { Disposable, interruptAndCheck, URI, UriUtils } from "langium";
5
5
  import { DiagnosticSeverity } from "vscode-languageserver";
6
6
  import { isLikeC4LangiumDocument } from "./ast.js";
7
- import { Scheme } from "./likec4lib.js";
7
+ import { isLikeC4Builtin } from "./likec4lib.js";
8
8
  import {
9
- buildDocuments,
10
- changeView,
11
- computeView,
12
- fetchComputedModel,
13
- fetchModel,
14
- layoutView,
15
- locate,
9
+ BuildDocuments,
10
+ ChangeView,
11
+ ComputeView,
12
+ FetchComputedModel,
13
+ FetchLayoutedModel,
14
+ LayoutView,
15
+ Locate,
16
16
  onDidChangeModel,
17
- validateLayout
17
+ ValidateLayout
18
18
  } from "./protocol.js";
19
19
  import { ADisposable } from "./utils/index.js";
20
+ const logger = rootLogger.getChild("rpc");
20
21
  export class Rpc extends ADisposable {
21
22
  constructor(services) {
22
23
  super();
@@ -37,21 +38,24 @@ export class Rpc extends ADisposable {
37
38
  const DocumentBuilder = this.services.shared.workspace.DocumentBuilder;
38
39
  const notifyModelParsed = funnel(
39
40
  () => {
41
+ logger.debug`sendNotification ${"onDidChangeModel"}`;
40
42
  connection.sendNotification(onDidChangeModel, "").catch((e) => {
41
43
  logger.warn(`[ServerRpc] error sending onDidChangeModel: ${e}`);
42
44
  return Promise.resolve();
43
45
  });
44
46
  },
45
47
  {
46
- minQuietPeriodMs: 250,
47
- maxBurstDurationMs: 1e3,
48
- minGapMs: 200
48
+ triggerAt: "end",
49
+ minQuietPeriodMs: 150,
50
+ maxBurstDurationMs: 500,
51
+ minGapMs: 300
49
52
  }
50
53
  );
51
54
  let isFirstBuild = true;
52
55
  this.onDispose(
53
56
  modelBuilder.onModelParsed(() => notifyModelParsed.call()),
54
- connection.onRequest(fetchComputedModel, async ({ cleanCaches }, cancelToken) => {
57
+ connection.onRequest(FetchComputedModel.Req, async ({ cleanCaches }, cancelToken) => {
58
+ logger.debug`received request ${"fetchComputedModel"}`;
55
59
  if (cleanCaches) {
56
60
  const all = LangiumDocuments.all.map((d) => d.uri).toArray();
57
61
  await DocumentBuilder.update(all, [], cancelToken);
@@ -62,27 +66,38 @@ export class Rpc extends ADisposable {
62
66
  }
63
67
  return { model: null };
64
68
  }),
65
- connection.onRequest(fetchModel, async (cancelToken) => {
66
- const parsed = await modelBuilder.parseModel(cancelToken);
67
- return { model: parsed?.model ?? null };
68
- }),
69
- connection.onRequest(computeView, async ({ viewId }, cancelToken) => {
69
+ connection.onRequest(ComputeView.Req, async ({ viewId }, cancelToken) => {
70
70
  const view = await modelBuilder.computeView(viewId, cancelToken);
71
71
  return { view };
72
72
  }),
73
- connection.onRequest(layoutView, async ({ viewId }, cancelToken) => {
73
+ connection.onRequest(FetchLayoutedModel.Req, async (cancelToken) => {
74
+ const model = await modelBuilder.parseModel(cancelToken);
75
+ if (model === null) {
76
+ return { model: null };
77
+ }
78
+ const diagrams = await views.diagrams();
79
+ return {
80
+ model: {
81
+ ...model,
82
+ __: "layouted",
83
+ views: indexBy(diagrams, (d) => d.id)
84
+ }
85
+ };
86
+ }),
87
+ connection.onRequest(LayoutView.Req, async ({ viewId }, cancelToken) => {
88
+ logger.debug`received request ${"layoutView"} of ${viewId}`;
74
89
  const result = await views.layoutView(viewId, cancelToken);
75
90
  return { result };
76
91
  }),
77
- connection.onRequest(validateLayout, async (_, cancelToken) => {
92
+ connection.onRequest(ValidateLayout.Req, async (cancelToken) => {
78
93
  const layouts = await views.layoutAllViews(cancelToken);
79
94
  const result = reportLayoutDrift(layouts.map((l) => l.diagram));
80
95
  return { result };
81
96
  }),
82
- connection.onRequest(buildDocuments, async ({ docs }, cancelToken) => {
97
+ connection.onRequest(BuildDocuments.Req, async ({ docs }, cancelToken) => {
83
98
  const changed = docs.map((d) => URI.parse(d));
84
99
  const notChanged = (uri) => changed.every((c) => !UriUtils.equals(c, uri));
85
- const deleted = LangiumDocuments.all.filter((d) => isLikeC4LangiumDocument(d) && notChanged(d.uri) && d.uri.scheme !== Scheme).map((d) => d.uri).toArray();
100
+ const deleted = LangiumDocuments.all.toArray().filter((d) => !isLikeC4Builtin(d.uri) && isLikeC4LangiumDocument(d) && notChanged(d.uri)).map((d) => d.uri);
86
101
  logger.debug(
87
102
  `[ServerRpc] received request to build:
88
103
  changed (total ${changed.length}):${docs.map((d) => "\n - " + d).join("")}
@@ -108,7 +123,7 @@ export class Rpc extends ADisposable {
108
123
  await interruptAndCheck(cancelToken);
109
124
  await DocumentBuilder.update(changed, deleted, cancelToken);
110
125
  }),
111
- connection.onRequest(locate, (params) => {
126
+ connection.onRequest(Locate.Req, (params) => {
112
127
  switch (true) {
113
128
  case "element" in params:
114
129
  return modelLocator.locateElement(params.element, params.property ?? "name");
@@ -122,7 +137,8 @@ export class Rpc extends ADisposable {
122
137
  nonexhaustive(params);
123
138
  }
124
139
  }),
125
- connection.onRequest(changeView, async (request, _cancelToken) => {
140
+ connection.onRequest(ChangeView.Req, async (request, _cancelToken) => {
141
+ logger.debug`received request ${"changeView"} of ${request.viewId}`;
126
142
  return await modelEditor.applyChange(request);
127
143
  }),
128
144
  Disposable.create(() => {