@likec4/language-server 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 +6 -0
- package/bin/likec4-language-server.mjs +1 -1
- package/dist/_chunks/LikeC4FileSystem.mjs +2 -2
- package/dist/_chunks/icons.d.mts +18 -0
- package/dist/_chunks/icons.mjs +2 -0
- package/dist/_chunks/module.d.mts +13 -42
- package/dist/_chunks/module.mjs +20 -20
- package/dist/_chunks/utils.mjs +1 -1
- package/dist/browser/index.d.mts +2 -2
- package/dist/browser/index.mjs +1 -1
- package/dist/browser/worker.mjs +1 -1
- package/dist/filesystem/index.d.mts +1 -1
- package/dist/filesystem/index.mjs +1 -1
- package/dist/icons.d.mts +2 -0
- package/dist/icons.mjs +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/likec4lib.d.mts +1 -3
- package/dist/likec4lib.mjs +1 -1
- package/dist/module.d.mts +2 -2
- package/dist/module.mjs +1 -1
- package/icons/package.json +4 -0
- package/package.json +27 -31
- package/src/test/index.ts +1 -0
- package/src/test/testServices.ts +258 -0
- package/dist/_chunks/likec4lib.mjs +0 -2
- package/dist/_chunks/mcp.mjs +0 -1154
- package/dist/_chunks/noop.mjs +0 -1
- package/dist/_chunks/noop2.mjs +0 -1
- package/dist/mcp/index.d.mts +0 -3
- package/dist/mcp/index.mjs +0 -1
- package/mcp/package.json +0 -4
package/dist/browser/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as NoFileSystem, C as LikeC4ModelBuilder, E as LangiumDocuments, F as FileSystemProvider, H as ProjectData, I as FileSystemWatcher, L as FileSystemWatcherModuleContext, M as NoLikeC4ManualLayouts, P as FileSystemModuleContext, R as LikeC4ManualLayouts, S as ViewLocateResult, T as LikeC4WorkspaceManager, U as ProjectsManager, V as Project, _ as LikeC4ViewsModuleContext, b as LikeC4Views, d as LikeC4LanguageServices, f as DocumentParser, j as NoFileSystemWatcher, n as LikeC4AddedServices, o as LikeC4SharedServices, p as LikeC4ModelParser, r as LikeC4Services, s as createLanguageServices, t as LanguageServicesContext, u as FormatOptions, w as FqnIndex, x as LikeC4ModelLocator, y as WithWasmGraphviz, z as LikeC4ManualLayoutsModuleContext } from "../_chunks/module.mjs";
|
|
2
2
|
import "../_chunks/protocol.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/browser/index.d.ts
|
|
@@ -12,4 +12,4 @@ declare function startLanguageServer(port: MessagePort | DedicatedWorkerGlobalSc
|
|
|
12
12
|
likec4: LikeC4Services;
|
|
13
13
|
};
|
|
14
14
|
//#endregion
|
|
15
|
-
export { DocumentParser, FileSystemModuleContext, FileSystemProvider, FileSystemWatcher, FileSystemWatcherModuleContext, FormatOptions, FqnIndex, LangiumDocuments, LanguageServicesContext, LikeC4AddedServices, LikeC4LanguageServices, LikeC4ManualLayouts, LikeC4ManualLayoutsModuleContext, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser, LikeC4Services, LikeC4SharedServices, LikeC4Views, LikeC4ViewsModuleContext, LikeC4WorkspaceManager, NoFileSystem, NoFileSystemWatcher, NoLikeC4ManualLayouts,
|
|
15
|
+
export { DocumentParser, FileSystemModuleContext, FileSystemProvider, FileSystemWatcher, FileSystemWatcherModuleContext, FormatOptions, FqnIndex, LangiumDocuments, LanguageServicesContext, LikeC4AddedServices, LikeC4LanguageServices, LikeC4ManualLayouts, LikeC4ManualLayoutsModuleContext, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser, LikeC4Services, LikeC4SharedServices, LikeC4Views, LikeC4ViewsModuleContext, LikeC4WorkspaceManager, NoFileSystem, NoFileSystemWatcher, NoLikeC4ManualLayouts, Project, ProjectData, ProjectsManager, ViewLocateResult, WithWasmGraphviz, createLanguageServices, startLanguageServer };
|
package/dist/browser/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_chunks/
|
|
1
|
+
import"../_chunks/icons.mjs";import{ci as e,li as t,si as n}from"../_chunks/utils.mjs";import{t as r}from"../_chunks/module.mjs";import"../_chunks/common-exports.mjs";import{configureLogger as i,getConsoleSink as a,getTextFormatter as o}from"@likec4/log";import{startLanguageServer as s}from"langium/lsp";import{BrowserMessageReader as c,BrowserMessageWriter as l,createConnection as u}from"vscode-languageserver/browser";function startLanguageServer(e){let t=u(new c(e),new l(e));i({sinks:{console:a({formatter:o({format:({level:e,category:t,message:n})=>`${e} ${t} ${n}`})})},loggers:[{category:`likec4`,sinks:[`console`],lowestLevel:`debug`}]});let n=r({connection:t});return s(n.shared),n}export{n as NoFileSystem,e as NoFileSystemWatcher,t as NoLikeC4ManualLayouts,r as createLanguageServices,startLanguageServer};
|
package/dist/browser/worker.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_chunks/
|
|
1
|
+
import"../_chunks/icons.mjs";import"../_chunks/utils.mjs";import"../_chunks/module.mjs";import"../_chunks/common-exports.mjs";import{startLanguageServer as e}from"./index.mjs";function errToString(e){switch(!0){case e instanceof Error:return e.message;case typeof e==`object`&&!!e:try{return JSON.stringify(e)}catch{return`[unserializable value]`}case typeof e==`string`:return e;case e==null:return``;case typeof e==`number`||typeof e==`boolean`:return String(e);case typeof e==`symbol`:return e.toString();default:return`unknown`}}const log=(e,t)=>{let n=t==null?e:`${e} ${errToString(t)}`;try{console.error(`[LikeC4 LSP worker]`,n)}catch{}};self.onerror=e=>(log(`Uncaught error`,e.message??e.error),!1),self.onunhandledrejection=e=>{log(`Unhandled rejection`,e.reason)};try{e(self)}catch(e){throw log(`Failed to start language server`,e),e}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as NoFileSystem, B as ManualLayoutsSnapshot, D as WithLikeC4ManualLayouts, F as FileSystemProvider, I as FileSystemWatcher, L as FileSystemWatcherModuleContext, M as NoLikeC4ManualLayouts, N as FileNode, O as WithChokidarWatcher, P as FileSystemModuleContext, R as LikeC4ManualLayouts, j as NoFileSystemWatcher, k as WithFileSystem, z as LikeC4ManualLayoutsModuleContext } from "../_chunks/module.mjs";
|
|
2
2
|
import "../_chunks/protocol.mjs";
|
|
3
3
|
export { FileNode, FileSystemModuleContext, FileSystemProvider, FileSystemWatcher, FileSystemWatcherModuleContext, LikeC4ManualLayouts, LikeC4ManualLayoutsModuleContext, ManualLayoutsSnapshot, NoFileSystem, NoFileSystemWatcher, NoLikeC4ManualLayouts, WithChokidarWatcher, WithFileSystem, WithLikeC4ManualLayouts };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../_chunks/
|
|
1
|
+
import"../_chunks/icons.mjs";import{ci as e,li as t,si as n}from"../_chunks/utils.mjs";import{n as r,r as i,t as a}from"../_chunks/LikeC4FileSystem.mjs";export{n as NoFileSystem,e as NoFileSystemWatcher,t as NoLikeC4ManualLayouts,r as WithChokidarWatcher,a as WithFileSystem,i as WithLikeC4ManualLayouts};
|
package/dist/icons.d.mts
ADDED
package/dist/icons.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,r as t}from"./_chunks/icons.mjs";export{e as iconGroups,t as iconRegistry};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as NoFileSystem, C as LikeC4ModelBuilder, D as WithLikeC4ManualLayouts, E as LangiumDocuments, F as FileSystemProvider, H as ProjectData, I as FileSystemWatcher, L as FileSystemWatcherModuleContext, M as NoLikeC4ManualLayouts, P as FileSystemModuleContext, R as LikeC4ManualLayouts, S as ViewLocateResult, T as LikeC4WorkspaceManager, U as ProjectsManager, V as Project, _ as LikeC4ViewsModuleContext, b as LikeC4Views, d as LikeC4LanguageServices, f as DocumentParser, g as configureLanguageServerLogger, h as ConfigureLanguageServerLoggerOptions, j as NoFileSystemWatcher, k as WithFileSystem, m as startLanguageServer, n as LikeC4AddedServices, o as LikeC4SharedServices, p as LikeC4ModelParser, r as LikeC4Services, s as createLanguageServices, t as LanguageServicesContext, u as FormatOptions, w as FqnIndex, x as LikeC4ModelLocator, y as WithWasmGraphviz, z as LikeC4ManualLayoutsModuleContext } from "./_chunks/module.mjs";
|
|
2
2
|
import "./_chunks/protocol.mjs";
|
|
3
|
-
export { ConfigureLanguageServerLoggerOptions, DocumentParser, FileSystemModuleContext, FileSystemProvider, FileSystemWatcher, FileSystemWatcherModuleContext, FormatOptions, FqnIndex, LangiumDocuments, LanguageServicesContext, LikeC4AddedServices, LikeC4LanguageServices, LikeC4ManualLayouts, LikeC4ManualLayoutsModuleContext, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser, LikeC4Services, LikeC4SharedServices, LikeC4Views, LikeC4ViewsModuleContext, LikeC4WorkspaceManager, NoFileSystem, NoFileSystemWatcher, NoLikeC4ManualLayouts,
|
|
3
|
+
export { ConfigureLanguageServerLoggerOptions, DocumentParser, FileSystemModuleContext, FileSystemProvider, FileSystemWatcher, FileSystemWatcherModuleContext, FormatOptions, FqnIndex, LangiumDocuments, LanguageServicesContext, LikeC4AddedServices, LikeC4LanguageServices, LikeC4ManualLayouts, LikeC4ManualLayoutsModuleContext, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser, LikeC4Services, LikeC4SharedServices, LikeC4Views, LikeC4ViewsModuleContext, LikeC4WorkspaceManager, NoFileSystem, NoFileSystemWatcher, NoLikeC4ManualLayouts, Project, ProjectData, ProjectsManager, ViewLocateResult, WithFileSystem, WithLikeC4ManualLayouts, WithWasmGraphviz, configureLanguageServerLogger, createLanguageServices, startLanguageServer };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_chunks/
|
|
1
|
+
import"./_chunks/icons.mjs";import{ci as e,ii as t,li as n,oi as r,si as i}from"./_chunks/utils.mjs";import{r as a,t as o}from"./_chunks/LikeC4FileSystem.mjs";import{i as s,t as c}from"./_chunks/module.mjs";import"./_chunks/common-exports.mjs";import{configureLogger as l,getAnsiColorFormatter as u,getConsoleSink as d,getConsoleStderrSink as f,getTextFormatter as p}from"@likec4/log";import{isEmpty as m}from"remeda";import{startLanguageServer as h}from"langium/lsp";import{GraphvizWasmAdapter as g,QueueGraphvizLayoter as _}from"@likec4/layouts";import{GraphvizBinaryAdapter as v}from"@likec4/layouts/graphviz/binary";import{defu as y}from"defu";import{isDevelopment as b}from"std-env";import x from"which";function configureLanguageServerLogger({lspConnection:e,enableTelemetry:n=!!e,useStdErr:i=!1,logLevel:a=b?`debug`:`warning`,nonBlocking:o=!1,colors:s=!1}={}){let c=!!e&&n&&!b;l({reset:!0,sinks:{console:i?f({formatter:p()}):d({formatter:s?u():p(),nonBlocking:o}),...c&&{telemetry:t(e)}},loggers:[{category:[`likec4`],sinks:[`console`,...c?[`telemetry`]:[]],lowestLevel:a}]}),r.trace(`logger configured`)}function graphvizBinPath(){try{return x.sync(`dot`)}catch(e){return r.error(`Error checking for native Graphviz:`,{error:e}),null}}const S={likec4:{Layouter(e){r.debug(`Creating ConfigurableLayouter`);let t=e.likec4.Graphviz,n=new _({graphviz:t});return e.shared.workspace.ConfigurationProvider.onConfigurationSectionUpdate(t=>{if(r.debug(`Configuration update: {update}`,{update:t}),t.section!==e.LanguageMetaData.languageId){r.debug(`Ignoring configuration update as it is not for ${e.LanguageMetaData.languageId}`);return}try{let{mode:i,path:a}=t.configuration.graphviz??{mode:`wasm`,path:``};if(i!==`wasm`){let t=m(a)?graphvizBinPath():a;if(!m(t)){n.changePort(new v(t)),r.info`use graphviz binary: ${t}`;return}r.warn(`No Graphviz binaries found on PATH, use graphviz wasm`),e.shared.lsp.Connection?.window.showWarningMessage(`No Graphviz binaries found on PATH, set path to binaries in settings.`)}n.changePort(new g),r.info(`use graphviz wasm`)}catch(e){r.error(`Failed to update configuration`,{error:e})}}),n}}};function startLanguageServer(e){let t=e?.connection,n=y(e,{enableWatcher:!0,enableManualLayouts:!0,graphviz:`wasm`,configureLogger:!1});n.configureLogger!==!1&&(n.configureLogger===`stderr`?configureLanguageServerLogger({lspConnection:t,enableTelemetry:!1,useStdErr:!0}):n.configureLogger===`console`&&configureLanguageServerLogger({lspConnection:t})),t?r.info(`Starting LikeC4 language server`):r.warn(`Starting LikeC4 language server (headless - no LSP connection)`);let i=c({...t&&{connection:t},...o(n.enableWatcher),...n.enableManualLayouts&&a,...s(n.graphviz===`binary`?new v:new g)},t?{likec4:{...S.likec4}}:void 0);return h(i.shared),i}export{i as NoFileSystem,e as NoFileSystemWatcher,n as NoLikeC4ManualLayouts,o as WithFileSystem,a as WithLikeC4ManualLayouts,configureLanguageServerLogger,c as createLanguageServices,startLanguageServer};
|
package/dist/likec4lib.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import { r as LibIcons } from "./_chunks/icons.mjs";
|
|
1
2
|
import { URI } from "vscode-uri";
|
|
2
3
|
|
|
3
|
-
//#region src/generated-lib/icons.d.ts
|
|
4
|
-
declare const LibIcons: string;
|
|
5
|
-
//#endregion
|
|
6
4
|
//#region src/likec4lib.d.ts
|
|
7
5
|
declare const Scheme = "likec4builtin";
|
|
8
6
|
declare const Uri: "likec4builtin:///likec4/lib/icons.c4";
|
package/dist/likec4lib.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{t as e}from"./_chunks/icons.mjs";const t=`likec4builtin`,n=`${t}:///likec4/lib/icons.c4`;function isLikeC4Builtin(e){return(`uri`in e?e.uri:e).scheme===t}function isNotLikeC4Builtin(e){return!isLikeC4Builtin(e)}export{e as Content,t as Scheme,n as Uri,isLikeC4Builtin,isNotLikeC4Builtin};
|
package/dist/module.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as NoFileSystem, M as NoLikeC4ManualLayouts, a as LikeC4SharedModuleContext, c as createLikeC4Module, i as LikeC4ServicesContext, l as createSharedServices, n as LikeC4AddedServices, o as LikeC4SharedServices, r as LikeC4Services, s as createLanguageServices, t as LanguageServicesContext, v as WithGraphviz, y as WithWasmGraphviz } from "./_chunks/module.mjs";
|
|
2
2
|
import "./_chunks/protocol.mjs";
|
|
3
|
-
export { LanguageServicesContext, LikeC4AddedServices, LikeC4Services, LikeC4ServicesContext, LikeC4SharedModuleContext, LikeC4SharedServices, NoFileSystem, NoLikeC4ManualLayouts,
|
|
3
|
+
export { LanguageServicesContext, LikeC4AddedServices, LikeC4Services, LikeC4ServicesContext, LikeC4SharedModuleContext, LikeC4SharedServices, NoFileSystem, NoLikeC4ManualLayouts, WithGraphviz, WithWasmGraphviz, createLanguageServices, createLikeC4Module, createSharedServices };
|
package/dist/module.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_chunks/
|
|
1
|
+
import"./_chunks/icons.mjs";import{li as e,si as t}from"./_chunks/utils.mjs";import{a as n,i as r,n as i,r as a,t as o}from"./_chunks/module.mjs";export{t as NoFileSystem,e as NoLikeC4ManualLayouts,r as WithGraphviz,n as WithWasmGraphviz,o as createLanguageServices,i as createLikeC4Module,a as createSharedServices};
|
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.
|
|
4
|
+
"version": "1.55.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
7
7
|
"homepage": "https://likec4.dev",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"bin",
|
|
11
11
|
"dist",
|
|
12
|
+
"src/test",
|
|
12
13
|
"**/package.json",
|
|
13
14
|
"!**/__mocks__/",
|
|
14
15
|
"!**/__tests__/",
|
|
@@ -61,6 +62,14 @@
|
|
|
61
62
|
"default": "./dist/likec4lib.mjs"
|
|
62
63
|
}
|
|
63
64
|
},
|
|
65
|
+
"./icons": {
|
|
66
|
+
"sources": "./src/icons.ts",
|
|
67
|
+
"default": {
|
|
68
|
+
"types": "./dist/icons.d.mts",
|
|
69
|
+
"import": "./dist/icons.mjs",
|
|
70
|
+
"default": "./dist/icons.mjs"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
64
73
|
"./browser-worker": {
|
|
65
74
|
"sources": "./src/browser/worker.ts",
|
|
66
75
|
"default": {
|
|
@@ -85,14 +94,6 @@
|
|
|
85
94
|
"default": "./dist/protocol.mjs"
|
|
86
95
|
}
|
|
87
96
|
},
|
|
88
|
-
"./mcp": {
|
|
89
|
-
"sources": "./src/mcp/index.ts",
|
|
90
|
-
"default": {
|
|
91
|
-
"types": "./dist/mcp/index.d.mts",
|
|
92
|
-
"import": "./dist/mcp/index.mjs",
|
|
93
|
-
"default": "./dist/mcp/index.mjs"
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
97
|
"./module": {
|
|
97
98
|
"sources": "./src/module.ts",
|
|
98
99
|
"default": {
|
|
@@ -109,6 +110,7 @@
|
|
|
109
110
|
"default": "./dist/filesystem/index.mjs"
|
|
110
111
|
}
|
|
111
112
|
},
|
|
113
|
+
"./test": "./src/test/index.ts",
|
|
112
114
|
"./package.json": "./package.json"
|
|
113
115
|
},
|
|
114
116
|
"publishConfig": {
|
|
@@ -116,29 +118,28 @@
|
|
|
116
118
|
"access": "public"
|
|
117
119
|
},
|
|
118
120
|
"dependencies": {
|
|
119
|
-
"@hono/mcp": "^0.2.4",
|
|
120
|
-
"@hono/node-server": "^1.19.11",
|
|
121
121
|
"@hpcc-js/wasm-graphviz": "1.21.2",
|
|
122
122
|
"chokidar": "^5.0.0",
|
|
123
|
-
"defu": "^6.1.
|
|
123
|
+
"defu": "^6.1.7",
|
|
124
124
|
"fast-equals": "^6.0.0",
|
|
125
125
|
"fdir": "6.4.0",
|
|
126
|
-
"hono": "^4.12.8",
|
|
127
126
|
"immer": "^11.1.4",
|
|
128
127
|
"indent-string": "^5.0.0",
|
|
129
128
|
"json5": "^2.2.3",
|
|
130
129
|
"langium": "3.5.0",
|
|
131
130
|
"nano-spawn": "^2.0.0",
|
|
131
|
+
"pathe": "^2.0.3",
|
|
132
132
|
"p-limit": "7.3.0",
|
|
133
133
|
"p-queue": "8.1.1",
|
|
134
|
-
"
|
|
134
|
+
"p-timeout": "7.0.1",
|
|
135
|
+
"picomatch": "^4.0.4",
|
|
135
136
|
"pretty-ms": "^9.3.0",
|
|
136
|
-
"remeda": "^2.33.
|
|
137
|
+
"remeda": "^2.33.7",
|
|
137
138
|
"std-env": "^3.10.0",
|
|
138
139
|
"strip-indent": "^4.1.1",
|
|
139
140
|
"type-fest": "^4.41.0",
|
|
140
141
|
"ufo": "1.6.3",
|
|
141
|
-
"unstorage": "^1.17.
|
|
142
|
+
"unstorage": "^1.17.5",
|
|
142
143
|
"vscode-jsonrpc": "8.2.1",
|
|
143
144
|
"vscode-languageserver": "9.0.1",
|
|
144
145
|
"vscode-languageserver-protocol": "3.17.5",
|
|
@@ -146,14 +147,13 @@
|
|
|
146
147
|
"vscode-languageserver-types": "3.17.5",
|
|
147
148
|
"vscode-uri": "3.1.0",
|
|
148
149
|
"which": "^5.0.0",
|
|
149
|
-
"zod": "^3.
|
|
150
|
-
"@likec4/
|
|
151
|
-
"@likec4/
|
|
152
|
-
"@likec4/
|
|
153
|
-
"@likec4/log": "1.
|
|
150
|
+
"zod": "^4.3.6",
|
|
151
|
+
"@likec4/config": "1.55.0",
|
|
152
|
+
"@likec4/core": "1.55.0",
|
|
153
|
+
"@likec4/layouts": "1.55.0",
|
|
154
|
+
"@likec4/log": "1.55.0"
|
|
154
155
|
},
|
|
155
156
|
"peerDependencies": {
|
|
156
|
-
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
157
157
|
"bundle-require": "^5.1.0",
|
|
158
158
|
"esbuild": "0.27.4"
|
|
159
159
|
},
|
|
@@ -163,30 +163,26 @@
|
|
|
163
163
|
},
|
|
164
164
|
"bundle-require": {
|
|
165
165
|
"optional": true
|
|
166
|
-
},
|
|
167
|
-
"@modelcontextprotocol/sdk": {
|
|
168
|
-
"optional": true
|
|
169
166
|
}
|
|
170
167
|
},
|
|
171
168
|
"devDependencies": {
|
|
172
|
-
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
173
169
|
"@types/natural-compare-lite": "^1.4.2",
|
|
174
170
|
"@types/node": "~22.19.15",
|
|
175
|
-
"@types/picomatch": "^4.0.
|
|
171
|
+
"@types/picomatch": "^4.0.3",
|
|
176
172
|
"@types/vscode": "^1.106.1",
|
|
177
173
|
"@types/which": "^3.0.4",
|
|
178
174
|
"bundle-require": "^5.1.0",
|
|
179
175
|
"esbuild": "0.27.4",
|
|
180
176
|
"langium-cli": "3.5.2",
|
|
181
177
|
"obuild": "0.4.31",
|
|
182
|
-
"oxlint": "1.
|
|
178
|
+
"oxlint": "1.59.0",
|
|
183
179
|
"tsx": "4.21.0",
|
|
184
|
-
"turbo": "2.
|
|
180
|
+
"turbo": "2.9.5",
|
|
185
181
|
"typescript": "5.9.3",
|
|
186
|
-
"vitest": "4.1.
|
|
182
|
+
"vitest": "4.1.3",
|
|
187
183
|
"@likec4/devops": "1.42.0",
|
|
188
184
|
"@likec4/icons": "1.46.4",
|
|
189
|
-
"@likec4/tsconfig": "1.
|
|
185
|
+
"@likec4/tsconfig": "1.55.0"
|
|
190
186
|
},
|
|
191
187
|
"scripts": {
|
|
192
188
|
"typecheck": "tsc -b --verbose",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './testServices'
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import type { LikeC4ProjectJsonConfig } from '@likec4/config'
|
|
2
|
+
import type { ComputedLikeC4ModelData, ProjectId } from '@likec4/core'
|
|
3
|
+
import { type LangiumDocument, DocumentState, TextDocument, UriUtils } from 'langium'
|
|
4
|
+
import * as assert from 'node:assert'
|
|
5
|
+
import { entries, once } from 'remeda'
|
|
6
|
+
import stripIndent from 'strip-indent'
|
|
7
|
+
import type { LiteralUnion } from 'type-fest'
|
|
8
|
+
import { DiagnosticSeverity } from 'vscode-languageserver-types'
|
|
9
|
+
import { URI, Utils } from 'vscode-uri'
|
|
10
|
+
import type { LikeC4LangiumDocument } from '../ast'
|
|
11
|
+
import { createLanguageServices } from '../module'
|
|
12
|
+
|
|
13
|
+
export function createTestServices(options?: {
|
|
14
|
+
workspace?: string
|
|
15
|
+
projectConfig?: Partial<LikeC4ProjectJsonConfig>
|
|
16
|
+
}) {
|
|
17
|
+
const workspace = options?.workspace ?? 'file:///test/workspace'
|
|
18
|
+
const projectConfig = options?.projectConfig
|
|
19
|
+
|
|
20
|
+
const services = createLanguageServices({}).likec4
|
|
21
|
+
const metaData = services.LanguageMetaData
|
|
22
|
+
const langiumDocuments = services.shared.workspace.LangiumDocuments
|
|
23
|
+
const documentBuilder = services.shared.workspace.DocumentBuilder
|
|
24
|
+
const modelBuilder = services.likec4.ModelBuilder
|
|
25
|
+
const workspaceUri = URI.parse(workspace)
|
|
26
|
+
const formatter = services.lsp.Formatter
|
|
27
|
+
const workspaceFolder = {
|
|
28
|
+
name: projectConfig?.name || 'test-project',
|
|
29
|
+
uri: workspaceUri.toString(),
|
|
30
|
+
}
|
|
31
|
+
let documentIndex = 1
|
|
32
|
+
|
|
33
|
+
const initialize = once(async () => {
|
|
34
|
+
services.shared.workspace.ConfigurationProvider.updateConfiguration({
|
|
35
|
+
settings: { likec4: { formatting: { quoteStyle: 'single' } } },
|
|
36
|
+
})
|
|
37
|
+
services.shared.workspace.WorkspaceManager.initialize({
|
|
38
|
+
capabilities: {},
|
|
39
|
+
processId: null,
|
|
40
|
+
rootUri: workspaceFolder.uri,
|
|
41
|
+
workspaceFolders: [workspaceFolder],
|
|
42
|
+
})
|
|
43
|
+
await services.shared.workspace.WorkspaceManager.initializeWorkspace([workspaceFolder])
|
|
44
|
+
|
|
45
|
+
// Register project with config if provided...
|
|
46
|
+
if (projectConfig) {
|
|
47
|
+
const projectFolderUri = Utils.resolvePath(workspaceUri, 'src')
|
|
48
|
+
await services.shared.workspace.ProjectsManager.registerProject({
|
|
49
|
+
config: {
|
|
50
|
+
name: projectConfig?.name || 'test-project',
|
|
51
|
+
title: projectConfig?.title || 'Test Project',
|
|
52
|
+
contactPerson: projectConfig?.contactPerson || 'Unknown',
|
|
53
|
+
imageAliases: projectConfig?.imageAliases || {},
|
|
54
|
+
exclude: projectConfig?.exclude || ['node_modules'],
|
|
55
|
+
inferTechnologyFromIcon: projectConfig?.inferTechnologyFromIcon,
|
|
56
|
+
implicitViews: projectConfig?.implicitViews ?? false,
|
|
57
|
+
},
|
|
58
|
+
folderUri: projectFolderUri,
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const addDocument = async (input: string, uri?: string) => {
|
|
64
|
+
await initialize()
|
|
65
|
+
const docUri = Utils.resolvePath(
|
|
66
|
+
workspaceUri,
|
|
67
|
+
'./src/',
|
|
68
|
+
uri ?? `${documentIndex++}${metaData.fileExtensions[0]}`,
|
|
69
|
+
)
|
|
70
|
+
const document = services.shared.workspace.LangiumDocumentFactory.fromString(
|
|
71
|
+
stripIndent(input),
|
|
72
|
+
docUri,
|
|
73
|
+
)
|
|
74
|
+
langiumDocuments.addDocument(document)
|
|
75
|
+
return document as LikeC4LangiumDocument
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const removeDocument = async (doc: LangiumDocument | URI) => {
|
|
79
|
+
const uri = doc instanceof URI ? doc : doc.uri
|
|
80
|
+
await documentBuilder.update([], [uri])
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const parse = async (input: string, uri?: string) => {
|
|
84
|
+
const document = await addDocument(input, uri)
|
|
85
|
+
await documentBuilder.build([document], { validation: false })
|
|
86
|
+
return document as LikeC4LangiumDocument
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const validate = async (input: string | LikeC4LangiumDocument, uri?: string) => {
|
|
90
|
+
const document = typeof input === 'string' ? await addDocument(input, uri) : input
|
|
91
|
+
await documentBuilder.build([document], { validation: true })
|
|
92
|
+
const diagnostics = document.diagnostics ?? []
|
|
93
|
+
const warnings = diagnostics.flatMap(d => d.severity === DiagnosticSeverity.Warning ? d.message : [])
|
|
94
|
+
const errors = diagnostics.flatMap(d => d.severity === DiagnosticSeverity.Error ? d.message : [])
|
|
95
|
+
return {
|
|
96
|
+
document,
|
|
97
|
+
diagnostics,
|
|
98
|
+
warnings,
|
|
99
|
+
errors,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const format = async (input: string | LikeC4LangiumDocument, uri?: string) => {
|
|
104
|
+
const document = typeof input === 'string' ? await parse(stripIndent(input), uri) : input
|
|
105
|
+
await documentBuilder.build([document], { validation: true })
|
|
106
|
+
|
|
107
|
+
const edits = await formatter?.formatDocument(
|
|
108
|
+
document,
|
|
109
|
+
{
|
|
110
|
+
options: { tabSize: 2, insertSpaces: true },
|
|
111
|
+
textDocument: { uri: document.uri.toString() },
|
|
112
|
+
},
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
return TextDocument.applyEdits(document.textDocument, edits ?? [])
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const validateAll = async () => {
|
|
119
|
+
const docs = langiumDocuments.all.toArray()
|
|
120
|
+
assert.ok(docs.length > 0, 'no documents to validate')
|
|
121
|
+
await documentBuilder.build(docs, { validation: true })
|
|
122
|
+
const diagnostics = docs.flatMap(doc => doc.diagnostics ?? [])
|
|
123
|
+
const warnings = diagnostics.flatMap(d => d.severity === DiagnosticSeverity.Warning ? d.message : [])
|
|
124
|
+
const errors = diagnostics.flatMap(d => d.severity === DiagnosticSeverity.Error ? d.message : [])
|
|
125
|
+
return {
|
|
126
|
+
diagnostics,
|
|
127
|
+
errors,
|
|
128
|
+
warnings,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const buildModel = async (): Promise<ComputedLikeC4ModelData> => {
|
|
133
|
+
if (langiumDocuments.all.some(doc => doc.state < DocumentState.Validated)) {
|
|
134
|
+
await validateAll()
|
|
135
|
+
}
|
|
136
|
+
const likec4model = await modelBuilder.computeModel()
|
|
137
|
+
if (!likec4model) throw new Error('No model found')
|
|
138
|
+
return likec4model.$data
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const buildLikeC4Model = async () => {
|
|
142
|
+
if (langiumDocuments.all.some(doc => doc.state < DocumentState.Validated)) {
|
|
143
|
+
await validateAll()
|
|
144
|
+
}
|
|
145
|
+
const likec4model = await modelBuilder.computeModel()
|
|
146
|
+
if (!likec4model) throw new Error('No model found')
|
|
147
|
+
return likec4model
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* This will clear all documents
|
|
152
|
+
*/
|
|
153
|
+
const resetState = async () => {
|
|
154
|
+
const docs = langiumDocuments.resetProjectIds()
|
|
155
|
+
await documentBuilder.update([], docs)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
services,
|
|
160
|
+
addDocument,
|
|
161
|
+
removeDocument,
|
|
162
|
+
parse,
|
|
163
|
+
validate,
|
|
164
|
+
validateAll,
|
|
165
|
+
buildModel,
|
|
166
|
+
buildLikeC4Model,
|
|
167
|
+
resetState,
|
|
168
|
+
format,
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* const { projects } = await createMultiProjectTestServices({
|
|
176
|
+
* project1: {
|
|
177
|
+
* doc1: `...`,
|
|
178
|
+
* doc2: `...`,
|
|
179
|
+
* },
|
|
180
|
+
* project2: {
|
|
181
|
+
* doc1: `...`,
|
|
182
|
+
* },
|
|
183
|
+
* })
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export async function createMultiProjectTestServices<const Projects extends Record<string, Record<string, string>>>(
|
|
187
|
+
data: Projects,
|
|
188
|
+
) {
|
|
189
|
+
const workspace = 'file:///test/workspace'
|
|
190
|
+
const {
|
|
191
|
+
services,
|
|
192
|
+
addDocument,
|
|
193
|
+
validateAll,
|
|
194
|
+
resetState,
|
|
195
|
+
} = createTestServices({ workspace })
|
|
196
|
+
|
|
197
|
+
const projects = {} as {
|
|
198
|
+
readonly [K in keyof Projects]: {
|
|
199
|
+
readonly [L in keyof Projects[K]]: LikeC4LangiumDocument
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
for (const [name, files] of entries(data)) {
|
|
204
|
+
const folderUri = UriUtils.joinPath(URI.parse(workspace), 'src', name)
|
|
205
|
+
await services.shared.workspace.ProjectsManager.registerProject({
|
|
206
|
+
config: {
|
|
207
|
+
name,
|
|
208
|
+
exclude: ['node_modules'],
|
|
209
|
+
},
|
|
210
|
+
folderUri,
|
|
211
|
+
})
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
projects[name] = {} as any
|
|
214
|
+
|
|
215
|
+
for (let [docName, content] of entries(files)) {
|
|
216
|
+
const fileName = docName.endsWith('.c4') ? docName : `${docName}.c4`
|
|
217
|
+
// @ts-ignore
|
|
218
|
+
projects[name][docName] = await addDocument(content, `${name}/${fileName}`)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async function buildLikeC4Model(projectId: LiteralUnion<keyof Projects, string>) {
|
|
223
|
+
if (services.shared.workspace.LangiumDocuments.all.some(doc => doc.state < DocumentState.Validated)) {
|
|
224
|
+
await validateAll()
|
|
225
|
+
}
|
|
226
|
+
const likec4model = await services.likec4.ModelBuilder.computeModel(projectId as ProjectId)
|
|
227
|
+
if (!likec4model) throw new Error('No model found')
|
|
228
|
+
return likec4model
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function buildModel(projectId: LiteralUnion<keyof Projects, string>) {
|
|
232
|
+
const model = await buildLikeC4Model(projectId)
|
|
233
|
+
return model.$data as ComputedLikeC4ModelData
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
services,
|
|
238
|
+
projects,
|
|
239
|
+
projectsManager: services.shared.workspace.ProjectsManager,
|
|
240
|
+
addDocument: async (uri: string | URI, input: string) => {
|
|
241
|
+
return await addDocument(input, uri.toString())
|
|
242
|
+
},
|
|
243
|
+
/**
|
|
244
|
+
* Add document outside of projects
|
|
245
|
+
*/
|
|
246
|
+
addDocumentOutside: async (input: string) => {
|
|
247
|
+
return await addDocument(input)
|
|
248
|
+
},
|
|
249
|
+
validateAll,
|
|
250
|
+
buildModel,
|
|
251
|
+
buildLikeC4Model,
|
|
252
|
+
resetState,
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export type TestServices = ReturnType<typeof createTestServices>
|
|
257
|
+
export type TestParseFn = TestServices['validate']
|
|
258
|
+
export type TestValidateFn = TestServices['validate']
|