@likec4/language-services 1.53.0 → 1.55.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/README.md CHANGED
@@ -79,11 +79,6 @@ const model = await likec4.layoutedModel()
79
79
  const projects = likec4.projects()
80
80
  ```
81
81
 
82
- > [!NOTE]
83
- > There is a separate entry point for node.js environment without MCP support: `@likec4/language-services/node/without-mcp`
84
- >
85
- > Useful to reduce bundle size
86
-
87
82
  ## API
88
83
 
89
84
  ### Factory Functions
@@ -1,20 +1,12 @@
1
1
  import { loggable, rootLogger } from "@likec4/log";
2
- import { extname } from "pathe";
2
+ import { URI, UriUtils } from "langium";
3
3
  import k from "tinyrainbow";
4
4
  import { LikeC4ProjectConfigOps, isLikeC4JsonConfig } from "@likec4/config";
5
- import { URI, UriUtils } from "langium";
5
+ import { extname } from "pathe";
6
6
  import { entries, flatMap, hasAtLeast, join, map, partition, pipe, prop } from "remeda";
7
7
  const isErrorDiagnostic = (diagnostic) => {
8
8
  return diagnostic.severity === 1;
9
9
  };
10
- const firstFiveLines = (message) => {
11
- const messages = message.split("\n");
12
- if (messages.length > 5) {
13
- messages.length = 5;
14
- messages.push("...");
15
- }
16
- return messages.join("\n");
17
- };
18
10
  var LikeC4 = class {
19
11
  langium;
20
12
  logger;
@@ -109,7 +101,7 @@ Please specify a project folder`);
109
101
  getErrors() {
110
102
  return [...this.LangiumDocuments.userDocuments].flatMap((doc) => {
111
103
  return (doc.diagnostics?.filter(isErrorDiagnostic) ?? []).map(({ message, range }) => ({
112
- message: firstFiveLines(message),
104
+ message,
113
105
  line: range.start.line,
114
106
  range,
115
107
  sourceFsPath: doc.uri.fsPath
@@ -130,9 +122,14 @@ Please specify a project folder`);
130
122
  const errors = doc.diagnostics?.filter(isErrorDiagnostic) ?? [];
131
123
  if (!hasAtLeast(errors, 1)) continue;
132
124
  hasErrors = true;
133
- const messages = pipe(errors, flatMap((error) => {
134
- const line = error.range.start.line;
135
- return firstFiveLines(error.message).split("\n").map((message, i) => {
125
+ const messages = pipe(errors, flatMap((validationError) => {
126
+ const line = validationError.range.start.line;
127
+ const messages = validationError.message.split("\n");
128
+ if (messages.length > 5) {
129
+ messages.length = 5;
130
+ messages.push("...");
131
+ }
132
+ return messages.map((message, i) => {
136
133
  if (i === 0) return " " + k.dim(`Line ${line}: `) + k.red(message);
137
134
  return " ".repeat(10) + k.red(message);
138
135
  });
@@ -3,7 +3,6 @@ import { i as LikeC4Langium, n as InitOptions, r as LikeC4, t as FromWorkspaceOp
3
3
  //#region src/node/index.d.ts
4
4
  /**
5
5
  * Create a LikeC4 instance from a workspace directory
6
- * The instance is cached in globalThis to avoid creating multiple instances for the same workspace
7
6
  *
8
7
  * @param path - The workspace directory path
9
8
  * @param options - Optional configuration options
@@ -1,29 +1,43 @@
1
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";
3
- import { memoizeProp } from "@likec4/core";
4
- import { loggable, rootLogger } from "@likec4/log";
2
+ import { rootLogger } from "@likec4/log";
5
3
  import defu from "defu";
6
- import { basename, resolve } from "pathe";
4
+ import { URI } from "langium";
5
+ import { basename, resolve } from "node:path";
7
6
  import k from "tinyrainbow";
8
7
  import { withTrailingSlash } from "ufo";
9
- import { pathToFileURL } from "url";
8
+ import { configureLanguageServerLogger } from "@likec4/language-server";
9
+ import { isColorSupported } from "std-env";
10
10
  import { WithFileSystem, WithLikeC4ManualLayouts } from "@likec4/language-server/filesystem";
11
- import { WithMCPServer } from "@likec4/language-server/mcp";
12
11
  import { NoFileSystem, NoLikeC4ManualLayouts, WithGraphviz, createLanguageServices } from "@likec4/language-server/module";
13
12
  import { GraphvizWasmAdapter } from "@likec4/layouts";
14
13
  import { GraphvizBinaryAdapter } from "@likec4/layouts/graphviz/binary";
14
+ function configureLogger$1(options) {
15
+ const opt = options?.configureLogger ?? false;
16
+ if (opt === false) return;
17
+ if (opt === "stderr" || options?.mcp === "stdio") {
18
+ configureLanguageServerLogger({
19
+ useStdErr: true,
20
+ colors: false,
21
+ logLevel: options?.logLevel
22
+ });
23
+ return;
24
+ }
25
+ configureLanguageServerLogger({
26
+ colors: isColorSupported,
27
+ logLevel: options?.logLevel
28
+ });
29
+ }
15
30
  function createLanguageServices$1(opts) {
16
31
  const logger = rootLogger.getChild("lang");
17
32
  const options = defu(opts, {
18
33
  useFileSystem: true,
19
34
  manualLayouts: true,
20
35
  watch: false,
21
- graphviz: "wasm",
22
- mcp: false
36
+ graphviz: "wasm"
23
37
  });
24
38
  const useDotBin = options.graphviz === "binary";
25
39
  logger.info(`${k.dim("layout")} ${useDotBin ? "binary" : "wasm"}`);
26
- const langium = createLanguageServices({
40
+ return createLanguageServices({
27
41
  ...options.useFileSystem ? {
28
42
  ...WithFileSystem(options.watch),
29
43
  ...options.manualLayouts ? WithLikeC4ManualLayouts : NoLikeC4ManualLayouts
@@ -31,20 +45,11 @@ function createLanguageServices$1(opts) {
31
45
  ...NoFileSystem,
32
46
  ...NoLikeC4ManualLayouts
33
47
  },
34
- ...options.mcp ? WithMCPServer(options.mcp === "stdio" ? "stdio" : options.mcp) : {},
35
48
  ...WithGraphviz(useDotBin ? new GraphvizBinaryAdapter() : new GraphvizWasmAdapter())
36
49
  });
37
- if (typeof options.mcp === "object" && options.mcp.port) langium.likec4.mcp.Server.start(options.mcp.port).catch((e) => {
38
- logger.error(loggable(e));
39
- });
40
- if (options.mcp === "stdio") langium.likec4.mcp.Server.start().catch((e) => {
41
- logger.error(loggable(e));
42
- });
43
- return langium;
44
50
  }
45
51
  /**
46
52
  * 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
53
  *
49
54
  * @param path - The workspace directory path
50
55
  * @param options - Optional configuration options
@@ -52,39 +57,36 @@ function createLanguageServices$1(opts) {
52
57
  */
53
58
  async function fromWorkspace(path, options) {
54
59
  const workspacePath = resolve(path);
55
- const workspaceUri = withTrailingSlash(pathToFileURL(workspacePath).toString());
56
- return memoizeProp(globalThis, "likec4:" + workspacePath, async () => {
57
- const logger = rootLogger.getChild("lang");
58
- const opts = defu(options, {
59
- ...DefaultInitOptions,
60
- useFileSystem: true,
61
- manualLayouts: true,
62
- watch: false,
63
- mcp: false
64
- });
65
- configureLogger$1(opts);
66
- const langium = createLanguageServices$1(opts);
67
- const workspace = {
68
- name: basename(workspacePath),
69
- uri: workspaceUri
70
- };
71
- const WorkspaceManager = langium.shared.workspace.WorkspaceManager;
72
- logger.info(`${k.dim("workspace:")} ${workspacePath}`);
73
- WorkspaceManager.initialize({
74
- capabilities: {},
75
- processId: null,
76
- rootUri: null,
77
- workspaceFolders: [workspace]
78
- });
79
- await WorkspaceManager.initializeWorkspace([workspace]);
80
- const userDocuments = langium.shared.workspace.LangiumDocuments.userDocuments.toArray();
81
- if (userDocuments.length === 0) {
82
- logger.error(`no LikeC4 sources found`);
83
- if (options?.throwIfInvalid) throw new Error(`no LikeC4 sources found`);
84
- }
85
- logger.info(`${k.dim("workspace:")} found ${userDocuments.length} source files`);
86
- return handleInitOptions(langium, rootLogger, options);
60
+ const workspaceUri = withTrailingSlash(URI.file(workspacePath).toString());
61
+ const logger = rootLogger.getChild("lang");
62
+ const opts = defu(options, {
63
+ ...DefaultInitOptions,
64
+ useFileSystem: true,
65
+ manualLayouts: true,
66
+ watch: false
67
+ });
68
+ configureLogger$1(opts);
69
+ const langium = createLanguageServices$1(opts);
70
+ const workspace = {
71
+ name: basename(workspacePath),
72
+ uri: workspaceUri
73
+ };
74
+ const WorkspaceManager = langium.shared.workspace.WorkspaceManager;
75
+ logger.info(`${k.dim("workspace:")} ${workspacePath}`);
76
+ WorkspaceManager.initialize({
77
+ capabilities: {},
78
+ processId: null,
79
+ rootUri: workspace.uri,
80
+ workspaceFolders: [workspace]
87
81
  });
82
+ await WorkspaceManager.initializeWorkspace([workspace]);
83
+ const userDocuments = langium.shared.workspace.LangiumDocuments.userDocuments.toArray();
84
+ if (userDocuments.length === 0) {
85
+ logger.error(`no LikeC4 sources found`);
86
+ if (options?.throwIfInvalid) throw new Error(`no LikeC4 sources found`);
87
+ }
88
+ logger.info(`${k.dim("workspace:")} found ${userDocuments.length} source files`);
89
+ return handleInitOptions(langium, rootLogger, options);
88
90
  }
89
91
  /**
90
92
  * Create a LikeC4 instance from the current working directory
@@ -117,8 +119,7 @@ async function fromSources(sources, options) {
117
119
  ...DefaultInitOptions,
118
120
  useFileSystem: false,
119
121
  watch: false,
120
- manualLayouts: false,
121
- mcp: false
122
+ manualLayouts: false
122
123
  })), logger, sources, options);
123
124
  }
124
125
  /**
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.53.0",
4
+ "version": "1.55.0",
5
5
  "license": "MIT",
6
6
  "bugs": "https://github.com/likec4/likec4/issues",
7
7
  "homepage": "https://likec4.dev",
@@ -46,14 +46,6 @@
46
46
  "default": "./dist/browser/index.mjs"
47
47
  }
48
48
  },
49
- "./node/without-mcp": {
50
- "sources": "./src/node/without-mcp/index.ts",
51
- "default": {
52
- "types": "./dist/node/without-mcp/index.d.mts",
53
- "import": "./dist/node/without-mcp/index.mjs",
54
- "default": "./dist/node/without-mcp/index.mjs"
55
- }
56
- },
57
49
  "./node": {
58
50
  "sources": "./src/node/index.ts",
59
51
  "default": {
@@ -69,8 +61,8 @@
69
61
  "access": "public"
70
62
  },
71
63
  "dependencies": {
72
- "defu": "^6.1.4",
73
- "remeda": "^2.33.6",
64
+ "defu": "^6.1.7",
65
+ "remeda": "^2.33.7",
74
66
  "langium": "3.5.0",
75
67
  "tinyrainbow": "^3.0.3",
76
68
  "pathe": "^2.0.3",
@@ -78,24 +70,24 @@
78
70
  "std-env": "^3.10.0",
79
71
  "type-fest": "^4.41.0",
80
72
  "vscode-languageserver-types": "3.17.5",
81
- "@likec4/config": "1.53.0",
82
- "@likec4/core": "1.53.0",
73
+ "@likec4/config": "1.55.0",
74
+ "@likec4/generators": "1.55.0",
83
75
  "@likec4/icons": "1.46.4",
84
- "@likec4/language-server": "1.53.0",
85
- "@likec4/layouts": "1.53.0",
86
- "@likec4/generators": "1.53.0",
87
- "@likec4/log": "1.53.0"
76
+ "@likec4/language-server": "1.55.0",
77
+ "@likec4/layouts": "1.55.0",
78
+ "@likec4/core": "1.55.0",
79
+ "@likec4/log": "1.55.0"
88
80
  },
89
81
  "devDependencies": {
90
82
  "@types/node": "~22.19.15",
91
83
  "obuild": "0.4.31",
92
- "oxlint": "1.55.0",
84
+ "oxlint": "1.59.0",
93
85
  "tsx": "4.21.0",
94
- "turbo": "2.8.17",
86
+ "turbo": "2.9.5",
95
87
  "typescript": "5.9.3",
96
- "vitest": "4.1.0",
88
+ "vitest": "4.1.3",
97
89
  "@likec4/devops": "1.42.0",
98
- "@likec4/tsconfig": "1.53.0"
90
+ "@likec4/tsconfig": "1.55.0"
99
91
  },
100
92
  "scripts": {
101
93
  "typecheck": "tsc -b --verbose",
@@ -1,19 +0,0 @@
1
- import { configureLanguageServerLogger } from "@likec4/language-server";
2
- import { isColorSupported } from "std-env";
3
- function configureLogger(options) {
4
- const opt = options?.configureLogger ?? false;
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,44 +0,0 @@
1
- import { i as LikeC4Langium, n as InitOptions, r as LikeC4, t as FromWorkspaceOptions } from "../../_chunks/options.mjs";
2
-
3
- //#region src/node/without-mcp/index.d.ts
4
- /**
5
- * Create a LikeC4 instance from a workspace directory
6
- * The instance is cached in globalThis to avoid creating multiple instances for the same workspace
7
- *
8
- * @param path - The workspace directory path
9
- * @param options - Optional configuration options
10
- * @returns A Promise that resolves to a LikeC4 instance
11
- */
12
- declare function fromWorkspace(path: string, options?: FromWorkspaceOptions): Promise<LikeC4>;
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
- */
18
- declare function fromWorkdir(options?: FromWorkspaceOptions): Promise<LikeC4>;
19
- /**
20
- * Create a LikeC4 instance from a record of source files
21
- *
22
- * @example
23
- * ```ts
24
- * const likec4 = await fromSources({
25
- * 'likec4.config.json': '...', // optional, stringified LikeC4Config
26
- * 'model.c4': 'model { ... }',
27
- * 'path/views.c4': 'views { ... }',
28
- * })
29
- * ```
30
- *
31
- * @param sources - A record of file paths to source content
32
- * @param options - Optional configuration options
33
- * @returns A Promise that resolves to a LikeC4 instance
34
- */
35
- declare function fromSources(sources: Record<string, string>, options?: InitOptions): Promise<LikeC4>;
36
- /**
37
- * Create a LikeC4 instance from a single source string
38
- * @param source - The LikeC4 source code
39
- * @param options - Optional configuration options
40
- * @returns A Promise that resolves to a LikeC4 instance
41
- */
42
- declare function fromSource(source: string, options?: InitOptions): Promise<LikeC4>;
43
- //#endregion
44
- export { type FromWorkspaceOptions, type InitOptions, LikeC4, type LikeC4Langium, fromSource, fromSources, fromWorkdir, fromWorkspace };
@@ -1,121 +0,0 @@
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";
3
- import { memoizeProp } from "@likec4/core";
4
- import { rootLogger } from "@likec4/log";
5
- import defu from "defu";
6
- import { basename, resolve } from "pathe";
7
- import k from "tinyrainbow";
8
- import { pathToFileURL } from "url";
9
- import { WithFileSystem, WithLikeC4ManualLayouts } from "@likec4/language-server/filesystem";
10
- import { NoFileSystem, NoLikeC4ManualLayouts, WithGraphviz, createLanguageServices } from "@likec4/language-server/module";
11
- import { GraphvizWasmAdapter } from "@likec4/layouts";
12
- import { GraphvizBinaryAdapter } from "@likec4/layouts/graphviz/binary";
13
- function createLanguageServices$1(opts) {
14
- const logger = rootLogger.getChild("lang");
15
- const options = defu(opts, {
16
- useFileSystem: true,
17
- manualLayouts: true,
18
- watch: false,
19
- graphviz: "wasm"
20
- });
21
- const useDotBin = options.graphviz === "binary";
22
- logger.info(`${k.dim("layout")} ${useDotBin ? "binary" : "wasm"}`);
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
- });
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
- */
42
- async function fromWorkspace(path, options) {
43
- const workspacePath = resolve(path);
44
- const folderUri = pathToFileURL(workspacePath).toString();
45
- const workspaceUri = folderUri.endsWith("/") ? folderUri : folderUri + "/";
46
- return memoizeProp(globalThis, "likec4:" + workspacePath, async () => {
47
- const logger = rootLogger.getChild("lang");
48
- const mergedOptions = defu(options, {
49
- ...DefaultInitOptions,
50
- useFileSystem: true,
51
- manualLayouts: true,
52
- watch: false
53
- });
54
- configureLogger$1(mergedOptions);
55
- if (mergedOptions.mcp) throw new Error("MCP server is not supported in this build");
56
- const langium = createLanguageServices$1(mergedOptions);
57
- const workspace = {
58
- name: basename(workspacePath),
59
- uri: workspaceUri
60
- };
61
- const WorkspaceManager = langium.shared.workspace.WorkspaceManager;
62
- logger.info(`${k.dim("workspace:")} ${workspacePath}`);
63
- WorkspaceManager.initialize({
64
- capabilities: {},
65
- processId: null,
66
- rootUri: null,
67
- workspaceFolders: [workspace]
68
- });
69
- await WorkspaceManager.initializeWorkspace([workspace]);
70
- const userDocuments = langium.shared.workspace.LangiumDocuments.userDocuments.toArray();
71
- if (userDocuments.length === 0) {
72
- logger.error(`no LikeC4 sources found`);
73
- throw new Error(`no LikeC4 sources found`);
74
- }
75
- logger.info(`${k.dim("workspace:")} found ${userDocuments.length} source files`);
76
- return handleInitOptions(langium, rootLogger, options);
77
- });
78
- }
79
- /**
80
- * Create a LikeC4 instance from the current working directory
81
- * @param options - Optional configuration options
82
- * @returns A Promise that resolves to a LikeC4 instance
83
- */
84
- async function fromWorkdir(options) {
85
- return fromWorkspace(".", options);
86
- }
87
- /**
88
- * Create a LikeC4 instance from a record of source files
89
- *
90
- * @example
91
- * ```ts
92
- * const likec4 = await fromSources({
93
- * 'likec4.config.json': '...', // optional, stringified LikeC4Config
94
- * 'model.c4': 'model { ... }',
95
- * 'path/views.c4': 'views { ... }',
96
- * })
97
- * ```
98
- *
99
- * @param sources - A record of file paths to source content
100
- * @param options - Optional configuration options
101
- * @returns A Promise that resolves to a LikeC4 instance
102
- */
103
- async function fromSources(sources, options) {
104
- configureLogger$1(options);
105
- const logger = rootLogger.getChild("lang");
106
- return await createFromSources(createLanguageServices$1(defu(options, {
107
- useFileSystem: false,
108
- watch: false,
109
- manualLayouts: false
110
- })), logger, sources, options);
111
- }
112
- /**
113
- * Create a LikeC4 instance from a single source string
114
- * @param source - The LikeC4 source code
115
- * @param options - Optional configuration options
116
- * @returns A Promise that resolves to a LikeC4 instance
117
- */
118
- async function fromSource(source, options) {
119
- return fromSources({ "source.c4": source }, options);
120
- }
121
- export { LikeC4, fromSource, fromSources, fromWorkdir, fromWorkspace };
@@ -1,4 +0,0 @@
1
- {
2
- "types": "../../dist/node/without-mcp/index.d.mts",
3
- "module": "../../dist/node/without-mcp/index.mjs"
4
- }