@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.
@@ -1,79 +1,106 @@
1
- import type { ComputedLikeC4Model, ComputedView, DiagramView, Fqn, ParsedLikeC4Model, RelationId, ViewChange, ViewId } from '@likec4/core';
1
+ import type { ComputedLikeC4Model, ComputedView, DiagramView, Fqn, LayoutedLikeC4Model, RelationId, ViewChange, ViewId } from '@likec4/core';
2
2
  import { NotificationType, RequestType, RequestType0 } from 'vscode-jsonrpc';
3
3
  import type { DiagnosticSeverity, DocumentUri, Location, Position } from 'vscode-languageserver-types';
4
4
  export declare const onDidChangeModel: NotificationType<string>;
5
5
  export type OnDidChangeModelNotification = typeof onDidChangeModel;
6
- export declare const fetchModel: RequestType0<{
7
- model: ParsedLikeC4Model | null;
8
- }, void>;
9
- export type FetchModelRequest = typeof fetchModel;
10
- export declare const fetchComputedModel: RequestType<{
11
- cleanCaches?: boolean | undefined;
12
- }, {
13
- model: ComputedLikeC4Model | null;
14
- }, void>;
15
- export type FetchComputedModelRequest = typeof fetchComputedModel;
16
- export declare const computeView: RequestType<{
17
- viewId: ViewId;
18
- }, {
19
- view: ComputedView | null;
20
- }, void>;
21
- export type ComputeViewRequest = typeof computeView;
6
+ export declare namespace FetchComputedModel {
7
+ type Params = {
8
+ cleanCaches?: boolean | undefined;
9
+ };
10
+ type Res = {
11
+ model: ComputedLikeC4Model | null;
12
+ };
13
+ const Req: RequestType<Params, Res, void>;
14
+ type Req = typeof Req;
15
+ }
16
+ export declare namespace ComputeView {
17
+ type Params = {
18
+ viewId: ViewId;
19
+ };
20
+ type Result = {
21
+ view: ComputedView | null;
22
+ };
23
+ const Req: RequestType<Params, Result, void>;
24
+ type Req = typeof Req;
25
+ }
26
+ export declare namespace FetchLayoutedModel {
27
+ type Res = {
28
+ model: LayoutedLikeC4Model | null;
29
+ };
30
+ const Req: RequestType0<Res, void>;
31
+ type Req = typeof Req;
32
+ }
22
33
  /**
23
34
  * Request to layout a view.
24
35
  */
25
- export declare const layoutView: RequestType<{
26
- viewId: ViewId;
27
- }, {
28
- result: {
29
- dot: string;
30
- diagram: DiagramView;
31
- } | null;
32
- }, void>;
33
- export type LayoutViewRequest = typeof layoutView;
36
+ export declare namespace LayoutView {
37
+ type Params = {
38
+ viewId: ViewId;
39
+ };
40
+ type Res = {
41
+ result: {
42
+ dot: string;
43
+ diagram: DiagramView;
44
+ } | null;
45
+ };
46
+ const Req: RequestType<Params, Res, void>;
47
+ type Req = typeof Req;
48
+ }
34
49
  /**
35
50
  * Request to layout all existing views.
36
51
  */
37
- export declare const validateLayout: RequestType<{}, {
38
- result: {
39
- uri: string;
40
- viewId: ViewId;
41
- message: string;
42
- severity: DiagnosticSeverity;
43
- range: {
44
- start: Position;
45
- end: Position;
46
- };
47
- }[] | null;
48
- }, void>;
49
- export type ValidateLayoutRequest = typeof validateLayout;
52
+ export declare namespace ValidateLayout {
53
+ type Params = never;
54
+ type Res = {
55
+ result: {
56
+ uri: string;
57
+ viewId: ViewId;
58
+ message: string;
59
+ severity: DiagnosticSeverity;
60
+ range: {
61
+ start: Position;
62
+ end: Position;
63
+ };
64
+ }[] | null;
65
+ };
66
+ const Req: RequestType0<Res, void>;
67
+ type Req = typeof Req;
68
+ }
50
69
  /**
51
70
  * Request to build documents.
52
71
  */
