@likec4/language-server 1.46.4 → 1.48.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 (316) hide show
  1. package/LICENSE +1 -1
  2. package/browser/package.json +2 -2
  3. package/browser-worker/package.json +2 -2
  4. package/bundled/package.json +4 -0
  5. package/dist/LikeC4LanguageServices.d.mts +4 -0
  6. package/dist/LikeC4LanguageServices.mjs +3 -0
  7. package/dist/_chunks/ConfigurableLayouter.mjs +1956 -0
  8. package/dist/_chunks/LikeC4LanguageServices.d.mts +1978 -0
  9. package/dist/_chunks/LikeC4LanguageServices.mjs +725 -0
  10. package/dist/_chunks/ast.d.mts +1444 -0
  11. package/dist/_chunks/ast.mjs +2375 -0
  12. package/dist/_chunks/ast2.mjs +176 -0
  13. package/dist/_chunks/common-exports.mjs +0 -0
  14. package/dist/_chunks/filesystem.mjs +58 -0
  15. package/dist/_chunks/grammar.mjs +8 -0
  16. package/dist/_chunks/icons.mjs +5211 -0
  17. package/dist/_chunks/libs/@hono/node-server.mjs +436 -0
  18. package/dist/_chunks/libs/@msgpack/msgpack.mjs +805 -0
  19. package/dist/_chunks/libs/eventemitter3.mjs +243 -0
  20. package/dist/_chunks/libs/fast-equals.mjs +446 -0
  21. package/dist/_chunks/libs/hono.mjs +1829 -0
  22. package/dist/_chunks/libs/p-queue.mjs +449 -0
  23. package/dist/_chunks/libs/parse-ms.mjs +36 -0
  24. package/dist/_chunks/libs/picomatch.mjs +1673 -0
  25. package/dist/_chunks/libs/pretty-ms.mjs +80 -0
  26. package/dist/_chunks/libs/remeda.mjs +482 -0
  27. package/dist/_chunks/libs/strip-indent.mjs +15 -0
  28. package/dist/_chunks/libs/ufo.mjs +166 -0
  29. package/dist/_chunks/likec4lib.mjs +9 -0
  30. package/dist/_chunks/mcp.mjs +33 -0
  31. package/dist/_chunks/module.mjs +28 -0
  32. package/dist/_chunks/module2.mjs +6576 -0
  33. package/dist/_chunks/protocol.d.mts +311 -0
  34. package/dist/_chunks/protocol.mjs +78 -0
  35. package/dist/_chunks/rolldown-runtime.mjs +42 -0
  36. package/dist/ast.d.mts +4 -0
  37. package/dist/ast.mjs +4 -0
  38. package/dist/browser-worker.d.mts +1 -0
  39. package/dist/browser-worker.mjs +6 -0
  40. package/dist/browser.d.mts +11 -0
  41. package/dist/browser.mjs +27 -0
  42. package/dist/bundled.d.mts +28 -0
  43. package/dist/bundled.mjs +51 -4681
  44. package/dist/common-exports.d.mts +4 -0
  45. package/dist/common-exports.mjs +5 -0
  46. package/dist/filesystem/index.d.mts +4 -0
  47. package/dist/filesystem/index.mjs +3 -0
  48. package/dist/generated/ast.d.mts +2 -0
  49. package/dist/generated/ast.mjs +3 -0
  50. package/dist/generated/grammar.d.mts +6 -0
  51. package/dist/generated/grammar.mjs +3 -0
  52. package/dist/generated/module.d.mts +14 -0
  53. package/dist/generated/module.mjs +3 -0
  54. package/dist/generated-lib/icons.d.mts +4 -0
  55. package/dist/generated-lib/icons.mjs +3 -0
  56. package/dist/index.d.mts +4 -0
  57. package/dist/index.mjs +48 -0
  58. package/dist/likec4lib.d.mts +9 -0
  59. package/dist/likec4lib.mjs +4 -0
  60. package/dist/mcp/index.d.mts +4 -0
  61. package/dist/mcp/index.mjs +3 -0
  62. package/dist/module.d.mts +4 -0
  63. package/dist/module.mjs +3 -0
  64. package/dist/protocol.d.mts +2 -0
  65. package/dist/protocol.mjs +3 -0
  66. package/likec4lib/package.json +2 -2
  67. package/package.json +106 -62
  68. package/protocol/package.json +2 -2
  69. package/dist/LikeC4LanguageServices.d.ts +0 -109
  70. package/dist/LikeC4LanguageServices.js +0 -154
  71. package/dist/Rpc.d.ts +0 -9
  72. package/dist/Rpc.js +0 -270
  73. package/dist/ast.d.ts +0 -226
  74. package/dist/ast.js +0 -264
  75. package/dist/browser-worker.d.ts +0 -1
  76. package/dist/browser-worker.js +0 -4
  77. package/dist/browser.d.ts +0 -11
  78. package/dist/browser.js +0 -35
  79. package/dist/bundled.d.ts +0 -8
  80. package/dist/bundled.js +0 -44
  81. package/dist/documentation/documentation-provider.d.ts +0 -8
  82. package/dist/documentation/documentation-provider.js +0 -51
  83. package/dist/documentation/index.d.ts +0 -1
  84. package/dist/documentation/index.js +0 -1
  85. package/dist/empty.d.ts +0 -2
  86. package/dist/empty.js +0 -2
  87. package/dist/filesystem/ChokidarWatcher.d.ts +0 -16
  88. package/dist/filesystem/ChokidarWatcher.js +0 -108
  89. package/dist/filesystem/FileSystemWatcher.d.ts +0 -19
  90. package/dist/filesystem/FileSystemWatcher.js +0 -14
  91. package/dist/filesystem/LikeC4FileSystem.d.ts +0 -3
  92. package/dist/filesystem/LikeC4FileSystem.js +0 -130
  93. package/dist/filesystem/index.d.ts +0 -55
  94. package/dist/filesystem/index.js +0 -29
  95. package/dist/formatting/LikeC4Formatter.d.ts +0 -59
  96. package/dist/formatting/LikeC4Formatter.js +0 -637
  97. package/dist/formatting/utils.d.ts +0 -6
  98. package/dist/formatting/utils.js +0 -18
  99. package/dist/generated/ast.d.ts +0 -1411
  100. package/dist/generated/ast.js +0 -2207
  101. package/dist/generated/grammar.d.ts +0 -6
  102. package/dist/generated/grammar.js +0 -7
  103. package/dist/generated/module.d.ts +0 -14
  104. package/dist/generated/module.js +0 -27
  105. package/dist/generated-lib/icons.d.ts +0 -1
  106. package/dist/generated-lib/icons.js +0 -18
  107. package/dist/index.d.ts +0 -38
  108. package/dist/index.js +0 -55
  109. package/dist/likec4lib.d.ts +0 -6
  110. package/dist/likec4lib.js +0 -7
  111. package/dist/logger.d.ts +0 -17
  112. package/dist/logger.js +0 -81
  113. package/dist/lsp/CodeActionProvider.d.ts +0 -14
  114. package/dist/lsp/CodeActionProvider.js +0 -33
  115. package/dist/lsp/CodeLensProvider.d.ts +0 -9
  116. package/dist/lsp/CodeLensProvider.js +0 -44
  117. package/dist/lsp/CompletionProvider.d.ts +0 -11
  118. package/dist/lsp/CompletionProvider.js +0 -200
  119. package/dist/lsp/DocumentHighlightProvider.d.ts +0 -9
  120. package/dist/lsp/DocumentHighlightProvider.js +0 -10
  121. package/dist/lsp/DocumentLinkProvider.d.ts +0 -11
  122. package/dist/lsp/DocumentLinkProvider.js +0 -58
  123. package/dist/lsp/DocumentSymbolProvider.d.ts +0 -33
  124. package/dist/lsp/DocumentSymbolProvider.js +0 -317
  125. package/dist/lsp/HoverProvider.d.ts +0 -10
  126. package/dist/lsp/HoverProvider.js +0 -106
  127. package/dist/lsp/RenameProvider.d.ts +0 -5
  128. package/dist/lsp/RenameProvider.js +0 -6
  129. package/dist/lsp/SemanticTokenProvider.d.ts +0 -12
  130. package/dist/lsp/SemanticTokenProvider.js +0 -264
  131. package/dist/lsp/index.d.ts +0 -8
  132. package/dist/lsp/index.js +0 -9
  133. package/dist/mcp/MCPServerFactory.d.ts +0 -8
  134. package/dist/mcp/MCPServerFactory.js +0 -73
  135. package/dist/mcp/NoopLikeC4MCPServer.d.ts +0 -9
  136. package/dist/mcp/NoopLikeC4MCPServer.js +0 -17
  137. package/dist/mcp/interfaces.d.ts +0 -13
  138. package/dist/mcp/interfaces.js +0 -5
  139. package/dist/mcp/server/StdioLikeC4MCPServer.d.ts +0 -16
  140. package/dist/mcp/server/StdioLikeC4MCPServer.js +0 -51
  141. package/dist/mcp/server/StreamableLikeC4MCPServer.d.ts +0 -16
  142. package/dist/mcp/server/StreamableLikeC4MCPServer.js +0 -145
  143. package/dist/mcp/server/WithMCPServer.d.ts +0 -4
  144. package/dist/mcp/server/WithMCPServer.js +0 -54
  145. package/dist/mcp/tools/_common.d.ts +0 -88
  146. package/dist/mcp/tools/_common.js +0 -49
  147. package/dist/mcp/tools/find-relationships.d.ts +0 -12
  148. package/dist/mcp/tools/find-relationships.js +0 -150
  149. package/dist/mcp/tools/list-projects.d.ts +0 -6
  150. package/dist/mcp/tools/list-projects.js +0 -62
  151. package/dist/mcp/tools/open-view.d.ts +0 -10
  152. package/dist/mcp/tools/open-view.js +0 -52
  153. package/dist/mcp/tools/read-deployment.d.ts +0 -10
  154. package/dist/mcp/tools/read-deployment.js +0 -150
  155. package/dist/mcp/tools/read-element.d.ts +0 -10
  156. package/dist/mcp/tools/read-element.js +0 -218
  157. package/dist/mcp/tools/read-project-summary.d.ts +0 -8
  158. package/dist/mcp/tools/read-project-summary.js +0 -176
  159. package/dist/mcp/tools/read-view.d.ts +0 -10
  160. package/dist/mcp/tools/read-view.js +0 -203
  161. package/dist/mcp/tools/search-element.d.ts +0 -8
  162. package/dist/mcp/tools/search-element.js +0 -177
  163. package/dist/mcp/utils.d.ts +0 -18
  164. package/dist/mcp/utils.js +0 -48
  165. package/dist/model/builder/MergedExtends.d.ts +0 -13
  166. package/dist/model/builder/MergedExtends.js +0 -74
  167. package/dist/model/builder/MergedSpecification.d.ts +0 -32
  168. package/dist/model/builder/MergedSpecification.js +0 -175
  169. package/dist/model/builder/buildModel.d.ts +0 -16
  170. package/dist/model/builder/buildModel.js +0 -245
  171. package/dist/model/deployments-index.d.ts +0 -10
  172. package/dist/model/deployments-index.js +0 -102
  173. package/dist/model/fqn-index.d.ts +0 -61
  174. package/dist/model/fqn-index.js +0 -253
  175. package/dist/model/index.d.ts +0 -6
  176. package/dist/model/index.js +0 -6
  177. package/dist/model/model-builder.d.ts +0 -52
  178. package/dist/model/model-builder.js +0 -224
  179. package/dist/model/model-locator.d.ts +0 -39
  180. package/dist/model/model-locator.js +0 -240
  181. package/dist/model/model-parser-where.d.ts +0 -4
  182. package/dist/model/model-parser-where.js +0 -81
  183. package/dist/model/model-parser.d.ts +0 -645
  184. package/dist/model/model-parser.js +0 -133
  185. package/dist/model/parser/Base.d.ts +0 -69
  186. package/dist/model/parser/Base.js +0 -372
  187. package/dist/model/parser/DeploymentModelParser.d.ts +0 -71
  188. package/dist/model/parser/DeploymentModelParser.js +0 -176
  189. package/dist/model/parser/DeploymentViewParser.d.ts +0 -75
  190. package/dist/model/parser/DeploymentViewParser.js +0 -86
  191. package/dist/model/parser/FqnRefParser.d.ts +0 -66
  192. package/dist/model/parser/FqnRefParser.js +0 -382
  193. package/dist/model/parser/GlobalsParser.d.ts +0 -109
  194. package/dist/model/parser/GlobalsParser.js +0 -84
  195. package/dist/model/parser/ImportsParser.d.ts +0 -46
  196. package/dist/model/parser/ImportsParser.js +0 -24
  197. package/dist/model/parser/ModelParser.d.ts +0 -71
  198. package/dist/model/parser/ModelParser.js +0 -209
  199. package/dist/model/parser/PredicatesParser.d.ts +0 -75
  200. package/dist/model/parser/PredicatesParser.js +0 -45
  201. package/dist/model/parser/SpecificationParser.d.ts +0 -53
  202. package/dist/model/parser/SpecificationParser.js +0 -113
  203. package/dist/model/parser/ValueConverter.d.ts +0 -4
  204. package/dist/model/parser/ValueConverter.js +0 -12
  205. package/dist/model/parser/ViewsParser.d.ts +0 -112
  206. package/dist/model/parser/ViewsParser.js +0 -492
  207. package/dist/model-change/ModelChanges.d.ts +0 -18
  208. package/dist/model-change/ModelChanges.js +0 -129
  209. package/dist/model-change/changeElementStyle.d.ts +0 -16
  210. package/dist/model-change/changeElementStyle.js +0 -134
  211. package/dist/model-change/changeViewLayout.d.ts +0 -12
  212. package/dist/model-change/changeViewLayout.js +0 -28
  213. package/dist/model-change/removeManualLayoutV1.d.ts +0 -7
  214. package/dist/model-change/removeManualLayoutV1.js +0 -27
  215. package/dist/module.d.ts +0 -92
  216. package/dist/module.js +0 -143
  217. package/dist/protocol.d.ts +0 -284
  218. package/dist/protocol.js +0 -123
  219. package/dist/references/index.d.ts +0 -3
  220. package/dist/references/index.js +0 -3
  221. package/dist/references/name-provider.d.ts +0 -9
  222. package/dist/references/name-provider.js +0 -37
  223. package/dist/references/scope-computation.d.ts +0 -20
  224. package/dist/references/scope-computation.js +0 -288
  225. package/dist/references/scope-provider.d.ts +0 -40
  226. package/dist/references/scope-provider.js +0 -239
  227. package/dist/shared/NodeKindProvider.d.ts +0 -15
  228. package/dist/shared/NodeKindProvider.js +0 -57
  229. package/dist/shared/WorkspaceSymbolProvider.d.ts +0 -3
  230. package/dist/shared/WorkspaceSymbolProvider.js +0 -3
  231. package/dist/shared/index.d.ts +0 -2
  232. package/dist/shared/index.js +0 -2
  233. package/dist/test/index.d.ts +0 -1
  234. package/dist/test/index.js +0 -1
  235. package/dist/test/testServices.d.ts +0 -64
  236. package/dist/test/testServices.js +0 -210
  237. package/dist/utils/disposable.d.ts +0 -8
  238. package/dist/utils/disposable.js +0 -26
  239. package/dist/utils/elementRef.d.ts +0 -11
  240. package/dist/utils/elementRef.js +0 -27
  241. package/dist/utils/fqnRef.d.ts +0 -11
  242. package/dist/utils/fqnRef.js +0 -63
  243. package/dist/utils/index.d.ts +0 -11
  244. package/dist/utils/index.js +0 -35
  245. package/dist/utils/printDocs.d.ts +0 -2
  246. package/dist/utils/printDocs.js +0 -1
  247. package/dist/utils/projectId.d.ts +0 -4
  248. package/dist/utils/projectId.js +0 -16
  249. package/dist/utils/stringHash.d.ts +0 -1
  250. package/dist/utils/stringHash.js +0 -5
  251. package/dist/validation/DocumentValidator.d.ts +0 -11
  252. package/dist/validation/DocumentValidator.js +0 -17
  253. package/dist/validation/_shared.d.ts +0 -3
  254. package/dist/validation/_shared.js +0 -26
  255. package/dist/validation/deployment-checks.d.ts +0 -7
  256. package/dist/validation/deployment-checks.js +0 -140
  257. package/dist/validation/dynamic-view.d.ts +0 -6
  258. package/dist/validation/dynamic-view.js +0 -67
  259. package/dist/validation/element-ref.d.ts +0 -4
  260. package/dist/validation/element-ref.js +0 -12
  261. package/dist/validation/element.d.ts +0 -4
  262. package/dist/validation/element.js +0 -49
  263. package/dist/validation/imports.d.ts +0 -4
  264. package/dist/validation/imports.js +0 -46
  265. package/dist/validation/index.d.ts +0 -15
  266. package/dist/validation/index.js +0 -167
  267. package/dist/validation/property-checks.d.ts +0 -7
  268. package/dist/validation/property-checks.js +0 -108
  269. package/dist/validation/relation.d.ts +0 -6
  270. package/dist/validation/relation.js +0 -141
  271. package/dist/validation/specification.d.ts +0 -12
  272. package/dist/validation/specification.js +0 -190
  273. package/dist/validation/view-checks.d.ts +0 -4
  274. package/dist/validation/view-checks.js +0 -46
  275. package/dist/validation/view-predicates/fqn-expr-with.d.ts +0 -4
  276. package/dist/validation/view-predicates/fqn-expr-with.js +0 -43
  277. package/dist/validation/view-predicates/fqn-ref-expr.d.ts +0 -4
  278. package/dist/validation/view-predicates/fqn-ref-expr.js +0 -51
  279. package/dist/validation/view-predicates/incoming.d.ts +0 -4
  280. package/dist/validation/view-predicates/incoming.js +0 -16
  281. package/dist/validation/view-predicates/index.d.ts +0 -6
  282. package/dist/validation/view-predicates/index.js +0 -6
  283. package/dist/validation/view-predicates/outgoing.d.ts +0 -4
  284. package/dist/validation/view-predicates/outgoing.js +0 -20
  285. package/dist/validation/view-predicates/relation-expr.d.ts +0 -4
  286. package/dist/validation/view-predicates/relation-expr.js +0 -46
  287. package/dist/validation/view-predicates/relation-with.d.ts +0 -4
  288. package/dist/validation/view-predicates/relation-with.js +0 -16
  289. package/dist/validation/view.d.ts +0 -4
  290. package/dist/validation/view.js +0 -42
  291. package/dist/view-utils/assignNavigateTo.d.ts +0 -2
  292. package/dist/view-utils/assignNavigateTo.js +0 -27
  293. package/dist/view-utils/index.d.ts +0 -2
  294. package/dist/view-utils/index.js +0 -2
  295. package/dist/view-utils/manual-layout.d.ts +0 -13
  296. package/dist/view-utils/manual-layout.js +0 -149
  297. package/dist/views/ConfigurableLayouter.d.ts +0 -7
  298. package/dist/views/ConfigurableLayouter.js +0 -51
  299. package/dist/views/LikeC4ManualLayouts.d.ts +0 -42
  300. package/dist/views/LikeC4ManualLayouts.js +0 -209
  301. package/dist/views/LikeC4Views.d.ts +0 -89
  302. package/dist/views/LikeC4Views.js +0 -216
  303. package/dist/views/index.d.ts +0 -4
  304. package/dist/views/index.js +0 -11
  305. package/dist/workspace/AstNodeDescriptionProvider.d.ts +0 -7
  306. package/dist/workspace/AstNodeDescriptionProvider.js +0 -18
  307. package/dist/workspace/IndexManager.d.ts +0 -10
  308. package/dist/workspace/IndexManager.js +0 -26
  309. package/dist/workspace/LangiumDocuments.d.ts +0 -25
  310. package/dist/workspace/LangiumDocuments.js +0 -98
  311. package/dist/workspace/ProjectsManager.d.ts +0 -130
  312. package/dist/workspace/ProjectsManager.js +0 -605
  313. package/dist/workspace/WorkspaceManager.d.ts +0 -31
  314. package/dist/workspace/WorkspaceManager.js +0 -132
  315. package/dist/workspace/index.d.ts +0 -5
  316. package/dist/workspace/index.js +0 -5
