@likec4/language-server 1.18.0 → 1.19.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 (220) 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 +126 -0
  5. package/dist/ast.d.ts +200 -0
  6. package/dist/ast.js +276 -0
  7. package/dist/browser.d.ts +6 -20
  8. package/dist/browser.js +13 -0
  9. package/dist/formatting/LikeC4Formatter.d.ts +27 -0
  10. package/dist/formatting/LikeC4Formatter.js +261 -0
  11. package/dist/formatting/utils.d.ts +6 -0
  12. package/dist/formatting/utils.js +15 -0
  13. package/dist/generated/ast.d.ts +1242 -0
  14. package/dist/generated/ast.js +1945 -0
  15. package/dist/generated/grammar.d.ts +6 -0
  16. package/dist/generated/grammar.js +3 -0
  17. package/dist/generated/module.d.ts +9 -0
  18. package/dist/generated/module.js +23 -0
  19. package/dist/generated-lib/icons.d.ts +1 -0
  20. package/dist/{likec4lib.mjs → generated-lib/icons.js} +1 -6
  21. package/dist/index.d.ts +8 -31
  22. package/dist/index.js +13 -0
  23. package/dist/like-c4.langium +845 -0
  24. package/dist/likec4lib.d.ts +4 -6
  25. package/dist/likec4lib.js +4 -0
  26. package/dist/logger.d.ts +7 -0
  27. package/dist/logger.js +73 -0
  28. package/dist/lsp/CodeLensProvider.d.ts +9 -0
  29. package/dist/lsp/CodeLensProvider.js +40 -0
  30. package/dist/lsp/CompletionProvider.d.ts +6 -0
  31. package/dist/lsp/CompletionProvider.js +135 -0
  32. package/dist/lsp/DocumentHighlightProvider.d.ts +9 -0
  33. package/dist/lsp/DocumentHighlightProvider.js +10 -0
  34. package/dist/lsp/DocumentLinkProvider.d.ts +11 -0
  35. package/dist/lsp/DocumentLinkProvider.js +49 -0
  36. package/dist/lsp/DocumentSymbolProvider.d.ts +23 -0
  37. package/dist/lsp/DocumentSymbolProvider.js +202 -0
  38. package/dist/lsp/HoverProvider.d.ts +10 -0
  39. package/dist/lsp/HoverProvider.js +69 -0
  40. package/dist/lsp/RenameProvider.d.ts +5 -0
  41. package/dist/lsp/RenameProvider.js +6 -0
  42. package/dist/lsp/SemanticTokenProvider.d.ts +7 -0
  43. package/dist/lsp/SemanticTokenProvider.js +297 -0
  44. package/dist/lsp/index.d.ts +7 -0
  45. package/dist/lsp/index.js +7 -0
  46. package/dist/model/deployments-index.d.ts +60 -0
  47. package/dist/model/deployments-index.js +181 -0
  48. package/dist/model/fqn-computation.d.ts +3 -0
  49. package/dist/model/fqn-computation.js +72 -0
  50. package/dist/model/fqn-index.d.ts +25 -0
  51. package/dist/model/fqn-index.js +96 -0
  52. package/dist/model/index.d.ts +6 -0
  53. package/dist/model/index.js +6 -0
  54. package/dist/model/model-builder.d.ts +32 -0
  55. package/dist/model/model-builder.js +598 -0
  56. package/dist/model/model-locator.d.ts +23 -0
  57. package/dist/model/model-locator.js +126 -0
  58. package/dist/model/model-parser-where.d.ts +3 -0
  59. package/dist/model/model-parser-where.js +70 -0
  60. package/dist/model/model-parser.d.ts +292 -0
  61. package/dist/model/model-parser.js +72 -0
  62. package/dist/model/parser/Base.d.ts +28 -0
  63. package/dist/model/parser/Base.js +87 -0
  64. package/dist/model/parser/DeploymentModelParser.d.ts +33 -0
  65. package/dist/model/parser/DeploymentModelParser.js +162 -0
  66. package/dist/model/parser/DeploymentViewParser.d.ts +38 -0
  67. package/dist/model/parser/DeploymentViewParser.js +98 -0
  68. package/dist/model/parser/FqnRefParser.d.ts +29 -0
  69. package/dist/model/parser/FqnRefParser.js +108 -0
  70. package/dist/model/parser/GlobalsParser.d.ts +66 -0
  71. package/dist/model/parser/GlobalsParser.js +80 -0
  72. package/dist/model/parser/ModelParser.d.ts +27 -0
  73. package/dist/model/parser/ModelParser.js +122 -0
  74. package/dist/model/parser/PredicatesParser.d.ts +34 -0
  75. package/dist/model/parser/PredicatesParser.js +272 -0
  76. package/dist/model/parser/SpecificationParser.d.ts +27 -0
  77. package/dist/model/parser/SpecificationParser.js +120 -0
  78. package/dist/model/parser/ViewsParser.d.ts +64 -0
  79. package/dist/model/parser/ViewsParser.js +377 -0
  80. package/dist/model-change/ModelChanges.d.ts +15 -0
  81. package/dist/model-change/ModelChanges.js +89 -0
  82. package/dist/model-change/changeElementStyle.d.ts +16 -0
  83. package/dist/model-change/changeElementStyle.js +136 -0
  84. package/dist/model-change/changeViewLayout.d.ts +12 -0
  85. package/dist/model-change/changeViewLayout.js +32 -0
  86. package/dist/model-change/saveManualLayout.d.ts +11 -0
  87. package/dist/model-change/saveManualLayout.js +27 -0
  88. package/dist/module.d.ts +62 -0
  89. package/dist/module.js +123 -0
  90. package/dist/protocol.d.ts +20 -23
  91. package/dist/protocol.js +14 -0
  92. package/dist/references/index.d.ts +3 -0
  93. package/dist/references/index.js +3 -0
  94. package/dist/references/name-provider.d.ts +9 -0
  95. package/dist/references/name-provider.js +33 -0
  96. package/dist/references/scope-computation.d.ts +20 -0
  97. package/dist/references/scope-computation.js +281 -0
  98. package/dist/references/scope-provider.d.ts +16 -0
  99. package/dist/references/scope-provider.js +165 -0
  100. package/dist/shared/NodeKindProvider.d.ts +15 -0
  101. package/dist/shared/NodeKindProvider.js +108 -0
  102. package/dist/shared/WorkspaceManager.d.ts +18 -0
  103. package/dist/shared/WorkspaceManager.js +36 -0
  104. package/dist/shared/WorkspaceSymbolProvider.d.ts +3 -0
  105. package/dist/shared/WorkspaceSymbolProvider.js +3 -0
  106. package/dist/shared/index.d.ts +3 -0
  107. package/dist/shared/index.js +3 -0
  108. package/dist/test/index.d.ts +1 -0
  109. package/dist/test/index.js +1 -0
  110. package/dist/test/setup.d.ts +1 -0
  111. package/dist/test/setup.js +7 -0
  112. package/dist/test/testServices.d.ts +22 -0
  113. package/dist/test/testServices.js +119 -0
  114. package/dist/utils/elementRef.d.ts +11 -0
  115. package/dist/utils/elementRef.js +15 -0
  116. package/dist/utils/fqnRef.d.ts +8 -0
  117. package/dist/utils/fqnRef.js +46 -0
  118. package/dist/utils/index.d.ts +1 -0
  119. package/dist/utils/index.js +1 -0
  120. package/dist/utils/printDocs.d.ts +2 -0
  121. package/dist/utils/printDocs.js +1 -0
  122. package/dist/utils/stringHash.d.ts +1 -0
  123. package/dist/utils/stringHash.js +5 -0
  124. package/dist/validation/_shared.d.ts +3 -0
  125. package/dist/validation/_shared.js +22 -0
  126. package/dist/validation/deployment-checks.d.ts +6 -0
  127. package/dist/validation/deployment-checks.js +114 -0
  128. package/dist/validation/dynamic-view-rule.d.ts +4 -0
  129. package/dist/validation/dynamic-view-rule.js +16 -0
  130. package/dist/validation/dynamic-view-step.d.ts +4 -0
  131. package/dist/validation/dynamic-view-step.js +33 -0
  132. package/dist/validation/element.d.ts +4 -0
  133. package/dist/validation/element.js +49 -0
  134. package/dist/validation/index.d.ts +15 -0
  135. package/dist/validation/index.js +152 -0
  136. package/dist/validation/property-checks.d.ts +6 -0
  137. package/dist/validation/property-checks.js +38 -0
  138. package/dist/validation/relation.d.ts +5 -0
  139. package/dist/validation/relation.js +56 -0
  140. package/dist/validation/specification.d.ts +11 -0
  141. package/dist/validation/specification.js +136 -0
  142. package/dist/validation/view-predicates/element-with.d.ts +4 -0
  143. package/dist/validation/view-predicates/element-with.js +30 -0
  144. package/dist/validation/view-predicates/expanded-element.d.ts +4 -0
  145. package/dist/validation/view-predicates/expanded-element.js +11 -0
  146. package/dist/validation/view-predicates/expression-v2.d.ts +5 -0
  147. package/dist/validation/view-predicates/expression-v2.js +83 -0
  148. package/dist/validation/view-predicates/incoming.d.ts +4 -0
  149. package/dist/validation/view-predicates/incoming.js +15 -0
  150. package/dist/validation/view-predicates/index.d.ts +6 -0
  151. package/dist/validation/view-predicates/index.js +6 -0
  152. package/dist/validation/view-predicates/outgoing.d.ts +4 -0
  153. package/dist/validation/view-predicates/outgoing.js +15 -0
  154. package/dist/validation/view-predicates/relation-with.d.ts +4 -0
  155. package/dist/validation/view-predicates/relation-with.js +12 -0
  156. package/dist/validation/view.d.ts +4 -0
  157. package/dist/validation/view.js +23 -0
  158. package/dist/view-utils/assignNavigateTo.d.ts +2 -0
  159. package/dist/view-utils/assignNavigateTo.js +25 -0
  160. package/dist/view-utils/index.d.ts +2 -0
  161. package/dist/view-utils/index.js +2 -0
  162. package/dist/view-utils/manual-layout.d.ts +7 -0
  163. package/dist/view-utils/manual-layout.js +99 -0
  164. package/dist/view-utils/resolve-relative-paths.d.ts +2 -0
  165. package/dist/view-utils/resolve-relative-paths.js +78 -0
  166. package/package.json +36 -53
  167. package/src/LikeC4FileSystem.ts +22 -21
  168. package/src/ast.ts +44 -133
  169. package/src/browser.ts +10 -11
  170. package/src/generated/ast.ts +177 -177
  171. package/src/generated/grammar.ts +1 -1
  172. package/src/index.ts +10 -8
  173. package/src/like-c4.langium +37 -34
  174. package/src/logger.ts +34 -55
  175. package/src/lsp/CompletionProvider.ts +4 -4
  176. package/src/lsp/HoverProvider.ts +5 -3
  177. package/src/lsp/SemanticTokenProvider.ts +2 -2
  178. package/src/model/deployments-index.ts +18 -14
  179. package/src/model/model-builder.ts +10 -8
  180. package/src/model/model-parser.ts +62 -1574
  181. package/src/model/parser/Base.ts +107 -0
  182. package/src/model/parser/DeploymentModelParser.ts +192 -0
  183. package/src/model/parser/DeploymentViewParser.ts +116 -0
  184. package/src/model/parser/FqnRefParser.ts +118 -0
  185. package/src/model/parser/GlobalsParser.ts +96 -0
  186. package/src/model/parser/ModelParser.ts +141 -0
  187. package/src/model/parser/PredicatesParser.ts +291 -0
  188. package/src/model/parser/SpecificationParser.ts +133 -0
  189. package/src/model/parser/ViewsParser.ts +428 -0
  190. package/src/module.ts +17 -18
  191. package/src/references/scope-provider.ts +13 -7
  192. package/src/utils/{deploymentRef.ts → fqnRef.ts} +27 -2
  193. package/src/validation/_shared.ts +0 -1
  194. package/src/validation/deployment-checks.ts +49 -62
  195. package/src/validation/index.ts +100 -9
  196. package/src/validation/view-predicates/expression-v2.ts +101 -0
  197. package/src/validation/view-predicates/index.ts +1 -1
  198. package/src/view-utils/assignNavigateTo.ts +1 -1
  199. package/src/view-utils/manual-layout.ts +25 -0
  200. package/dist/browser.cjs +0 -25
  201. package/dist/browser.d.cts +0 -23
  202. package/dist/browser.d.mts +0 -23
  203. package/dist/browser.mjs +0 -20
  204. package/dist/index.cjs +0 -53
  205. package/dist/index.d.cts +0 -34
  206. package/dist/index.d.mts +0 -34
  207. package/dist/index.mjs +0 -46
  208. package/dist/likec4lib.cjs +0 -1546
  209. package/dist/likec4lib.d.cts +0 -6
  210. package/dist/likec4lib.d.mts +0 -6
  211. package/dist/protocol.cjs +0 -25
  212. package/dist/protocol.d.cts +0 -48
  213. package/dist/protocol.d.mts +0 -48
  214. package/dist/protocol.mjs +0 -17
  215. package/dist/shared/language-server.CO_nmHiL.cjs +0 -7689
  216. package/dist/shared/language-server.Da6ey08o.d.cts +0 -1619
  217. package/dist/shared/language-server.De7S3e5Z.d.ts +0 -1619
  218. package/dist/shared/language-server.Dj4iDjtB.d.mts +0 -1619
  219. package/dist/shared/language-server.oO_9JoAG.mjs +0 -7666
  220. 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,62 @@
