@likec4/language-server 1.24.1 → 1.25.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.
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { startLanguageServer } from '.../dist/bundled.mjs'
3
+ import { startLanguageServer } from '../dist/bundled.mjs'
4
4
 
5
5
  startLanguageServer().catch((e) => {
6
6
  console.error(e)
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
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,20 +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
- triggerAt: "both",
47
- minGapMs: 350
48
+ triggerAt: "end",
49
+ minQuietPeriodMs: 150,
50
+ maxBurstDurationMs: 500,
51
+ minGapMs: 300
48
52
  }
49
53
  );
50
54
  let isFirstBuild = true;
51
55
  this.onDispose(
52
56
  modelBuilder.onModelParsed(() => notifyModelParsed.call()),
53
- connection.onRequest(fetchComputedModel, async ({ cleanCaches }, cancelToken) => {
57
+ connection.onRequest(FetchComputedModel.Req, async ({ cleanCaches }, cancelToken) => {
58
+ logger.debug`received request ${"fetchComputedModel"}`;
54
59
  if (cleanCaches) {
55
60
  const all = LangiumDocuments.all.map((d) => d.uri).toArray();
56
61
  await DocumentBuilder.update(all, [], cancelToken);
@@ -61,24 +66,35 @@ export class Rpc extends ADisposable {
61
66
  }
62
67
  return { model: null };
63
68
  }),
64
- connection.onRequest(fetchModel, async (cancelToken) => {
65
- const model = await modelBuilder.parseModel(cancelToken);
66
- return { model };
67
- }),
68
- connection.onRequest(computeView, async ({ viewId }, cancelToken) => {
69
+ connection.onRequest(ComputeView.Req, async ({ viewId }, cancelToken) => {
69
70
  const view = await modelBuilder.computeView(viewId, cancelToken);
70
71
  return { view };
71
72
  }),
72
- 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}`;
73
89
  const result = await views.layoutView(viewId, cancelToken);
74
90
  return { result };
75
91
  }),
76
- connection.onRequest(validateLayout, async (_, cancelToken) => {
92
+ connection.onRequest(ValidateLayout.Req, async (cancelToken) => {
77
93
  const layouts = await views.layoutAllViews(cancelToken);
78
94
  const result = reportLayoutDrift(layouts.map((l) => l.diagram));
79
95
  return { result };
80
96
  }),
81
- connection.onRequest(buildDocuments, async ({ docs }, cancelToken) => {
97
+ connection.onRequest(BuildDocuments.Req, async ({ docs }, cancelToken) => {
82
98
  const changed = docs.map((d) => URI.parse(d));
83
99
  const notChanged = (uri) => changed.every((c) => !UriUtils.equals(c, uri));
84
100
  const deleted = LangiumDocuments.all.toArray().filter((d) => !isLikeC4Builtin(d.uri) && isLikeC4LangiumDocument(d) && notChanged(d.uri)).map((d) => d.uri);
@@ -107,7 +123,7 @@ export class Rpc extends ADisposable {
107
123
  await interruptAndCheck(cancelToken);
108
124
  await DocumentBuilder.update(changed, deleted, cancelToken);
109
125
  }),
110
- connection.onRequest(locate, (params) => {
126
+ connection.onRequest(Locate.Req, (params) => {
111
127
  switch (true) {
112
128
  case "element" in params:
113
129
  return modelLocator.locateElement(params.element, params.property ?? "name");
@@ -121,7 +137,8 @@ export class Rpc extends ADisposable {
121
137
  nonexhaustive(params);
122
138
  }
123
139
  }),
124
- connection.onRequest(changeView, async (request, _cancelToken) => {
140
+ connection.onRequest(ChangeView.Req, async (request, _cancelToken) => {
141
+ logger.debug`received request ${"changeView"} of ${request.viewId}`;
125
142
  return await modelEditor.applyChange(request);
126
143
  }),
127
144
  Disposable.create(() => {