@likec4/language-server 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.
- package/browser/package.json +2 -2
- package/browser-worker/package.json +2 -2
- package/dist/THIRD-PARTY-LICENSES.md +178 -0
- package/dist/_chunks/ConfigurableLayouter.mjs +1 -1956
- package/dist/_chunks/LikeC4FileSystem.mjs +3 -0
- package/dist/_chunks/WithMCPServer.mjs +1154 -0
- package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -805
- package/dist/_chunks/libs/eventemitter3.mjs +1 -243
- package/dist/_chunks/libs/fast-equals.mjs +1 -446
- package/dist/_chunks/libs/p-queue.mjs +1 -449
- package/dist/_chunks/libs/parse-ms.mjs +1 -36
- package/dist/_chunks/libs/picomatch.mjs +1 -1673
- package/dist/_chunks/libs/pretty-ms.mjs +1 -80
- package/dist/_chunks/libs/remeda.mjs +2 -482
- package/dist/_chunks/libs/strip-indent.mjs +1 -15
- package/dist/_chunks/libs/ufo.mjs +1 -166
- package/dist/_chunks/likec4lib.mjs +2 -9
- package/dist/_chunks/{LikeC4LanguageServices.d.mts → module.d.mts} +2101 -732
- package/dist/_chunks/module.mjs +34 -28
- package/dist/_chunks/noop.mjs +1 -0
- package/dist/_chunks/protocol.d.mts +6 -2
- package/dist/_chunks/rolldown-runtime.mjs +1 -42
- package/dist/_chunks/utils.mjs +1 -0
- package/dist/_chunks/workspace.mjs +1 -0
- package/dist/browser/index.d.mts +15 -0
- package/dist/browser/index.mjs +1 -0
- package/dist/browser/worker.mjs +1 -0
- package/dist/bundled.d.mts +1 -2
- package/dist/bundled.mjs +1 -51
- package/dist/filesystem/index.d.mts +2 -3
- package/dist/filesystem/index.mjs +1 -3
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +1 -48
- package/dist/likec4lib.d.mts +10 -3
- package/dist/likec4lib.mjs +1 -4
- package/dist/mcp/index.d.mts +2 -3
- package/dist/mcp/index.mjs +1 -3
- package/dist/module.d.mts +2 -3
- package/dist/module.mjs +1 -3
- package/dist/protocol.mjs +1 -3
- package/filesystem/package.json +4 -0
- package/mcp/package.json +4 -0
- package/module/package.json +4 -0
- package/package.json +79 -56
- package/LICENSE +0 -21
- package/dist/LikeC4LanguageServices.d.mts +0 -4
- package/dist/LikeC4LanguageServices.mjs +0 -3
- package/dist/_chunks/LikeC4LanguageServices.mjs +0 -725
- package/dist/_chunks/ast.d.mts +0 -1444
- package/dist/_chunks/ast.mjs +0 -2375
- package/dist/_chunks/ast2.mjs +0 -176
- package/dist/_chunks/filesystem.mjs +0 -58
- package/dist/_chunks/grammar.mjs +0 -8
- package/dist/_chunks/icons.mjs +0 -5211
- package/dist/_chunks/libs/@hono/node-server.mjs +0 -436
- package/dist/_chunks/libs/hono.mjs +0 -1829
- package/dist/_chunks/mcp.mjs +0 -33
- package/dist/_chunks/module2.mjs +0 -6576
- package/dist/_chunks/protocol.mjs +0 -78
- package/dist/ast.d.mts +0 -4
- package/dist/ast.mjs +0 -4
- package/dist/browser-worker.mjs +0 -6
- package/dist/browser.d.mts +0 -11
- package/dist/browser.mjs +0 -27
- package/dist/common-exports.d.mts +0 -4
- package/dist/common-exports.mjs +0 -5
- package/dist/generated/ast.d.mts +0 -2
- package/dist/generated/ast.mjs +0 -3
- package/dist/generated/grammar.d.mts +0 -6
- package/dist/generated/grammar.mjs +0 -3
- package/dist/generated/module.d.mts +0 -14
- package/dist/generated/module.mjs +0 -3
- package/dist/generated-lib/icons.d.mts +0 -4
- package/dist/generated-lib/icons.mjs +0 -3
- /package/dist/{browser-worker.d.mts → browser/worker.d.mts} +0 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{a as e,r as t}from"./likec4lib.mjs";import{n}from"./noop.mjs";import{Er as r,n as i,r as a,t as o}from"./utils.mjs";import{t as s}from"./libs/p-queue.mjs";import{D as c,o as l}from"./libs/remeda.mjs";import{isLikeC4Config as u,loadConfig as d}from"@likec4/config/node";import{fdir as f}from"fdir";import{SimpleCache as p,URI as m,UriUtils as h}from"langium";import{NodeFileSystemProvider as g}from"langium/node";import{mkdirSync as _,statSync as v}from"node:fs";import{unlink as y,writeFile as b}from"node:fs/promises";import{basename as x,dirname as S}from"node:path";import{objectHash as C,onNextTick as w}from"@likec4/core/utils";import T from"chokidar";import E from"json5";import{Position as D,Range as O}from"vscode-languageserver-types";const k=r.getChild(`manual-layouts`),isManualLayoutFile=e=>e.endsWith(`.likec4.snap`);function fileName(e){return`${e}.likec4.snap`}function getManualLayoutsOutDir(e){return h.resolvePath(e.folderUri,e.config.manualLayouts?.outDir??`.likec4`)}const A={manualLayouts:e=>new DefaultLikeC4ManualLayouts(e)},j=`file://./`;var DefaultLikeC4ManualLayouts=class{cache;constructor(e){this.services=e,this.cache=new p,w(()=>{e.workspace.ProjectsManager.onProjectsUpdate(()=>{this.clearCaches()})})}async read(e){return await this.cache.get(e.id,async()=>{let t=k.getChild(e.id),n=this.services.workspace.FileSystemProvider,r=getManualLayoutsOutDir(e),i=[];try{let a=await n.scanDirectory(r,isManualLayoutFile);if(a.length===0)return null;for(let r of a)try{let t=await n.readFile(r.uri),a=E.parse(t),o=this.resolveIconPathsAfterRead(a,e.folderUri);i.push({...o,_layout:`manual`})}catch(e){t.warn(`Failed to read view snapshot ${r.uri.fsPath}`,{err:e})}i.length&&t.debug`read manual layouts for ${e.id}, found ${i.length}`}catch(n){t.warn(`Failed to read manual layouts for ${e.folderUri.fsPath}`,{err:n})}if(i.length===0)return null;let a=c(i,l(`id`));return{hash:C(a),views:a}})}async write(e,t){let n=k.getChild(e.id),r=getManualLayoutsOutDir(e),i=h.joinPath(r,fileName(t.id));if(`manualLayout`in t){let{manualLayout:e,...n}=t;t=n}let a=E.stringify(this.normalizeIconPathsForWrite(t,e.folderUri),{space:2,quote:`'`}),o={uri:i.toString(),range:O.create(D.create(0,0),D.create(a.split(`
|
|
2
|
+
`).length-1,1))};n.debug`write snapshot of ${t.id} in project ${e.id} to ${i.fsPath}`;let s=this.services.workspace.FileSystemProvider;try{await s.writeFile(i,a+`
|
|
3
|
+
`)}catch(e){n.warn(`Failed to write snapshot ${t.id} to ${i.fsPath}`,{err:e})}return this.cache.delete(e.id),o}async remove(e,t){let n=k.getChild(e.id),r=getManualLayoutsOutDir(e),i=h.joinPath(r,fileName(t));n.debug`delete snapshot of ${t} in project ${e.id}. File: ${i.fsPath}`;let a={uri:i.toString(),range:O.create(0,0,0,0)};this.cache.delete(e.id);try{if(!await this.services.workspace.FileSystemProvider.deleteFile(i))return n.warn`Snapshot ${t} did not exist at ${i.fsPath}`,null}catch(e){n.warn(`Failed to delete snapshot ${t} from ${i.fsPath}`,{err:e})}return a}clearCaches(){k.trace`clear caches`,this.cache.clear()}normalizeIconPathsForWrite(e,t){let n=e.nodes.map(e=>{if(!e.icon||typeof e.icon!=`string`)return e;if(e.icon.startsWith(`file://`)){let n=m.parse(e.icon),r=h.relative(t,n);return r.startsWith(`..`)?e:{...e,icon:`${j}${r}`}}return e});return{...e,nodes:n}}resolveIconPathsAfterRead(e,t){let n=e.nodes.map(e=>{if(!e.icon||typeof e.icon!=`string`)return e;if(e.icon.startsWith(j)){let n=e.icon.substring(9),r=h.joinPath(t,n);return{...e,icon:r.toString()}}return e});return{...e,nodes:n}}};const M=r.getChild(`chokidar`),N={fileSystemWatcher:e=>new ChokidarFileSystemWatcher(e)},isAnyLikeC4File=e=>{let t=x(e);return a(t)||u(t)||isManualLayoutFile(t)};var ChokidarFileSystemWatcher=class{watcher;queue=new s({concurrency:1,timeout:5e3});constructor(e){this.services=e}watch(e){if(this.watcher){M.debug`add watching folder: ${e}`,this.watcher.add(e);return}this.watcher=this.createWatcher(e)}async dispose(){if(this.watcher){let e=this.watcher;this.watcher=void 0,await e.close()}}createWatcher(e){M.debug`create watcher for folder: ${e}`;let t=T.watch(e,{ignored:[e=>e.includes(`node_modules`)||e.includes(`.git`),(e,t)=>!!t?.isFile()&&!isAnyLikeC4File(e)],followSymlinks:!0,ignoreInitial:!0}),onAddOrChange=(e,t)=>{t?.isDirectory()||this.enqueueFileOp(`addOrChange: `+e,async()=>{await this.onAddOrChange(e)})};return t.on(`add`,onAddOrChange).on(`change`,onAddOrChange).on(`unlink`,(e,t)=>{t?.isDirectory()||this.enqueueFileOp(`remove: `+e,async()=>{await this.onRemove(e)})}).on(`unlinkDir`,e=>{this.enqueueFileOp(`removeDir: `+e,async()=>{await this.onRemoveDir(e)})}),t}enqueueFileOp(e,t){this.queue.add(async()=>{try{await t()}catch(t){M.warn(`Failed on {fileop}`,{fileop:e,error:t})}}).catch(t=>{M.error(`Error on {fileop}`,{fileop:e,error:t})})}async onAddOrChange(e){let t=this.services.workspace,n=x(e),r=m.file(e);switch(!0){case u(n):M.debug`project file changed: ${e}`,t.ManualLayouts.clearCaches(),await t.ProjectsManager.registerConfigFile(r);break;case a(n):M.debug`file changed: ${e}`,await t.DocumentBuilder.update([r],[]);break;case isManualLayoutFile(n):{M.debug`manual layout file changed: ${e}`,t.ManualLayouts.clearCaches();let n=t.ProjectsManager.ownerProjectId(r);await t.ProjectsManager.rebuildProject(n);break}default:M.warn`Unknown file change: ${e}`}}async onRemove(e){let t=this.services.workspace,n=x(e),r=m.file(e);switch(!0){case u(n):M.debug`project file removed: ${e}`,t.ManualLayouts.clearCaches(),await t.ProjectsManager.reloadProjects();break;case a(n):M.debug`file removed: ${e}`,await t.DocumentBuilder.update([],[r]);break;case isManualLayoutFile(n):{M.debug`manual layout file removed: ${e}`;let n=t.ProjectsManager.ownerProjectId(r);t.ManualLayouts.clearCaches(),await t.ProjectsManager.rebuildProject(n);break}default:M.warn`Unknown file removal: ${e}`}}async onRemoveDir(e){M.debug`directory removed: ${e}`;let t=this.services.workspace;t.ProjectsManager.findOverlaped(e).length>0&&(t.ManualLayouts.clearCaches(),await t.ProjectsManager.reloadProjects())}};const P=r.getChild(`filesystem`);function isLikeC4ConfigFile(e,t=!1){return!t&&u(x(e))}function isLikeC4File(e,t=!1){return!t&&a(x(e))}const WithFileSystem=(e=!0)=>({fileSystemProvider:()=>new SymLinkTraversingFileSystemProvider,...e?N:n});var SymLinkTraversingFileSystemProvider=class extends g{async readFile(n){if(t(n))return Promise.resolve(e);try{return await super.readFile(n)}catch(e){return P.warn(`Failed to read file ${n.fsPath}`,{error:e}),``}}async readDirectory(e,t){let n=t?.recursive??!0,r=t?.maxDepth??1/0,a=[];try{let t=new f().withSymlinks({resolvePaths:!1}).exclude(i).withFullPaths().filter(isLikeC4File);n?r!==1/0&&(t=t.withMaxDepth(r)):t=t.withMaxDepth(1);let o=await t.crawl(e.fsPath).withPromise();for(let e of o)a.push({isFile:!0,isDirectory:!1,uri:m.file(e)})}catch(t){P.warn(`Failed to read directory ${e.fsPath}`,{error:t})}return a.sort(o)}async scanProjectFiles(e){return await this.scanDirectory(e,isLikeC4ConfigFile)}async scanDirectory(e,t){let n=[];try{let r=await new f().withSymlinks({resolvePaths:!1}).exclude(i).withFullPaths().filter(t).crawl(e.fsPath).withPromise();for(let e of r)n.push({isFile:!0,isDirectory:!1,uri:m.file(e)})}catch(t){P.warn(`Failed to scan directory {path}`,{path:e.fsPath,error:t})}return n}async loadProjectConfig(e){return await d(e)}async writeFile(e,t){let n=S(e.fsPath),r=v(n,{throwIfNoEntry:!1});if(r?.isFile())throw Error(`Cannot create directory ${n} because a file with the same name exists.`);return r||(P.debug(`creating directory {path}`,{path:n}),_(n,{recursive:!0})),P.debug(`writing file {path}`,{path:e.fsPath}),await b(e.fsPath,t,{encoding:`utf-8`})}async deleteFile(e){try{let t=e.fsPath,n=v(t,{throwIfNoEntry:!1});return n?.isFile()||n?.isSymbolicLink()?(await y(t),P.debug(`deleted file {path}`,{path:t}),!0):(P.warn(`deleteFile failed: {path} does not exist, or is not a file`,{path:t}),!1)}catch(t){P.warn(`Failed to delete file ${e.fsPath}`,{error:t})}return!1}};export{N as n,A as r,WithFileSystem as t};
|