53
- export interface BuildDocumentsParams {
54
- docs: DocumentUri[];
72
+ export declare namespace BuildDocuments {
73
+ type Params = {
74
+ docs: DocumentUri[];
75
+ };
76
+ const Req: RequestType<Params, void, void>;
77
+ type Req = typeof Req;
55
78
  }
56
- export declare const buildDocuments: RequestType<BuildDocumentsParams, void, void>;
57
- export type BuildDocumentsRequest = typeof buildDocuments;
58
79
  /**
59
80
  * Request to locate an element, relation, deployment or view.
60
81
  */
61
- export type LocateParams = {
62
- element: Fqn;
63
- property?: string;
64
- } | {
65
- relation: RelationId;
66
- } | {
67
- deployment: Fqn;
68
- property?: string;
69
- } | {
70
- view: ViewId;
71
- };
72
- export declare const locate: RequestType<LocateParams, Location | null, void>;
73
- export type LocateRequest = typeof locate;
74
- export interface ChangeViewRequestParams {
75
- viewId: ViewId;
76
- change: ViewChange;
82
+ export declare namespace Locate {
83
+ type Params = {
84
+ element: Fqn;
85
+ property?: string;
86
+ } | {
87
+ relation: RelationId;
88
+ } | {
89
+ deployment: Fqn;
90
+ property?: string;
91
+ } | {
92
+ view: ViewId;
93
+ };
94
+ type Res = Location | null;
95
+ const Req: RequestType<Params, Res, void>;
96
+ type Req = typeof Req;
97
+ }
98
+ export declare namespace ChangeView {
99
+ type Params = {
100
+ viewId: ViewId;
101
+ change: ViewChange;
102
+ };
103
+ type Res = Location | null;
104
+ const Req: RequestType<Params, Res, void>;
105
+ type Req = typeof Req;
77
106
  }
78
- export declare const changeView: RequestType<ChangeViewRequestParams, Location | null, void>;
79
- export type ChangeViewRequest = typeof changeView;
package/dist/protocol.js CHANGED
@@ -1,16 +1,34 @@
1
1
  import { NotificationType, RequestType, RequestType0 } from "vscode-jsonrpc";
2
2
  export const onDidChangeModel = new NotificationType("likec4/onDidChangeModel");
3
- export const fetchModel = new RequestType0(
4
- "likec4/fetchModel"
5
- );
6
- export const fetchComputedModel = new RequestType(
7
- "likec4/fetchComputedModel"
8
- );
9
- export const computeView = new RequestType(
10
- "likec4/computeView"
11
- );
12
- export const layoutView = new RequestType("likec4/layout-view");
13
- export const validateLayout = new RequestType("likec4/validate-layout");
14
- export const buildDocuments = new RequestType("likec4/build");
15
- export const locate = new RequestType("likec4/locate");
16
- export const changeView = new RequestType("likec4/change-view");
3
+ export var FetchComputedModel;
4
+ ((FetchComputedModel2) => {
5
+ FetchComputedModel2.Req = new RequestType("likec4/fetchComputedModel");
6
+ })(FetchComputedModel || (FetchComputedModel = {}));
7
+ export var ComputeView;
8
+ ((ComputeView2) => {
9
+ ComputeView2.Req = new RequestType("likec4/computeView");
10
+ })(ComputeView || (ComputeView = {}));
11
+ export var FetchLayoutedModel;
12
+ ((FetchLayoutedModel2) => {
13
+ FetchLayoutedModel2.Req = new RequestType0("likec4/fetchLayoutedModel");
14
+ })(FetchLayoutedModel || (FetchLayoutedModel = {}));
15
+ export var LayoutView;
16
+ ((LayoutView2) => {
17
+ LayoutView2.Req = new RequestType("likec4/layout-view");
18
+ })(LayoutView || (LayoutView = {}));
19
+ export var ValidateLayout;
20
+ ((ValidateLayout2) => {
21
+ ValidateLayout2.Req = new RequestType0("likec4/validate-layout");
22
+ })(ValidateLayout || (ValidateLayout = {}));
23
+ export var BuildDocuments;
24
+ ((BuildDocuments2) => {
25
+ BuildDocuments2.Req = new RequestType("likec4/build");
26
+ })(BuildDocuments || (BuildDocuments = {}));
27
+ export var Locate;
28
+ ((Locate2) => {
29
+ Locate2.Req = new RequestType("likec4/locate");
30
+ })(Locate || (Locate = {}));
31
+ export var ChangeView;
32
+ ((ChangeView2) => {
33
+ ChangeView2.Req = new RequestType("likec4/change-view");
34
+ })(ChangeView || (ChangeView = {}));
@@ -20,11 +20,8 @@ export function createTestServices(workspace = "file:///test/workspace") {
20
20
  let documentIndex = 1;
21
21
  const addDocument = async (input, uri) => {
22
22
  if (!isInitialized) {
23
+ isInitialized = true;
23
24
  await services.shared.workspace.WorkspaceLock.write(async (_cancelToken) => {
24
- if (isInitialized) {
25
- return;
26
- }
27
- isInitialized = true;
28
25
  services.shared.workspace.WorkspaceManager.initialize({
29
26
  capabilities: {},
30
27
  processId: null,
@@ -88,7 +85,6 @@ export function createTestServices(workspace = "file:///test/workspace") {
88
85
  await services.shared.workspace.WorkspaceLock.write(async (cancelToken) => {
89
86
  await documentBuilder.build(docs, { validation: true }, cancelToken);
90
87
  });
91
- await documentBuilder.waitUntil(DocumentState.Validated);
92
88
  const diagnostics = docs.flatMap((doc) => doc.diagnostics ?? []);
93
89
  const warnings = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Warning ? d.message : []);
94
90
  const errors = diagnostics.flatMap((d) => d.severity === DiagnosticSeverity.Error ? d.message : []);
@@ -99,13 +95,17 @@ export function createTestServices(workspace = "file:///test/workspace") {
99
95
  };
100
96
  };
101
97
  const buildModel = async () => {
102
- await validateAll();
98
+ if (langiumDocuments.all.some((doc) => doc.state < DocumentState.Validated)) {
99
+ await validateAll();
100
+ }
103
101
  const likec4model = await modelBuilder.buildLikeC4Model();
104
102
  if (!likec4model) throw new Error("No model found");
105
103
  return likec4model.$model;
106
104
  };
107
105
  const buildLikeC4Model = async () => {
108
- await validateAll();
106
+ if (langiumDocuments.all.some((doc) => doc.state < DocumentState.Validated)) {
107
+ await validateAll();
108
+ }
109
109
  const likec4model = await modelBuilder.buildLikeC4Model();
110
110
  if (!likec4model) throw new Error("No model found");
111
111
  return likec4model;
@@ -1,5 +1,8 @@
1
+ import { loggable } from "@likec4/log";
2
+ import prettyMs from "pretty-ms";
1
3
  import { values } from "remeda";
2
- import { logError, logWarnError } from "../logger.js";
4
+ import { logError, logger as rootLogger, logWarnError } from "../logger.js";
5
+ const logger = rootLogger.getChild("Views");
3
6
  export class LikeC4Views {
4
7
  constructor(services) {
5
8
  this.services = services;
@@ -20,6 +23,7 @@ export class LikeC4Views {
20
23
  if (views.length === 0) {
21
24
  return [];
22
25
  }
26
+ logger.debug`layoutAll: ${views.length} views`;
23
27
  const results = [];
24
28
  const tasks = [];
25
29
  for (const view of views) {
@@ -41,26 +45,35 @@ export class LikeC4Views {
41
45
  results.push(task.value);
42
46
  }
43
47
  }
48
+ if (results.length !== views.length) {
49
+ logger.warn`layouted ${results.length} of ${views.length} views`;
50
+ } else if (results.length > 0) {
51
+ logger.debug`layouted all ${results.length} views`;
52
+ }
44
53
  return results;
45
54
  }
46
55
  async layoutView(viewId, cancelToken) {
47
56
  const model = await this.ModelBuilder.buildLikeC4Model(cancelToken);
48
57
  const view = model.findView(viewId)?.$view;
49
58
  if (!view) {
59
+ logger.warn`layoutView ${viewId} not found`;
50
60
  return null;
51
61
  }
52
62
  let cached = this.cache.get(view);
53
63
  if (cached) {
64
+ logger.debug`layout ${viewId} from cache`;
54
65
  return await Promise.resolve(cached);
55
66
  }
56
67
  try {
68
+ const start = performance.now();
57
69
  const result = await this.layouter.layout(view);
58
70
  this.viewsWithReportedErrors.delete(viewId);
59
71
  this.cache.set(view, result);
72
+ logger.debug(`layout {viewId} ready in ${prettyMs(performance.now() - start)}`, { viewId });
60
73
  return result;
61
74
  } catch (e) {
62
75
  if (!this.viewsWithReportedErrors.has(viewId)) {
63
- const errMessage = e instanceof Error ? e.message : "" + e;
76
+ const errMessage = loggable(e);
64
77
  this.services.shared.lsp.Connection?.window.showErrorMessage(`LikeC4: ${errMessage}`);
65
78
  this.viewsWithReportedErrors.add(viewId);
66
79
  logError(e);
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.24.0",
4
+ "version": "1.25.0",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -80,15 +80,13 @@
80
80
  "registry": "https://registry.npmjs.org",
81
81
  "access": "public"
82
82
  },
83
- "dependencies": {
84
- "@hpcc-js/wasm-graphviz": "1.7.0"
85
- },
86
83
  "devDependencies": {
87
- "@msgpack/msgpack": "^3.0.0",
84
+ "@hpcc-js/wasm-graphviz": "1.7.0",
85
+ "@msgpack/msgpack": "^3.1.0",
88
86
  "@smithy/util-base64": "^4.0.0",
89
87
  "@types/node": "^20.17.17",
90
88
  "@types/which": "^3.0.4",
91
- "@vitest/coverage-v8": "^3.0.4",
89
+ "@vitest/coverage-v8": "^3.0.6",
92
90
  "esm-env": "^1.2.2",
93
91
  "fast-equals": "^5.2.2",
94
92
  "fdir": "^6.4.3",
@@ -98,25 +96,26 @@
98
96
  "langium-cli": "3.3.0",
99
97
  "natural-compare-lite": "^1.4.0",
100
98
  "p-debounce": "^4.0.0",
101
- "remeda": "^2.20.1",
99
+ "pretty-ms": "^9.2.0",
100
+ "remeda": "^2.20.2",
102
101
  "strip-indent": "^4.0.0",
103
- "tsx": "~4.19.2",
102
+ "tsx": "~4.19.3",
104
103
  "turbo": "^2.4.2",
105
104
  "type-fest": "4.34.1",
106
105
  "typescript": "5.7.3",
107
106
  "ufo": "^1.5.4",
108
107
  "unbuild": "^3.3.1",
109
- "vitest": "^3.0.4",
108
+ "vitest": "^3.0.6",
110
109
  "vscode-jsonrpc": "8.2.0",
111
110
  "vscode-languageserver": "9.0.1",
112
111
  "vscode-languageserver-types": "3.17.5",
113
112
  "vscode-uri": "3.1.0",
114
113
  "which": "^5.0.0",
115
- "@likec4/core": "1.24.0",
116
- "@likec4/icons": "1.24.0",
117
- "@likec4/log": "1.24.0",
118
- "@likec4/tsconfig": "1.24.0",
119
- "@likec4/layouts": "1.24.0"
114
+ "@likec4/core": "1.25.0",
115
+ "@likec4/layouts": "1.25.0",
116
+ "@likec4/log": "1.25.0",
117
+ "@likec4/tsconfig": "1.25.0",
118
+ "@likec4/icons": "1.25.0"
120
119
  },
121
120
  "scripts": {
122
121
  "typecheck": "tsc --noEmit",
@@ -125,7 +124,7 @@
125
124
  "watch:langium": "langium generate --watch",
126
125
  "watch:ts": "tsc --watch",
127
126
  "generate": "langium generate && tsx scripts/generate-icons.ts",
128
- "dev": "run-p 'watch:*'",
127
+ "dev": "run-p \"watch:*\"",
129
128
  "lint": "run -T eslint src/ --fix",
130
129
  "clean": "rm -r -f dist contrib",
131
130
  "test": "vitest run --no-isolate",