@likec4/language-services 1.50.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.
|
@@ -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";
|
|
@@ -154,18 +153,22 @@ Please specify a project folder`);
|
|
|
154
153
|
await this.dispose();
|
|
155
154
|
}
|
|
156
155
|
};
|
|
156
|
+
const DefaultInitOptions = {
|
|
157
|
+
printErrors: true,
|
|
158
|
+
throwIfInvalid: false,
|
|
159
|
+
graphviz: "wasm",
|
|
160
|
+
mcp: false,
|
|
161
|
+
configureLogger: false,
|
|
162
|
+
logLevel: void 0
|
|
163
|
+
};
|
|
157
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")}`);
|
|
158
165
|
async function handleInitOptions(langium, logger = rootLogger, options) {
|
|
159
166
|
const likec4 = new LikeC4(langium, logger);
|
|
160
|
-
|
|
161
|
-
printErrors: true,
|
|
162
|
-
throwIfInvalid: false
|
|
163
|
-
});
|
|
164
|
-
if (opts.throwIfInvalid === true && likec4.hasErrors()) {
|
|
167
|
+
if ((options?.throwIfInvalid ?? DefaultInitOptions.throwIfInvalid) === true && likec4.hasErrors()) {
|
|
165
168
|
await likec4.dispose();
|
|
166
169
|
return Promise.reject(validationErrorsToError(likec4));
|
|
167
170
|
}
|
|
168
|
-
if (
|
|
171
|
+
if ((options?.printErrors ?? DefaultInitOptions.printErrors) && likec4.hasErrors()) likec4.printErrors();
|
|
169
172
|
return likec4;
|
|
170
173
|
}
|
|
171
174
|
/**
|
|
@@ -209,4 +212,4 @@ async function createFromSources(langium, logger, sources, initOptions) {
|
|
|
209
212
|
await langium.shared.workspace.DocumentBuilder.build(docs, { validation: true });
|
|
210
213
|
return handleInitOptions(langium, logger, initOptions);
|
|
211
214
|
}
|
|
212
|
-
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/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
|
});
|
|
@@ -57,12 +51,13 @@ function createLanguageServices$1(opts) {
|
|
|
57
51
|
* @returns A Promise that resolves to a LikeC4 instance
|
|
58
52
|
*/
|
|
59
53
|
async function fromWorkspace(path, options) {
|
|
54
|
+
configureLogger$1(options);
|
|
60
55
|
const workspacePath = resolve(path);
|
|
61
|
-
const
|
|
62
|
-
const workspaceUri = folderUri.endsWith("/") ? folderUri : folderUri + "/";
|
|
56
|
+
const workspaceUri = withTrailingSlash(pathToFileURL(workspacePath).toString());
|
|
63
57
|
return memoizeProp(globalThis, "likec4:" + workspacePath, async () => {
|
|
64
58
|
const logger = rootLogger.getChild("lang");
|
|
65
59
|
const langium = createLanguageServices$1(defu(options, {
|
|
60
|
+
...DefaultInitOptions,
|
|
66
61
|
useFileSystem: true,
|
|
67
62
|
manualLayouts: true,
|
|
68
63
|
watch: false,
|
|
@@ -115,8 +110,10 @@ async function fromWorkdir(options) {
|
|
|
115
110
|
* @returns A Promise that resolves to a LikeC4 instance
|
|
116
111
|
*/
|
|
117
112
|
async function fromSources(sources, options) {
|
|
113
|
+
configureLogger$1(options);
|
|
118
114
|
const logger = rootLogger.getChild("lang");
|
|
119
115
|
return await createFromSources(createLanguageServices$1(defu(options, {
|
|
116
|
+
...DefaultInitOptions,
|
|
120
117
|
useFileSystem: false,
|
|
121
118
|
watch: false,
|
|
122
119
|
manualLayouts: false,
|
|
@@ -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,13 +20,16 @@ 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
|
}
|
|
30
34
|
/**
|
|
31
35
|
* Create a LikeC4 instance from a workspace directory
|
|
@@ -36,6 +40,7 @@ function createLanguageServices$1(opts) {
|
|
|
36
40
|
* @returns A Promise that resolves to a LikeC4 instance
|
|
37
41
|
*/
|
|
38
42
|
async function fromWorkspace(path, options) {
|
|
43
|
+
configureLogger$1(options);
|
|
39
44
|
const workspacePath = resolve(path);
|
|
40
45
|
const folderUri = pathToFileURL(workspacePath).toString();
|
|
41
46
|
const workspaceUri = folderUri.endsWith("/") ? folderUri : folderUri + "/";
|
|
@@ -95,6 +100,7 @@ async function fromWorkdir(options) {
|
|
|
95
100
|
* @returns A Promise that resolves to a LikeC4 instance
|
|
96
101
|
*/
|
|
97
102
|
async function fromSources(sources, options) {
|
|
103
|
+
configureLogger$1(options);
|
|
98
104
|
const logger = rootLogger.getChild("lang");
|
|
99
105
|
return await createFromSources(createLanguageServices$1(defu(options, {
|
|
100
106
|
useFileSystem: false,
|
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/
|
|
82
|
-
"@likec4/
|
|
81
|
+
"@likec4/config": "1.51.0",
|
|
82
|
+
"@likec4/generators": "1.51.0",
|
|
83
|
+
"@likec4/core": "1.51.0",
|
|
83
84
|
"@likec4/icons": "1.46.4",
|
|
84
|
-
"@likec4/
|
|
85
|
-
"@likec4/
|
|
86
|
-
"@likec4/
|
|
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
90
|
"@types/node": "~22.19.11",
|
|
90
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",
|