@likec4/language-services 1.48.0 → 1.50.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.
@@ -13,12 +13,21 @@ var LikeC4 = class {
13
13
  this.langium = langium;
14
14
  this.logger = logger;
15
15
  }
16
+ /**
17
+ * File system path to the workspace root
18
+ */
16
19
  get workspace() {
17
20
  return this.langium.shared.workspace.WorkspaceManager.workspaceUri.fsPath;
18
21
  }
22
+ /**
23
+ * URI of the workspace root
24
+ */
19
25
  get workspaceURI() {
20
26
  return this.langium.shared.workspace.WorkspaceManager.workspaceUri;
21
27
  }
28
+ /**
29
+ * URL of the workspace root
30
+ */
22
31
  get workspaceURL() {
23
32
  return this.langium.shared.workspace.WorkspaceManager.workspaceURL;
24
33
  }
@@ -47,14 +56,32 @@ Please specify a project folder`);
47
56
  throw new Error(`Multiple projects found`);
48
57
  }
49
58
  }
59
+ /**
60
+ * Diagram is a computed view, layouted using Graphviz
61
+ * If diagram has manual layout, it will be used.
62
+ * Used in React components
63
+ */
50
64
  async diagrams(project) {
51
65
  const projectId = this.projectsManager.ensureProjectId(project);
52
66
  return await this.viewsService.diagrams(projectId);
53
67
  }
68
+ /**
69
+ * Builds LikeC4Model from all documents
70
+ * Only computes view predicates {@link ComputedView} - i.e. no layout
71
+ * Not ready for rendering, but enough to traverse
72
+ *
73
+ * Sync version does not read manual layouts
74
+ * Use {@link computedModel} for a version that includes manual layouts
75
+ */
54
76
  syncComputedModel(project) {
55
77
  const projectId = this.projectsManager.ensureProjectId(project);
56
78
  return this.modelBuilder.unsafeSyncComputeModel(projectId);
57
79
  }
80
+ /**
81
+ * Builds LikeC4Model from all documents
82
+ * Only computes view predicates {@link ComputedView} - i.e. no layout
83
+ * Not ready for rendering, but enough to traverse
84
+ */
58
85
  async computedModel(project) {
59
86
  const projectId = this.projectsManager.ensureProjectId(project);
60
87
  return await this.modelBuilder.computeModel(projectId);
@@ -62,6 +89,10 @@ Please specify a project folder`);
62
89
  projects() {
63
90
  return map(this.languageServices.projects(), prop("id"));
64
91
  }
92
+ /**
93
+ * Same as {@link computedModel()}, but also applies layout
94
+ * Ready for rendering
95
+ */
65
96
  async layoutedModel(project) {
66
97
  const projectId = this.projectsManager.ensureProjectId(project);
67
98
  return await this.languageServices.layoutedModel(projectId);
@@ -81,6 +112,9 @@ Please specify a project folder`);
81
112
  return doc.diagnostics?.some((d) => d.severity === DiagnosticSeverity.Error) ?? false;
82
113
  });
83
114
  }
115
+ /**
116
+ * @returns true if there are errors
117
+ */
84
118
  printErrors() {
85
119
  let hasErrors = false;
86
120
  for (const doc of this.LangiumDocuments.all) {
@@ -104,6 +138,9 @@ Please specify a project folder`);
104
138
  }
105
139
  return hasErrors;
106
140
  }