1
+ import { type Module, DocumentCache, WorkspaceCache } from 'langium';
2
+ import { type DefaultSharedModuleContext, type LangiumServices, type LangiumSharedServices, type PartialLangiumServices } from 'langium/lsp';
3
+ import { LikeC4CodeLensProvider, LikeC4CompletionProvider, LikeC4DocumentHighlightProvider, LikeC4DocumentLinkProvider, LikeC4DocumentSymbolProvider, LikeC4HoverProvider, LikeC4SemanticTokenProvider } from './lsp';
4
+ import { DeploymentsIndex, FqnIndex, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser } from './model';
5
+ import { LikeC4ModelChanges } from './model-change/ModelChanges';
6
+ import { LikeC4NameProvider, LikeC4ScopeComputation, LikeC4ScopeProvider } from './references';
7
+ import { Rpc } from './Rpc';
8
+ import { LikeC4WorkspaceManager, NodeKindProvider, WorkspaceSymbolProvider } from './shared';
9
+ interface LikeC4AddedSharedServices {
10
+ lsp: {
11
+ NodeKindProvider: NodeKindProvider;
12
+ WorkspaceSymbolProvider: WorkspaceSymbolProvider;
13
+ };
14
+ workspace: {
15
+ WorkspaceManager: LikeC4WorkspaceManager;
16
+ };
17
+ }
18
+ export type LikeC4SharedServices = LangiumSharedServices & LikeC4AddedSharedServices;
19
+ /**
20
+ * Declaration of custom services - add your own service classes here.
21
+ */
22
+ export interface LikeC4AddedServices {
23
+ WorkspaceCache: WorkspaceCache<string, any>;
24
+ DocumentCache: DocumentCache<string, any>;
25
+ Rpc: Rpc;
26
+ likec4: {
27
+ DeploymentsIndex: DeploymentsIndex;
28
+ FqnIndex: FqnIndex;
29
+ ModelParser: LikeC4ModelParser;
30
+ ModelBuilder: LikeC4ModelBuilder;
31
+ ModelLocator: LikeC4ModelLocator;
32
+ ModelChanges: LikeC4ModelChanges;
33
+ };
34
+ lsp: {
35
+ CompletionProvider: LikeC4CompletionProvider;
36
+ DocumentHighlightProvider: LikeC4DocumentHighlightProvider;
37
+ DocumentSymbolProvider: LikeC4DocumentSymbolProvider;
38
+ SemanticTokenProvider: LikeC4SemanticTokenProvider;
39
+ HoverProvider: LikeC4HoverProvider;
40
+ CodeLensProvider: LikeC4CodeLensProvider;
41
+ DocumentLinkProvider: LikeC4DocumentLinkProvider;
42
+ };
43
+ references: {
44
+ NameProvider: LikeC4NameProvider;
45
+ ScopeComputation: LikeC4ScopeComputation;
46
+ ScopeProvider: LikeC4ScopeProvider;
47
+ };
48
+ shared?: LikeC4SharedServices;
49
+ }
50
+ export type LikeC4Services = LangiumServices & LikeC4AddedServices;
51
+ export declare const LikeC4Module: Module<LikeC4Services, PartialLangiumServices & LikeC4AddedServices>;
52
+ export type LanguageServicesContext = Partial<DefaultSharedModuleContext>;
53
+ 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>): {
54
+ shared: LikeC4SharedServices;
55
+ likec4: I;
56
+ };
57
+ export declare function createSharedServices(context?: LanguageServicesContext): LikeC4SharedServices;
58
+ export declare function createLanguageServices(context?: LanguageServicesContext): {
59
+ shared: LikeC4SharedServices;
60
+ likec4: LikeC4Services;
61
+ };
62
+ export {};
package/dist/module.js ADDED
@@ -0,0 +1,123 @@
1
+ import { DocumentCache, EmptyFileSystem, inject, WorkspaceCache } from "langium";
2
+ import {
3
+ createDefaultModule,
4
+ createDefaultSharedModule
5
+ } from "langium/lsp";
6
+ import { LikeC4Formatter } from "./formatting/LikeC4Formatter.js";
7
+ import { LikeC4GeneratedModule, LikeC4GeneratedSharedModule } from "./generated/module.js";
8
+ import { logToLspConnection } from "./logger.js";
9
+ import {
10
+ LikeC4CodeLensProvider,
11
+ LikeC4CompletionProvider,
12
+ LikeC4DocumentHighlightProvider,
13
+ LikeC4DocumentLinkProvider,
14
+ LikeC4DocumentSymbolProvider,
15
+ LikeC4HoverProvider,
16
+ LikeC4SemanticTokenProvider
17
+ } from "./lsp/index.js";
18
+ import { DeploymentsIndex, FqnIndex, LikeC4ModelBuilder, LikeC4ModelLocator, LikeC4ModelParser } from "./model/index.js";
19
+ import { LikeC4ModelChanges } from "./model-change/ModelChanges.js";
20
+ import { LikeC4NameProvider, LikeC4ScopeComputation, LikeC4ScopeProvider } from "./references/index.js";
21
+ import { Rpc } from "./Rpc.js";
22
+ import { LikeC4WorkspaceManager, NodeKindProvider, WorkspaceSymbolProvider } from "./shared/index.js";
23
+ import { registerValidationChecks } from "./validation/index.js";
24
+ const LikeC4SharedModule = {
25
+ lsp: {
26
+ NodeKindProvider: (services) => new NodeKindProvider(services),
27
+ WorkspaceSymbolProvider: (services) => new WorkspaceSymbolProvider(services)
28
+ },
29
+ workspace: {
30
+ WorkspaceManager: (services) => new LikeC4WorkspaceManager(services)
31
+ }
32
+ };
33
+ function bind(Type) {
34
+ return (services) => new Type(services);
35
+ }
36
+ export const LikeC4Module = {
37
+ WorkspaceCache: (services) => new WorkspaceCache(services.shared),
38
+ DocumentCache: (services) => new DocumentCache(services.shared),
39
+ Rpc: bind(Rpc),
40
+ likec4: {
41
+ DeploymentsIndex: bind(DeploymentsIndex),
42
+ ModelChanges: bind(LikeC4ModelChanges),
43
+ FqnIndex: bind(FqnIndex),
44
+ ModelParser: bind(LikeC4ModelParser),
45
+ ModelBuilder: bind(LikeC4ModelBuilder),
46
+ ModelLocator: bind(LikeC4ModelLocator)
47
+ },
48
+ lsp: {
49
+ // RenameProvider: bind(LikeC4RenameProvider),
50
+ CompletionProvider: bind(LikeC4CompletionProvider),
51
+ DocumentHighlightProvider: bind(LikeC4DocumentHighlightProvider),
52
+ DocumentSymbolProvider: bind(LikeC4DocumentSymbolProvider),
53
+ SemanticTokenProvider: bind(LikeC4SemanticTokenProvider),
54
+ HoverProvider: bind(LikeC4HoverProvider),
55
+ CodeLensProvider: bind(LikeC4CodeLensProvider),
56
+ DocumentLinkProvider: bind(LikeC4DocumentLinkProvider),
57
+ Formatter: bind(LikeC4Formatter)
58
+ },
59
+ references: {
60
+ NameProvider: bind(LikeC4NameProvider),
61
+ ScopeComputation: bind(LikeC4ScopeComputation),
62
+ ScopeProvider: bind(LikeC4ScopeProvider)
63
+ }
64
+ };
65
+ export function createCustomLanguageServices(context, module, module2, module3) {
66
+ const shared = createSharedServices(context);
67
+ const modules = [
68
+ createDefaultModule({ shared }),
69
+ LikeC4GeneratedModule,
70
+ LikeC4Module,
71
+ module,
72
+ module2,
73
+ module3
74
+ ].reduce(_merge, {});
75
+ const likec4 = inject(modules);
76
+ shared.ServiceRegistry.register(likec4);
77
+ registerValidationChecks(likec4);
78
+ if (!context.connection) {
79
+ shared.workspace.ConfigurationProvider.initialized({});
80
+ } else {
81
+ likec4.Rpc.init();
82
+ }
83
+ return { shared, likec4 };
84
+ }
85
+ export function createSharedServices(context = {}) {
86
+ const moduleContext = {
87
+ ...EmptyFileSystem,
88
+ ...context
89
+ };
90
+ if (context.connection) {
91
+ logToLspConnection(context.connection);
92
+ }
93
+ return inject(
94
+ createDefaultSharedModule(moduleContext),
95
+ LikeC4GeneratedSharedModule,
96
+ LikeC4SharedModule
97
+ );
98
+ }
99
+ export function createLanguageServices(context = {}) {
100
+ const shared = createSharedServices(context);
101
+ const likec4 = inject(createDefaultModule({ shared }), LikeC4GeneratedModule, LikeC4Module);
102
+ shared.ServiceRegistry.register(likec4);
103
+ registerValidationChecks(likec4);
104
+ if (context.connection) {
105
+ likec4.Rpc.init();
106
+ }
107
+ return { shared, likec4 };
108
+ }
109
+ function _merge(target, source) {
110
+ if (source) {
111
+ for (const [key, value2] of Object.entries(source)) {
112
+ if (value2 !== void 0) {
113
+ const value1 = target[key];
114
+ if (value1 !== null && value2 !== null && typeof value1 === "object" && typeof value2 === "object") {
115
+ target[key] = _merge(value1, value2);
116
+ } else {
117
+ target[key] = value2;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ return target;
123
+ }
@@ -1,31 +1,30 @@
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, 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
+ export interface BuildDocumentsParams {
24
23
  docs: DocumentUri[];
25
24
  }
26
- declare const buildDocuments: RequestType<BuildDocumentsParams, void, void>;
27
- type BuildDocumentsRequest = typeof buildDocuments;
28
- type LocateParams = {
25
+ export declare const buildDocuments: RequestType<BuildDocumentsParams, void, void>;
26
+ export type BuildDocumentsRequest = typeof buildDocuments;
27
+ export type LocateParams = {
29
28
  element: Fqn;
30
29
  property?: string;
31
30
  } | {
@@ -36,13 +35,11 @@ type LocateParams = {
36
35
  } | {
37
36
  view: ViewId;
38
37
  };
39
- declare const locate: RequestType<LocateParams, Location, void>;
40
- type LocateRequest = typeof locate;
41
- interface ChangeViewRequestParams {
38
+ export declare const locate: RequestType<LocateParams, Location | null, void>;
39
+ export type LocateRequest = typeof locate;
40
+ export interface ChangeViewRequestParams {
42
41
  viewId: ViewId;
43
42
  change: ViewChange;
44
43
  }
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 };
44
+ export declare const changeView: RequestType<ChangeViewRequestParams, Location | null, void>;
45
+ export type ChangeViewRequest = typeof changeView;
@@ -0,0 +1,14 @@
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 buildDocuments = new RequestType("likec4/build");
13
+ export const locate = new RequestType("likec4/locate");
14
+ 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, DefaultScopeComputation, type PrecomputedScopes } from 'langium';
2
+ import type { CancellationToken } from 'vscode-languageserver';
3
+ import { ast, type LikeC4LangiumDocument } 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 {};