@likec4/language-server 1.47.0 → 1.49.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.
Files changed (297) hide show
  1. package/browser/package.json +2 -2
  2. package/browser-worker/package.json +2 -2
  3. package/bundled/package.json +4 -0
  4. package/dist/THIRD-PARTY-LICENSES.md +178 -0
  5. package/dist/_chunks/ConfigurableLayouter.mjs +1 -0
  6. package/dist/_chunks/LikeC4FileSystem.mjs +3 -0
  7. package/dist/_chunks/LikeC4Views.mjs +34 -0
  8. package/dist/_chunks/ProjectsManager.mjs +1 -0
  9. package/dist/_chunks/WithMCPServer.mjs +481 -0
  10. package/dist/_chunks/icons.mjs +2 -0
  11. package/dist/_chunks/index.d.mts +3107 -0
  12. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -0
  13. package/dist/_chunks/libs/eventemitter3.mjs +1 -0
  14. package/dist/_chunks/libs/fast-equals.mjs +1 -0
  15. package/dist/_chunks/libs/p-queue.mjs +1 -0
  16. package/dist/_chunks/libs/parse-ms.mjs +1 -0
  17. package/dist/_chunks/libs/picomatch.mjs +1 -0
  18. package/dist/_chunks/libs/pretty-ms.mjs +1 -0
  19. package/dist/_chunks/libs/remeda.mjs +1 -0
  20. package/dist/_chunks/libs/strip-indent.mjs +1 -0
  21. package/dist/_chunks/libs/ufo.mjs +1 -0
  22. package/dist/_chunks/logger.mjs +1 -0
  23. package/dist/_chunks/rolldown-runtime.mjs +1 -0
  24. package/dist/_chunks/utils.mjs +1 -0
  25. package/dist/browser/index.d.mts +10 -0
  26. package/dist/browser/index.mjs +1 -0
  27. package/dist/browser/worker.d.mts +1 -0
  28. package/dist/browser/worker.mjs +1 -0
  29. package/dist/bundled.d.mts +27 -0
  30. package/dist/bundled.mjs +1 -4853
  31. package/dist/filesystem/index.d.mts +2 -0
  32. package/dist/filesystem/index.mjs +1 -0
  33. package/dist/index.d.mts +39 -0
  34. package/dist/index.mjs +1 -0
  35. package/dist/likec4lib.d.mts +16 -0
  36. package/dist/likec4lib.mjs +1 -0
  37. package/dist/mcp/index.d.mts +2 -0
  38. package/dist/mcp/index.mjs +1 -0
  39. package/dist/module.d.mts +126 -0
  40. package/dist/module.mjs +1 -0
  41. package/dist/protocol.d.mts +315 -0
  42. package/dist/protocol.mjs +1 -0
  43. package/filesystem/package.json +4 -0
  44. package/likec4lib/package.json +2 -2
  45. package/mcp/package.json +4 -0
  46. package/module/package.json +4 -0
  47. package/package.json +128 -62
  48. package/protocol/package.json +2 -2
  49. package/LICENSE +0 -21
  50. package/dist/LikeC4LanguageServices.d.ts +0 -115
  51. package/dist/LikeC4LanguageServices.js +0 -164
  52. package/dist/Rpc.d.ts +0 -9
  53. package/dist/Rpc.js +0 -276
  54. package/dist/ast.d.ts +0 -226
  55. package/dist/ast.js +0 -264
  56. package/dist/browser-worker.d.ts +0 -1
  57. package/dist/browser-worker.js +0 -4
  58. package/dist/browser.d.ts +0 -10
  59. package/dist/browser.js +0 -34
  60. package/dist/bundled.d.ts +0 -8
  61. package/dist/bundled.js +0 -44
  62. package/dist/documentation/documentation-provider.d.ts +0 -8
  63. package/dist/documentation/documentation-provider.js +0 -51
  64. package/dist/documentation/index.d.ts +0 -1
  65. package/dist/documentation/index.js +0 -1
  66. package/dist/empty.d.ts +0 -2
  67. package/dist/empty.js +0 -2
  68. package/dist/filesystem/ChokidarWatcher.d.ts +0 -19
  69. package/dist/filesystem/ChokidarWatcher.js +0 -133
  70. package/dist/filesystem/FileSystemWatcher.d.ts +0 -19
  71. package/dist/filesystem/FileSystemWatcher.js +0 -14
  72. package/dist/filesystem/LikeC4FileSystem.d.ts +0 -3
  73. package/dist/filesystem/LikeC4FileSystem.js +0 -140
  74. package/dist/filesystem/index.d.ts +0 -55
  75. package/dist/filesystem/index.js +0 -29
  76. package/dist/formatting/LikeC4Formatter.d.ts +0 -59
  77. package/dist/formatting/LikeC4Formatter.js +0 -637
  78. package/dist/formatting/utils.d.ts +0 -6
  79. package/dist/formatting/utils.js +0 -18
  80. package/dist/generated/ast.d.ts +0 -1411
  81. package/dist/generated/ast.js +0 -2207
  82. package/dist/generated/grammar.d.ts +0 -6
  83. package/dist/generated/grammar.js +0 -7
  84. package/dist/generated/module.d.ts +0 -14
  85. package/dist/generated/module.js +0 -27
  86. package/dist/generated-lib/icons.d.ts +0 -1
  87. package/dist/generated-lib/icons.js +0 -18
  88. package/dist/index.d.ts +0 -37
  89. package/dist/index.js +0 -54
  90. package/dist/likec4lib.d.ts +0 -6
  91. package/dist/likec4lib.js +0 -7
  92. package/dist/logger.d.ts +0 -17
  93. package/dist/logger.js +0 -81
  94. package/dist/lsp/CodeActionProvider.d.ts +0 -14
  95. package/dist/lsp/CodeActionProvider.js +0 -33
  96. package/dist/lsp/CodeLensProvider.d.ts +0 -9
  97. package/dist/lsp/CodeLensProvider.js +0 -44
  98. package/dist/lsp/CompletionProvider.d.ts +0 -13
  99. package/dist/lsp/CompletionProvider.js +0 -238
  100. package/dist/lsp/DocumentHighlightProvider.d.ts +0 -9
  101. package/dist/lsp/DocumentHighlightProvider.js +0 -10
  102. package/dist/lsp/DocumentLinkProvider.d.ts +0 -11
  103. package/dist/lsp/DocumentLinkProvider.js +0 -58
  104. package/dist/lsp/DocumentSymbolProvider.d.ts +0 -33
  105. package/dist/lsp/DocumentSymbolProvider.js +0 -317
  106. package/dist/lsp/HoverProvider.d.ts +0 -10
  107. package/dist/lsp/HoverProvider.js +0 -106
  108. package/dist/lsp/RenameProvider.d.ts +0 -5
  109. package/dist/lsp/RenameProvider.js +0 -6
  110. package/dist/lsp/SemanticTokenProvider.d.ts +0 -19
  111. package/dist/lsp/SemanticTokenProvider.js +0 -305
  112. package/dist/lsp/index.d.ts +0 -8
  113. package/dist/lsp/index.js +0 -9
  114. package/dist/mcp/MCPServerFactory.d.ts +0 -8
  115. package/dist/mcp/MCPServerFactory.js +0 -73
  116. package/dist/mcp/NoopLikeC4MCPServer.d.ts +0 -9
  117. package/dist/mcp/NoopLikeC4MCPServer.js +0 -17
  118. package/dist/mcp/interfaces.d.ts +0 -13
  119. package/dist/mcp/interfaces.js +0 -4
  120. package/dist/mcp/server/StdioLikeC4MCPServer.d.ts +0 -16
  121. package/dist/mcp/server/StdioLikeC4MCPServer.js +0 -51
  122. package/dist/mcp/server/StreamableLikeC4MCPServer.d.ts +0 -16
  123. package/dist/mcp/server/StreamableLikeC4MCPServer.js +0 -121
  124. package/dist/mcp/server/WithMCPServer.d.ts +0 -4
  125. package/dist/mcp/server/WithMCPServer.js +0 -54
  126. package/dist/mcp/tools/_common.d.ts +0 -88
  127. package/dist/mcp/tools/_common.js +0 -49
  128. package/dist/mcp/tools/find-relationships.d.ts +0 -202
  129. package/dist/mcp/tools/find-relationships.js +0 -150
  130. package/dist/mcp/tools/list-projects.d.ts +0 -194
  131. package/dist/mcp/tools/list-projects.js +0 -62
  132. package/dist/mcp/tools/open-view.d.ts +0 -200
  133. package/dist/mcp/tools/open-view.js +0 -52
  134. package/dist/mcp/tools/read-deployment.d.ts +0 -200
  135. package/dist/mcp/tools/read-deployment.js +0 -150
  136. package/dist/mcp/tools/read-element.d.ts +0 -200
  137. package/dist/mcp/tools/read-element.js +0 -218
  138. package/dist/mcp/tools/read-project-summary.d.ts +0 -198
  139. package/dist/mcp/tools/read-project-summary.js +0 -176
  140. package/dist/mcp/tools/read-view.d.ts +0 -200
  141. package/dist/mcp/tools/read-view.js +0 -203
  142. package/dist/mcp/tools/search-element.d.ts +0 -198
  143. package/dist/mcp/tools/search-element.js +0 -177
  144. package/dist/mcp/utils.d.ts +0 -18
  145. package/dist/mcp/utils.js +0 -48
  146. package/dist/model/builder/MergedExtends.d.ts +0 -13
  147. package/dist/model/builder/MergedExtends.js +0 -74
  148. package/dist/model/builder/MergedSpecification.d.ts +0 -32
  149. package/dist/model/builder/MergedSpecification.js +0 -175
  150. package/dist/model/builder/buildModel.d.ts +0 -16
  151. package/dist/model/builder/buildModel.js +0 -245
  152. package/dist/model/deployments-index.d.ts +0 -10
  153. package/dist/model/deployments-index.js +0 -102
  154. package/dist/model/fqn-index.d.ts +0 -61
  155. package/dist/model/fqn-index.js +0 -253
  156. package/dist/model/index.d.ts +0 -6
  157. package/dist/model/index.js +0 -6
  158. package/dist/model/model-builder.d.ts +0 -54
  159. package/dist/model/model-builder.js +0 -233
  160. package/dist/model/model-locator.d.ts +0 -39
  161. package/dist/model/model-locator.js +0 -240
  162. package/dist/model/model-parser-where.d.ts +0 -4
  163. package/dist/model/model-parser-where.js +0 -81
  164. package/dist/model/model-parser.d.ts +0 -645
  165. package/dist/model/model-parser.js +0 -133
  166. package/dist/model/parser/Base.d.ts +0 -69
  167. package/dist/model/parser/Base.js +0 -382
  168. package/dist/model/parser/DeploymentModelParser.d.ts +0 -71
  169. package/dist/model/parser/DeploymentModelParser.js +0 -176
  170. package/dist/model/parser/DeploymentViewParser.d.ts +0 -75
  171. package/dist/model/parser/DeploymentViewParser.js +0 -86
  172. package/dist/model/parser/FqnRefParser.d.ts +0 -66
  173. package/dist/model/parser/FqnRefParser.js +0 -382
  174. package/dist/model/parser/GlobalsParser.d.ts +0 -109
  175. package/dist/model/parser/GlobalsParser.js +0 -84
  176. package/dist/model/parser/ImportsParser.d.ts +0 -46
  177. package/dist/model/parser/ImportsParser.js +0 -24
  178. package/dist/model/parser/ModelParser.d.ts +0 -71
  179. package/dist/model/parser/ModelParser.js +0 -209
  180. package/dist/model/parser/PredicatesParser.d.ts +0 -75
  181. package/dist/model/parser/PredicatesParser.js +0 -45
  182. package/dist/model/parser/SpecificationParser.d.ts +0 -53
  183. package/dist/model/parser/SpecificationParser.js +0 -113
  184. package/dist/model/parser/ValueConverter.d.ts +0 -4
  185. package/dist/model/parser/ValueConverter.js +0 -12
  186. package/dist/model/parser/ViewsParser.d.ts +0 -112
  187. package/dist/model/parser/ViewsParser.js +0 -492
  188. package/dist/model-change/ModelChanges.d.ts +0 -18
  189. package/dist/model-change/ModelChanges.js +0 -129
  190. package/dist/model-change/changeElementStyle.d.ts +0 -16
  191. package/dist/model-change/changeElementStyle.js +0 -134
  192. package/dist/model-change/changeViewLayout.d.ts +0 -12
  193. package/dist/model-change/changeViewLayout.js +0 -28
  194. package/dist/model-change/removeManualLayoutV1.d.ts +0 -7
  195. package/dist/model-change/removeManualLayoutV1.js +0 -27
  196. package/dist/module.d.ts +0 -92
  197. package/dist/module.js +0 -143
  198. package/dist/protocol.d.ts +0 -289
  199. package/dist/protocol.js +0 -123
  200. package/dist/references/index.d.ts +0 -3
  201. package/dist/references/index.js +0 -3
  202. package/dist/references/name-provider.d.ts +0 -9
  203. package/dist/references/name-provider.js +0 -37
  204. package/dist/references/scope-computation.d.ts +0 -20
  205. package/dist/references/scope-computation.js +0 -288
  206. package/dist/references/scope-provider.d.ts +0 -40
  207. package/dist/references/scope-provider.js +0 -239
  208. package/dist/shared/NodeKindProvider.d.ts +0 -15
  209. package/dist/shared/NodeKindProvider.js +0 -57
  210. package/dist/shared/WorkspaceSymbolProvider.d.ts +0 -3
  211. package/dist/shared/WorkspaceSymbolProvider.js +0 -3
  212. package/dist/shared/index.d.ts +0 -2
  213. package/dist/shared/index.js +0 -2
  214. package/dist/test/index.d.ts +0 -1
  215. package/dist/test/index.js +0 -1
  216. package/dist/test/testServices.d.ts +0 -64
  217. package/dist/test/testServices.js +0 -210
  218. package/dist/utils/disposable.d.ts +0 -8
  219. package/dist/utils/disposable.js +0 -26
  220. package/dist/utils/elementRef.d.ts +0 -11
  221. package/dist/utils/elementRef.js +0 -33
  222. package/dist/utils/fqnRef.d.ts +0 -11
  223. package/dist/utils/fqnRef.js +0 -63
  224. package/dist/utils/index.d.ts +0 -11
  225. package/dist/utils/index.js +0 -35
  226. package/dist/utils/printDocs.d.ts +0 -2
  227. package/dist/utils/printDocs.js +0 -1
  228. package/dist/utils/projectId.d.ts +0 -4
  229. package/dist/utils/projectId.js +0 -16
  230. package/dist/utils/stringHash.d.ts +0 -1
  231. package/dist/utils/stringHash.js +0 -5
  232. package/dist/validation/DocumentValidator.d.ts +0 -11
  233. package/dist/validation/DocumentValidator.js +0 -17
  234. package/dist/validation/_shared.d.ts +0 -3
  235. package/dist/validation/_shared.js +0 -26
  236. package/dist/validation/deployment-checks.d.ts +0 -7
  237. package/dist/validation/deployment-checks.js +0 -140
  238. package/dist/validation/dynamic-view.d.ts +0 -6
  239. package/dist/validation/dynamic-view.js +0 -67
  240. package/dist/validation/element-ref.d.ts +0 -4
  241. package/dist/validation/element-ref.js +0 -12
  242. package/dist/validation/element.d.ts +0 -4
  243. package/dist/validation/element.js +0 -49
  244. package/dist/validation/imports.d.ts +0 -4
  245. package/dist/validation/imports.js +0 -46
  246. package/dist/validation/index.d.ts +0 -15
  247. package/dist/validation/index.js +0 -167
  248. package/dist/validation/property-checks.d.ts +0 -7
  249. package/dist/validation/property-checks.js +0 -108
  250. package/dist/validation/relation.d.ts +0 -6
  251. package/dist/validation/relation.js +0 -141
  252. package/dist/validation/specification.d.ts +0 -12
  253. package/dist/validation/specification.js +0 -190
  254. package/dist/validation/view-checks.d.ts +0 -4
  255. package/dist/validation/view-checks.js +0 -46
  256. package/dist/validation/view-predicates/fqn-expr-with.d.ts +0 -4
  257. package/dist/validation/view-predicates/fqn-expr-with.js +0 -43
  258. package/dist/validation/view-predicates/fqn-ref-expr.d.ts +0 -4
  259. package/dist/validation/view-predicates/fqn-ref-expr.js +0 -51
  260. package/dist/validation/view-predicates/incoming.d.ts +0 -4
  261. package/dist/validation/view-predicates/incoming.js +0 -16
  262. package/dist/validation/view-predicates/index.d.ts +0 -6
  263. package/dist/validation/view-predicates/index.js +0 -6
  264. package/dist/validation/view-predicates/outgoing.d.ts +0 -4
  265. package/dist/validation/view-predicates/outgoing.js +0 -20
  266. package/dist/validation/view-predicates/relation-expr.d.ts +0 -4
  267. package/dist/validation/view-predicates/relation-expr.js +0 -46
  268. package/dist/validation/view-predicates/relation-with.d.ts +0 -4
  269. package/dist/validation/view-predicates/relation-with.js +0 -16
  270. package/dist/validation/view.d.ts +0 -4
  271. package/dist/validation/view.js +0 -42
  272. package/dist/view-utils/assignNavigateTo.d.ts +0 -2
  273. package/dist/view-utils/assignNavigateTo.js +0 -27
  274. package/dist/view-utils/index.d.ts +0 -2
  275. package/dist/view-utils/index.js +0 -2
  276. package/dist/view-utils/manual-layout.d.ts +0 -13
  277. package/dist/view-utils/manual-layout.js +0 -149
  278. package/dist/views/ConfigurableLayouter.d.ts +0 -7
  279. package/dist/views/ConfigurableLayouter.js +0 -51
  280. package/dist/views/LikeC4ManualLayouts.d.ts +0 -42
  281. package/dist/views/LikeC4ManualLayouts.js +0 -209
  282. package/dist/views/LikeC4Views.d.ts +0 -89
  283. package/dist/views/LikeC4Views.js +0 -216
  284. package/dist/views/index.d.ts +0 -4
  285. package/dist/views/index.js +0 -11
  286. package/dist/workspace/AstNodeDescriptionProvider.d.ts +0 -7
  287. package/dist/workspace/AstNodeDescriptionProvider.js +0 -18
  288. package/dist/workspace/IndexManager.d.ts +0 -10
  289. package/dist/workspace/IndexManager.js +0 -26
  290. package/dist/workspace/LangiumDocuments.d.ts +0 -29
  291. package/dist/workspace/LangiumDocuments.js +0 -104
  292. package/dist/workspace/ProjectsManager.d.ts +0 -134
  293. package/dist/workspace/ProjectsManager.js +0 -610
  294. package/dist/workspace/WorkspaceManager.d.ts +0 -31
  295. package/dist/workspace/WorkspaceManager.js +0 -132
  296. package/dist/workspace/index.d.ts +0 -5
  297. package/dist/workspace/index.js +0 -5
