@likec4/language-services 1.49.0 → 1.51.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/_chunks/configureLogger.mjs +19 -0
- package/dist/_chunks/createFromSources.mjs +51 -8
- package/dist/_chunks/options.d.mts +18 -3
- package/dist/browser/index.mjs +32 -0
- package/dist/node/index.mjs +50 -16
- package/dist/node/without-mcp/index.mjs +54 -11
- package/package.json +14 -13
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { configureLanguageServerLogger } from "@likec4/language-server";
|
|
2
|
+
import { isColorSupported } from "std-env";
|
|
3
|
+
function configureLogger(options) {
|
|
4
|
+
const opt = options?.configureLogger ?? "console";
|
|
5
|
+
if (opt === false) return;
|
|
6
|
+
if (opt === "stderr" || options?.mcp === "stdio") {
|
|
7
|
+
configureLanguageServerLogger({
|
|
8
|
+
useStdErr: true,
|
|
9
|
+
colors: false,
|
|
10
|
+
logLevel: options?.logLevel
|
|
11
|
+
});
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
configureLanguageServerLogger({
|
|
15
|
+
colors: isColorSupported,
|
|
16
|
+
logLevel: options?.logLevel
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export { configureLogger as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { loggable, rootLogger } from "@likec4/log";
|
|
2
|
-
import defu from "defu";
|
|
3
2
|
import { extname } from "pathe";
|
|
4
3
|
import k from "tinyrainbow";
|
|
5
4
|
import { LikeC4ProjectConfigOps, isLikeC4JsonConfig } from "@likec4/config";
|
|
@@ -13,12 +12,21 @@ var LikeC4 = class {
|
|
|
13
12
|
this.langium = langium;
|
|
14
13
|
this.logger = logger;
|
|
15
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* File system path to the workspace root
|
|
17
|
+
*/
|
|
16
18
|
get workspace() {
|
|
17
19
|
return this.langium.shared.workspace.WorkspaceManager.workspaceUri.fsPath;
|
|
18
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* URI of the workspace root
|
|
23
|
+
*/
|
|
19
24
|
get workspaceURI() {
|
|
20
25
|
return this.langium.shared.workspace.WorkspaceManager.workspaceUri;
|
|
21
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* URL of the workspace root
|
|
29
|
+
*/
|
|
22
30
|
get workspaceURL() {
|
|
23
31
|
return this.langium.shared.workspace.WorkspaceManager.workspaceURL;
|
|
24
32
|
}
|
|
@@ -47,14 +55,32 @@ Please specify a project folder`);
|
|
|
47
55
|
throw new Error(`Multiple projects found`);
|
|
48
56
|
}
|
|
49
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Diagram is a computed view, layouted using Graphviz
|
|
60
|
+
* If diagram has manual layout, it will be used.
|
|
61
|
+
* Used in React components
|
|
62
|
+
*/
|
|
50
63
|
async diagrams(project) {
|
|
51
64
|
const projectId = this.projectsManager.ensureProjectId(project);
|
|
52
65
|
return await this.viewsService.diagrams(projectId);
|
|
53
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Builds LikeC4Model from all documents
|
|
69
|
+
* Only computes view predicates {@link ComputedView} - i.e. no layout
|
|
70
|
+
* Not ready for rendering, but enough to traverse
|
|
71
|
+
*
|
|
72
|
+
* Sync version does not read manual layouts
|
|
73
|
+
* Use {@link computedModel} for a version that includes manual layouts
|
|
74
|
+
*/
|
|
54
75
|
syncComputedModel(project) {
|
|
55
76
|
const projectId = this.projectsManager.ensureProjectId(project);
|
|
56
77
|
return this.modelBuilder.unsafeSyncComputeModel(projectId);
|
|
57
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Builds LikeC4Model from all documents
|
|
81
|
+
* Only computes view predicates {@link ComputedView} - i.e. no layout
|
|
82
|
+
* Not ready for rendering, but enough to traverse
|
|
83
|
+
*/
|
|
58
84
|
async computedModel(project) {
|
|
59
85
|
const projectId = this.projectsManager.ensureProjectId(project);
|
|
60
86
|
return await this.modelBuilder.computeModel(projectId);
|
|
@@ -62,6 +88,10 @@ Please specify a project folder`);
|
|
|
62
88
|
projects() {
|
|
63
89
|
return map(this.languageServices.projects(), prop("id"));
|
|
64
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Same as {@link computedModel()}, but also applies layout
|
|
93
|
+
* Ready for rendering
|
|
94
|
+
*/
|
|
65
95
|
async layoutedModel(project) {
|
|
66
96
|
const projectId = this.projectsManager.ensureProjectId(project);
|
|
67
97
|
return await this.languageServices.layoutedModel(projectId);
|
|
@@ -81,6 +111,9 @@ Please specify a project folder`);
|
|
|
81
111
|
return doc.diagnostics?.some((d) => d.severity === DiagnosticSeverity.Error) ?? false;
|
|
82
112
|
});
|
|
83
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* @returns true if there are errors
|
|
116
|
+
*/
|
|
84
117
|
printErrors() {
|
|
85
118
|
let hasErrors = false;
|
|
86
119
|
for (const doc of this.LangiumDocuments.all) {
|
|
@@ -104,6 +137,9 @@ Please specify a project folder`);
|
|
|
104
137
|
}
|
|
105
138
|
return hasErrors;
|
|
106
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* @returns a function to dispose the listener
|
|
142
|
+
*/
|
|
107
143
|
onModelUpdate(listener) {
|
|
108
144
|
const sib = this.modelBuilder.onModelParsed(() => listener());
|
|
109
145
|
return () => {
|
|
@@ -117,20 +153,27 @@ Please specify a project folder`);
|
|
|
117
153
|
await this.dispose();
|
|
118
154
|
}
|
|
119
155
|
};
|
|
156
|
+
const DefaultInitOptions = {
|
|
157
|
+
printErrors: true,
|
|
158
|
+
throwIfInvalid: false,
|
|
159
|
+
graphviz: "wasm",
|
|
160
|
+
mcp: false,
|
|
161
|
+
configureLogger: false,
|
|
162
|
+
logLevel: void 0
|
|
163
|
+
};
|
|
120
164
|
const validationErrorsToError = (likec4) => /* @__PURE__ */ new Error(`Invalid model:\n${likec4.getErrors().map((e) => ` ${e.sourceFsPath}:${e.line} ${e.message.slice(0, 200)}`).join("\n")}`);
|
|
121
165
|
async function handleInitOptions(langium, logger = rootLogger, options) {
|
|
122
166
|
const likec4 = new LikeC4(langium, logger);
|
|
123
|
-
|
|
124
|
-
printErrors: true,
|
|
125
|
-
throwIfInvalid: false
|
|
126
|
-
});
|
|
127
|
-
if (opts.throwIfInvalid === true && likec4.hasErrors()) {
|
|
167
|
+
if ((options?.throwIfInvalid ?? DefaultInitOptions.throwIfInvalid) === true && likec4.hasErrors()) {
|
|
128
168
|
await likec4.dispose();
|
|
129
169
|
return Promise.reject(validationErrorsToError(likec4));
|
|
130
170
|
}
|
|
131
|
-
if (
|
|
171
|
+
if ((options?.printErrors ?? DefaultInitOptions.printErrors) && likec4.hasErrors()) likec4.printErrors();
|
|
132
172
|
return likec4;
|
|
133
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Runtime-agnostic factory function to create a LikeC4 instance from sources
|
|
176
|
+
*/
|
|
134
177
|
async function createFromSources(langium, logger, sources, initOptions) {
|
|
135
178
|
const uri = URI.from({
|
|
136
179
|
scheme: "virtual",
|
|
@@ -169,4 +212,4 @@ async function createFromSources(langium, logger, sources, initOptions) {
|
|
|
169
212
|
await langium.shared.workspace.DocumentBuilder.build(docs, { validation: true });
|
|
170
213
|
return handleInitOptions(langium, logger, initOptions);
|
|
171
214
|
}
|
|
172
|
-
export { handleInitOptions as n,
|
|
215
|
+
export { LikeC4 as i, handleInitOptions as n, DefaultInitOptions as r, createFromSources as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger } from "@likec4/log";
|
|
2
|
+
import { LikeC4LanguageServices, LikeC4ModelBuilder, LikeC4Services, LikeC4SharedServices, LikeC4Views, ProjectsManager } from "@likec4/language-server";
|
|
2
3
|
import { LikeC4Model } from "@likec4/core/model";
|
|
3
4
|
import { LayoutedView, NonEmptyArray, ProjectId } from "@likec4/core/types";
|
|
4
|
-
import { LikeC4LanguageServices, LikeC4ModelBuilder, LikeC4Services, LikeC4SharedServices, LikeC4Views, ProjectsManager } from "@likec4/language-server";
|
|
5
5
|
|
|
6
6
|
//#region src/common/LikeC4.d.ts
|
|
7
7
|
interface LikeC4Langium {
|
|
@@ -86,7 +86,7 @@ declare class LikeC4 {
|
|
|
86
86
|
}
|
|
87
87
|
//#endregion
|
|
88
88
|
//#region src/common/options.d.ts
|
|
89
|
-
|
|
89
|
+
interface InitOptions {
|
|
90
90
|
/**
|
|
91
91
|
* By default, if LikeC4 model is invalid, errors are printed to the console.
|
|
92
92
|
* Disable this behavior by setting this option to false.
|
|
@@ -115,7 +115,22 @@ type InitOptions = {
|
|
|
115
115
|
mcp?: false | 'stdio' | {
|
|
116
116
|
port: number;
|
|
117
117
|
};
|
|
118
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Whether to configure the logger.
|
|
120
|
+
*
|
|
121
|
+
* - `false` - don't configure the logger
|
|
122
|
+
* - `'console'` - configure the logger with console sink
|
|
123
|
+
* - `'stderr'` - configure the logger with stderr (for LSP or MCP)
|
|
124
|
+
*
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
configureLogger?: false | 'console' | 'stderr';
|
|
128
|
+
/**
|
|
129
|
+
* The log level to use.
|
|
130
|
+
* Applied if {@link configureLogger} is not `false`
|
|
131
|
+
*/
|
|
132
|
+
logLevel?: 'trace' | 'debug' | 'info' | 'warning' | 'error' | undefined;
|
|
133
|
+
}
|
|
119
134
|
type FromWorkspaceOptions = InitOptions & {
|
|
120
135
|
/**
|
|
121
136
|
* Whether to read and use manual layouts from the workspace.
|
package/dist/browser/index.mjs
CHANGED
|
@@ -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
|
}
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { n as handleInitOptions, r as
|
|
1
|
+
import { i as LikeC4, n as handleInitOptions, r as DefaultInitOptions, t as createFromSources } from "../_chunks/createFromSources.mjs";
|
|
2
|
+
import { t as configureLogger$1 } from "../_chunks/configureLogger.mjs";
|
|
2
3
|
import { memoizeProp } from "@likec4/core";
|
|
3
|
-
import {
|
|
4
|
+
import { loggable, rootLogger } from "@likec4/log";
|
|
4
5
|
import defu from "defu";
|
|
5
6
|
import { basename, resolve } from "pathe";
|
|
6
7
|
import k from "tinyrainbow";
|
|
8
|
+
import { withTrailingSlash } from "ufo";
|
|
7
9
|
import { pathToFileURL } from "url";
|
|
8
10
|
import { WithFileSystem, WithLikeC4ManualLayouts } from "@likec4/language-server/filesystem";
|
|
9
11
|
import { WithMCPServer } from "@likec4/language-server/mcp";
|
|
10
|
-
import { NoFileSystem, NoLikeC4ManualLayouts, createLanguageServices } from "@likec4/language-server/module";
|
|
11
|
-
import { GraphvizWasmAdapter
|
|
12
|
+
import { NoFileSystem, NoLikeC4ManualLayouts, WithGraphviz, createLanguageServices } from "@likec4/language-server/module";
|
|
13
|
+
import { GraphvizWasmAdapter } from "@likec4/layouts";
|
|
12
14
|
import { GraphvizBinaryAdapter } from "@likec4/layouts/graphviz/binary";
|
|
13
15
|
function createLanguageServices$1(opts) {
|
|
14
16
|
const logger = rootLogger.getChild("lang");
|
|
@@ -19,15 +21,6 @@ function createLanguageServices$1(opts) {
|
|
|
19
21
|
graphviz: "wasm",
|
|
20
22
|
mcp: false
|
|
21
23
|
});
|
|
22
|
-
if (options.mcp === "stdio") configureLogger({
|
|
23
|
-
reset: true,
|
|
24
|
-
sinks: { console: getConsoleStderrSink() },
|
|
25
|
-
loggers: [{
|
|
26
|
-
category: "likec4",
|
|
27
|
-
sinks: ["console"],
|
|
28
|
-
lowestLevel: "warning"
|
|
29
|
-
}]
|
|
30
|
-
});
|
|
31
24
|
const useDotBin = options.graphviz === "binary";
|
|
32
25
|
logger.info(`${k.dim("layout")} ${useDotBin ? "binary" : "wasm"}`);
|
|
33
26
|
const langium = createLanguageServices({
|
|
@@ -38,8 +31,9 @@ function createLanguageServices$1(opts) {
|
|
|
38
31
|
...NoFileSystem,
|
|
39
32
|
...NoLikeC4ManualLayouts
|
|
40
33
|
},
|
|
41
|
-
...options.mcp ? WithMCPServer(options.mcp === "stdio" ? "stdio" : options.mcp) : {}
|
|
42
|
-
|
|
34
|
+
...options.mcp ? WithMCPServer(options.mcp === "stdio" ? "stdio" : options.mcp) : {},
|
|
35
|
+
...WithGraphviz(useDotBin ? new GraphvizBinaryAdapter() : new GraphvizWasmAdapter())
|
|
36
|
+
});
|
|
43
37
|
if (typeof options.mcp === "object" && options.mcp.port) langium.likec4.mcp.Server.start(options.mcp.port).catch((e) => {
|
|
44
38
|
logger.error(loggable(e));
|
|
45
39
|
});
|
|
@@ -48,11 +42,22 @@ function createLanguageServices$1(opts) {
|
|
|
48
42
|
});
|
|
49
43
|
return langium;
|
|
50
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a LikeC4 instance from a workspace directory
|
|
47
|
+
* The instance is cached in globalThis to avoid creating multiple instances for the same workspace
|
|
48
|
+
*
|
|
49
|
+
* @param path - The workspace directory path
|
|
50
|
+
* @param options - Optional configuration options
|
|
51
|
+
* @returns A Promise that resolves to a LikeC4 instance
|
|
52
|
+
*/
|
|
51
53
|
async function fromWorkspace(path, options) {
|
|
54
|
+
configureLogger$1(options);
|
|
52
55
|
const workspacePath = resolve(path);
|
|
56
|
+
const workspaceUri = withTrailingSlash(pathToFileURL(workspacePath).toString());
|
|
53
57
|
return memoizeProp(globalThis, "likec4:" + workspacePath, async () => {
|
|
54
58
|
const logger = rootLogger.getChild("lang");
|
|
55
59
|
const langium = createLanguageServices$1(defu(options, {
|
|
60
|
+
...DefaultInitOptions,
|
|
56
61
|
useFileSystem: true,
|
|
57
62
|
manualLayouts: true,
|
|
58
63
|
watch: false,
|
|
@@ -60,7 +65,7 @@ async function fromWorkspace(path, options) {
|
|
|
60
65
|
}));
|
|
61
66
|
const workspace = {
|
|
62
67
|
name: basename(workspacePath),
|
|
63
|
-
uri:
|
|
68
|
+
uri: workspaceUri
|
|
64
69
|
};
|
|
65
70
|
const WorkspaceManager = langium.shared.workspace.WorkspaceManager;
|
|
66
71
|
logger.info(`${k.dim("workspace:")} ${workspacePath}`);
|
|
@@ -80,18 +85,47 @@ async function fromWorkspace(path, options) {
|
|
|
80
85
|
return handleInitOptions(langium, rootLogger, options);
|
|
81
86
|
});
|
|
82
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a LikeC4 instance from the current working directory
|
|
90
|
+
* @param options - Optional configuration options
|
|
91
|
+
* @returns A Promise that resolves to a LikeC4 instance
|
|
92
|
+
*/
|
|
83
93
|
async function fromWorkdir(options) {
|
|
84
94
|
return fromWorkspace(".", options);
|
|
85
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Create a LikeC4 instance from a record of source files
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const likec4 = await fromSources({
|
|
102
|
+
* 'likec4.config.json': '...', // optional, stringified LikeC4Config
|
|
103
|
+
* 'model.c4': 'model { ... }',
|
|
104
|
+
* 'path/views.c4': 'views { ... }',
|
|
105
|
+
* })
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @param sources - A record of file paths to source content
|
|
109
|
+
* @param options - Optional configuration options
|
|
110
|
+
* @returns A Promise that resolves to a LikeC4 instance
|
|
111
|
+
*/
|
|
86
112
|
async function fromSources(sources, options) {
|
|
113
|
+
configureLogger$1(options);
|
|
87
114
|
const logger = rootLogger.getChild("lang");
|
|
88
115
|
return await createFromSources(createLanguageServices$1(defu(options, {
|
|
116
|
+
...DefaultInitOptions,
|
|
89
117
|
useFileSystem: false,
|
|
90
118
|
watch: false,
|
|
91
119
|
manualLayouts: false,
|
|
92
120
|
mcp: false
|
|
93
121
|
})), logger, sources, options);
|
|
94
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Create a LikeC4 instance from a single source string
|
|
125
|
+
* @param source - The LikeC4 source code
|
|
126
|
+
* @param options - Optional configuration options
|
|
127
|
+
* @returns A Promise that resolves to a LikeC4 instance
|
|
128
|
+
*/
|
|
95
129
|
async function fromSource(source, options) {
|
|
96
130
|
return fromSources({ "source.c4": source }, options);
|
|
97
131
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as LikeC4, n as handleInitOptions, t as createFromSources } from "../../_chunks/createFromSources.mjs";
|
|
2
|
+
import { t as configureLogger$1 } from "../../_chunks/configureLogger.mjs";
|
|
2
3
|
import { memoizeProp } from "@likec4/core";
|
|
3
4
|
import { rootLogger } from "@likec4/log";
|
|
4
5
|
import defu from "defu";
|
|
@@ -6,8 +7,8 @@ import { basename, resolve } from "pathe";
|
|
|
6
7
|
import k from "tinyrainbow";
|
|
7
8
|
import { pathToFileURL } from "url";
|
|
8
9
|
import { WithFileSystem, WithLikeC4ManualLayouts } from "@likec4/language-server/filesystem";
|
|
9
|
-
import { NoFileSystem, NoLikeC4ManualLayouts, createLanguageServices } from "@likec4/language-server/module";
|
|
10
|
-
import { GraphvizWasmAdapter
|
|
10
|
+
import { NoFileSystem, NoLikeC4ManualLayouts, WithGraphviz, createLanguageServices } from "@likec4/language-server/module";
|
|
11
|
+
import { GraphvizWasmAdapter } from "@likec4/layouts";
|
|
11
12
|
import { GraphvizBinaryAdapter } from "@likec4/layouts/graphviz/binary";
|
|
12
13
|
function createLanguageServices$1(opts) {
|
|
13
14
|
const logger = rootLogger.getChild("lang");
|
|
@@ -19,16 +20,30 @@ function createLanguageServices$1(opts) {
|
|
|
19
20
|
});
|
|
20
21
|
const useDotBin = options.graphviz === "binary";
|
|
21
22
|
logger.info(`${k.dim("layout")} ${useDotBin ? "binary" : "wasm"}`);
|
|
22
|
-
return createLanguageServices({
|
|
23
|
-
...
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
return createLanguageServices({
|
|
24
|
+
...options.useFileSystem ? {
|
|
25
|
+
...WithFileSystem(options.watch),
|
|
26
|
+
...options.manualLayouts ? WithLikeC4ManualLayouts : NoLikeC4ManualLayouts
|
|
27
|
+
} : {
|
|
28
|
+
...NoFileSystem,
|
|
29
|
+
...NoLikeC4ManualLayouts
|
|
30
|
+
},
|
|
31
|
+
...WithGraphviz(useDotBin ? new GraphvizBinaryAdapter() : new GraphvizWasmAdapter())
|
|
32
|
+
});
|
|
29
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a LikeC4 instance from a workspace directory
|
|
36
|
+
* The instance is cached in globalThis to avoid creating multiple instances for the same workspace
|
|
37
|
+
*
|
|
38
|
+
* @param path - The workspace directory path
|
|
39
|
+
* @param options - Optional configuration options
|
|
40
|
+
* @returns A Promise that resolves to a LikeC4 instance
|
|
41
|
+
*/
|
|
30
42
|
async function fromWorkspace(path, options) {
|
|
43
|
+
configureLogger$1(options);
|
|
31
44
|
const workspacePath = resolve(path);
|
|
45
|
+
const folderUri = pathToFileURL(workspacePath).toString();
|
|
46
|
+
const workspaceUri = folderUri.endsWith("/") ? folderUri : folderUri + "/";
|
|
32
47
|
return memoizeProp(globalThis, "likec4:" + workspacePath, async () => {
|
|
33
48
|
const logger = rootLogger.getChild("lang");
|
|
34
49
|
const mergedOptions = defu(options, {
|
|
@@ -40,7 +55,7 @@ async function fromWorkspace(path, options) {
|
|
|
40
55
|
const langium = createLanguageServices$1(mergedOptions);
|
|
41
56
|
const workspace = {
|
|
42
57
|
name: basename(workspacePath),
|
|
43
|
-
uri:
|
|
58
|
+
uri: workspaceUri
|
|
44
59
|
};
|
|
45
60
|
const WorkspaceManager = langium.shared.workspace.WorkspaceManager;
|
|
46
61
|
logger.info(`${k.dim("workspace:")} ${workspacePath}`);
|
|
@@ -60,10 +75,32 @@ async function fromWorkspace(path, options) {
|
|
|
60
75
|
return handleInitOptions(langium, rootLogger, options);
|
|
61
76
|
});
|
|
62
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a LikeC4 instance from the current working directory
|
|
80
|
+
* @param options - Optional configuration options
|
|
81
|
+
* @returns A Promise that resolves to a LikeC4 instance
|
|
82
|
+
*/
|
|
63
83
|
async function fromWorkdir(options) {
|
|
64
84
|
return fromWorkspace(".", options);
|
|
65
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Create a LikeC4 instance from a record of source files
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const likec4 = await fromSources({
|
|
92
|
+
* 'likec4.config.json': '...', // optional, stringified LikeC4Config
|
|
93
|
+
* 'model.c4': 'model { ... }',
|
|
94
|
+
* 'path/views.c4': 'views { ... }',
|
|
95
|
+
* })
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @param sources - A record of file paths to source content
|
|
99
|
+
* @param options - Optional configuration options
|
|
100
|
+
* @returns A Promise that resolves to a LikeC4 instance
|
|
101
|
+
*/
|
|
66
102
|
async function fromSources(sources, options) {
|
|
103
|
+
configureLogger$1(options);
|
|
67
104
|
const logger = rootLogger.getChild("lang");
|
|
68
105
|
return await createFromSources(createLanguageServices$1(defu(options, {
|
|
69
106
|
useFileSystem: false,
|
|
@@ -71,6 +108,12 @@ async function fromSources(sources, options) {
|
|
|
71
108
|
manualLayouts: false
|
|
72
109
|
})), logger, sources, options);
|
|
73
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Create a LikeC4 instance from a single source string
|
|
113
|
+
* @param source - The LikeC4 source code
|
|
114
|
+
* @param options - Optional configuration options
|
|
115
|
+
* @returns A Promise that resolves to a LikeC4 instance
|
|
116
|
+
*/
|
|
74
117
|
async function fromSource(source, options) {
|
|
75
118
|
return fromSources({ "source.c4": source }, options);
|
|
76
119
|
}
|
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.
|
|
4
|
+
"version": "1.51.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
7
7
|
"homepage": "https://likec4.dev",
|
|
@@ -70,31 +70,32 @@
|
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"defu": "^6.1.4",
|
|
73
|
-
"remeda": "^2.33.
|
|
73
|
+
"remeda": "^2.33.6",
|
|
74
74
|
"langium": "3.5.0",
|
|
75
|
-
"tinyrainbow": "^
|
|
75
|
+
"tinyrainbow": "^3.0.3",
|
|
76
76
|
"pathe": "^2.0.3",
|
|
77
|
+
"ufo": "1.6.3",
|
|
77
78
|
"std-env": "^3.10.0",
|
|
78
79
|
"type-fest": "^4.41.0",
|
|
79
80
|
"vscode-languageserver-types": "3.17.5",
|
|
80
|
-
"@likec4/config": "1.
|
|
81
|
-
"@likec4/generators": "1.
|
|
81
|
+
"@likec4/config": "1.51.0",
|
|
82
|
+
"@likec4/generators": "1.51.0",
|
|
83
|
+
"@likec4/core": "1.51.0",
|
|
82
84
|
"@likec4/icons": "1.46.4",
|
|
83
|
-
"@likec4/
|
|
84
|
-
"@likec4/language-server": "1.
|
|
85
|
-
"@likec4/
|
|
86
|
-
"@likec4/log": "1.49.0"
|
|
85
|
+
"@likec4/layouts": "1.51.0",
|
|
86
|
+
"@likec4/language-server": "1.51.0",
|
|
87
|
+
"@likec4/log": "1.51.0"
|
|
87
88
|
},
|
|
88
89
|
"devDependencies": {
|
|
89
|
-
"@types/node": "~22.19.
|
|
90
|
-
"obuild": "^0.4.
|
|
90
|
+
"@types/node": "~22.19.11",
|
|
91
|
+
"obuild": "^0.4.31",
|
|
91
92
|
"oxlint": "1.43.0",
|
|
92
93
|
"tsx": "4.21.0",
|
|
93
|
-
"turbo": "2.8.
|
|
94
|
+
"turbo": "2.8.12",
|
|
94
95
|
"typescript": "5.9.3",
|
|
95
96
|
"vitest": "4.0.18",
|
|
96
97
|
"@likec4/devops": "1.42.0",
|
|
97
|
-
"@likec4/tsconfig": "1.
|
|
98
|
+
"@likec4/tsconfig": "1.51.0"
|
|
98
99
|
},
|
|
99
100
|
"scripts": {
|
|
100
101
|
"typecheck": "tsc -b --verbose",
|