@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,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
- }