@@ -1,129 +0,0 @@
1
- import { invariant, nonexhaustive } from '@likec4/core';
2
- import { loggable, wrapError } from '@likec4/log';
3
- import { Range, TextEdit } from 'vscode-languageserver-types';
4
- import { logger as mainLogger } from '../logger';
5
- import { changeElementStyle } from './changeElementStyle';
6
- import { changeViewLayout } from './changeViewLayout';
7
- import { removeManualLayoutV1 } from './removeManualLayoutV1';
8
- const logger = mainLogger.getChild('model-changes');
9
- export class LikeC4ModelChanges {
10
- services;
11
- locator;
12
- constructor(services) {
13
- this.services = services;
14
- this.locator = services.likec4.ModelLocator;
15
- }
16
- async applyChange(changeView) {
17
- const lspConnection = this.services.shared.lsp.Connection;
18
- try {
19
- let { viewId, projectId: _projectId, change } = changeView;
20
- const project = this.services.shared.workspace.ProjectsManager.ensureProject(_projectId);
21
- logger.debug `Applying model change ${change.op} to view ${viewId} in project ${project.id}`;
22
- const lookup = this.locator.locateViewAst(viewId, project.id);
23
- if (!lookup) {
24
- throw new Error(`View ${viewId} not found in project ${project.id}`);
25
- }
26
- const textDocument = {
27
- uri: lookup.doc.textDocument.uri,
28
- version: lookup.doc.textDocument.version,
29
- };
30
- // TODO refactor to use separate methods for save/reset operations
31
- if (change.op === 'save-view-snapshot') {
32
- invariant(viewId === change.layout.id, 'View ID does not match, expected ' + viewId + ', got ' + change.layout.id);
33
- // If there is an existing manual layout v1
34
- if (lookup.view.manualLayout) {
35
- // We clean it up
36
- await removeManualLayoutV1(this.services, { lookup }).catch(err => {
37
- logger.warn(`Failed to remove manual layout v1 for view ${viewId} in project ${project.id}`, { err });
38
- });
39
- }
40
- const location = await this.services.likec4.ManualLayouts.write(project, change.layout);
41
- return {
42
- success: true,
43
- location,
44
- };
45
- }
46
- if (change.op === 'reset-manual-layout') {
47
- // If there is an existing manual layout v1
48
- if (lookup.view.manualLayout) {
49
- // We clean it up
50
- await removeManualLayoutV1(this.services, { lookup }).catch(err => {
51
- logger.warn(`Failed to remove manual layout v1 for view ${viewId} in project ${project.id}`, { err });
52
- });
53
- }
54
- const location = await this.services.likec4.ManualLayouts.remove(project, viewId);
55
- return {
56
- success: true,
57
- location,
58
- };
59
- }
60
- invariant(lspConnection, 'This change only supported in IDE (running as Extension)');
61
- const { edits, modifiedRange } = this.convertToTextEdit({
62
- lookup,
63
- change,
64
- });
65
- if (!edits.length) {
66
- return {
67
- success: false,
68
- error: 'No changes to apply',
69
- };
70
- }
71
- const applyResult = await lspConnection.workspace.applyEdit({
72
- label: `LikeC4 - change view ${changeView.viewId}`,
73
- edit: {
74
- changes: {
75
- [textDocument.uri]: edits,
76
- },
77
- },
78
- });
79
- if (!applyResult.applied) {
80
- lspConnection.window.showErrorMessage(`Failed to apply changes ${applyResult.failureReason}`);
81
- return {
82
- success: false,
83
- error: `Failed to apply changes ${applyResult.failureReason}`,
84
- };
85
- }
86
- return {
87
- success: true,
88
- location: {
89
- uri: textDocument.uri,
90
- range: modifiedRange,
91
- },
92
- };
93
- }
94
- catch (err) {
95
- const error = loggable(wrapError(err, `Failed to apply change ${changeView.change.op} ${changeView.viewId}`));
96
- logger.error(error);
97
- return {
98
- success: false,
99
- error,
100
- };
101
- }
102
- finally {
103
- this.services.likec4.ModelBuilder.clearCache();
104
- }
105
- }
106
- convertToTextEdit({ lookup, change }) {
107
- switch (change.op) {
108
- case 'change-element-style': {
109
- return changeElementStyle(this.services, {
110
- ...lookup,
111
- targets: change.targets,
112
- style: change.style,
113
- });
114
- }
115
- case 'change-autolayout': {
116
- const edit = changeViewLayout(this.services, {
117
- ...lookup,
118
- layout: change.layout,
119
- });
120
- return {
121
- modifiedRange: edit.range,
122
- edits: [edit],
123
- };
124
- }
125
- default:
126
- nonexhaustive(change);
127
- }
128
- }
129
- }
@@ -1,16 +0,0 @@
1
- import { type DeploymentFqn, type Fqn, type NonEmptyArray, type ViewChange } from '@likec4/core';
2
- import { type Range, TextEdit } from 'vscode-languageserver-types';
3
- import { type ParsedAstView, type ParsedLikeC4LangiumDocument, ast } from '../ast';
4
- import type { LikeC4Services } from '../module';
5
- type ChangeElementStyleArg = {
6
- view: ParsedAstView;
7
- doc: ParsedLikeC4LangiumDocument;
8
- viewAst: ast.LikeC4View;
9
- targets: NonEmptyArray<Fqn | DeploymentFqn>;
10
- style: ViewChange.ChangeElementStyle['style'];
11
- };
12
- export declare function changeElementStyle(services: LikeC4Services, { view, viewAst, targets, style, }: ChangeElementStyleArg): {
13
- modifiedRange: Range;
14
- edits: TextEdit[];
15
- };
16
- export {};
@@ -1,134 +0,0 @@
1
- import { _type, invariant, isAncestor, } from '@likec4/core';
2
- import { GrammarUtils } from 'langium';
3
- import { entries, filter, findLast, isTruthy, last } from 'remeda';
4
- import { TextEdit } from 'vscode-languageserver-types';
5
- import { ast } from '../ast';
6
- const { findNodeForKeyword } = GrammarUtils;
7
- const asViewStyleRule = (target, style, indent = 0) => {
8
- const indentStr = indent > 0 ? ' '.repeat(indent) : '';
9
- return [
10
- indentStr + `style ${target} {`,
11
- ...entries(style).map(([key, value]) => indentStr + ` ${key} ${key === 'opacity' ? value.toString() + '%' : value}`),
12
- indentStr + `}`,
13
- ];
14
- };
15
- /**
16
- * - is ViewRuleStyle
17
- * - has exactly one target
18
- * - the target is an ElementRef to the given fqn
19
- */
20
- const isMatchingViewRule = (fqn, index) => (rule) => {
21
- if (!ast.isViewRuleStyle(rule) && !ast.isDeploymentViewRuleStyle(rule)) {
22
- return false;
23
- }
24
- const target = rule.targets.value;
25
- if (!target || isTruthy(rule.targets.prev) || target.$type !== 'FqnRefExpr' || isTruthy(target.selector)) {
26
- return false;
27
- }
28
- const ref = target.ref?.value?.ref;
29
- const _fqn = ref ? index.resolve(ref) : null;
30
- return _fqn === fqn;
31
- };
32
- export function changeElementStyle(services, { view, viewAst, targets, style, }) {
33
- // Should never happen
34
- invariant(viewAst.body, `View ${view.id} has no body`);
35
- const viewCstNode = viewAst.$cstNode;
36
- invariant(viewCstNode, 'viewCstNode');
37
- const insertPos = last(viewAst.body.rules)?.$cstNode?.range.end
38
- ?? viewAst.body.$cstNode?.range.end;
39
- invariant(insertPos, 'insertPos is not defined');
40
- const indent = viewCstNode.range.start.character + 2;
41
- const fqnIndex = services.likec4.FqnIndex;
42
- const styleRules = filter(viewAst.body.rules, (r) => ast.isViewRuleStyle(r) || ast.isDeploymentViewRuleStyle(r));
43
- const viewOf = view[_type] === 'element' ? view.viewOf ?? null : null;
44
- // Find existing rules
45
- const existing = [];
46
- const insert = [];
47
- // const existingRules = [] as Array<{ fqn: Fqn, rule: ast.ViewRuleStyle }>
48
- targets.forEach(target => {
49
- const rule = findLast(styleRules, isMatchingViewRule(target, fqnIndex));
50
- // remove viewOf from the target to shorten the fqn
51
- const fqn = (viewOf && isAncestor(viewOf, target) ? target.substring(viewOf.length + 1) : target);
52
- if (rule) {
53
- existing.push({ fqn, rule });
54
- }
55
- else {
56
- insert.push({ fqn });
57
- }
58
- });
59
- const modifiedRange = {
60
- start: insertPos,
61
- end: insertPos,
62
- };
63
- const includeRange = (range) => {
64
- if (range.start.line <= modifiedRange.start.line) {
65
- if (range.start.line == modifiedRange.start.line) {
66
- modifiedRange.start.character = Math.min(range.start.character, modifiedRange.start.character);
67
- }
68
- else {
69
- modifiedRange.start = range.start;
70
- }
71
- }
72
- if (range.end.line >= modifiedRange.end.line) {
73
- if (range.end.line == modifiedRange.end.line) {
74
- modifiedRange.end.character = Math.max(range.end.character, modifiedRange.end.character);
75
- }
76
- else {
77
- modifiedRange.end = range.end;
78
- }
79
- }
80
- };
81
- const edits = [];
82
- if (insert.length > 0) {
83
- const linesToInsert = insert.flatMap(({ fqn }) => asViewStyleRule(fqn, style, indent));
84
- edits.push(TextEdit.insert(insertPos, '\n' + linesToInsert.join('\n')));
85
- modifiedRange.start = {
86
- line: insertPos.line + 1,
87
- character: indent,
88
- };
89
- modifiedRange.end = {
90
- line: insertPos.line + linesToInsert.length,
91
- character: (last(linesToInsert)?.length ?? 0),
92
- };
93
- }
94
- if (existing.length > 0) {
95
- for (const { rule } of existing) {
96
- const ruleCstNode = rule.$cstNode;
97
- invariant(ruleCstNode, 'RuleCstNode not found');
98
- for (const [key, _value] of entries(style)) {
99
- const value = key === 'opacity' ? _value.toString() + '%' : _value;
100
- const ruleProp = rule.props.find(p => p.key === key);
101
- // replace existing property
102
- if (ruleProp && ruleProp.$cstNode) {
103
- const { range: { start, end } } = ruleProp.$cstNode;
104
- includeRange({
105
- start,
106
- end,
107
- });
108
- edits.push(TextEdit.replace({ start, end }, key + ' ' + value));
109
- continue;
110
- }
111
- // insert new style property right after the opening brace
112
- const insertPos = findNodeForKeyword(ruleCstNode, '{')?.range.end;
113
- invariant(insertPos, 'Opening brace not found');
114
- const indentStr = ' '.repeat(ruleCstNode.range.start.character) + '\t';
115
- const insertKeyValue = indentStr + key + ' ' + value;
116
- edits.push(TextEdit.insert(insertPos, '\n' + insertKeyValue));
117
- includeRange({
118
- start: {
119
- line: insertPos.line + 1,
120
- character: indentStr.length,
121
- },
122
- end: {
123
- line: insertPos.line + 1,
124
- character: insertKeyValue.length,
125
- },
126
- });
127
- }
128
- }
129
- }
130
- return {
131
- modifiedRange,
132
- edits,
133
- };
134
- }
@@ -1,12 +0,0 @@
1
- import { type ViewChange } from '@likec4/core';
2
- import { TextEdit } from 'vscode-languageserver-types';
3
- import { type ParsedAstView, type ParsedLikeC4LangiumDocument, ast } from '../ast';
4
- import type { LikeC4Services } from '../module';
5
- type ChangeViewLayoutArg = {
6
- view: ParsedAstView;
7
- doc: ParsedLikeC4LangiumDocument;
8
- viewAst: ast.LikeC4View;
9
- layout: ViewChange.ChangeAutoLayout['layout'];
10
- };
11
- export declare function changeViewLayout(_services: LikeC4Services, { view, viewAst, layout, }: ChangeViewLayoutArg): TextEdit;
12
- export {};
@@ -1,28 +0,0 @@
1
- import { invariant } from '@likec4/core';
2
- import { GrammarUtils } from 'langium';
3
- import { findLast, isNumber } from 'remeda';
4
- import { TextEdit } from 'vscode-languageserver-types';
5
- import { ast, toAstViewLayoutDirection } from '../ast';
6
- const { findNodeForKeyword } = GrammarUtils;
7
- export function changeViewLayout(_services, { view, viewAst, layout, }) {
8
- // Should never happen
9
- invariant(viewAst.body, `View ${view.id} has no body`);
10
- const viewCstNode = viewAst.$cstNode;
11
- invariant(viewCstNode, 'viewCstNode');
12
- const newdirection = toAstViewLayoutDirection(layout.direction);
13
- const existingRule = findLast(viewAst.body.rules, ast.isViewRuleAutoLayout);
14
- let newRule = `autoLayout ${newdirection}`;
15
- if (isNumber(layout.rankSep)) {
16
- newRule += ` ${layout.rankSep}`;
17
- if (isNumber(layout.nodeSep)) {
18
- newRule += ` ${layout.nodeSep}`;
19
- }
20
- }
21
- if (existingRule && existingRule.$cstNode) {
22
- return TextEdit.replace(existingRule.$cstNode.range, newRule);
23
- }
24
- const insertPos = findNodeForKeyword(viewAst.body.$cstNode, '}')?.range.start;
25
- invariant(insertPos, 'Closing brace not found');
26
- const insert = `\t${newRule}\n\t`;
27
- return TextEdit.insert(insertPos, insert);
28
- }
@@ -1,7 +0,0 @@
1
- import type { ViewLocateResult } from '../model/model-locator';
2
- import type { LikeC4Services } from '../module';
3
- type RemoveManualLayoutV1Args = {
4
- lookup: ViewLocateResult;
5
- };
6
- export declare function removeManualLayoutV1(services: LikeC4Services, { lookup, }: RemoveManualLayoutV1Args): Promise<boolean>;
7
- export {};
@@ -1,27 +0,0 @@
1
- import { invariant } from '@likec4/core';
2
- import { CstUtils } from 'langium';
3
- import { TextEdit } from 'vscode-languageserver-types';
4
- import { hasManualLayout } from '../view-utils/manual-layout';
5
- export async function removeManualLayoutV1(services, { lookup, }) {
6
- // No manual layout v1 present
7
- if (!lookup.view.manualLayout) {
8
- return false;
9
- }
10
- const cstnode = lookup.viewAst.$cstNode;
11
- invariant(cstnode, 'invalid view.$cstNode');
12
- const lspConnection = services.shared.lsp.Connection;
13
- invariant(lspConnection, 'LSP Connection not available');
14
- const commentCst = CstUtils.findCommentNode(cstnode, ['BLOCK_COMMENT']);
15
- if (commentCst && hasManualLayout(commentCst.text)) {
16
- const edit = await lspConnection.workspace.applyEdit({
17
- label: `LikeC4 - remove manual layout v1 for ${lookup.view.id}`,
18
- edit: {
19
- changes: {
20
- [lookup.doc.textDocument.uri]: [TextEdit.del(commentCst.range)],
21
- },
22
- },
23
- });
24
- return edit.applied;
25
- }
26
- return false;
27
- }
package/dist/module.d.ts DELETED
@@ -1,92 +0,0 @@
1
- import { QueueGraphvizLayoter } from '@likec4/layouts';
2
- import { type Module, WorkspaceCache } from 'langium';
3
- import { type DefaultSharedModuleContext, type LangiumServices, type LangiumSharedServices, type PartialLangiumServices } from 'langium/lsp';
4
- import { LikeC4DocumentationProvider } from './documentation';
5
- import { type FileSystemModuleContext, type FileSystemProvider, type FileSystemWatcher } from './filesystem';
6
- import { LikeC4Formatter } from './formatting/LikeC4Formatter';
7
- import { type LikeC4LanguageServices } from './LikeC4LanguageServices';
8
- import { LikeC4CodeActionProvider, LikeC4CodeLensProvider, LikeC4CompletionProvider, LikeC4DocumentHighlightProvider, LikeC4DocumentLinkProvider, LikeC4DocumentSymbolProvider, LikeC4HoverProvider, LikeC4SemanticTokenProvider } from './lsp';
9
- import { type LikeC4MCPServer, type LikeC4MCPServerModuleContext } from './mcp/interfaces';
10
- import { LikeC4MCPServerFactory } from './mcp/MCPServerFactory';
11
- import { type LikeC4ModelBuilder, DeploymentsIndex, FqnIndex, LikeC4ModelLocator, LikeC4ModelParser, LikeC4ValueConverter } from './model';
12
- import { LikeC4ModelChanges } from './model-change/ModelChanges';
13
- import { LikeC4NameProvider, LikeC4ScopeComputation, LikeC4ScopeProvider } from './references';
14
- import { Rpc } from './Rpc';
15
- import { NodeKindProvider, WorkspaceSymbolProvider } from './shared';
16
- import { LikeC4DocumentValidator } from './validation';
17
- import { type LikeC4ManualLayouts, type LikeC4Views } from './views';
18
- import type { LikeC4ManualLayoutsModuleContext } from './views/LikeC4ManualLayouts';
19
- import { IndexManager, LangiumDocuments, LikeC4WorkspaceManager, ProjectsManager } from './workspace';
20
- export type LanguageServicesContext = Omit<DefaultSharedModuleContext, 'fileSystemProvider'> & FileSystemModuleContext & LikeC4MCPServerModuleContext & LikeC4ManualLayoutsModuleContext;
21
- interface LikeC4AddedSharedServices {
22
- lsp: {
23
- NodeKindProvider: NodeKindProvider;
24
- WorkspaceSymbolProvider: WorkspaceSymbolProvider;
25
- };
26
- workspace: {
27
- Cache: WorkspaceCache<string, any>;
28
- ProjectsManager: ProjectsManager;
29
- IndexManager: IndexManager;
30
- LangiumDocuments: LangiumDocuments;
31
- WorkspaceManager: LikeC4WorkspaceManager;
32
- FileSystemProvider: FileSystemProvider;
33
- FileSystemWatcher: FileSystemWatcher;
34
- };
35
- }
36
- export type LikeC4SharedServices = LangiumSharedServices & LikeC4AddedSharedServices;
37
- /**
38
- * Declaration of custom services - add your own service classes here.
39
- */
40
- export interface LikeC4AddedServices {
41
- documentation: {
42
- DocumentationProvider: LikeC4DocumentationProvider;
43
- };
44
- validation: {
45
- DocumentValidator: LikeC4DocumentValidator;
46
- };
47
- Rpc: Rpc;
48
- mcp: {
49
- Server: LikeC4MCPServer;
50
- ServerFactory: LikeC4MCPServerFactory;
51
- };
52
- likec4: {
53
- LanguageServices: LikeC4LanguageServices;
54
- Views: LikeC4Views;
55
- ManualLayouts: LikeC4ManualLayouts;
56
- Layouter: QueueGraphvizLayoter;
57
- DeploymentsIndex: DeploymentsIndex;
58
- FqnIndex: FqnIndex;
59
- ModelParser: LikeC4ModelParser;
60
- ModelBuilder: LikeC4ModelBuilder;
61
- ModelLocator: LikeC4ModelLocator;
62
- ModelChanges: LikeC4ModelChanges;
63
- };
64
- lsp: {
65
- CompletionProvider: LikeC4CompletionProvider;
66
- DocumentHighlightProvider: LikeC4DocumentHighlightProvider;
67
- DocumentSymbolProvider: LikeC4DocumentSymbolProvider;
68
- SemanticTokenProvider: LikeC4SemanticTokenProvider;
69
- HoverProvider: LikeC4HoverProvider;
70
- CodeLensProvider: LikeC4CodeLensProvider;
71
- DocumentLinkProvider: LikeC4DocumentLinkProvider;
72
- Formatter: LikeC4Formatter;
73
- CodeActionProvider: LikeC4CodeActionProvider;
74
- };
75
- references: {
76
- NameProvider: LikeC4NameProvider;
77
- ScopeComputation: LikeC4ScopeComputation;
78
- ScopeProvider: LikeC4ScopeProvider;
79
- };
80
- shared?: LikeC4SharedServices;
81
- parser: {
82
- ValueConverter: LikeC4ValueConverter;
83
- };
84
- }
85
- export type LikeC4Services = LangiumServices & LikeC4AddedServices;
86
- export declare const createLikeC4Module: (context: LikeC4MCPServerModuleContext & LikeC4ManualLayoutsModuleContext) => Module<LikeC4Services, PartialLangiumServices & LikeC4AddedServices>;
87
- export declare function createLanguageServices<I1, I2, I3, I extends I1 & I2 & I3 & LikeC4Services>(context: Partial<LanguageServicesContext>, module?: Module<I, I1>, module2?: Module<I, I2>, module3?: Module<I, I3>): {
88
- shared: LikeC4SharedServices;
89
- likec4: I;
90
- };
91
- export declare function createSharedServices(context?: Partial<LanguageServicesContext>): LikeC4SharedServices;
92
- export {};
package/dist/module.js DELETED
@@ -1,143 +0,0 @@
1
- import { onNextTick } from '@likec4/core/utils';
2
- import { GraphvizWasmAdapter, QueueGraphvizLayoter } from '@likec4/layouts';
3
- import { DocumentState, inject, WorkspaceCache, } from 'langium';
4
- import { createDefaultModule, createDefaultSharedModule, } from 'langium/lsp';
5
- import { LikeC4DocumentationProvider } from './documentation';
6
- import { NoopFileSystem, } from './filesystem';
7
- import { LikeC4Formatter } from './formatting/LikeC4Formatter';
8
- import { LikeC4GeneratedModule, LikeC4GeneratedSharedModule, } from './generated/module';
9
- import { DefaultLikeC4LanguageServices } from './LikeC4LanguageServices';
10
- import { LikeC4CodeActionProvider, LikeC4CodeLensProvider, LikeC4CompletionProvider, LikeC4DocumentHighlightProvider, LikeC4DocumentLinkProvider, LikeC4DocumentSymbolProvider, LikeC4HoverProvider, LikeC4SemanticTokenProvider, } from './lsp';
11
- import { NoMCPServer, } from './mcp/interfaces';
12
- import { LikeC4MCPServerFactory } from './mcp/MCPServerFactory';
13
- import { DefaultLikeC4ModelBuilder, DeploymentsIndex, FqnIndex, LikeC4ModelLocator, LikeC4ModelParser, LikeC4ValueConverter, } from './model';
14
- import { LikeC4ModelChanges } from './model-change/ModelChanges';
15
- import { LikeC4NameProvider, LikeC4ScopeComputation, LikeC4ScopeProvider, } from './references';
16
- import { Rpc } from './Rpc';
17
- import { NodeKindProvider, WorkspaceSymbolProvider, } from './shared';
18
- import { LikeC4DocumentValidator, registerValidationChecks } from './validation';
19
- import { DefaultLikeC4Views, NoopLikeC4ManualLayouts } from './views';
20
- import { AstNodeDescriptionProvider, IndexManager, LangiumDocuments, LikeC4WorkspaceManager, ProjectsManager, } from './workspace';
21
- const createLikeC4SharedModule = (context) => ({
22
- lsp: {
23
- NodeKindProvider: services => new NodeKindProvider(services),
24
- WorkspaceSymbolProvider: services => new WorkspaceSymbolProvider(services),
25
- },
26
- workspace: {
27
- Cache: services => new WorkspaceCache(services, DocumentState.Validated),
28
- IndexManager: services => new IndexManager(services),
29
- LangiumDocuments: services => new LangiumDocuments(services),
30
- ProjectsManager: services => new ProjectsManager(services),
31
- WorkspaceManager: services => new LikeC4WorkspaceManager(services),
32
- FileSystemProvider: services => context.fileSystemProvider(services),
33
- FileSystemWatcher: services => context.fileSystemWatcher(services),
34
- },
35
- });
36
- function bind(Type) {
37
- return (services) => new Type(services);
38
- }
39
- export const createLikeC4Module = (context) => ({
40
- documentation: {
41
- DocumentationProvider: bind(LikeC4DocumentationProvider),
42
- },
43
- validation: {
44
- DocumentValidator: bind(LikeC4DocumentValidator),
45
- },
46
- Rpc: bind(Rpc),
47
- mcp: {
48
- Server: (services) => context.mcpServer(services),
49
- ServerFactory: bind(LikeC4MCPServerFactory),
50
- },
51
- likec4: {
52
- LanguageServices: bind(DefaultLikeC4LanguageServices),
53
- Layouter: (_services) => {
54
- return new QueueGraphvizLayoter({
55
- graphviz: new GraphvizWasmAdapter(),
56
- });
57
- },
58
- Views: bind(DefaultLikeC4Views),
59
- ManualLayouts: (services) => context.manualLayouts(services),
60
- DeploymentsIndex: bind(DeploymentsIndex),
61
- ModelChanges: bind(LikeC4ModelChanges),
62
- FqnIndex: bind(FqnIndex),
63
- ModelParser: bind(LikeC4ModelParser),
64
- ModelBuilder: bind(DefaultLikeC4ModelBuilder),
65
- ModelLocator: bind(LikeC4ModelLocator),
66
- },
67
- lsp: {
68
- // RenameProvider: bind(LikeC4RenameProvider),
69
- CompletionProvider: bind(LikeC4CompletionProvider),
70
- DocumentHighlightProvider: bind(LikeC4DocumentHighlightProvider),
71
- DocumentSymbolProvider: bind(LikeC4DocumentSymbolProvider),
72
- SemanticTokenProvider: bind(LikeC4SemanticTokenProvider),
73
- HoverProvider: bind(LikeC4HoverProvider),
74
- CodeLensProvider: bind(LikeC4CodeLensProvider),
75
- DocumentLinkProvider: bind(LikeC4DocumentLinkProvider),
76
- Formatter: bind(LikeC4Formatter),
77
- CodeActionProvider: bind(LikeC4CodeActionProvider),
78
- },
79
- workspace: {
80
- AstNodeDescriptionProvider: bind(AstNodeDescriptionProvider),
81
- },
82
- references: {
83
- NameProvider: bind(LikeC4NameProvider),
84
- ScopeComputation: bind(LikeC4ScopeComputation),
85
- ScopeProvider: bind(LikeC4ScopeProvider),
86
- },
87
- parser: {
88
- ValueConverter: bind(LikeC4ValueConverter),
89
- },
90
- });
91
- export function createLanguageServices(context, module, module2, module3) {
92
- const shared = createSharedServices(context);
93
- const modules = [
94
- createDefaultModule({ shared }),
95
- LikeC4GeneratedModule,
96
- createLikeC4Module({
97
- ...NoMCPServer,
98
- ...NoopLikeC4ManualLayouts,
99
- ...context,
100
- }),
101
- module,
102
- module2,
103
- module3,
104
- ].reduce(_merge, {});
105
- const likec4 = inject(modules);
106
- shared.ServiceRegistry.register(likec4);
107
- registerValidationChecks(likec4);
108
- if (!context.connection) {
109
- // We don't run inside a language server
110
- // Therefore, initialize the configuration provider instantly
111
- void shared.workspace.ConfigurationProvider.initialized({});
112
- }
113
- else {
114
- onNextTick(() => likec4.Rpc.init());
115
- }
116
- return { shared, likec4 };
117
- }
118
- export function createSharedServices(context = {}) {
119
- const moduleContext = {
120
- ...NoMCPServer,
121
- ...NoopFileSystem,
122
- ...NoopLikeC4ManualLayouts,
123
- ...context,
124
- };
125
- return inject(createDefaultSharedModule(moduleContext), LikeC4GeneratedSharedModule, createLikeC4SharedModule(moduleContext));
126
- }
127
- // Copied from langium/src/dependency-injection.ts as it is not exported
128
- function _merge(target, source) {
129
- if (source) {
130
- for (const [key, value2] of Object.entries(source)) {
131
- if (value2 !== undefined) {
132
- const value1 = target[key];
133
- if (value1 !== null && value2 !== null && typeof value1 === 'object' && typeof value2 === 'object') {
134
- target[key] = _merge(value1, value2);
135
- }
136
- else {
137
- target[key] = value2;
138
- }
139
- }
140
- }
141
- }
142
- return target;
143
- }