@likec4/language-server 1.18.0 → 1.19.1

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 (250) hide show
  1. package/dist/LikeC4FileSystem.d.ts +13 -0
  2. package/dist/LikeC4FileSystem.js +27 -0
  3. package/dist/Rpc.d.ts +9 -0
  4. package/dist/Rpc.js +132 -0
  5. package/dist/ast.d.ts +200 -0
  6. package/dist/ast.js +276 -0
  7. package/dist/browser.d.ts +7 -20
  8. package/dist/browser.js +13 -0
  9. package/dist/documentation/documentation-provider.d.ts +8 -0
  10. package/dist/documentation/documentation-provider.js +46 -0
  11. package/dist/documentation/index.d.ts +1 -0
  12. package/dist/documentation/index.js +1 -0
  13. package/dist/formatting/LikeC4Formatter.d.ts +27 -0
  14. package/dist/formatting/LikeC4Formatter.js +261 -0
  15. package/dist/formatting/utils.d.ts +6 -0
  16. package/dist/formatting/utils.js +15 -0
  17. package/dist/generated/ast.d.ts +1242 -0
  18. package/dist/generated/ast.js +1945 -0
  19. package/dist/generated/grammar.d.ts +6 -0
  20. package/dist/generated/grammar.js +3 -0
  21. package/dist/generated/module.d.ts +9 -0
  22. package/dist/generated/module.js +23 -0
  23. package/dist/generated-lib/icons.d.ts +1 -0
  24. package/dist/{likec4lib.mjs → generated-lib/icons.js} +1 -6
  25. package/dist/index.d.ts +9 -31
  26. package/dist/index.js +14 -0
  27. package/dist/like-c4.langium +845 -0
  28. package/dist/likec4lib.d.ts +4 -6
  29. package/dist/likec4lib.js +4 -0
  30. package/dist/logger.d.ts +7 -0
  31. package/dist/logger.js +73 -0
  32. package/dist/lsp/CodeLensProvider.d.ts +9 -0
  33. package/dist/lsp/CodeLensProvider.js +40 -0
  34. package/dist/lsp/CompletionProvider.d.ts +6 -0
  35. package/dist/lsp/CompletionProvider.js +135 -0
  36. package/dist/lsp/DocumentHighlightProvider.d.ts +9 -0
  37. package/dist/lsp/DocumentHighlightProvider.js +10 -0
  38. package/dist/lsp/DocumentLinkProvider.d.ts +11 -0
  39. package/dist/lsp/DocumentLinkProvider.js +49 -0
  40. package/dist/lsp/DocumentSymbolProvider.d.ts +32 -0
  41. package/dist/lsp/DocumentSymbolProvider.js +274 -0
  42. package/dist/lsp/HoverProvider.d.ts +10 -0
  43. package/dist/lsp/HoverProvider.js +69 -0
  44. package/dist/lsp/RenameProvider.d.ts +5 -0
  45. package/dist/lsp/RenameProvider.js +6 -0
  46. package/dist/lsp/SemanticTokenProvider.d.ts +7 -0
  47. package/dist/lsp/SemanticTokenProvider.js +297 -0
  48. package/dist/lsp/index.d.ts +7 -0
  49. package/dist/lsp/index.js +7 -0
  50. package/dist/model/deployments-index.d.ts +60 -0
  51. package/dist/model/deployments-index.js +181 -0
  52. package/dist/model/fqn-computation.d.ts +3 -0
  53. package/dist/model/fqn-computation.js +72 -0
  54. package/dist/model/fqn-index.d.ts +25 -0
  55. package/dist/model/fqn-index.js +96 -0
  56. package/dist/model/index.d.ts +6 -0
  57. package/dist/model/index.js +6 -0
  58. package/dist/model/model-builder.d.ts +32 -0
  59. package/dist/model/model-builder.js +598 -0
  60. package/dist/model/model-locator.d.ts +23 -0
  61. package/dist/model/model-locator.js +126 -0
  62. package/dist/model/model-parser-where.d.ts +3 -0
  63. package/dist/model/model-parser-where.js +70 -0
  64. package/dist/model/model-parser.d.ts +292 -0
  65. package/dist/model/model-parser.js +72 -0
  66. package/dist/model/parser/Base.d.ts +28 -0
  67. package/dist/model/parser/Base.js +87 -0
  68. package/dist/model/parser/DeploymentModelParser.d.ts +33 -0
  69. package/dist/model/parser/DeploymentModelParser.js +162 -0
  70. package/dist/model/parser/DeploymentViewParser.d.ts +38 -0
  71. package/dist/model/parser/DeploymentViewParser.js +98 -0
  72. package/dist/model/parser/FqnRefParser.d.ts +29 -0
  73. package/dist/model/parser/FqnRefParser.js +108 -0
  74. package/dist/model/parser/GlobalsParser.d.ts +66 -0
  75. package/dist/model/parser/GlobalsParser.js +80 -0
  76. package/dist/model/parser/ModelParser.d.ts +27 -0
  77. package/dist/model/parser/ModelParser.js +122 -0
  78. package/dist/model/parser/PredicatesParser.d.ts +34 -0
  79. package/dist/model/parser/PredicatesParser.js +272 -0
  80. package/dist/model/parser/SpecificationParser.d.ts +27 -0
  81. package/dist/model/parser/SpecificationParser.js +120 -0
  82. package/dist/model/parser/ViewsParser.d.ts +64 -0
  83. package/dist/model/parser/ViewsParser.js +377 -0
  84. package/dist/model-change/ModelChanges.d.ts +15 -0
  85. package/dist/model-change/ModelChanges.js +89 -0
  86. package/dist/model-change/changeElementStyle.d.ts +16 -0
  87. package/dist/model-change/changeElementStyle.js +136 -0
  88. package/dist/model-change/changeViewLayout.d.ts +12 -0
  89. package/dist/model-change/changeViewLayout.js +32 -0
  90. package/dist/model-change/saveManualLayout.d.ts +11 -0
  91. package/dist/model-change/saveManualLayout.js +27 -0
  92. package/dist/module.d.ts +70 -0
  93. package/dist/module.js +162 -0
  94. package/dist/protocol.d.ts +38 -23
  95. package/dist/protocol.js +15 -0
  96. package/dist/references/index.d.ts +3 -0
  97. package/dist/references/index.js +3 -0
  98. package/dist/references/name-provider.d.ts +9 -0
  99. package/dist/references/name-provider.js +33 -0
  100. package/dist/references/scope-computation.d.ts +20 -0
  101. package/dist/references/scope-computation.js +281 -0
  102. package/dist/references/scope-provider.d.ts +16 -0
  103. package/dist/references/scope-provider.js +165 -0
  104. package/dist/shared/NodeKindProvider.d.ts +15 -0
  105. package/dist/shared/NodeKindProvider.js +108 -0
  106. package/dist/shared/WorkspaceManager.d.ts +18 -0
  107. package/dist/shared/WorkspaceManager.js +36 -0
  108. package/dist/shared/WorkspaceSymbolProvider.d.ts +3 -0
  109. package/dist/shared/WorkspaceSymbolProvider.js +3 -0
  110. package/dist/shared/index.d.ts +3 -0
  111. package/dist/shared/index.js +3 -0
  112. package/dist/test/index.d.ts +1 -0
  113. package/dist/test/index.js +1 -0
  114. package/dist/test/setup.d.ts +1 -0
  115. package/dist/test/setup.js +7 -0
  116. package/dist/test/testServices.d.ts +22 -0
  117. package/dist/test/testServices.js +119 -0
  118. package/dist/utils/elementRef.d.ts +11 -0
  119. package/dist/utils/elementRef.js +15 -0
  120. package/dist/utils/fqnRef.d.ts +8 -0
  121. package/dist/utils/fqnRef.js +46 -0
  122. package/dist/utils/index.d.ts +1 -0
  123. package/dist/utils/index.js +1 -0
  124. package/dist/utils/printDocs.d.ts +2 -0
  125. package/dist/utils/printDocs.js +1 -0
  126. package/dist/utils/stringHash.d.ts +1 -0
  127. package/dist/utils/stringHash.js +5 -0
  128. package/dist/validation/_shared.d.ts +3 -0
  129. package/dist/validation/_shared.js +22 -0
  130. package/dist/validation/deployment-checks.d.ts +6 -0
  131. package/dist/validation/deployment-checks.js +114 -0
  132. package/dist/validation/dynamic-view-rule.d.ts +4 -0
  133. package/dist/validation/dynamic-view-rule.js +17 -0
  134. package/dist/validation/dynamic-view-step.d.ts +4 -0
  135. package/dist/validation/dynamic-view-step.js +29 -0
  136. package/dist/validation/element.d.ts +4 -0
  137. package/dist/validation/element.js +49 -0
  138. package/dist/validation/index.d.ts +15 -0
  139. package/dist/validation/index.js +152 -0
  140. package/dist/validation/property-checks.d.ts +6 -0
  141. package/dist/validation/property-checks.js +39 -0
  142. package/dist/validation/relation.d.ts +5 -0
  143. package/dist/validation/relation.js +56 -0
  144. package/dist/validation/specification.d.ts +11 -0
  145. package/dist/validation/specification.js +136 -0
  146. package/dist/validation/view-predicates/element-with.d.ts +4 -0
  147. package/dist/validation/view-predicates/element-with.js +31 -0
  148. package/dist/validation/view-predicates/expanded-element.d.ts +4 -0
  149. package/dist/validation/view-predicates/expanded-element.js +12 -0
  150. package/dist/validation/view-predicates/expression-v2.d.ts +5 -0
  151. package/dist/validation/view-predicates/expression-v2.js +83 -0
  152. package/dist/validation/view-predicates/incoming.d.ts +4 -0
  153. package/dist/validation/view-predicates/incoming.js +16 -0
  154. package/dist/validation/view-predicates/index.d.ts +6 -0
  155. package/dist/validation/view-predicates/index.js +6 -0
  156. package/dist/validation/view-predicates/outgoing.d.ts +4 -0
  157. package/dist/validation/view-predicates/outgoing.js +16 -0
  158. package/dist/validation/view-predicates/relation-with.d.ts +4 -0
  159. package/dist/validation/view-predicates/relation-with.js +13 -0
  160. package/dist/validation/view.d.ts +4 -0
  161. package/dist/validation/view.js +23 -0
  162. package/dist/view-utils/assignNavigateTo.d.ts +2 -0
  163. package/dist/view-utils/assignNavigateTo.js +25 -0
  164. package/dist/view-utils/index.d.ts +2 -0
  165. package/dist/view-utils/index.js +2 -0
  166. package/dist/view-utils/manual-layout.d.ts +7 -0
  167. package/dist/view-utils/manual-layout.js +99 -0
  168. package/dist/view-utils/resolve-relative-paths.d.ts +2 -0
  169. package/dist/view-utils/resolve-relative-paths.js +78 -0
  170. package/dist/views/configurable-layouter.d.ts +7 -0
  171. package/dist/views/configurable-layouter.js +55 -0
  172. package/dist/views/index.d.ts +1 -0
  173. package/dist/views/index.js +1 -0
  174. package/dist/views/likec4-views.d.ts +26 -0
  175. package/dist/views/likec4-views.js +113 -0
  176. package/package.json +40 -54
  177. package/src/LikeC4FileSystem.ts +22 -21
  178. package/src/Rpc.ts +13 -7
  179. package/src/ast.ts +44 -133
  180. package/src/browser.ts +11 -11
  181. package/src/documentation/documentation-provider.ts +52 -0
  182. package/src/documentation/index.ts +1 -0
  183. package/src/generated/ast.ts +177 -177
  184. package/src/generated/grammar.ts +1 -1
  185. package/src/index.ts +13 -9
  186. package/src/like-c4.langium +37 -34
  187. package/src/logger.ts +34 -55
  188. package/src/lsp/CompletionProvider.ts +4 -4
  189. package/src/lsp/DocumentSymbolProvider.ts +110 -28
  190. package/src/lsp/HoverProvider.ts +5 -3
  191. package/src/lsp/SemanticTokenProvider.ts +2 -2
  192. package/src/model/deployments-index.ts +18 -14
  193. package/src/model/fqn-computation.ts +8 -8
  194. package/src/model/model-builder.ts +62 -60
  195. package/src/model/model-parser.ts +62 -1574
  196. package/src/model/parser/Base.ts +107 -0
  197. package/src/model/parser/DeploymentModelParser.ts +192 -0
  198. package/src/model/parser/DeploymentViewParser.ts +116 -0
  199. package/src/model/parser/FqnRefParser.ts +118 -0
  200. package/src/model/parser/GlobalsParser.ts +96 -0
  201. package/src/model/parser/ModelParser.ts +141 -0
  202. package/src/model/parser/PredicatesParser.ts +291 -0
  203. package/src/model/parser/SpecificationParser.ts +133 -0
  204. package/src/model/parser/ViewsParser.ts +428 -0
  205. package/src/module.ts +71 -25
  206. package/src/protocol.ts +29 -4
  207. package/src/references/scope-computation.ts +35 -35
  208. package/src/references/scope-provider.ts +13 -7
  209. package/src/utils/{deploymentRef.ts → fqnRef.ts} +27 -2
  210. package/src/validation/_shared.ts +0 -1
  211. package/src/validation/deployment-checks.ts +49 -62
  212. package/src/validation/dynamic-view-rule.ts +5 -4
  213. package/src/validation/dynamic-view-step.ts +23 -26
  214. package/src/validation/index.ts +100 -9
  215. package/src/validation/property-checks.ts +11 -10
  216. package/src/validation/specification.ts +38 -38
  217. package/src/validation/view-predicates/element-with.ts +6 -5
  218. package/src/validation/view-predicates/expanded-element.ts +6 -5
  219. package/src/validation/view-predicates/expression-v2.ts +101 -0
  220. package/src/validation/view-predicates/incoming.ts +6 -5
  221. package/src/validation/view-predicates/index.ts +1 -1
  222. package/src/validation/view-predicates/outgoing.ts +6 -5
  223. package/src/validation/view-predicates/relation-with.ts +6 -5
  224. package/src/validation/view.ts +5 -5
  225. package/src/view-utils/assignNavigateTo.ts +1 -1
  226. package/src/view-utils/manual-layout.ts +25 -0
  227. package/src/views/configurable-layouter.ts +65 -0
  228. package/src/views/index.ts +1 -0
  229. package/src/views/likec4-views.ts +139 -0
  230. package/dist/browser.cjs +0 -25
  231. package/dist/browser.d.cts +0 -23
  232. package/dist/browser.d.mts +0 -23
  233. package/dist/browser.mjs +0 -20
  234. package/dist/index.cjs +0 -53
  235. package/dist/index.d.cts +0 -34
  236. package/dist/index.d.mts +0 -34
  237. package/dist/index.mjs +0 -46
  238. package/dist/likec4lib.cjs +0 -1546
  239. package/dist/likec4lib.d.cts +0 -6
  240. package/dist/likec4lib.d.mts +0 -6
  241. package/dist/protocol.cjs +0 -25
  242. package/dist/protocol.d.cts +0 -48
  243. package/dist/protocol.d.mts +0 -48
  244. package/dist/protocol.mjs +0 -17
  245. package/dist/shared/language-server.CO_nmHiL.cjs +0 -7689
  246. package/dist/shared/language-server.Da6ey08o.d.cts +0 -1619
  247. package/dist/shared/language-server.De7S3e5Z.d.ts +0 -1619
  248. package/dist/shared/language-server.Dj4iDjtB.d.mts +0 -1619
  249. package/dist/shared/language-server.oO_9JoAG.mjs +0 -7666
  250. package/src/validation/view-predicates/deployments.ts +0 -56