@@ -1,610 +0,0 @@
1
- var _a;
2
- import { isLikeC4Config, normalizeIncludeConfig, validateProjectConfig, } from '@likec4/config';
3
- import { BiMap, compareNaturalHierarchically, DefaultMap, invariant, memoizeProp, nonNullable, } from '@likec4/core/utils';
4
- import { loggable, wrapError } from '@likec4/log';
5
- import { deepEqual } from 'fast-equals';
6
- import { isOperationCancelled, OperationCancelled, URI, WorkspaceCache, } from 'langium';
7
- import picomatch from 'picomatch';
8
- import { filter, hasAtLeast, isNullish, map, pipe, prop, sort } from 'remeda';
9
- import { cleanDoubleSlashes, isRelative, joinRelativeURL, joinURL, parseFilename, withoutProtocol, withoutTrailingSlash, withTrailingSlash, } from 'ufo';
10
- import { isLikeC4Builtin } from '../likec4lib';
11
- import { logger as mainLogger } from '../logger';
12
- const logger = mainLogger.getChild('ProjectsManager');
13
- function normalizeUri(uri) {
14
- if (URI.isUri(uri)) {
15
- return uri.toString();
16
- }
17
- else if (typeof uri === 'string') {
18
- // TODO: handle non-file URIs, i.e. vscode-remote://
19
- return uri.startsWith('file://') ? uri : URI.file(uri).toString();
20
- }
21
- else {
22
- return uri.uri.toString();
23
- }
24
- }
25
- /**
26
- * Compare function to ensure consistent order
27
- */
28
- const compare = compareNaturalHierarchically('/', true);
29
- const compareUri = (a, b) => compare(withoutTrailingSlash(a.path), withoutTrailingSlash(b.path));
30
- /**
31
- * Returns a predicate that checks if the given path is included in the project folder.
32
- */
33
- function isParentFolderFor(uri) {
34
- const path = normalizeUri(uri);
35
- return (p) => path.startsWith(p.folder);
36
- }
37
- export function ProjectFolder(folder) {
38
- folder = normalizeUri(folder);
39
- return withTrailingSlash(folder);
40
- }
41
- const DefaultProject = {
42
- id: 'default',
43
- config: {
44
- name: 'default',
45
- exclude: ['**/node_modules/**'],
46
- },
47
- exclude: picomatch('**/node_modules/**', { dot: true }),
48
- includeConfig: { paths: [], maxDepth: 3, fileThreshold: 30 },
49
- };
50
- export class ProjectsManager {
51
- services;
52
- /**
53
- * The global project ID used for all documents
54
- * that are not part of a specific project.
55
- */
56
- static DefaultProjectId = DefaultProject.id;
57
- /**
58
- * Configured default project ID.
59
- * (it is used in CLI and Vite plugin)
60
- */
61
- #defaultProjectId = undefined;
62
- /**
63
- * Cached default project.
64
- */
65
- #defaultProject = undefined;
66
- /**
67
- * The mapping between project config files and project IDs.
68
- */
69
- #projectIdToFolder = new BiMap();
70
- /**
71
- * Registered projects.
72
- * Sorted descending by the number of segments in the folder path.
73
- * This ensures that the most specific project is used for a document.
74
- */
75
- #projects = [];
76
- /**
77
- * This is a cached lookup for performance.
78
- */
79
- #lookupById = new DefaultMap((id) => {
80
- if (id === _a.DefaultProjectId) {
81
- const folder = ProjectFolder(this.getWorkspaceFolder());
82
- return {
83
- id,
84
- config: DefaultProject.config,
85
- folder,
86
- folderUri: URI.parse(folder),
87
- exclude: DefaultProject.exclude,
88
- includeConfig: DefaultProject.includeConfig,
89
- };
90
- }
91
- return nonNullable(this.#projects.find(p => p.id === id), `Project ${id} not found`);
92
- });
93
- #excludedDocuments = new WeakMap();
94
- constructor(services) {
95
- this.services = services;
96
- logger.debug `created`;
97
- }
98
- /**
99
- * Returns:
100
- * - configured default project ID if set
101
- * - the default project ID if there are no projects.
102
- * - the ID of the only project
103
- * - undefined if there are multiple projects.
104
- */
105
- get defaultProjectId() {
106
- if (this.#defaultProjectId) {
107
- return this.#defaultProjectId;
108
- }
109
- if (this.#projects.length > 1) {
110
- return undefined;
111
- }
112
- return this.#projects[0]?.id ?? _a.DefaultProjectId;
113
- }
114
- set defaultProjectId(id) {
115
- if (id === this.#defaultProjectId) {
116
- return;
117
- }
118
- this.#defaultProject = undefined;
119
- if (!id || id === _a.DefaultProjectId) {
120
- logger.debug `reset default project ID`;
121
- this.#defaultProjectId = undefined;
122
- return;
123
- }
124
- invariant(this.#projects.find(p => p.id === id), `Project "${id}" not found`);
125
- logger.debug `set default project ID to ${id}`;
126
- this.#defaultProjectId = id;
127
- }
128
- get default() {
129
- if (!this.#defaultProject) {
130
- const id = this.defaultProjectId ?? _a.DefaultProjectId;
131
- this.#defaultProject = this.#lookupById.get(id);
132
- }
133
- return this.#defaultProject;
134
- }
135
- get all() {
136
- if (hasAtLeast(this.#projects, 1)) {
137
- const ids = [
138
- ...map(this.#projects, prop('id')),
139
- DefaultProject.id,
140
- ];
141
- // if default project is set, ensure it is first
142
- if (this.#defaultProjectId) {
143
- const idx = ids.findIndex(p => p === this.#defaultProjectId);
144
- if (idx > 0) {
145
- const [defaultProject] = ids.splice(idx, 1);
146
- return [defaultProject, ...ids];
147
- }
148
- }
149
- return ids;
150
- }
151
- return [DefaultProject.id];
152
- }
153
- getProject(arg) {
154
- const id = typeof arg === 'string' ? arg : (arg.likec4ProjectId || this.belongsTo(arg));
155
- const project = this.#lookupById.get(id);
156
- return {
157
- id,
158
- folderUri: project.folderUri,
159
- config: project.config,
160
- ...(project.includePaths && { includePaths: map(project.includePaths, prop('uri')) }),
161
- };
162
- }
163
- /**
164
- * Returns all projects that include the specified folder, or inside the folder.
165
- */
166
- findAllProjectsByFolder(folder) {
167
- const projectFolder = ProjectFolder(folder);
168
- const isInsideOrIncludes = (p) => p.folder.startsWith(projectFolder) || projectFolder.startsWith(p.folder);
169
- return this.#projects.filter(isInsideOrIncludes);
170
- }
171
- /**
172
- * Validates and ensures the project ID.
173
- * If no project ID is specified, returns default project ID
174
- * If there are multiple projects and default project is not set, throws an error
175
- */
176
- ensureProjectId(projectId) {
177
- if (projectId === _a.DefaultProjectId) {
178
- return this.defaultProjectId ?? _a.DefaultProjectId;
179
- }
180
- if (projectId) {
181
- invariant(this.#projectIdToFolder.has(projectId), `Project ID ${projectId} is not registered`);
182
- return projectId;
183
- }
184
- return nonNullable(this.defaultProjectId, () => `Specify exact project, known: [${[...this.#projectIdToFolder.keys()].join(', ')}]`);
185
- }
186
- /**
187
- * Validates and ensures the project.
188
- */
189
- ensureProject(projectId) {
190
- projectId = this.ensureProjectId(projectId);
191
- return this.getProject(projectId);
192
- }
193
- hasMultipleProjects() {
194
- return this.#projects.length > 1;
195
- }
196
- /**
197
- * Checks if the specified document should be excluded from processing.
198
- */
199
- isExcluded(document) {
200
- if (typeof document === 'string' || URI.isUri(document)) {
201
- let docUriAsString = normalizeUri(document);
202
- const project = this.findProjectForDocument(docUriAsString);
203
- if (!project.exclude) {
204
- return false;
205
- }
206
- const input = withoutProtocol(docUriAsString);
207
- return project.exclude(input);
208
- }
209
- let isExcluded = this.#excludedDocuments.get(document);
210
- if (isExcluded === undefined) {
211
- isExcluded = this.isExcluded(document.uri);
212
- this.#excludedDocuments.set(document, isExcluded);
213
- }
214
- return isExcluded;
215
- }
216
- /**
217
- * Checks if the specified document is included by the project:
218
- * - if the document belongs to the project and is not excluded
219
- * - if the document is included by the project
220
- */
221
- isIncluded(projectId, document) {
222
- if (typeof document !== 'string' && !URI.isUri(document)) {
223
- return this.isIncluded(projectId, document.uri);
224
- }
225
- const belongsTo = this.belongsTo(document);
226
- if (belongsTo === projectId) {
227
- return !this.isExcluded(document);
228
- }
229
- let includePaths = this.#lookupById.get(projectId)?.includePaths;
230
- if (!includePaths) {
231
- return false;
232
- }
233
- return includePaths.some(isParentFolderFor(document));
234
- }
235
- /**
236
- * Checks if it is a config file and it is not excluded by default exclude pattern
237
- *
238
- * @param entry The file system entry to check
239
- */
240
- isConfigFile(entry) {
241
- const filename = parseFilename(entry.toString(), { strict: false })?.toLowerCase();
242
- const isConfigFile = !!filename && isLikeC4Config(filename);
243
- if (isConfigFile) {
244
- if (DefaultProject.exclude(entry.path)) {
245
- logger.debug `exclude config file ${entry.path}`;
246
- return false;
247
- }
248
- }
249
- return isConfigFile;
250
- }
251
- /**
252
- * Registers likec4 project by config file.
253
- */
254
- async registerConfigFile(configFile, cancelToken) {
255
- if (DefaultProject.exclude(configFile.path)) {
256
- throw new Error(`Path to ${configFile.fsPath} is excluded by: ${DefaultProject.config.exclude.join(', ')}`);
257
- }
258
- if (!this.isConfigFile(configFile)) {
259
- throw new Error(`${configFile.fsPath} is not a valid LikeC4 config filename.`);
260
- }
261
- try {
262
- const config = await this.services.workspace.FileSystemProvider.loadProjectConfig(configFile);
263
- const path = joinRelativeURL(configFile.path, '..');
264
- const folderUri = configFile.with({ path });
265
- return await this.registerProject({ config, folderUri }, cancelToken);
266
- }
267
- catch (error) {
268
- if (!isOperationCancelled(error)) {
269
- this.services.lsp.Connection?.window.showErrorMessage(`LikeC4: Failed to register project at ${configFile.fsPath}`);
270
- throw wrapError(error, `Failed to register project config ${configFile.fsPath}:\n`);
271
- }
272
- return Promise.reject(error);
273
- }
274
- }
275
- /**
276
- * Registers (or reloads) likec4 project by config file or config object.
277
- * If there is some project registered at same folder, it will be reloaded.
278
- */
279
- async registerProject(opts, cancelToken) {
280
- const config = validateProjectConfig(opts.config);
281
- const folder = ProjectFolder(opts.folderUri);
282
- let project = this.#projects.find(p => p.folder === folder);
283
- if (project && deepEqual(project.config, config)) {
284
- return project;
285
- }
286
- let mustReset = false;
287
- let id;
288
- if (!project) {
289
- if (this.#projectIdToFolder.has(config.name)) {
290
- logger.warn `Project "${config.name}" already exists, generating unique ID`;
291
- }
292
- id = this.uniqueProjectId(config.name);
293
- const includeConfig = normalizeIncludeConfig(config.include);
294
- project = {
295
- id,
296
- config,
297
- folder,
298
- folderUri: URI.parse(folder),
299
- includeConfig,
300
- };
301
- // if there is any project within subfolder or parent folder
302
- // we need to reset assigned to documents project IDs
303
- mustReset = this.#projects.some(p => p.folder.startsWith(folder) || folder.startsWith(p.folder));
304
- this.#projects = pipe([...this.#projects, project], sort((a, b) => compareUri(a.folderUri, b.folderUri)));
305
- logger.info `register project ${project.id} folder: ${folder}`;
306
- }
307
- else {
308
- // Project exists but configs are different (deepEqual check above)
309
- mustReset = true;
310
- if (project.config.name !== config.name) {
311
- this.#projectIdToFolder.delete(project.id);
312
- logger.info `unregister project ${project.id} folder: ${folder}`;
313
- id = this.uniqueProjectId(config.name);
314
- project.id = id;
315
- logger.info `re-register project ${project.id} folder: ${folder}`;
316
- }
317
- else {
318
- id = project.id;
319
- logger.info `update project ${project.id} on config change`;
320
- }
321
- project.config = config;
322
- const includeConfig = normalizeIncludeConfig(config.include);
323
- project.includeConfig = includeConfig;
324
- }
325
- if (isNullish(config.exclude)) {
326
- project.exclude = DefaultProject.exclude;
327
- }
328
- else if (hasAtLeast(config.exclude, 1)) {
329
- const patterns = map(config.exclude, p => {
330
- if (!isRelative(p) && !p.startsWith('**')) {
331
- p = joinURL('**', p);
332
- }
333
- return cleanDoubleSlashes(joinRelativeURL(project.folderUri.path, p));
334
- });
335
- project.exclude = picomatch(patterns, {
336
- contains: true,
337
- dot: true,
338
- });
339
- }
340
- // Resolve include paths relative to project folder
341
- if (project.includeConfig.paths && hasAtLeast(project.includeConfig.paths, 1)) {
342
- project.includePaths = map(project.includeConfig.paths, includePath => {
343
- const resolvedPath = joinRelativeURL(project.folderUri.path, includePath);
344
- const uri = project.folderUri.with({ path: resolvedPath });
345
- return {
346
- uri,
347
- folder: ProjectFolder(uri),
348
- };
349
- });
350
- logger.debug `project ${project.id} include paths: ${project.includePaths.map(p => p.uri.fsPath).join(', ')}`;
351
- // Check for overlapping include paths with other projects
352
- for (const includePath of project.includePaths) {
353
- // Check if this include path overlaps with another project's folder
354
- for (const otherProject of this.#projects) {
355
- if (otherProject.id === project.id)
356
- continue;
357
- if (includePath.folder.startsWith(otherProject.folder) || otherProject.folder.startsWith(includePath.folder)) {
358
- mustReset = true;
359
- logger.warn('Project "{projectId}" include path "{includePath}" overlaps with project "{otherProjectId}" folder. ' +
360
- 'Files in overlapping areas will only belong to one project.', { projectId: project.id, includePath: includePath.folder, otherProjectId: otherProject.id });
361
- }
362
- // Check if this include path overlaps with another project's include paths
363
- if (otherProject.includePaths) {
364
- for (const otherIncludePath of otherProject.includePaths) {
365
- if (includePath.folder.startsWith(otherIncludePath.folder)
366
- || otherIncludePath.folder.startsWith(includePath.folder)) {
367
- mustReset = true;
368
- logger.warn('Project "{projectId}" include path "{includePath}" overlaps with project "{otherProjectId}" ' +
369
- 'include path "{otherIncludePath}". Files in overlapping areas will only belong to one project.', {
370
- projectId: project.id,
371
- includePath: includePath.folder,
372
- otherProjectId: otherProject.id,
373
- otherIncludePath: otherIncludePath.folder,
374
- });
375
- }
376
- }
377
- }
378
- }
379
- }
380
- }
381
- else {
382
- delete project.includePaths;
383
- }
384
- // Reset cached default project
385
- this.#defaultProject = undefined;
386
- this.#projectIdToFolder.set(project.id, folder);
387
- this.#lookupById.clear();
388
- // Reset assigned project IDs if no projects reload is active
389
- if (mustReset && !this.#activeReload) {
390
- await this.rebuidProject(project.id, cancelToken).catch(error => {
391
- if (isOperationCancelled(error)) {
392
- return Promise.reject(error);
393
- }
394
- logger.warn('Failed to rebuild project {projectId} after config change', {
395
- projectId: project.id,
396
- error,
397
- });
398
- // ignore error, we logged it
399
- return Promise.resolve();
400
- });
401
- }
402
- return project;
403
- }
404
- /**
405
- * Determines which project the given document belongs to.
406
- * If the document does not belong to any project, returns the default project ID.
407
- */
408
- belongsTo(document) {
409
- if (URI.isUri(document) || typeof document === 'string') {
410
- const documentUri = normalizeUri(document);
411
- return this.findProjectForDocument(documentUri).id;
412
- }
413
- return this.documentBelongsTo.get(document, () => {
414
- return this.findProjectForDocument(normalizeUri(document.uri));
415
- }).id;
416
- }
417
- #activeReload = null;
418
- async reloadProjects(cancelToken) {
419
- if (this.#activeReload) {
420
- logger.debug `reload projects is already in progress, waiting`;
421
- return await this.#activeReload.catch(() => {
422
- // ignore errors
423
- });
424
- }
425
- logger.debug `schedule reload projects`;
426
- this.#activeReload = Promise.resolve()
427
- .then(() => this._reloadProjects(cancelToken))
428
- .catch(error => {
429
- if (!isOperationCancelled(error)) {
430
- logger.warn('Failed to reload projects', { error });
431
- }
432
- return Promise.reject(error);
433
- })
434
- .finally(() => {
435
- this.#activeReload = null;
436
- });
437
- return await this.#activeReload;
438
- }
439
- async _reloadProjects(cancelToken) {
440
- const folders = this.services.workspace.WorkspaceManager.workspaceFolders;
441
- if (!folders) {
442
- logger.warn('No workspace folders found');
443
- return;
444
- }
445
- logger.debug `start reload projects`;
446
- const configFiles = [];
447
- for (const folder of folders) {
448
- try {
449
- logger.debug `scan projects in folder ${folder.uri}`;
450
- const files = await this.services.workspace.FileSystemProvider.scanProjectFiles(URI.parse(folder.uri));
451
- for (const file of files) {
452
- if (file.isFile && this.isConfigFile(file.uri)) {
453
- logger.debug `found config ${file.uri.fsPath}`;
454
- configFiles.push(file.uri);
455
- }
456
- }
457
- }
458
- catch (error) {
459
- logger.error('Failed to scanProjectFiles, {folder}', { folder: folder.uri, error });
460
- }
461
- }
462
- if (configFiles.length === 0 && this.#projects.length !== 0) {
463
- logger.warning('No config files found, but some projects were registered before');
464
- }
465
- // Sort config files hierarchically, ensuring consistent order
466
- configFiles.sort(compareUri);
467
- this.#projects = [];
468
- this.#projectIdToFolder.clear();
469
- this.#lookupById.clear();
470
- for (const uri of configFiles) {
471
- if (cancelToken?.isCancellationRequested) {
472
- break;
473
- }
474
- await this.registerConfigFile(uri, cancelToken).catch(error => {
475
- if (!isOperationCancelled(error)) {
476
- logger.warn(loggable(error));
477
- }
478
- });
479
- }
480
- this.reset();
481
- if (cancelToken?.isCancellationRequested) {
482
- throw OperationCancelled;
483
- }
484
- await this.services.workspace.WorkspaceManager.rebuildAll(cancelToken);
485
- }
486
- uniqueProjectId(name) {
487
- let id = name;
488
- let i = 1;
489
- while (this.#projectIdToFolder.has(id)) {
490
- id = `${name}-${i++}`;
491
- }
492
- return id;
493
- }
494
- reset() {
495
- logger.debug('reset');
496
- this.#defaultProject = undefined;
497
- if (this.#defaultProjectId && !this.#projectIdToFolder.has(this.#defaultProjectId)) {
498
- this.#defaultProjectId = undefined;
499
- }
500
- this.services.workspace.LangiumDocuments.resetProjectIds();
501
- this.documentBelongsTo.clear();
502
- this.mappingsToProject.clear();
503
- this.#lookupById.clear();
504
- this.#excludedDocuments = new WeakMap();
505
- }
506
- async rebuidProject(projectId, cancelToken) {
507
- // reset default project cache
508
- this.#defaultProject = undefined;
509
- const project = this.#projects.find(p => p.id === projectId) ?? this.default;
510
- if (project.id !== projectId) {
511
- logger.warn `Project ${projectId} not found, rebuilding default project ${project.id}`;
512
- }
513
- const log = logger.getChild(project.id);
514
- const folder = project.folder;
515
- const includePaths = project.includePaths;
516
- const allDocs = this.services.workspace.LangiumDocuments
517
- .allKnownDocuments
518
- .filter(doc => !isLikeC4Builtin(doc.uri))
519
- .toArray();
520
- // If no documents are found, return early
521
- if (allDocs.length === 0) {
522
- return;
523
- }
524
- const docs = pipe(allDocs, filter(doc => {
525
- if (project.exclude?.(doc.uri.path)) {
526
- return false;
527
- }
528
- const docUriStr = normalizeUri(doc.uri);
529
- if (docUriStr.startsWith(folder)) {
530
- return true;
531
- }
532
- if (includePaths && includePaths.some(isParentFolderFor(docUriStr))) {
533
- return true;
534
- }
535
- const docdir = withTrailingSlash(joinRelativeURL(docUriStr, '..'));
536
- return docdir.startsWith(folder) || folder.startsWith(docdir);
537
- }), map(d => d.uri));
538
- if (docs.length === 0) {
539
- log.debug('no documents in project, skipping rebuild');
540
- return;
541
- }
542
- log.info('rebuild project documents: {docs}', {
543
- docs: docs.length,
544
- });
545
- this.reset();
546
- await this.services.workspace.DocumentBuilder
547
- .update(docs, [], cancelToken)
548
- .catch(error => {
549
- log.warn('Failed to rebuild project', {
550
- error,
551
- });
552
- });
553
- }
554
- findProjectForDocument(documentUri) {
555
- return this.mappingsToProject.get(documentUri, () => {
556
- const hasThisDoc = isParentFolderFor(documentUri);
557
- const project = this.#projects.find(hasThisDoc);
558
- if (project) {
559
- return project;
560
- }
561
- const projectIncludingThisDoc = this.#projects.find(({ includePaths }) => {
562
- return !!includePaths && includePaths.some(hasThisDoc);
563
- });
564
- // If the document is not part of any project, assign it to the global project ID
565
- return projectIncludingThisDoc ?? this.default;
566
- });
567
- }
568
- // The mapping between document URIs and their corresponding project ID
569
- // Lazy-created due to initialization order of the LanguageServer
570
- get mappingsToProject() {
571
- return memoizeProp(this, '_mappingsToProject', () => new WorkspaceCache(this.services));
572
- }
573
- /**
574
- * The mapping between documents and projects they belong to.
575
- * Lazy-created due to initialization order of the LanguageServer
576
- */
577
- get documentBelongsTo() {
578
- return memoizeProp(this, '_documentBelongsTo', () => new WorkspaceCache(this.services));
579
- }
580
- /**
581
- * Returns all include paths from all projects.
582
- * Used by WorkspaceManager to scan additional directories for C4 files.
583
- */
584
- getAllIncludePaths() {
585
- const result = [];
586
- for (const project of this.#projects) {
587
- if (project.includePaths) {
588
- for (const includePath of project.includePaths) {
589
- result.push({
590
- projectId: project.id,
591
- includePath: includePath.uri,
592
- includeConfig: project.includeConfig,
593
- });
594
- }
595
- }
596
- }
597
- return result;
598
- }
599
- getWorkspaceFolder() {
600
- try {
601
- return this.services.workspace.WorkspaceManager.workspaceUri;
602
- }
603
- catch (error) {
604
- logger.warn('Failed to get workspace URI, using default folder', { error });
605
- return URI.file('/');
606
- // ignore - workspace not initialized
607
- }
608
- }
609
- }
610
- _a = ProjectsManager;
@@ -1,31 +0,0 @@
1
- import type { BuildOptions, Cancellation, FileSelector, FileSystemNode, LangiumDocument, LangiumDocumentFactory } from 'langium';
2
- import { DefaultWorkspaceManager } from 'langium';
3
- import { type WorkspaceFolder } from 'vscode-languageserver';
4
- import { URI } from 'vscode-uri';
5
- import type { FileSystemProvider } from '../filesystem';
6
- import type { LikeC4SharedServices } from '../module';
7
- export declare class LikeC4WorkspaceManager extends DefaultWorkspaceManager {
8
- private services;
9
- protected readonly documentFactory: LangiumDocumentFactory;
10
- protected readonly fileSystemProvider: FileSystemProvider;
11
- initialBuildOptions: BuildOptions;
12
- constructor(services: LikeC4SharedServices);
13
- /**
14
- * First load all project config files, then load all documents in the workspace.
15
- */
16
- protected performStartup(folders: WorkspaceFolder[]): Promise<LangiumDocument[]>;
17
- /**
18
- * Load all additional documents that shall be visible in the context of the given workspace
19
- * folders and add them to the collector. This can be used to include built-in libraries of
20
- * your language, which can be either loaded from provided files or constructed in memory.
21
- */
22
- protected loadAdditionalDocuments(folders: WorkspaceFolder[], collector: (document: LangiumDocument) => void): Promise<void>;
23
- /**
24
- * Determine whether the given folder entry shall be included while indexing the workspace.
25
- */
26
- protected includeEntry(_workspaceFolder: WorkspaceFolder, entry: FileSystemNode, selector: FileSelector): boolean;
27
- workspace(): WorkspaceFolder | null;
28
- rebuildAll(cancelToken?: Cancellation.CancellationToken): Promise<void>;
29
- get workspaceUri(): URI;
30
- get workspaceURL(): URL;
31
- }