@likec4/language-server 1.42.1 → 1.44.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.
- package/browser/package.json +1 -1
- package/browser-worker/package.json +1 -1
- package/dist/LikeC4LanguageServices.d.ts +12 -19
- package/dist/LikeC4LanguageServices.js +182 -0
- package/dist/Rpc.js +245 -0
- package/dist/ast.d.ts +10 -6
- package/dist/ast.js +253 -0
- package/dist/browser-worker.js +4 -0
- package/dist/browser.js +35 -0
- package/dist/bundled.js +42 -0
- package/dist/bundled.mjs +3830 -4172
- package/dist/documentation/documentation-provider.js +51 -0
- package/dist/documentation/index.js +1 -0
- package/dist/empty.js +2 -0
- package/dist/filesystem/ChokidarWatcher.js +97 -0
- package/dist/filesystem/FileSystemWatcher.js +14 -0
- package/dist/filesystem/LikeC4FileSystem.d.ts +1 -2
- package/dist/filesystem/LikeC4FileSystem.js +126 -0
- package/dist/filesystem/index.d.ts +26 -0
- package/dist/filesystem/index.js +29 -0
- package/dist/formatting/LikeC4Formatter.js +637 -0
- package/dist/formatting/utils.js +18 -0
- package/dist/generated/ast.d.ts +19 -3
- package/dist/generated/ast.js +2155 -0
- package/dist/generated/grammar.js +7 -0
- package/dist/generated/module.d.ts +6 -1
- package/dist/generated/module.js +27 -0
- package/dist/generated-lib/{icons.mjs → icons.js} +11 -7
- package/dist/index.d.ts +7 -0
- package/dist/index.js +53 -0
- package/dist/{likec4lib.mjs → likec4lib.js} +3 -3
- package/dist/logger.js +81 -0
- package/dist/lsp/CodeActionProvider.d.ts +14 -0
- package/dist/lsp/CodeActionProvider.js +33 -0
- package/dist/lsp/CodeLensProvider.js +44 -0
- package/dist/lsp/CompletionProvider.d.ts +3 -1
- package/dist/lsp/CompletionProvider.js +200 -0
- package/dist/lsp/DocumentHighlightProvider.js +10 -0
- package/dist/lsp/DocumentLinkProvider.js +58 -0
- package/dist/lsp/DocumentSymbolProvider.js +306 -0
- package/dist/lsp/HoverProvider.js +106 -0
- package/dist/lsp/RenameProvider.js +6 -0
- package/dist/lsp/SemanticTokenProvider.d.ts +5 -0
- package/dist/lsp/SemanticTokenProvider.js +257 -0
- package/dist/lsp/index.d.ts +1 -0
- package/dist/lsp/index.js +9 -0
- package/dist/mcp/MCPServerFactory.js +73 -0
- package/dist/mcp/NoopLikeC4MCPServer.js +17 -0
- package/dist/mcp/interfaces.js +5 -0
- package/dist/mcp/server/StdioLikeC4MCPServer.js +47 -0
- package/dist/mcp/server/StreamableLikeC4MCPServer.js +145 -0
- package/dist/mcp/server/WithMCPServer.js +56 -0
- package/dist/mcp/tools/_common.d.ts +8 -7
- package/dist/mcp/tools/_common.js +49 -0
- package/dist/mcp/tools/find-relationships.d.ts +7 -8
- package/dist/mcp/tools/find-relationships.js +150 -0
- package/dist/mcp/tools/list-projects.d.ts +3 -3
- package/dist/mcp/tools/list-projects.js +62 -0
- package/dist/mcp/tools/open-view.d.ts +6 -7
- package/dist/mcp/tools/open-view.js +52 -0
- package/dist/mcp/tools/read-deployment.d.ts +6 -7
- package/dist/mcp/tools/read-deployment.js +132 -0
- package/dist/mcp/tools/read-element.d.ts +6 -7
- package/dist/mcp/tools/read-element.js +194 -0
- package/dist/mcp/tools/read-project-summary.d.ts +5 -6
- package/dist/mcp/tools/read-project-summary.js +176 -0
- package/dist/mcp/tools/read-view.d.ts +6 -7
- package/dist/mcp/tools/read-view.js +203 -0
- package/dist/mcp/tools/search-element.d.ts +3 -3
- package/dist/mcp/tools/search-element.js +177 -0
- package/dist/mcp/utils.d.ts +2 -2
- package/dist/mcp/utils.js +48 -0
- package/dist/model/builder/MergedExtends.d.ts +2 -1
- package/dist/model/builder/MergedExtends.js +74 -0
- package/dist/model/builder/MergedSpecification.js +175 -0
- package/dist/model/builder/buildModel.js +176 -0
- package/dist/model/deployments-index.js +102 -0
- package/dist/model/fqn-index.js +250 -0
- package/dist/model/index.js +6 -0
- package/dist/model/model-builder.d.ts +13 -11
- package/dist/model/model-builder.js +234 -0
- package/dist/model/model-locator.d.ts +6 -5
- package/dist/model/model-locator.js +240 -0
- package/dist/model/model-parser-where.js +81 -0
- package/dist/model/model-parser.d.ts +318 -313
- package/dist/model/model-parser.js +119 -0
- package/dist/model/parser/Base.d.ts +3 -3
- package/dist/model/parser/Base.js +367 -0
- package/dist/model/parser/DeploymentModelParser.d.ts +3 -3
- package/dist/model/parser/DeploymentModelParser.js +176 -0
- package/dist/model/parser/DeploymentViewParser.d.ts +4 -4
- package/dist/model/parser/DeploymentViewParser.js +86 -0
- package/dist/model/parser/FqnRefParser.d.ts +3 -3
- package/dist/model/parser/FqnRefParser.js +382 -0
- package/dist/model/parser/GlobalsParser.d.ts +7 -7
- package/dist/model/parser/GlobalsParser.js +84 -0
- package/dist/model/parser/ImportsParser.d.ts +12 -13
- package/dist/model/parser/ImportsParser.js +24 -0
- package/dist/model/parser/ModelParser.d.ts +3 -3
- package/dist/model/parser/ModelParser.js +165 -0
- package/dist/model/parser/PredicatesParser.d.ts +3 -3
- package/dist/model/parser/PredicatesParser.js +45 -0
- package/dist/model/parser/SpecificationParser.d.ts +3 -3
- package/dist/model/parser/SpecificationParser.js +109 -0
- package/dist/model/parser/ValueConverter.js +12 -0
- package/dist/model/parser/ViewsParser.d.ts +4 -4
- package/dist/model/parser/ViewsParser.js +477 -0
- package/dist/model-change/ModelChanges.d.ts +6 -3
- package/dist/model-change/ModelChanges.js +102 -0
- package/dist/model-change/changeElementStyle.js +134 -0
- package/dist/model-change/changeViewLayout.d.ts +2 -2
- package/dist/model-change/changeViewLayout.js +28 -0
- package/dist/model-change/removeManualLayoutV1.d.ts +7 -0
- package/dist/model-change/removeManualLayoutV1.js +27 -0
- package/dist/module.d.ts +10 -5
- package/dist/module.js +143 -0
- package/dist/protocol.d.ts +1 -17
- package/dist/protocol.js +114 -0
- package/dist/references/index.js +3 -0
- package/dist/references/name-provider.js +37 -0
- package/dist/references/scope-computation.js +288 -0
- package/dist/references/scope-provider.d.ts +3 -3
- package/dist/references/scope-provider.js +242 -0
- package/dist/shared/NodeKindProvider.js +57 -0
- package/dist/shared/{WorkspaceSymbolProvider.mjs → WorkspaceSymbolProvider.js} +1 -1
- package/dist/shared/index.js +2 -0
- package/dist/test/index.js +1 -0
- package/dist/test/testServices.d.ts +16 -16
- package/dist/test/testServices.js +210 -0
- package/dist/utils/disposable.js +26 -0
- package/dist/utils/elementRef.d.ts +1 -1
- package/dist/utils/elementRef.js +27 -0
- package/dist/utils/fqnRef.js +63 -0
- package/dist/utils/index.js +35 -0
- package/dist/utils/printDocs.js +1 -0
- package/dist/utils/projectId.js +16 -0
- package/dist/utils/stringHash.js +5 -0
- package/dist/validation/DocumentValidator.js +17 -0
- package/dist/validation/_shared.js +26 -0
- package/dist/validation/deployment-checks.js +140 -0
- package/dist/validation/dynamic-view.js +67 -0
- package/dist/validation/element-ref.js +12 -0
- package/dist/validation/element.js +49 -0
- package/dist/validation/imports.js +46 -0
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +157 -0
- package/dist/validation/property-checks.js +108 -0
- package/dist/validation/relation.js +55 -0
- package/dist/validation/specification.js +190 -0
- package/dist/validation/view-predicates/fqn-expr-with.js +43 -0
- package/dist/validation/view-predicates/fqn-ref-expr.js +51 -0
- package/dist/validation/view-predicates/incoming.js +16 -0
- package/dist/validation/view-predicates/index.js +6 -0
- package/dist/validation/view-predicates/outgoing.js +20 -0
- package/dist/validation/view-predicates/relation-expr.js +46 -0
- package/dist/validation/view-predicates/relation-with.js +16 -0
- package/dist/validation/view.d.ts +1 -1
- package/dist/validation/view.js +42 -0
- package/dist/view-utils/assignNavigateTo.js +27 -0
- package/dist/view-utils/index.d.ts +1 -0
- package/dist/view-utils/index.js +2 -0
- package/dist/view-utils/manual-layout.d.ts +6 -0
- package/dist/view-utils/manual-layout.js +151 -0
- package/dist/views/ConfigurableLayouter.js +51 -0
- package/dist/views/LikeC4ManualLayouts.d.ts +28 -0
- package/dist/views/LikeC4ManualLayouts.js +132 -0
- package/dist/views/{likec4-views.d.ts → LikeC4Views.d.ts} +9 -8
- package/dist/views/LikeC4Views.js +200 -0
- package/dist/views/index.d.ts +4 -1
- package/dist/views/index.js +11 -0
- package/dist/workspace/AstNodeDescriptionProvider.js +15 -0
- package/dist/workspace/IndexManager.js +21 -0
- package/dist/workspace/LangiumDocuments.d.ts +1 -1
- package/dist/workspace/LangiumDocuments.js +58 -0
- package/dist/workspace/ProjectsManager.d.ts +8 -3
- package/dist/workspace/ProjectsManager.js +373 -0
- package/dist/workspace/WorkspaceManager.d.ts +3 -2
- package/dist/workspace/WorkspaceManager.js +93 -0
- package/dist/workspace/index.js +5 -0
- package/likec4lib/package.json +1 -1
- package/package.json +32 -31
- package/protocol/package.json +1 -1
- package/dist/LikeC4LanguageServices.mjs +0 -197
- package/dist/Rpc.mjs +0 -296
- package/dist/ast.mjs +0 -221
- package/dist/browser-worker.mjs +0 -2
- package/dist/browser.mjs +0 -32
- package/dist/documentation/documentation-provider.mjs +0 -48
- package/dist/documentation/index.mjs +0 -1
- package/dist/empty.mjs +0 -1
- package/dist/filesystem/ChokidarWatcher.mjs +0 -68
- package/dist/filesystem/FileSystemWatcher.mjs +0 -11
- package/dist/filesystem/LikeC4FileSystem.mjs +0 -64
- package/dist/filesystem/index.mjs +0 -19
- package/dist/formatting/LikeC4Formatter.mjs +0 -511
- package/dist/formatting/utils.mjs +0 -15
- package/dist/generated/ast.mjs +0 -2118
- package/dist/generated/grammar.mjs +0 -3
- package/dist/generated/module.mjs +0 -23
- package/dist/index.mjs +0 -50
- package/dist/logger.mjs +0 -82
- package/dist/lsp/CodeLensProvider.mjs +0 -42
- package/dist/lsp/CompletionProvider.mjs +0 -208
- package/dist/lsp/DocumentHighlightProvider.mjs +0 -10
- package/dist/lsp/DocumentLinkProvider.mjs +0 -53
- package/dist/lsp/DocumentSymbolProvider.mjs +0 -287
- package/dist/lsp/HoverProvider.mjs +0 -104
- package/dist/lsp/RenameProvider.mjs +0 -6
- package/dist/lsp/SemanticTokenProvider.mjs +0 -350
- package/dist/lsp/index.mjs +0 -7
- package/dist/mcp/MCPServerFactory.mjs +0 -70
- package/dist/mcp/NoopLikeC4MCPServer.mjs +0 -17
- package/dist/mcp/interfaces.mjs +0 -4
- package/dist/mcp/server/StdioLikeC4MCPServer.mjs +0 -46
- package/dist/mcp/server/StreamableLikeC4MCPServer.mjs +0 -153
- package/dist/mcp/server/WithMCPServer.mjs +0 -58
- package/dist/mcp/tools/_common.mjs +0 -42
- package/dist/mcp/tools/find-relationships.mjs +0 -151
- package/dist/mcp/tools/list-projects.mjs +0 -62
- package/dist/mcp/tools/open-view.mjs +0 -52
- package/dist/mcp/tools/read-deployment.mjs +0 -130
- package/dist/mcp/tools/read-element.mjs +0 -198
- package/dist/mcp/tools/read-project-summary.mjs +0 -178
- package/dist/mcp/tools/read-view.mjs +0 -205
- package/dist/mcp/tools/search-element.mjs +0 -171
- package/dist/mcp/utils.mjs +0 -47
- package/dist/model/builder/MergedExtends.mjs +0 -67
- package/dist/model/builder/MergedSpecification.mjs +0 -205
- package/dist/model/builder/assignTagColors.d.ts +0 -7
- package/dist/model/builder/assignTagColors.mjs +0 -51
- package/dist/model/builder/buildModel.mjs +0 -226
- package/dist/model/deployments-index.mjs +0 -100
- package/dist/model/fqn-index.mjs +0 -243
- package/dist/model/index.mjs +0 -6
- package/dist/model/model-builder.mjs +0 -285
- package/dist/model/model-locator.mjs +0 -239
- package/dist/model/model-parser-where.mjs +0 -81
- package/dist/model/model-parser.mjs +0 -127
- package/dist/model/parser/Base.mjs +0 -342
- package/dist/model/parser/DeploymentModelParser.mjs +0 -212
- package/dist/model/parser/DeploymentViewParser.mjs +0 -95
- package/dist/model/parser/FqnRefParser.mjs +0 -398
- package/dist/model/parser/GlobalsParser.mjs +0 -82
- package/dist/model/parser/ImportsParser.mjs +0 -28
- package/dist/model/parser/ModelParser.mjs +0 -190
- package/dist/model/parser/PredicatesParser.mjs +0 -45
- package/dist/model/parser/SpecificationParser.mjs +0 -120
- package/dist/model/parser/ValueConverter.mjs +0 -12
- package/dist/model/parser/ViewsParser.mjs +0 -490
- package/dist/model-change/ModelChanges.mjs +0 -89
- package/dist/model-change/changeElementStyle.mjs +0 -143
- package/dist/model-change/changeViewLayout.mjs +0 -32
- package/dist/model-change/saveManualLayout.d.ts +0 -11
- package/dist/model-change/saveManualLayout.mjs +0 -27
- package/dist/module.mjs +0 -180
- package/dist/protocol.mjs +0 -65
- package/dist/references/index.mjs +0 -3
- package/dist/references/name-provider.mjs +0 -39
- package/dist/references/scope-computation.mjs +0 -312
- package/dist/references/scope-provider.mjs +0 -239
- package/dist/shared/NodeKindProvider.mjs +0 -110
- package/dist/shared/index.mjs +0 -2
- package/dist/test/index.mjs +0 -1
- package/dist/test/testServices.mjs +0 -200
- package/dist/utils/disposable.mjs +0 -25
- package/dist/utils/elementRef.mjs +0 -20
- package/dist/utils/fqnRef.mjs +0 -57
- package/dist/utils/index.mjs +0 -33
- package/dist/utils/printDocs.mjs +0 -1
- package/dist/utils/projectId.mjs +0 -16
- package/dist/utils/stringHash.mjs +0 -5
- package/dist/validation/DocumentValidator.mjs +0 -16
- package/dist/validation/_shared.mjs +0 -25
- package/dist/validation/deployment-checks.mjs +0 -146
- package/dist/validation/dynamic-view.mjs +0 -67
- package/dist/validation/element-ref.mjs +0 -12
- package/dist/validation/element.mjs +0 -50
- package/dist/validation/imports.mjs +0 -25
- package/dist/validation/index.mjs +0 -180
- package/dist/validation/property-checks.mjs +0 -107
- package/dist/validation/relation.mjs +0 -53
- package/dist/validation/specification.mjs +0 -173
- package/dist/validation/view-predicates/fqn-expr-with.mjs +0 -43
- package/dist/validation/view-predicates/fqn-ref-expr.mjs +0 -53
- package/dist/validation/view-predicates/incoming.mjs +0 -16
- package/dist/validation/view-predicates/index.mjs +0 -6
- package/dist/validation/view-predicates/outgoing.mjs +0 -20
- package/dist/validation/view-predicates/relation-expr.mjs +0 -39
- package/dist/validation/view-predicates/relation-with.mjs +0 -16
- package/dist/validation/view.mjs +0 -25
- package/dist/view-utils/assignNavigateTo.mjs +0 -25
- package/dist/view-utils/index.mjs +0 -1
- package/dist/view-utils/manual-layout.mjs +0 -99
- package/dist/views/configurable-layouter.mjs +0 -51
- package/dist/views/index.mjs +0 -1
- package/dist/views/likec4-views.mjs +0 -166
- package/dist/workspace/AstNodeDescriptionProvider.mjs +0 -17
- package/dist/workspace/IndexManager.mjs +0 -17
- package/dist/workspace/LangiumDocuments.mjs +0 -53
- package/dist/workspace/ProjectsManager.mjs +0 -360
- package/dist/workspace/WorkspaceManager.mjs +0 -83
- package/dist/workspace/index.mjs +0 -5
- /package/dist/views/{configurable-layouter.d.ts → ConfigurableLayouter.d.ts} +0 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ThemeColors } from '@likec4/core/styles';
|
|
2
|
+
import { AstUtils } from 'langium';
|
|
3
|
+
import { DefaultCompletionProvider, } from 'langium/lsp';
|
|
4
|
+
import { anyPass } from 'remeda';
|
|
5
|
+
import { CompletionItemKind, InsertTextFormat } from 'vscode-languageserver-types';
|
|
6
|
+
import { ast } from '../ast';
|
|
7
|
+
const STYLE_FIELDS = [
|
|
8
|
+
'color',
|
|
9
|
+
'shape',
|
|
10
|
+
'icon',
|
|
11
|
+
'border',
|
|
12
|
+
'opacity',
|
|
13
|
+
'multiple',
|
|
14
|
+
'size',
|
|
15
|
+
'textSize',
|
|
16
|
+
].join(',');
|
|
17
|
+
export class LikeC4CompletionProvider extends DefaultCompletionProvider {
|
|
18
|
+
services;
|
|
19
|
+
constructor(services) {
|
|
20
|
+
super(services);
|
|
21
|
+
this.services = services;
|
|
22
|
+
}
|
|
23
|
+
completionOptions = {
|
|
24
|
+
triggerCharacters: ['.', '#'],
|
|
25
|
+
};
|
|
26
|
+
completionForKeyword(context, keyword, acceptor) {
|
|
27
|
+
if (!this.filterKeyword(context, keyword)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
switch (true) {
|
|
31
|
+
case keyword.value === 'import':
|
|
32
|
+
acceptor(context, {
|
|
33
|
+
label: keyword.value,
|
|
34
|
+
kind: CompletionItemKind.Snippet,
|
|
35
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
36
|
+
insertText: `${keyword.value} { $0 } from '\${1|${this.services.shared.workspace.ProjectsManager.all.join(',')}|}'`,
|
|
37
|
+
});
|
|
38
|
+
break;
|
|
39
|
+
case keyword.value === 'deployment' && AstUtils.hasContainerOfType(context.node, ast.isModelViews):
|
|
40
|
+
acceptor(context, {
|
|
41
|
+
label: keyword.value,
|
|
42
|
+
detail: `Insert deployment view`,
|
|
43
|
+
kind: CompletionItemKind.Class,
|
|
44
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
45
|
+
insertText: [
|
|
46
|
+
'deployment view ${1:view_${TM_FILENAME_BASE}_${CURRENT_SECOND}} {',
|
|
47
|
+
'\ttitle \'${2:Untitled}\'',
|
|
48
|
+
'\t',
|
|
49
|
+
'\tinclude $0',
|
|
50
|
+
'}',
|
|
51
|
+
].join('\n'),
|
|
52
|
+
});
|
|
53
|
+
break;
|
|
54
|
+
case ['title', 'description', 'technology', 'link'].includes(keyword.value):
|
|
55
|
+
acceptor(context, {
|
|
56
|
+
label: keyword.value,
|
|
57
|
+
detail: `Insert ${keyword.value} property`,
|
|
58
|
+
kind: CompletionItemKind.Property,
|
|
59
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
60
|
+
insertText: `${keyword.value} '\${0}'`,
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
63
|
+
case keyword.value === 'color':
|
|
64
|
+
acceptor(context, {
|
|
65
|
+
label: keyword.value,
|
|
66
|
+
kind: CompletionItemKind.Property,
|
|
67
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
68
|
+
insertText: `${keyword.value} \${1|${ThemeColors.join(',')}|}$0`,
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
case keyword.value === 'opacity':
|
|
72
|
+
acceptor(context, {
|
|
73
|
+
label: keyword.value,
|
|
74
|
+
kind: CompletionItemKind.Property,
|
|
75
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
76
|
+
insertText: `${keyword.value} \${0:100}%`,
|
|
77
|
+
});
|
|
78
|
+
break;
|
|
79
|
+
case ['views', 'specification', 'model', 'deployment', 'with'].includes(keyword.value):
|
|
80
|
+
acceptor(context, {
|
|
81
|
+
label: keyword.value,
|
|
82
|
+
detail: `Insert ${keyword.value} block`,
|
|
83
|
+
kind: CompletionItemKind.Module,
|
|
84
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
85
|
+
insertText: `${keyword.value} {\n\t$0\n}`,
|
|
86
|
+
});
|
|
87
|
+
break;
|
|
88
|
+
case keyword.value === 'group':
|
|
89
|
+
acceptor(context, {
|
|
90
|
+
label: keyword.value,
|
|
91
|
+
detail: `Insert group block`,
|
|
92
|
+
kind: CompletionItemKind.Module,
|
|
93
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
94
|
+
insertText: [
|
|
95
|
+
'group \'${1:Title}\' {',
|
|
96
|
+
'\t$0',
|
|
97
|
+
'}',
|
|
98
|
+
].join('\n'),
|
|
99
|
+
});
|
|
100
|
+
break;
|
|
101
|
+
case ['par', 'parallel'].includes(keyword.value):
|
|
102
|
+
acceptor(context, {
|
|
103
|
+
label: keyword.value,
|
|
104
|
+
detail: `Insert block of parallel steps`,
|
|
105
|
+
kind: CompletionItemKind.Module,
|
|
106
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
107
|
+
insertText: [
|
|
108
|
+
`${keyword.value} {`,
|
|
109
|
+
'\t$0',
|
|
110
|
+
'}',
|
|
111
|
+
].join('\n'),
|
|
112
|
+
});
|
|
113
|
+
break;
|
|
114
|
+
case keyword.value === 'dynamic' && AstUtils.hasContainerOfType(context.node, ast.isModelViews):
|
|
115
|
+
acceptor(context, {
|
|
116
|
+
label: keyword.value,
|
|
117
|
+
detail: `Insert dynamic view`,
|
|
118
|
+
kind: CompletionItemKind.Class,
|
|
119
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
120
|
+
insertText: [
|
|
121
|
+
'dynamic view ${1:view_${TM_FILENAME_BASE}_${CURRENT_SECOND}} {',
|
|
122
|
+
'\ttitle \'${2:Untitled}\'',
|
|
123
|
+
'\t',
|
|
124
|
+
'\t$0',
|
|
125
|
+
'}',
|
|
126
|
+
].join('\n'),
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
case keyword.value === 'style' && context.node && AstUtils.hasContainerOfType(context.node, ast.isGlobalStyle):
|
|
130
|
+
acceptor(context, {
|
|
131
|
+
label: keyword.value,
|
|
132
|
+
detail: `Insert ${keyword.value} block`,
|
|
133
|
+
kind: CompletionItemKind.Module,
|
|
134
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
135
|
+
insertText: `${keyword.value} \${1:name} \${2:*} {\n\t\${3|${STYLE_FIELDS}|} $0\n}`,
|
|
136
|
+
});
|
|
137
|
+
break;
|
|
138
|
+
case keyword.value === 'style' && context.node &&
|
|
139
|
+
AstUtils.hasContainerOfType(context.node, anyPass([ast.isModelViews, ast.isGlobalStyleGroup])):
|
|
140
|
+
acceptor(context, {
|
|
141
|
+
label: keyword.value,
|
|
142
|
+
detail: `Insert ${keyword.value} block`,
|
|
143
|
+
kind: CompletionItemKind.Module,
|
|
144
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
145
|
+
insertText: `${keyword.value} \${1:*} {\n\t\${2|${STYLE_FIELDS}|} $0\n}`,
|
|
146
|
+
});
|
|
147
|
+
break;
|
|
148
|
+
case keyword.value === 'style':
|
|
149
|
+
acceptor(context, {
|
|
150
|
+
label: keyword.value,
|
|
151
|
+
detail: `Insert ${keyword.value} block`,
|
|
152
|
+
kind: CompletionItemKind.Module,
|
|
153
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
154
|
+
insertText: `${keyword.value} {\n\t\${1|${STYLE_FIELDS}|} $0\n}`,
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
case keyword.value === 'extend':
|
|
158
|
+
acceptor(context, {
|
|
159
|
+
label: keyword.value,
|
|
160
|
+
detail: `Extend another view`,
|
|
161
|
+
kind: CompletionItemKind.Class,
|
|
162
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
163
|
+
insertText: 'extend $1 {\n\t$0\n}',
|
|
164
|
+
});
|
|
165
|
+
break;
|
|
166
|
+
case keyword.value === 'autoLayout':
|
|
167
|
+
acceptor(context, {
|
|
168
|
+
label: keyword.value,
|
|
169
|
+
kind: CompletionItemKind.Property,
|
|
170
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
171
|
+
insertText: 'autoLayout ${1|TopBottom,BottomTop,LeftRight,RightLeft|}$0',
|
|
172
|
+
});
|
|
173
|
+
break;
|
|
174
|
+
case keyword.value === 'mode':
|
|
175
|
+
acceptor(context, {
|
|
176
|
+
label: keyword.value,
|
|
177
|
+
kind: CompletionItemKind.Property,
|
|
178
|
+
insertTextFormat: InsertTextFormat.Snippet,
|
|
179
|
+
insertText: 'mode ${1|sequence,diagram|}$0',
|
|
180
|
+
});
|
|
181
|
+
break;
|
|
182
|
+
case ['include', 'exclude'].includes(keyword.value):
|
|
183
|
+
acceptor(context, {
|
|
184
|
+
label: keyword.value,
|
|
185
|
+
kind: CompletionItemKind.Operator,
|
|
186
|
+
detail: `Insert ${keyword.value} predicate`,
|
|
187
|
+
insertTextFormat: InsertTextFormat.PlainText,
|
|
188
|
+
insertText: `${keyword.value} `,
|
|
189
|
+
});
|
|
190
|
+
break;
|
|
191
|
+
default:
|
|
192
|
+
acceptor(context, {
|
|
193
|
+
label: keyword.value,
|
|
194
|
+
kind: this.getKeywordCompletionItemKind(keyword),
|
|
195
|
+
detail: 'Keyword',
|
|
196
|
+
sortText: '1',
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DefaultDocumentHighlightProvider } from 'langium/lsp';
|
|
2
|
+
import { DocumentHighlight, DocumentHighlightKind } from 'vscode-languageserver';
|
|
3
|
+
export class LikeC4DocumentHighlightProvider extends DefaultDocumentHighlightProvider {
|
|
4
|
+
/**
|
|
5
|
+
* Override this method to determine the highlight kind of the given reference.
|
|
6
|
+
*/
|
|
7
|
+
createDocumentHighlight(reference) {
|
|
8
|
+
return DocumentHighlight.create(reference.segment.range, DocumentHighlightKind.Read);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AstUtils, GrammarUtils } from 'langium';
|
|
2
|
+
import { hasLeadingSlash, hasProtocol, isRelative, joinRelativeURL, withoutBase, withoutLeadingSlash } from 'ufo';
|
|
3
|
+
import { ast, isLikeC4LangiumDocument } from '../ast';
|
|
4
|
+
import { logWarnError } from '../logger';
|
|
5
|
+
export class LikeC4DocumentLinkProvider {
|
|
6
|
+
services;
|
|
7
|
+
constructor(services) {
|
|
8
|
+
this.services = services;
|
|
9
|
+
//
|
|
10
|
+
}
|
|
11
|
+
async getDocumentLinks(doc, _params, _cancelToken) {
|
|
12
|
+
if (!isLikeC4LangiumDocument(doc) || this.services.shared.workspace.ProjectsManager.isExcluded(doc)) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
return AstUtils.streamAllContents(doc.parseResult.value)
|
|
16
|
+
.filter(ast.isLinkProperty)
|
|
17
|
+
.map((n) => {
|
|
18
|
+
try {
|
|
19
|
+
const range = GrammarUtils.findNodeForProperty(n.$cstNode, 'value')?.range;
|
|
20
|
+
const target = range && this.resolveLink(doc, n.value);
|
|
21
|
+
if (target && hasProtocol(target)) {
|
|
22
|
+
return {
|
|
23
|
+
range,
|
|
24
|
+
target,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
logWarnError(e);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
})
|
|
33
|
+
.nonNullable()
|
|
34
|
+
.toArray();
|
|
35
|
+
}
|
|
36
|
+
resolveLink(doc, link) {
|
|
37
|
+
if (hasProtocol(link) || hasLeadingSlash(link)) {
|
|
38
|
+
return link;
|
|
39
|
+
}
|
|
40
|
+
if (isRelative(link)) {
|
|
41
|
+
return joinRelativeURL(doc.uri.toString(), '../', link);
|
|
42
|
+
}
|
|
43
|
+
const base = this.services.shared.workspace.ProjectsManager.getProject(doc).folderUri;
|
|
44
|
+
return joinRelativeURL(base.toString(), link);
|
|
45
|
+
}
|
|
46
|
+
relativeLink(doc, link) {
|
|
47
|
+
if (hasLeadingSlash(link)) {
|
|
48
|
+
return withoutLeadingSlash(link);
|
|
49
|
+
}
|
|
50
|
+
if (isRelative(link)) {
|
|
51
|
+
const base = this.services.shared.workspace.ProjectsManager.getProject(doc).folderUri.toString();
|
|
52
|
+
const docURL = new URL(doc.uri.toString());
|
|
53
|
+
const linkURL = new URL(link, docURL).toString();
|
|
54
|
+
return withoutLeadingSlash(withoutBase(linkURL, base));
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { nonexhaustive } from '@likec4/core';
|
|
2
|
+
import { AstUtils, DocumentState, GrammarUtils } from 'langium';
|
|
3
|
+
import { filter, isEmpty, isTruthy, map, pipe } from 'remeda';
|
|
4
|
+
import { SymbolKind } from 'vscode-languageserver-types';
|
|
5
|
+
import { ast, isLikeC4LangiumDocument } from '../ast';
|
|
6
|
+
import { logger as rootLogger, logWarnError } from '../logger';
|
|
7
|
+
import { readStrictFqn } from '../utils/elementRef';
|
|
8
|
+
const logger = rootLogger.getChild('DocumentSymbolProvider');
|
|
9
|
+
export class LikeC4DocumentSymbolProvider {
|
|
10
|
+
services;
|
|
11
|
+
nodeKindProvider;
|
|
12
|
+
nameProvider;
|
|
13
|
+
parser;
|
|
14
|
+
locator;
|
|
15
|
+
constructor(services) {
|
|
16
|
+
this.services = services;
|
|
17
|
+
this.nodeKindProvider = services.shared.lsp.NodeKindProvider;
|
|
18
|
+
this.parser = services.likec4.ModelParser;
|
|
19
|
+
this.locator = services.likec4.ModelLocator;
|
|
20
|
+
this.nameProvider = services.references.NameProvider;
|
|
21
|
+
}
|
|
22
|
+
async getSymbols(doc, _params, cancelToken) {
|
|
23
|
+
if (!isLikeC4LangiumDocument(doc) || this.services.shared.workspace.ProjectsManager.isExcluded(doc)) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
if (doc.state <= DocumentState.Linked) {
|
|
27
|
+
logger.debug(`Waiting for document ${doc.uri.path} to be Linked`);
|
|
28
|
+
await this.services.shared.workspace.DocumentBuilder.waitUntil(DocumentState.Linked, doc.uri, cancelToken);
|
|
29
|
+
logger.debug(`document is Linked`);
|
|
30
|
+
}
|
|
31
|
+
const { parseResult: { value: { specifications, models, deployments, views, likec4lib }, }, } = doc;
|
|
32
|
+
return [
|
|
33
|
+
...likec4lib.map(l => () => this.getLikec4LibSymbol(l)),
|
|
34
|
+
...specifications.map(s => () => this.getSpecSymbol(s)),
|
|
35
|
+
...models.map(s => () => this.getModelSymbol(s)),
|
|
36
|
+
...deployments.map(s => () => this.getDeploymentModelSymbol(s)),
|
|
37
|
+
...views.map(s => () => this.getModelViewsSymbol(s)),
|
|
38
|
+
].flatMap(fn => {
|
|
39
|
+
try {
|
|
40
|
+
return fn() ?? [];
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
logWarnError(e);
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
getLikec4LibSymbol(astLib) {
|
|
49
|
+
const cstModel = astLib?.$cstNode;
|
|
50
|
+
if (!cstModel)
|
|
51
|
+
return [];
|
|
52
|
+
const children = astLib.icons.map(i => this.getLibIconSymbol(i)).filter(isTruthy);
|
|
53
|
+
if (children.length === 0)
|
|
54
|
+
return [];
|
|
55
|
+
return [
|
|
56
|
+
{
|
|
57
|
+
kind: SymbolKind.Namespace,
|
|
58
|
+
name: 'icons',
|
|
59
|
+
range: cstModel.range,
|
|
60
|
+
selectionRange: GrammarUtils.findNodeForKeyword(cstModel, 'icons')?.range ?? cstModel.range,
|
|
61
|
+
children,
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
getSpecSymbol(astSpec) {
|
|
66
|
+
const cstModel = astSpec?.$cstNode;
|
|
67
|
+
if (!cstModel)
|
|
68
|
+
return [];
|
|
69
|
+
const specKeywordNode = GrammarUtils.findNodeForProperty(cstModel, 'name');
|
|
70
|
+
if (!specKeywordNode)
|
|
71
|
+
return [];
|
|
72
|
+
const specSymbols = pipe([...astSpec.elements, ...astSpec.tags, ...astSpec.relationships], map(nd => {
|
|
73
|
+
try {
|
|
74
|
+
if (ast.isSpecificationElementKind(nd) || ast.isSpecificationRelationshipKind(nd)
|
|
75
|
+
|| ast.isSpecificationDeploymentNodeKind(nd)) {
|
|
76
|
+
return this.getKindSymbol(nd);
|
|
77
|
+
}
|
|
78
|
+
if (ast.isSpecificationTag(nd)) {
|
|
79
|
+
return this.getTagSymbol(nd);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
logWarnError(e);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
nonexhaustive(nd);
|
|
87
|
+
}), filter(isTruthy));
|
|
88
|
+
if (specSymbols.length === 0)
|
|
89
|
+
return [];
|
|
90
|
+
return [
|
|
91
|
+
{
|
|
92
|
+
kind: SymbolKind.Namespace,
|
|
93
|
+
name: astSpec.name,
|
|
94
|
+
range: cstModel.range,
|
|
95
|
+
selectionRange: specKeywordNode.range,
|
|
96
|
+
children: specSymbols,
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
getModelSymbol(astModel) {
|
|
101
|
+
const cstModel = astModel.$cstNode;
|
|
102
|
+
if (!cstModel)
|
|
103
|
+
return [];
|
|
104
|
+
const nameNode = GrammarUtils.findNodeForProperty(cstModel, 'name');
|
|
105
|
+
if (!nameNode)
|
|
106
|
+
return [];
|
|
107
|
+
return [
|
|
108
|
+
{
|
|
109
|
+
kind: this.symbolKind(astModel),
|
|
110
|
+
name: astModel.name,
|
|
111
|
+
range: cstModel.range,
|
|
112
|
+
selectionRange: nameNode.range,
|
|
113
|
+
children: astModel.elements.flatMap(e => this.getElementsSymbol(e)),
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
getDeploymentModelSymbol(astModel) {
|
|
118
|
+
const cstModel = astModel.$cstNode;
|
|
119
|
+
if (!cstModel)
|
|
120
|
+
return [];
|
|
121
|
+
const nameNode = GrammarUtils.findNodeForProperty(cstModel, 'name');
|
|
122
|
+
if (!nameNode)
|
|
123
|
+
return [];
|
|
124
|
+
return [
|
|
125
|
+
{
|
|
126
|
+
kind: this.symbolKind(astModel),
|
|
127
|
+
name: astModel.name,
|
|
128
|
+
range: cstModel.range,
|
|
129
|
+
selectionRange: nameNode.range,
|
|
130
|
+
children: astModel.elements.flatMap(e => this.getDeploymentElementSymbol(e)),
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
getElementsSymbol(el) {
|
|
135
|
+
try {
|
|
136
|
+
if (ast.isExtendElement(el)) {
|
|
137
|
+
return this.getExtendElementSymbol(el);
|
|
138
|
+
}
|
|
139
|
+
if (ast.isElement(el)) {
|
|
140
|
+
return this.getElementSymbol(el);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
logWarnError(e);
|
|
145
|
+
}
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
getExtendElementSymbol(astElement) {
|
|
149
|
+
const cst = astElement.$cstNode;
|
|
150
|
+
const nameNode = astElement.element.$cstNode;
|
|
151
|
+
const body = astElement.body;
|
|
152
|
+
if (!cst || !nameNode)
|
|
153
|
+
return [];
|
|
154
|
+
return [
|
|
155
|
+
{
|
|
156
|
+
kind: this.symbolKind(astElement),
|
|
157
|
+
name: readStrictFqn(astElement.element),
|
|
158
|
+
range: cst.range,
|
|
159
|
+
selectionRange: nameNode.range,
|
|
160
|
+
children: body.elements.flatMap(e => this.getElementsSymbol(e)),
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
getElementSymbol(astElement) {
|
|
165
|
+
const cst = astElement.$cstNode;
|
|
166
|
+
const nameNode = GrammarUtils.findNodeForProperty(cst, 'name');
|
|
167
|
+
if (!nameNode || !cst)
|
|
168
|
+
return [];
|
|
169
|
+
const name = astElement.name;
|
|
170
|
+
const kind = astElement.kind.$refText;
|
|
171
|
+
// TODO: return the title as well
|
|
172
|
+
const detail = kind; // + (astElement.title ? ': ' + astElement.title : '').replaceAll('\n', ' ').trim()
|
|
173
|
+
return [
|
|
174
|
+
{
|
|
175
|
+
kind: this.symbolKind(astElement),
|
|
176
|
+
name: name,
|
|
177
|
+
range: cst.range,
|
|
178
|
+
selectionRange: nameNode.range,
|
|
179
|
+
detail,
|
|
180
|
+
children: astElement.body?.elements.flatMap(e => this.getElementsSymbol(e)) ?? [],
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
getModelViewsSymbol(astViews) {
|
|
185
|
+
const cst = astViews.$cstNode;
|
|
186
|
+
const nameNode = GrammarUtils.findNodeForProperty(cst, 'name');
|
|
187
|
+
if (!nameNode || !cst)
|
|
188
|
+
return [];
|
|
189
|
+
return [
|
|
190
|
+
{
|
|
191
|
+
kind: this.symbolKind(astViews),
|
|
192
|
+
name: astViews.name,
|
|
193
|
+
range: cst.range,
|
|
194
|
+
selectionRange: nameNode.range,
|
|
195
|
+
children: astViews.views.flatMap(e => this.getViewSymbol(e)),
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
getKindSymbol(astKind) {
|
|
200
|
+
if (!astKind.$cstNode || !astKind.kind.$cstNode || isEmpty(astKind.kind.name))
|
|
201
|
+
return null;
|
|
202
|
+
return {
|
|
203
|
+
kind: this.symbolKind(astKind),
|
|
204
|
+
name: astKind.kind.name,
|
|
205
|
+
range: astKind.$cstNode.range,
|
|
206
|
+
selectionRange: astKind.kind.$cstNode.range,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
getTagSymbol(astTag) {
|
|
210
|
+
if (!astTag.$cstNode || !astTag.tag.$cstNode || isEmpty(astTag.tag.name))
|
|
211
|
+
return null;
|
|
212
|
+
return {
|
|
213
|
+
kind: this.symbolKind(astTag),
|
|
214
|
+
name: '#' + astTag.tag.name,
|
|
215
|
+
range: astTag.$cstNode.range,
|
|
216
|
+
selectionRange: astTag.tag.$cstNode.range,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
getLibIconSymbol(astTag) {
|
|
220
|
+
if (!astTag.$cstNode || isEmpty(astTag.name))
|
|
221
|
+
return null;
|
|
222
|
+
return {
|
|
223
|
+
kind: this.symbolKind(astTag),
|
|
224
|
+
name: astTag.name,
|
|
225
|
+
range: astTag.$cstNode.range,
|
|
226
|
+
selectionRange: astTag.$cstNode.range,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
getViewSymbol(astView) {
|
|
230
|
+
const cst = astView?.$cstNode;
|
|
231
|
+
if (!cst)
|
|
232
|
+
return [];
|
|
233
|
+
const nameNode = astView.name ? GrammarUtils.findNodeForProperty(cst, 'name') : null;
|
|
234
|
+
if (!nameNode)
|
|
235
|
+
return [];
|
|
236
|
+
return [
|
|
237
|
+
{
|
|
238
|
+
kind: this.symbolKind(astView),
|
|
239
|
+
name: nameNode.text,
|
|
240
|
+
range: cst.range,
|
|
241
|
+
selectionRange: nameNode.range,
|
|
242
|
+
children: [],
|
|
243
|
+
},
|
|
244
|
+
];
|
|
245
|
+
}
|
|
246
|
+
getDeploymentElementSymbol(el) {
|
|
247
|
+
try {
|
|
248
|
+
if (ast.isDeploymentNode(el)) {
|
|
249
|
+
return this.getDeploymentNodeSymbol(el);
|
|
250
|
+
}
|
|
251
|
+
if (ast.isDeployedInstance(el)) {
|
|
252
|
+
return this.getDeployedInstanceSymbol(el);
|
|
253
|
+
}
|
|
254
|
+
if (ast.isExtendDeployment(el)) {
|
|
255
|
+
return [];
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
logWarnError(e);
|
|
260
|
+
}
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
getDeploymentNodeSymbol(astElement) {
|
|
264
|
+
const cst = astElement.$cstNode;
|
|
265
|
+
const nameNode = this.nameProvider.getNameNode(astElement);
|
|
266
|
+
if (!nameNode || !cst)
|
|
267
|
+
return [];
|
|
268
|
+
const name = this.nameProvider.getNameStrict(astElement);
|
|
269
|
+
const kind = astElement.kind.$refText;
|
|
270
|
+
// TODO: return the title as well
|
|
271
|
+
const detail = kind; // + (astElement.title ? ': ' + astElement.title : '').replaceAll('\n', ' ').trim()
|
|
272
|
+
return [
|
|
273
|
+
{
|
|
274
|
+
kind: this.symbolKind(astElement),
|
|
275
|
+
name: name,
|
|
276
|
+
range: cst.range,
|
|
277
|
+
selectionRange: nameNode.range,
|
|
278
|
+
detail,
|
|
279
|
+
children: astElement.body?.elements.flatMap(e => this.getDeploymentElementSymbol(e)) ?? [],
|
|
280
|
+
},
|
|
281
|
+
];
|
|
282
|
+
}
|
|
283
|
+
getDeployedInstanceSymbol(astElement) {
|
|
284
|
+
const cst = astElement.$cstNode;
|
|
285
|
+
const nameNode = this.nameProvider.getNameNode(astElement);
|
|
286
|
+
if (!nameNode || !cst)
|
|
287
|
+
return [];
|
|
288
|
+
const doc = AstUtils.getDocument(astElement);
|
|
289
|
+
const instance = this.parser.forDocument(doc).parseDeployedInstance(astElement);
|
|
290
|
+
const name = this.nameProvider.getNameStrict(astElement);
|
|
291
|
+
const detail = 'instance of ' + instance.element.model;
|
|
292
|
+
return [
|
|
293
|
+
{
|
|
294
|
+
kind: this.symbolKind(astElement),
|
|
295
|
+
name: name,
|
|
296
|
+
range: cst.range,
|
|
297
|
+
selectionRange: nameNode.range,
|
|
298
|
+
detail,
|
|
299
|
+
children: [],
|
|
300
|
+
},
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
symbolKind(node) {
|
|
304
|
+
return this.nodeKindProvider.getSymbolKind(node);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { FqnRef, preferSummary } from '@likec4/core';
|
|
2
|
+
import { AstUtils } from 'langium';
|
|
3
|
+
import { AstNodeHoverProvider } from 'langium/lsp';
|
|
4
|
+
import { ast } from '../ast';
|
|
5
|
+
export class LikeC4HoverProvider extends AstNodeHoverProvider {
|
|
6
|
+
parser;
|
|
7
|
+
locator;
|
|
8
|
+
constructor(services) {
|
|
9
|
+
super(services);
|
|
10
|
+
this.parser = services.likec4.ModelParser;
|
|
11
|
+
this.locator = services.likec4.ModelLocator;
|
|
12
|
+
}
|
|
13
|
+
getAstNodeHoverContent(node) {
|
|
14
|
+
if (ast.isTag(node)) {
|
|
15
|
+
return {
|
|
16
|
+
contents: {
|
|
17
|
+
kind: 'markdown',
|
|
18
|
+
value: 'tag `' + node.name + '`',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (ast.isDeploymentNode(node)) {
|
|
23
|
+
const doc = AstUtils.getDocument(node);
|
|
24
|
+
const el = this.parser.forDocument(doc).parseDeploymentNode(node);
|
|
25
|
+
const lines = [el.id + ' '];
|
|
26
|
+
if (el.title !== node.name) {
|
|
27
|
+
lines.push(`### ${el.title}`);
|
|
28
|
+
}
|
|
29
|
+
lines.push('deployment node `' + el.kind + '` ');
|
|
30
|
+
const summary = preferSummary(el);
|
|
31
|
+
if (summary) {
|
|
32
|
+
lines.push('', summary.md ?? summary.txt);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
contents: {
|
|
36
|
+
kind: 'markdown',
|
|
37
|
+
value: lines.join('\n'),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (ast.isDeployedInstance(node)) {
|
|
42
|
+
const doc = AstUtils.getDocument(node);
|
|
43
|
+
const instance = this.parser.forDocument(doc).parseDeployedInstance(node);
|
|
44
|
+
const [projectId, fqn] = FqnRef.isImportRef(instance.element)
|
|
45
|
+
? [instance.element.project, instance.element.model]
|
|
46
|
+
: [doc.likec4ProjectId, instance.element.model];
|
|
47
|
+
const el = projectId ? this.locator.getParsedElement(fqn, projectId) : this.locator.getParsedElement(fqn);
|
|
48
|
+
const lines = [instance.id + ' ', `instance of \`${FqnRef.flatten(instance.element)}\``];
|
|
49
|
+
if (el) {
|
|
50
|
+
lines.push(`### ${el.title}`, 'element kind `' + el.kind + '` ');
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
contents: {
|
|
54
|
+
kind: 'markdown',
|
|
55
|
+
value: lines.join('\n'),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (ast.isElementKind(node)) {
|
|
60
|
+
return {
|
|
61
|
+
contents: {
|
|
62
|
+
kind: 'markdown',
|
|
63
|
+
value: 'element kind `' + node.name + '`',
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (ast.isDeploymentNodeKind(node)) {
|
|
68
|
+
return {
|
|
69
|
+
contents: {
|
|
70
|
+
kind: 'markdown',
|
|
71
|
+
value: 'deployment node `' + node.name + '`',
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (ast.isRelationshipKind(node)) {
|
|
76
|
+
return {
|
|
77
|
+
contents: {
|
|
78
|
+
kind: 'markdown',
|
|
79
|
+
value: 'relationship kind `' + node.name + '`',
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (ast.isElement(node)) {
|
|
84
|
+
const el = this.locator.getParsedElement(node);
|
|
85
|
+
if (!el) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const lines = [
|
|
89
|
+
el.id,
|
|
90
|
+
`### ${el.title}`,
|
|
91
|
+
'element kind `' + el.kind + '` ',
|
|
92
|
+
];
|
|
93
|
+
const summary = preferSummary(el);
|
|
94
|
+
if (summary) {
|
|
95
|
+
lines.push('', summary.md ?? summary.txt);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
contents: {
|
|
99
|
+
kind: 'markdown',
|
|
100
|
+
value: lines.join('\n'),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|