@@ -0,0 +1,12 @@
1
+ import { type ViewChange } from '@likec4/core';
2
+ import { TextEdit } from 'vscode-languageserver-types';
3
+ import { ast, type ParsedAstView, type ParsedLikeC4LangiumDocument } 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 {};
@@ -0,0 +1,32 @@
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.js";
6
+ const { findNodeForProperty, findNodeForKeyword } = GrammarUtils;
7
+ export function changeViewLayout(_services, {
8
+ view,
9
+ viewAst,
10
+ layout
11
+ }) {
12
+ invariant(viewAst.body, `View ${view.id} has no body`);
13
+ const viewCstNode = viewAst.$cstNode;
14
+ invariant(viewCstNode, "viewCstNode");
15
+ const newdirection = toAstViewLayoutDirection(layout.direction);
16
+ const existingRule = findLast(viewAst.body.rules, ast.isViewRuleAutoLayout);
17
+ let newRule = `autoLayout ${newdirection}`;
18
+ if (isNumber(layout.rankSep)) {
19
+ newRule += ` ${layout.rankSep}`;
20
+ if (isNumber(layout.nodeSep)) {
21
+ newRule += ` ${layout.nodeSep}`;
22
+ }
23
+ }
24
+ if (existingRule && existingRule.$cstNode) {
25
+ return TextEdit.replace(existingRule.$cstNode.range, newRule);
26
+ }
27
+ const insertPos = findNodeForKeyword(viewAst.body.$cstNode, "}")?.range.start;
28
+ invariant(insertPos, "Closing brace not found");
29
+ const insert = ` ${newRule}
30
+ `;
31
+ return TextEdit.insert(insertPos, insert);
32
+ }
@@ -0,0 +1,11 @@
1
+ import { type ViewChange } from '@likec4/core';
2
+ import { TextEdit } from 'vscode-languageserver-types';
3
+ import { ast, type ParsedAstView, type ParsedLikeC4LangiumDocument } from '../ast';
4
+ import type { LikeC4Services } from '../module';
5
+ export type ManualLayoutArg = {
6
+ view: ParsedAstView;
7
+ doc: ParsedLikeC4LangiumDocument;
8
+ viewAst: ast.LikeC4View;
9
+ layout: ViewChange.SaveManualLayout['layout'];
10
+ };
11
+ export declare function saveManualLayout(_services: LikeC4Services, { viewAst, layout }: ManualLayoutArg): TextEdit;
@@ -0,0 +1,27 @@
1
+ import { invariant } from "@likec4/core";
2
+ import indentString from "indent-string";
3
+ import { CstUtils, GrammarUtils } from "langium";
4
+ import { TextEdit } from "vscode-languageserver-types";
5
+ import { serializeToComment } from "../view-utils/manual-layout.js";
6
+ const { findNodeForProperty } = GrammarUtils;
7
+ export function saveManualLayout(_services, {
8
+ viewAst,
9
+ layout
10
+ }) {
11
+ invariant(viewAst.$cstNode, "invalid view.$cstNode");
12
+ const commentCst = CstUtils.findCommentNode(viewAst.$cstNode, ["BLOCK_COMMENT"]);
13
+ let txt = serializeToComment(layout);
14
+ if (viewAst.$cstNode.range.start.character > 0) {
15
+ txt = indentString(txt, viewAst.$cstNode.range.start.character);
16
+ }
17
+ if (commentCst) {
18
+ return TextEdit.replace(commentCst.range, txt.trimStart());
19
+ }
20
+ return TextEdit.insert(
21
+ {
22
+ line: viewAst.$cstNode.range.start.line,
23
+ character: 0
24
+ },
25
+ txt + "\n"
26
+ );
27
+ }
@@ -0,0 +1,70 @@
1
+ import { GraphvizLayouter } from '@likec4/layouts';
2
+ import { type Module, DocumentCache, WorkspaceCache } from 'langium';
3
+ import { type DefaultSharedModuleContext, type LangiumServices, type LangiumSharedServices, type PartialLangiumServices } from 'langium/lsp';
4
+ import { LikeC4DocumentationProvider } from './documentation';
5
+ import { LikeC4CodeLensProvider, LikeC4CompletionProvider, LikeC4DocumentHighlightProvider, LikeC4DocumentLinkProvider, LikeC4DocumentSymbolProvider, LikeC4HoverProvider, LikeC4SemanticTokenProvider } from './lsp';
6
+ import { DeploymentsIndex, FqnIndex, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser } from './model';
7
+ import { LikeC4ModelChanges } from './model-change/ModelChanges';
8
+ import { LikeC4NameProvider, LikeC4ScopeComputation, LikeC4ScopeProvider } from './references';
9
+ import { Rpc } from './Rpc';
10
+ import { LikeC4WorkspaceManager, NodeKindProvider, WorkspaceSymbolProvider } from './shared';
11
+ import { LikeC4Views } from './views';
12
+ interface LikeC4AddedSharedServices {
13
+ lsp: {
14
+ NodeKindProvider: NodeKindProvider;
15
+ WorkspaceSymbolProvider: WorkspaceSymbolProvider;
16
+ };
17
+ workspace: {
18
+ WorkspaceManager: LikeC4WorkspaceManager;
19
+ };
20
+ }
21
+ export type LikeC4SharedServices = LangiumSharedServices & LikeC4AddedSharedServices;
22
+ /**
23
+ * Declaration of custom services - add your own service classes here.
24
+ */
25
+ export interface LikeC4AddedServices {
26
+ documentation: {
27
+ DocumentationProvider: LikeC4DocumentationProvider;
28
+ };
29
+ WorkspaceCache: WorkspaceCache<string, any>;
30
+ DocumentCache: DocumentCache<string, any>;
31
+ Rpc: Rpc;
32
+ likec4: {
33
+ Views: LikeC4Views;
34
+ Layouter: GraphvizLayouter;
35
+ DeploymentsIndex: DeploymentsIndex;
36
+ FqnIndex: FqnIndex;
37
+ ModelParser: LikeC4ModelParser;
38
+ ModelBuilder: LikeC4ModelBuilder;
39
+ ModelLocator: LikeC4ModelLocator;
40
+ ModelChanges: LikeC4ModelChanges;
41
+ };
42
+ lsp: {
43
+ CompletionProvider: LikeC4CompletionProvider;
44
+ DocumentHighlightProvider: LikeC4DocumentHighlightProvider;
45
+ DocumentSymbolProvider: LikeC4DocumentSymbolProvider;
46
+ SemanticTokenProvider: LikeC4SemanticTokenProvider;
47
+ HoverProvider: LikeC4HoverProvider;
48
+ CodeLensProvider: LikeC4CodeLensProvider;
49
+ DocumentLinkProvider: LikeC4DocumentLinkProvider;
50
+ };
51
+ references: {
52
+ NameProvider: LikeC4NameProvider;
53
+ ScopeComputation: LikeC4ScopeComputation;
54
+ ScopeProvider: LikeC4ScopeProvider;
55
+ };
56
+ shared?: LikeC4SharedServices;
57
+ }
58
+ export type LikeC4Services = LangiumServices & LikeC4AddedServices;
59
+ export declare const LikeC4Module: Module<LikeC4Services, PartialLangiumServices & LikeC4AddedServices>;
60
+ export type LanguageServicesContext = Partial<DefaultSharedModuleContext>;
61
+ export declare function createCustomLanguageServices<I1, I2, I3, I extends I1 & I2 & I3 & LikeC4Services>(context: LanguageServicesContext, module?: Module<I, I1>, module2?: Module<I, I2>, module3?: Module<I, I3>): {
62
+ shared: LikeC4SharedServices;
63
+ likec4: I;
64
+ };
65
+ export declare function createSharedServices(context?: LanguageServicesContext): LikeC4SharedServices;
66
+ export declare function createLanguageServices(context?: LanguageServicesContext): {
67
+ shared: LikeC4SharedServices;
68
+ likec4: LikeC4Services;
69
+ };
70
+ export {};
package/dist/module.js ADDED
@@ -0,0 +1,162 @@
1
+ import { GraphvizLayouter, GraphvizWasmAdapter } from "@likec4/layouts";
2
+ import {
3
+ DocumentCache,
4
+ EmptyFileSystem,
5
+ inject,
6
+ WorkspaceCache
7
+ } from "langium";
8
+ import {
9
+ createDefaultModule,
10
+ createDefaultSharedModule
11
+ } from "langium/lsp";
12
+ import { LikeC4DocumentationProvider } from "./documentation/index.js";
13
+ import { LikeC4Formatter } from "./formatting/LikeC4Formatter.js";
14
+ import {
15
+ LikeC4GeneratedModule,
16
+ LikeC4GeneratedSharedModule
17
+ } from "./generated/module.js";
18
+ import { logger, logToLspConnection } from "./logger.js";
19
+ import {
20
+ LikeC4CodeLensProvider,
21
+ LikeC4CompletionProvider,
22
+ LikeC4DocumentHighlightProvider,
23
+ LikeC4DocumentLinkProvider,
24
+ LikeC4DocumentSymbolProvider,
25
+ LikeC4HoverProvider,
26
+ LikeC4SemanticTokenProvider
27
+ } from "./lsp/index.js";
28
+ import {
29
+ DeploymentsIndex,
30
+ FqnIndex,
31
+ LikeC4ModelBuilder,
32
+ LikeC4ModelLocator,
33
+ LikeC4ModelParser
34
+ } from "./model/index.js";
35
+ import { LikeC4ModelChanges } from "./model-change/ModelChanges.js";
36
+ import {
37
+ LikeC4NameProvider,
38
+ LikeC4ScopeComputation,
39
+ LikeC4ScopeProvider
40
+ } from "./references/index.js";
41
+ import { Rpc } from "./Rpc.js";
42
+ import {
43
+ LikeC4WorkspaceManager,
44
+ NodeKindProvider,
45
+ WorkspaceSymbolProvider
46
+ } from "./shared/index.js";
47
+ import { registerValidationChecks } from "./validation/index.js";
48
+ import { LikeC4Views } from "./views/index.js";
49
+ const LikeC4SharedModule = {
50
+ lsp: {
51
+ NodeKindProvider: (services) => new NodeKindProvider(services),
52
+ WorkspaceSymbolProvider: (services) => new WorkspaceSymbolProvider(services)
53
+ },
54
+ workspace: {
55
+ WorkspaceManager: (services) => new LikeC4WorkspaceManager(services)
56
+ }
57
+ };
58
+ function bind(Type) {
59
+ return (services) => new Type(services);
60
+ }
61
+ export const LikeC4Module = {
62
+ documentation: {
63
+ DocumentationProvider: bind(LikeC4DocumentationProvider)
64
+ },
65
+ WorkspaceCache: (services) => new WorkspaceCache(services.shared),
66
+ DocumentCache: (services) => new DocumentCache(services.shared),
67
+ Rpc: bind(Rpc),
68
+ likec4: {
69
+ Layouter: (_services) => {
70
+ logger.debug("Creating GraphvizLayouter with GraphvizWasmAdapter");
71
+ return new GraphvizLayouter(new GraphvizWasmAdapter());
72
+ },
73
+ Views: bind(LikeC4Views),
74
+ DeploymentsIndex: bind(DeploymentsIndex),
75
+ ModelChanges: bind(LikeC4ModelChanges),
76
+ FqnIndex: bind(FqnIndex),
77
+ ModelParser: bind(LikeC4ModelParser),
78
+ ModelBuilder: bind(LikeC4ModelBuilder),
79
+ ModelLocator: bind(LikeC4ModelLocator)
80
+ },
81
+ lsp: {
82
+ // RenameProvider: bind(LikeC4RenameProvider),
83
+ CompletionProvider: bind(LikeC4CompletionProvider),
84
+ DocumentHighlightProvider: bind(LikeC4DocumentHighlightProvider),
85
+ DocumentSymbolProvider: bind(LikeC4DocumentSymbolProvider),
86
+ SemanticTokenProvider: bind(LikeC4SemanticTokenProvider),
87
+ HoverProvider: bind(LikeC4HoverProvider),
88
+ CodeLensProvider: bind(LikeC4CodeLensProvider),
89
+ DocumentLinkProvider: bind(LikeC4DocumentLinkProvider),
90
+ Formatter: bind(LikeC4Formatter)
91
+ },
92
+ references: {
93
+ NameProvider: bind(LikeC4NameProvider),
94
+ ScopeComputation: bind(LikeC4ScopeComputation),
95
+ ScopeProvider: bind(LikeC4ScopeProvider)
96
+ }
97
+ };
98
+ export function createCustomLanguageServices(context, module, module2, module3) {
99
+ const shared = createSharedServices(context);
100
+ const modules = [
101
+ createDefaultModule({ shared }),
102
+ LikeC4GeneratedModule,
103
+ LikeC4Module,
104
+ module,
105
+ module2,
106
+ module3
107
+ ].reduce(_merge, {});
108
+ const likec4 = inject(modules);
109
+ shared.ServiceRegistry.register(likec4);
110
+ registerValidationChecks(likec4);
111
+ if (!context.connection) {
112
+ shared.workspace.ConfigurationProvider.initialized({});
113
+ } else {
114
+ likec4.Rpc.init();
115
+ }
116
+ return { shared, likec4 };
117
+ }
118
+ export function createSharedServices(context = {}) {
119
+ const moduleContext = {
120
+ ...EmptyFileSystem,
121
+ ...context
122
+ };
123
+ if (context.connection) {
124
+ logToLspConnection(context.connection);
125
+ }
126
+ return inject(
127
+ createDefaultSharedModule(moduleContext),
128
+ LikeC4GeneratedSharedModule,
129
+ LikeC4SharedModule
130
+ );
131
+ }
132
+ export function createLanguageServices(context = {}) {
133
+ const shared = createSharedServices(context);
134
+ const likec4 = inject(
135
+ createDefaultModule({ shared }),
136
+ LikeC4GeneratedModule,
137
+ LikeC4Module
138
+ );
139
+ shared.ServiceRegistry.register(likec4);
140
+ registerValidationChecks(likec4);
141
+ if (!context.connection) {
142
+ shared.workspace.ConfigurationProvider.initialized({});
143
+ } else {
144
+ likec4.Rpc.init();
145
+ }
146
+ return { shared, likec4 };
147
+ }
148
+ function _merge(target, source) {
149
+ if (source) {
150
+ for (const [key, value2] of Object.entries(source)) {
151
+ if (value2 !== void 0) {
152
+ const value1 = target[key];
153
+ if (value1 !== null && value2 !== null && typeof value1 === "object" && typeof value2 === "object") {
154
+ target[key] = _merge(value1, value2);
155
+ } else {
156
+ target[key] = value2;
157
+ }
158
+ }
159
+ }
160
+ }
161
+ return target;
162
+ }
@@ -1,31 +1,48 @@
1
- import { ParsedLikeC4Model, ComputedLikeC4Model, ViewId, ComputedView, Fqn, RelationId, ViewChange } from '@likec4/core';
2
- import { NotificationType, RequestType0, RequestType } from 'vscode-jsonrpc';
3
- import { DocumentUri, Location } from 'vscode-languageserver-types';
4
-
5
- declare const onDidChangeModel: NotificationType<string>;
6
- type OnDidChangeModelNotification = typeof onDidChangeModel;
7
- declare const fetchModel: RequestType0<{
1
+ import type { ComputedLikeC4Model, ComputedView, DiagramView, Fqn, ParsedLikeC4Model, RelationId, ViewChange, ViewId } from '@likec4/core';
2
+ import { NotificationType, RequestType, RequestType0 } from 'vscode-jsonrpc';
3
+ import type { DocumentUri, Location } from 'vscode-languageserver-types';
4
+ export declare const onDidChangeModel: NotificationType<string>;
5
+ export type OnDidChangeModelNotification = typeof onDidChangeModel;
6
+ export declare const fetchModel: RequestType0<{
8
7
  model: ParsedLikeC4Model | null;
9
8
  }, void>;
10
- type FetchModelRequest = typeof fetchModel;
11
- declare const fetchComputedModel: RequestType<{
9
+ export type FetchModelRequest = typeof fetchModel;
10
+ export declare const fetchComputedModel: RequestType<{
12
11
  cleanCaches?: boolean | undefined;
13
12
  }, {
14
13
  model: ComputedLikeC4Model | null;
15
14
  }, void>;
16
- type FetchComputedModelRequest = typeof fetchComputedModel;
17
- declare const computeView: RequestType<{
15
+ export type FetchComputedModelRequest = typeof fetchComputedModel;
16
+ export declare const computeView: RequestType<{
18
17
  viewId: ViewId;
19
18
  }, {
20
19
  view: ComputedView | null;
21
20
  }, void>;
22
- type ComputeViewRequest = typeof computeView;
23
- interface BuildDocumentsParams {
21
+ export type ComputeViewRequest = typeof computeView;
22
+ /**
23
+ * Request to layout a view.
24
+ */
25
+ export declare const layoutView: RequestType<{
26
+ viewId: ViewId;
27
+ }, {
28
+ result: {
29
+ dot: string;
30
+ diagram: DiagramView;
31
+ } | null;
32
+ }, void>;
33
+ export type LayoutViewRequest = typeof layoutView;
34
+ /**
35
+ * Request to build documents.
36
+ */
37
+ export interface BuildDocumentsParams {
24
38
  docs: DocumentUri[];
25
39
  }
26
- declare const buildDocuments: RequestType<BuildDocumentsParams, void, void>;
27
- type BuildDocumentsRequest = typeof buildDocuments;
28
- type LocateParams = {
40
+ export declare const buildDocuments: RequestType<BuildDocumentsParams, void, void>;
41
+ export type BuildDocumentsRequest = typeof buildDocuments;
42
+ /**
43
+ * Request to locate an element, relation, deployment or view.
44
+ */
45
+ export type LocateParams = {
29
46
  element: Fqn;
30
47
  property?: string;
31
48
  } | {
@@ -36,13 +53,11 @@ type LocateParams = {
36
53
  } | {
37
54
  view: ViewId;
38
55
  };
39
- declare const locate: RequestType<LocateParams, Location, void>;
40
- type LocateRequest = typeof locate;
41
- interface ChangeViewRequestParams {
56
+ export declare const locate: RequestType<LocateParams, Location | null, void>;
57
+ export type LocateRequest = typeof locate;
58
+ export interface ChangeViewRequestParams {
42
59
  viewId: ViewId;
43
60
  change: ViewChange;
44
61
  }
45
- declare const changeView: RequestType<ChangeViewRequestParams, Location, void>;
46
- type ChangeViewRequest = typeof changeView;
47
-
48
- export { type BuildDocumentsParams, type BuildDocumentsRequest, type ChangeViewRequest, type ChangeViewRequestParams, type ComputeViewRequest, type FetchComputedModelRequest, type FetchModelRequest, type LocateParams, type LocateRequest, type OnDidChangeModelNotification, buildDocuments, changeView, computeView, fetchComputedModel, fetchModel, locate, onDidChangeModel };
62
+ export declare const changeView: RequestType<ChangeViewRequestParams, Location | null, void>;
63
+ export type ChangeViewRequest = typeof changeView;
@@ -0,0 +1,15 @@
1
+ import { NotificationType, RequestType, RequestType0 } from "vscode-jsonrpc";
2
+ export const onDidChangeModel = new NotificationType("likec4/onDidChangeModel");
3
+ export const fetchModel = new RequestType0(
4
+ "likec4/fetchModel"
5
+ );
6
+ export const fetchComputedModel = new RequestType(
7
+ "likec4/fetchComputedModel"
8
+ );
9
+ export const computeView = new RequestType(
10
+ "likec4/computeView"
11
+ );
12
+ export const layoutView = new RequestType("likec4/layout-view");
13
+ export const buildDocuments = new RequestType("likec4/build");
14
+ export const locate = new RequestType("likec4/locate");
15
+ export const changeView = new RequestType("likec4/change-view");
@@ -0,0 +1,3 @@
1
+ export * from './name-provider';
2
+ export * from './scope-computation';
3
+ export * from './scope-provider';
@@ -0,0 +1,3 @@
1
+ export * from "./name-provider.js";
2
+ export * from "./scope-computation.js";
3
+ export * from "./scope-provider.js";
@@ -0,0 +1,9 @@
1
+ import { type AstNode, type CstNode, DefaultNameProvider } from 'langium';
2
+ import type { LikeC4Services } from '../module';
3
+ export declare class LikeC4NameProvider extends DefaultNameProvider {
4
+ protected services: LikeC4Services;
5
+ constructor(services: LikeC4Services);
6
+ getNameStrict(node: AstNode): string;
7
+ getName(node: AstNode): string | undefined;
8
+ getNameNode(node: AstNode): CstNode | undefined;
9
+ }
@@ -0,0 +1,33 @@
1
+ import { nonNullable } from "@likec4/core";
2
+ import { DefaultNameProvider, isNamed } from "langium";
3
+ import { ast } from "../ast.js";
4
+ export class LikeC4NameProvider extends DefaultNameProvider {
5
+ constructor(services) {
6
+ super();
7
+ this.services = services;
8
+ }
9
+ getNameStrict(node) {
10
+ return nonNullable(
11
+ this.getName(node),
12
+ `Failed getName for ${this.services.workspace.AstNodeLocator.getAstNodePath(node)}`
13
+ );
14
+ }
15
+ getName(node) {
16
+ if (isNamed(node)) {
17
+ return node.name;
18
+ }
19
+ if (ast.isDeployedInstance(node)) {
20
+ return node.element.el.$refText;
21
+ }
22
+ return void 0;
23
+ }
24
+ getNameNode(node) {
25
+ if (isNamed(node)) {
26
+ return super.getNameNode(node);
27
+ }
28
+ if (ast.isDeployedInstance(node)) {
29
+ return node.element.el.$refNode;
30
+ }
31
+ return void 0;
32
+ }
33
+ }
@@ -0,0 +1,20 @@
1
+ import { type AstNodeDescription, type PrecomputedScopes, DefaultScopeComputation } from 'langium';
2
+ import type { CancellationToken } from 'vscode-languageserver';
3
+ import { type LikeC4LangiumDocument, ast } from '../ast';
4
+ import type { LikeC4Services } from '../module';
5
+ type ElementsContainer = ast.Model | ast.ElementBody | ast.ExtendElementBody;
6
+ type DeploymentsContainer = ast.ModelDeployments | ast.DeploymentNodeBody;
7
+ export declare class LikeC4ScopeComputation extends DefaultScopeComputation {
8
+ constructor(services: LikeC4Services);
9
+ computeExports(document: LikeC4LangiumDocument, _cancelToken?: CancellationToken): Promise<AstNodeDescription[]>;
10
+ private exportViews;
11
+ private exportGlobals;
12
+ private exportModel;
13
+ private exportLibrary;
14
+ private exportSpecification;
15
+ private exportDeployments;
16
+ computeLocalScopes(document: LikeC4LangiumDocument, _cancelToken?: CancellationToken): Promise<PrecomputedScopes>;
17
+ protected processContainer(container: ElementsContainer, scopes: PrecomputedScopes, document: LikeC4LangiumDocument): AstNodeDescription[];
18
+ protected processDeployments(container: DeploymentsContainer, scopes: PrecomputedScopes, document: LikeC4LangiumDocument): AstNodeDescription[];
19
+ }
20
+ export {};