141
+ /**
142
+ * @returns a function to dispose the listener
143
+ */
107
144
  onModelUpdate(listener) {
108
145
  const sib = this.modelBuilder.onModelParsed(() => listener());
109
146
  return () => {
@@ -131,6 +168,9 @@ async function handleInitOptions(langium, logger = rootLogger, options) {
131
168
  if (opts.printErrors !== false && likec4.hasErrors()) likec4.printErrors();
132
169
  return likec4;
133
170
  }
171
+ /**
172
+ * Runtime-agnostic factory function to create a LikeC4 instance from sources
173
+ */
134
174
  async function createFromSources(langium, logger, sources, initOptions) {
135
175
  const uri = URI.from({
136
176
  scheme: "virtual",
@@ -1,5 +1,4 @@
1
1
  import { Logger } from "@likec4/log";
2
- import * as vscode_uri0 from "vscode-uri";
3
2
  import { LikeC4Model } from "@likec4/core/model";
4
3
  import { LayoutedView, NonEmptyArray, ProjectId } from "@likec4/core/types";
5
4
  import { LikeC4LanguageServices, LikeC4ModelBuilder, LikeC4Services, LikeC4SharedServices, LikeC4Views, ProjectsManager } from "@likec4/language-server";
@@ -16,15 +15,15 @@ declare class LikeC4 {
16
15
  /**
17
16
  * File system path to the workspace root
18
17
  */
19
- get workspace(): string;
18
+ get workspace(): any;
20
19
  /**
21
20
  * URI of the workspace root
22
21
  */
23
- get workspaceURI(): vscode_uri0.URI;
22
+ get workspaceURI(): any;
24
23
  /**
25
24
  * URL of the workspace root
26
25
  */
27
- get workspaceURL(): URL;
26
+ get workspaceURL(): any;
28
27
  get languageServices(): LikeC4LanguageServices;
29
28
  get projectsManager(): ProjectsManager;
30
29
  get viewsService(): LikeC4Views;
@@ -1,12 +1,38 @@
1
1
  import { t as createFromSources } from "../_chunks/createFromSources.mjs";
2
2
  import { configureLogger, getConsoleSink, getTextFormatter, rootLogger } from "@likec4/log";
3
3
  import { createLanguageServices } from "@likec4/language-server/browser";
4
+ /**
5
+ * Create a LikeC4 instance from a workspace directory
6
+ * @param _workspace - The workspace directory path
7
+ * @param options - Optional configuration options
8
+ * @returns A Promise that resolves to a LikeC4 instance
9
+ */
4
10
  async function fromWorkspace(_workspace, _options) {
5
11
  throw new Error(`fromWorkspace is not yet implemented in the browser environment. use fromSources`);
6
12
  }
13
+ /**
14
+ * Create a LikeC4 instance from the current working directory
15
+ * @param options - Optional configuration options
16
+ * @returns A Promise that resolves to a LikeC4 instance
17
+ */
7
18
  async function fromWorkdir(_options) {
8
19
  throw new Error(`fromWorkdir is not yet implemented in the browser environment, use fromSources`);
9
20
  }
21
+ /**
22
+ * Create a LikeC4 instance from a record of source files
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const likec4 = await fromSources({
27
+ * 'likec4.config.json': '...', // optional, stringified LikeC4Config
28
+ * 'model.c4': 'model { ... }',
29
+ * 'path/views.c4': 'views { ... }',
30
+ * })
31
+ * ```
32
+ *
33
+ * @param sources - A record of file paths to source content
34
+ * @returns A Promise that resolves to a LikeC4 instance
35
+ */
10
36
  async function fromSources(sources) {
11
37
  configureLogger({
12
38
  sinks: { console: getConsoleSink({ formatter: getTextFormatter({ format: ({ level, category, message }) => {
@@ -21,6 +47,12 @@ async function fromSources(sources) {
21
47
  const logger = rootLogger.getChild("lang");
22
48
  return await createFromSources(createLanguageServices(), logger, sources, {});
23
49
  }
50
+ /**
51
+ * Create a LikeC4 instance from a single source string
52
+ * @param source - The LikeC4 source code
53
+
54
+ * @returns A Promise that resolves to a LikeC4 instance
55
+ */
24
56
  async function fromSource(source) {
25
57
  return fromSources({ "source.c4": source });
26
58
  }
@@ -48,8 +48,18 @@ function createLanguageServices$1(opts) {
48
48
  });
49
49
  return langium;
50
50
  }
51
+ /**
52
+ * Create a LikeC4 instance from a workspace directory
53
+ * The instance is cached in globalThis to avoid creating multiple instances for the same workspace
54
+ *
55
+ * @param path - The workspace directory path
56
+ * @param options - Optional configuration options
57
+ * @returns A Promise that resolves to a LikeC4 instance
58
+ */
51
59
  async function fromWorkspace(path, options) {
52
60
  const workspacePath = resolve(path);
61
+ const folderUri = pathToFileURL(workspacePath).toString();
62
+ const workspaceUri = folderUri.endsWith("/") ? folderUri : folderUri + "/";
53
63
  return memoizeProp(globalThis, "likec4:" + workspacePath, async () => {
54
64
  const logger = rootLogger.getChild("lang");
55
65
  const langium = createLanguageServices$1(defu(options, {
@@ -60,7 +70,7 @@ async function fromWorkspace(path, options) {
60
70
  }));
61
71
  const workspace = {
62
72
  name: basename(workspacePath),
63
- uri: pathToFileURL(workspacePath).toString()
73
+ uri: workspaceUri
64
74
  };
65
75
  const WorkspaceManager = langium.shared.workspace.WorkspaceManager;
66
76
  logger.info(`${k.dim("workspace:")} ${workspacePath}`);
@@ -80,9 +90,30 @@ async function fromWorkspace(path, options) {
80
90
  return handleInitOptions(langium, rootLogger, options);
81
91
  });
82
92
  }
93
+ /**
94
+ * Create a LikeC4 instance from the current working directory
95
+ * @param options - Optional configuration options
96
+ * @returns A Promise that resolves to a LikeC4 instance
97
+ */
83
98
  async function fromWorkdir(options) {
84
99
  return fromWorkspace(".", options);
85
100
  }
101
+ /**
102
+ * Create a LikeC4 instance from a record of source files
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const likec4 = await fromSources({
107
+ * 'likec4.config.json': '...', // optional, stringified LikeC4Config
108
+ * 'model.c4': 'model { ... }',
109
+ * 'path/views.c4': 'views { ... }',
110
+ * })
111
+ * ```
112
+ *
113
+ * @param sources - A record of file paths to source content
114
+ * @param options - Optional configuration options
115
+ * @returns A Promise that resolves to a LikeC4 instance
116
+ */
86
117
  async function fromSources(sources, options) {
87
118
  const logger = rootLogger.getChild("lang");
88
119
  return await createFromSources(createLanguageServices$1(defu(options, {
@@ -92,6 +123,12 @@ async function fromSources(sources, options) {
92
123
  mcp: false
93
124
  })), logger, sources, options);
94
125
  }
126
+ /**
127
+ * Create a LikeC4 instance from a single source string
128
+ * @param source - The LikeC4 source code
129
+ * @param options - Optional configuration options
130
+ * @returns A Promise that resolves to a LikeC4 instance
131
+ */
95
132
  async function fromSource(source, options) {
96
133
  return fromSources({ "source.c4": source }, options);
97
134
  }
@@ -27,8 +27,18 @@ function createLanguageServices$1(opts) {
27
27
  ...NoLikeC4ManualLayouts
28
28
  } }, { likec4: { Layouter: () => new QueueGraphvizLayoter({ graphviz: useDotBin ? new GraphvizBinaryAdapter() : new GraphvizWasmAdapter() }) } });
29
29
  }
30
+ /**
31
+ * Create a LikeC4 instance from a workspace directory
32
+ * The instance is cached in globalThis to avoid creating multiple instances for the same workspace
33
+ *
34
+ * @param path - The workspace directory path
35
+ * @param options - Optional configuration options
36
+ * @returns A Promise that resolves to a LikeC4 instance
37
+ */
30
38
  async function fromWorkspace(path, options) {
31
39
  const workspacePath = resolve(path);
40
+ const folderUri = pathToFileURL(workspacePath).toString();
41
+ const workspaceUri = folderUri.endsWith("/") ? folderUri : folderUri + "/";
32
42
  return memoizeProp(globalThis, "likec4:" + workspacePath, async () => {
33
43
  const logger = rootLogger.getChild("lang");
34
44
  const mergedOptions = defu(options, {
@@ -40,7 +50,7 @@ async function fromWorkspace(path, options) {
40
50
  const langium = createLanguageServices$1(mergedOptions);
41
51
  const workspace = {
42
52
  name: basename(workspacePath),
43
- uri: pathToFileURL(workspacePath).toString()
53
+ uri: workspaceUri
44
54
  };
45
55
  const WorkspaceManager = langium.shared.workspace.WorkspaceManager;
46
56
  logger.info(`${k.dim("workspace:")} ${workspacePath}`);
@@ -60,9 +70,30 @@ async function fromWorkspace(path, options) {
60
70
  return handleInitOptions(langium, rootLogger, options);
61
71
  });
62
72
  }
73
+ /**
74
+ * Create a LikeC4 instance from the current working directory
75
+ * @param options - Optional configuration options
76
+ * @returns A Promise that resolves to a LikeC4 instance
77
+ */
63
78
  async function fromWorkdir(options) {
64
79
  return fromWorkspace(".", options);
65
80
  }
81
+ /**
82
+ * Create a LikeC4 instance from a record of source files
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const likec4 = await fromSources({
87
+ * 'likec4.config.json': '...', // optional, stringified LikeC4Config
88
+ * 'model.c4': 'model { ... }',
89
+ * 'path/views.c4': 'views { ... }',
90
+ * })
91
+ * ```
92
+ *
93
+ * @param sources - A record of file paths to source content
94
+ * @param options - Optional configuration options
95
+ * @returns A Promise that resolves to a LikeC4 instance
96
+ */
66
97
  async function fromSources(sources, options) {
67
98
  const logger = rootLogger.getChild("lang");
68
99
  return await createFromSources(createLanguageServices$1(defu(options, {
@@ -71,6 +102,12 @@ async function fromSources(sources, options) {
71
102
  manualLayouts: false
72
103
  })), logger, sources, options);
73
104
  }
105
+ /**
106
+ * Create a LikeC4 instance from a single source string
107
+ * @param source - The LikeC4 source code
108
+ * @param options - Optional configuration options
109
+ * @returns A Promise that resolves to a LikeC4 instance
110
+ */
74
111
  async function fromSource(source, options) {
75
112
  return fromSources({ "source.c4": source }, options);
76
113
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@likec4/language-services",
3
3
  "description": "LikeC4 Language Services",
4
- "version": "1.48.0",
4
+ "version": "1.50.0",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -77,24 +77,24 @@
77
77
  "std-env": "^3.10.0",
78
78
  "type-fest": "^4.41.0",
79
79
  "vscode-languageserver-types": "3.17.5",
80
- "@likec4/config": "1.48.0",
81
- "@likec4/core": "1.48.0",
82
- "@likec4/generators": "1.48.0",
80
+ "@likec4/config": "1.50.0",
81
+ "@likec4/core": "1.50.0",
82
+ "@likec4/generators": "1.50.0",
83
83
  "@likec4/icons": "1.46.4",
84
- "@likec4/language-server": "1.48.0",
85
- "@likec4/layouts": "1.48.0",
86
- "@likec4/log": "1.48.0"
84
+ "@likec4/language-server": "1.50.0",
85
+ "@likec4/log": "1.50.0",
86
+ "@likec4/layouts": "1.50.0"
87
87
  },
88
88
  "devDependencies": {
89
- "@types/node": "~22.19.10",
90
- "obuild": "^0.4.27",
89
+ "@types/node": "~22.19.11",
90
+ "obuild": "^0.4.31",
91
91
  "oxlint": "1.43.0",
92
92
  "tsx": "4.21.0",
93
- "turbo": "2.8.3",
93
+ "turbo": "2.8.10",
94
94
  "typescript": "5.9.3",
95
95
  "vitest": "4.0.18",
96
- "@likec4/tsconfig": "1.48.0",
97
- "@likec4/devops": "1.42.0"
96
+ "@likec4/devops": "1.42.0",
97
+ "@likec4/tsconfig": "1.50.0"
98
98
  },
99
99
  "scripts": {
100
100
  "typecheck": "tsc -b --verbose",