@difizen/libro-language-client 0.1.18
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/LICENSE +21 -0
- package/README.md +0 -0
- package/es/common/api.d.ts +38 -0
- package/es/common/api.d.ts.map +1 -0
- package/es/common/api.js +9 -0
- package/es/common/callHierarchy.d.ts +39 -0
- package/es/common/callHierarchy.d.ts.map +1 -0
- package/es/common/callHierarchy.js +139 -0
- package/es/common/client.d.ts +482 -0
- package/es/common/client.d.ts.map +1 -0
- package/es/common/client.js +2731 -0
- package/es/common/codeAction.d.ts +22 -0
- package/es/common/codeAction.d.ts.map +1 -0
- package/es/common/codeAction.js +149 -0
- package/es/common/codeConverter.d.ts +81 -0
- package/es/common/codeConverter.d.ts.map +1 -0
- package/es/common/codeConverter.js +1040 -0
- package/es/common/codeLens.d.ts +26 -0
- package/es/common/codeLens.d.ts.map +1 -0
- package/es/common/codeLens.js +125 -0
- package/es/common/colorProvider.d.ts +27 -0
- package/es/common/colorProvider.d.ts.map +1 -0
- package/es/common/colorProvider.js +104 -0
- package/es/common/completion.d.ts +22 -0
- package/es/common/completion.d.ts.map +1 -0
- package/es/common/completion.js +130 -0
- package/es/common/configuration.d.ts +71 -0
- package/es/common/configuration.d.ts.map +1 -0
- package/es/common/configuration.js +292 -0
- package/es/common/declaration.d.ts +18 -0
- package/es/common/declaration.d.ts.map +1 -0
- package/es/common/declaration.js +88 -0
- package/es/common/definition.d.ts +18 -0
- package/es/common/definition.d.ts.map +1 -0
- package/es/common/definition.js +80 -0
- package/es/common/diagnostic.d.ts +125 -0
- package/es/common/diagnostic.d.ts.map +1 -0
- package/es/common/diagnostic.js +1442 -0
- package/es/common/documentHighlight.d.ts +17 -0
- package/es/common/documentHighlight.d.ts.map +1 -0
- package/es/common/documentHighlight.js +73 -0
- package/es/common/documentLink.d.ts +21 -0
- package/es/common/documentLink.d.ts.map +1 -0
- package/es/common/documentLink.js +90 -0
- package/es/common/documentSymbol.d.ts +20 -0
- package/es/common/documentSymbol.d.ts.map +1 -0
- package/es/common/documentSymbol.js +134 -0
- package/es/common/executeCommand.d.ts +22 -0
- package/es/common/executeCommand.d.ts.map +1 -0
- package/es/common/executeCommand.js +117 -0
- package/es/common/features.d.ts +421 -0
- package/es/common/features.d.ts.map +1 -0
- package/es/common/features.js +576 -0
- package/es/common/fileOperations.d.ts +118 -0
- package/es/common/fileOperations.d.ts.map +1 -0
- package/es/common/fileOperations.js +705 -0
- package/es/common/fileSystemWatcher.d.ts +19 -0
- package/es/common/fileSystemWatcher.d.ts.map +1 -0
- package/es/common/fileSystemWatcher.js +173 -0
- package/es/common/foldingRange.d.ts +22 -0
- package/es/common/foldingRange.d.ts.map +1 -0
- package/es/common/foldingRange.js +127 -0
- package/es/common/formatting.d.ts +41 -0
- package/es/common/formatting.d.ts.map +1 -0
- package/es/common/formatting.js +233 -0
- package/es/common/hover.d.ts +18 -0
- package/es/common/hover.d.ts.map +1 -0
- package/es/common/hover.js +80 -0
- package/es/common/implementation.d.ts +18 -0
- package/es/common/implementation.d.ts.map +1 -0
- package/es/common/implementation.js +88 -0
- package/es/common/inlayHint.d.ts +23 -0
- package/es/common/inlayHint.d.ts.map +1 -0
- package/es/common/inlayHint.js +187 -0
- package/es/common/inlineCompletion.d.ts +20 -0
- package/es/common/inlineCompletion.d.ts.map +1 -0
- package/es/common/inlineCompletion.js +74 -0
- package/es/common/inlineValue.d.ts +21 -0
- package/es/common/inlineValue.d.ts.map +1 -0
- package/es/common/inlineValue.js +124 -0
- package/es/common/linkedEditingRange.d.ts +23 -0
- package/es/common/linkedEditingRange.d.ts.map +1 -0
- package/es/common/linkedEditingRange.js +94 -0
- package/es/common/notebook.d.ts +97 -0
- package/es/common/notebook.d.ts.map +1 -0
- package/es/common/notebook.js +1444 -0
- package/es/common/progress.d.ts +12 -0
- package/es/common/progress.d.ts.map +1 -0
- package/es/common/progress.js +75 -0
- package/es/common/progressPart.d.ts +25 -0
- package/es/common/progressPart.d.ts.map +1 -0
- package/es/common/progressPart.js +147 -0
- package/es/common/protocolCallHierarchyItem.d.ts +9 -0
- package/es/common/protocolCallHierarchyItem.d.ts.map +1 -0
- package/es/common/protocolCallHierarchyItem.js +34 -0
- package/es/common/protocolCodeAction.d.ts +7 -0
- package/es/common/protocolCodeAction.d.ts.map +1 -0
- package/es/common/protocolCodeAction.js +32 -0
- package/es/common/protocolCodeLens.d.ts +7 -0
- package/es/common/protocolCodeLens.d.ts.map +1 -0
- package/es/common/protocolCodeLens.js +29 -0
- package/es/common/protocolCompletionItem.d.ts +13 -0
- package/es/common/protocolCompletionItem.d.ts.map +1 -0
- package/es/common/protocolCompletionItem.js +29 -0
- package/es/common/protocolConverter.d.ts +174 -0
- package/es/common/protocolConverter.d.ts.map +1 -0
- package/es/common/protocolConverter.js +1982 -0
- package/es/common/protocolDiagnostic.d.ts +20 -0
- package/es/common/protocolDiagnostic.d.ts.map +1 -0
- package/es/common/protocolDiagnostic.js +46 -0
- package/es/common/protocolDocumentLink.d.ts +8 -0
- package/es/common/protocolDocumentLink.d.ts.map +1 -0
- package/es/common/protocolDocumentLink.js +29 -0
- package/es/common/protocolInlayHint.d.ts +8 -0
- package/es/common/protocolInlayHint.d.ts.map +1 -0
- package/es/common/protocolInlayHint.js +29 -0
- package/es/common/protocolTypeHierarchyItem.d.ts +9 -0
- package/es/common/protocolTypeHierarchyItem.d.ts.map +1 -0
- package/es/common/protocolTypeHierarchyItem.js +34 -0
- package/es/common/protocolWorkspaceSymbol.d.ts +9 -0
- package/es/common/protocolWorkspaceSymbol.d.ts.map +1 -0
- package/es/common/protocolWorkspaceSymbol.js +36 -0
- package/es/common/reference.d.ts +22 -0
- package/es/common/reference.d.ts.map +1 -0
- package/es/common/reference.js +78 -0
- package/es/common/rename.d.ts +29 -0
- package/es/common/rename.d.ts.map +1 -0
- package/es/common/rename.js +132 -0
- package/es/common/selectionRange.d.ts +18 -0
- package/es/common/selectionRange.d.ts.map +1 -0
- package/es/common/selectionRange.js +108 -0
- package/es/common/semanticTokens.d.ts +36 -0
- package/es/common/semanticTokens.d.ts.map +1 -0
- package/es/common/semanticTokens.js +226 -0
- package/es/common/signatureHelp.d.ts +18 -0
- package/es/common/signatureHelp.d.ts.map +1 -0
- package/es/common/signatureHelp.js +103 -0
- package/es/common/textSynchronization.d.ts +104 -0
- package/es/common/textSynchronization.d.ts.map +1 -0
- package/es/common/textSynchronization.js +771 -0
- package/es/common/typeDefinition.d.ts +18 -0
- package/es/common/typeDefinition.d.ts.map +1 -0
- package/es/common/typeDefinition.js +89 -0
- package/es/common/typeHierarchy.d.ts +33 -0
- package/es/common/typeHierarchy.d.ts.map +1 -0
- package/es/common/typeHierarchy.js +138 -0
- package/es/common/utils/async.d.ts +42 -0
- package/es/common/utils/async.d.ts.map +1 -0
- package/es/common/utils/async.js +441 -0
- package/es/common/utils/is.d.ts +13 -0
- package/es/common/utils/is.d.ts.map +1 -0
- package/es/common/utils/is.js +52 -0
- package/es/common/utils/uuid.d.ts +23 -0
- package/es/common/utils/uuid.d.ts.map +1 -0
- package/es/common/utils/uuid.js +85 -0
- package/es/common/vscodeAdaptor/convertor.d.ts +7 -0
- package/es/common/vscodeAdaptor/convertor.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/convertor.js +66 -0
- package/es/common/vscodeAdaptor/diagnosticCollection.d.ts +33 -0
- package/es/common/vscodeAdaptor/diagnosticCollection.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/diagnosticCollection.js +310 -0
- package/es/common/vscodeAdaptor/extHostTypes.d.ts +1496 -0
- package/es/common/vscodeAdaptor/extHostTypes.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/extHostTypes.js +3825 -0
- package/es/common/vscodeAdaptor/fileWatcher.d.ts +19 -0
- package/es/common/vscodeAdaptor/fileWatcher.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/fileWatcher.js +45 -0
- package/es/common/vscodeAdaptor/hostTypeUtil.d.ts +192 -0
- package/es/common/vscodeAdaptor/hostTypeUtil.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/hostTypeUtil.js +566 -0
- package/es/common/vscodeAdaptor/libro-fs.d.ts +21 -0
- package/es/common/vscodeAdaptor/libro-fs.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/libro-fs.js +64 -0
- package/es/common/vscodeAdaptor/libroWindow.d.ts +21 -0
- package/es/common/vscodeAdaptor/libroWindow.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/libroWindow.js +75 -0
- package/es/common/vscodeAdaptor/libroWorkspace.d.ts +33 -0
- package/es/common/vscodeAdaptor/libroWorkspace.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/libroWorkspace.js +250 -0
- package/es/common/vscodeAdaptor/lspEnv.d.ts +8 -0
- package/es/common/vscodeAdaptor/lspEnv.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/lspEnv.js +31 -0
- package/es/common/vscodeAdaptor/monaco-converter.d.ts +229 -0
- package/es/common/vscodeAdaptor/monaco-converter.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/monaco-converter.js +1613 -0
- package/es/common/vscodeAdaptor/monacoLanguages.d.ts +48 -0
- package/es/common/vscodeAdaptor/monacoLanguages.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/monacoLanguages.js +484 -0
- package/es/common/vscodeAdaptor/services.d.ts +85 -0
- package/es/common/vscodeAdaptor/services.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/services.js +3 -0
- package/es/common/vscodeAdaptor/typings.d.ts +10 -0
- package/es/common/vscodeAdaptor/util.d.ts +3 -0
- package/es/common/vscodeAdaptor/util.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/util.js +6 -0
- package/es/common/vscodeAdaptor/vscodeAdaptor.d.ts +77 -0
- package/es/common/vscodeAdaptor/vscodeAdaptor.d.ts.map +1 -0
- package/es/common/vscodeAdaptor/vscodeAdaptor.js +124 -0
- package/es/common/workspaceFolder.d.ts +32 -0
- package/es/common/workspaceFolder.d.ts.map +1 -0
- package/es/common/workspaceFolder.js +204 -0
- package/es/common/workspaceSymbol.d.ts +21 -0
- package/es/common/workspaceSymbol.d.ts.map +1 -0
- package/es/common/workspaceSymbol.js +101 -0
- package/es/constants.d.ts +2 -0
- package/es/constants.d.ts.map +1 -0
- package/es/constants.js +1 -0
- package/es/index.d.ts +6 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +5 -0
- package/es/libro-language-client-contribution.d.ts +10 -0
- package/es/libro-language-client-contribution.d.ts.map +1 -0
- package/es/libro-language-client-contribution.js +143 -0
- package/es/libro-language-client-manager.d.ts +34 -0
- package/es/libro-language-client-manager.d.ts.map +1 -0
- package/es/libro-language-client-manager.js +277 -0
- package/es/libro-language-client.d.ts +27 -0
- package/es/libro-language-client.d.ts.map +1 -0
- package/es/libro-language-client.js +141 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +13 -0
- package/package.json +69 -0
- package/src/common/api.ts +155 -0
- package/src/common/callHierarchy.ts +269 -0
- package/src/common/client.ts +3192 -0
- package/src/common/codeAction.ts +237 -0
- package/src/common/codeConverter.ts +1409 -0
- package/src/common/codeLens.ts +188 -0
- package/src/common/colorProvider.ts +192 -0
- package/src/common/completion.ts +281 -0
- package/src/common/configuration.ts +338 -0
- package/src/common/declaration.ts +140 -0
- package/src/common/definition.ts +138 -0
- package/src/common/diagnostic.ts +1408 -0
- package/src/common/documentHighlight.ts +140 -0
- package/src/common/documentLink.ts +180 -0
- package/src/common/documentSymbol.ts +186 -0
- package/src/common/executeCommand.ts +129 -0
- package/src/common/features.ts +1157 -0
- package/src/common/fileOperations.ts +635 -0
- package/src/common/fileSystemWatcher.ts +184 -0
- package/src/common/foldingRange.ts +160 -0
- package/src/common/formatting.ts +465 -0
- package/src/common/hover.ts +133 -0
- package/src/common/implementation.ts +142 -0
- package/src/common/inlayHint.ts +201 -0
- package/src/common/inlineCompletion.ts +160 -0
- package/src/common/inlineValue.ts +158 -0
- package/src/common/linkedEditingRange.ts +141 -0
- package/src/common/notebook.ts +1443 -0
- package/src/common/progress.ts +61 -0
- package/src/common/progressPart.ts +151 -0
- package/src/common/protocolCallHierarchyItem.ts +29 -0
- package/src/common/protocolCodeAction.ts +17 -0
- package/src/common/protocolCodeLens.ts +15 -0
- package/src/common/protocolCompletionItem.ts +22 -0
- package/src/common/protocolConverter.ts +2627 -0
- package/src/common/protocolDiagnostic.ts +47 -0
- package/src/common/protocolDocumentLink.ts +17 -0
- package/src/common/protocolInlayHint.ts +21 -0
- package/src/common/protocolTypeHierarchyItem.ts +29 -0
- package/src/common/protocolWorkspaceSymbol.ts +39 -0
- package/src/common/reference.ts +144 -0
- package/src/common/rename.ts +230 -0
- package/src/common/selectionRange.ts +136 -0
- package/src/common/semanticTokens.ts +383 -0
- package/src/common/signatureHelp.ts +170 -0
- package/src/common/textSynchronization.ts +819 -0
- package/src/common/typeDefinition.ts +146 -0
- package/src/common/typeHierarchy.ts +248 -0
- package/src/common/utils/async.ts +354 -0
- package/src/common/utils/is.ts +63 -0
- package/src/common/utils/uuid.ts +136 -0
- package/src/common/vscodeAdaptor/convertor.ts +73 -0
- package/src/common/vscodeAdaptor/diagnosticCollection.ts +238 -0
- package/src/common/vscodeAdaptor/extHostTypes.ts +4498 -0
- package/src/common/vscodeAdaptor/fileWatcher.ts +36 -0
- package/src/common/vscodeAdaptor/hostTypeUtil.ts +539 -0
- package/src/common/vscodeAdaptor/libro-fs.ts +51 -0
- package/src/common/vscodeAdaptor/libroWindow.ts +85 -0
- package/src/common/vscodeAdaptor/libroWorkspace.ts +261 -0
- package/src/common/vscodeAdaptor/lspEnv.ts +16 -0
- package/src/common/vscodeAdaptor/monaco-converter.ts +1800 -0
- package/src/common/vscodeAdaptor/monacoLanguages.ts +511 -0
- package/src/common/vscodeAdaptor/services.ts +278 -0
- package/src/common/vscodeAdaptor/typings.d.ts +10 -0
- package/src/common/vscodeAdaptor/util.ts +7 -0
- package/src/common/vscodeAdaptor/vscodeAdaptor.ts +122 -0
- package/src/common/workspaceFolder.ts +236 -0
- package/src/common/workspaceSymbol.ts +166 -0
- package/src/constants.ts +1 -0
- package/src/index.spec.ts +7 -0
- package/src/index.ts +5 -0
- package/src/libro-language-client-contribution.ts +49 -0
- package/src/libro-language-client-manager.ts +131 -0
- package/src/libro-language-client.ts +100 -0
- package/src/module.ts +19 -0
|
@@ -0,0 +1,1800 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
3
|
+
/* --------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) 2018-2022 TypeFox GmbH (http://www.typefox.io). All rights reserved.
|
|
5
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
6
|
+
* ------------------------------------------------------------------------------------------ */
|
|
7
|
+
import type * as monaco from '@difizen/monaco-editor-core';
|
|
8
|
+
import type {
|
|
9
|
+
CodeActionParams,
|
|
10
|
+
CodeLensParams,
|
|
11
|
+
DocumentFormattingParams,
|
|
12
|
+
DocumentOnTypeFormattingParams,
|
|
13
|
+
DocumentRangeFormattingParams,
|
|
14
|
+
ReferenceParams,
|
|
15
|
+
RenameParams,
|
|
16
|
+
TextDocumentPositionParams,
|
|
17
|
+
Position,
|
|
18
|
+
TextDocumentIdentifier,
|
|
19
|
+
CompletionItem,
|
|
20
|
+
CompletionList,
|
|
21
|
+
CompletionParams,
|
|
22
|
+
CompletionContext,
|
|
23
|
+
Range,
|
|
24
|
+
Hover,
|
|
25
|
+
SignatureHelp,
|
|
26
|
+
SignatureInformation,
|
|
27
|
+
ParameterInformation,
|
|
28
|
+
Definition,
|
|
29
|
+
DefinitionLink,
|
|
30
|
+
Location,
|
|
31
|
+
DocumentHighlight,
|
|
32
|
+
SymbolInformation,
|
|
33
|
+
DocumentSymbolParams,
|
|
34
|
+
FormattingOptions,
|
|
35
|
+
TextEdit,
|
|
36
|
+
WorkspaceEdit,
|
|
37
|
+
DocumentLinkParams,
|
|
38
|
+
MarkedString,
|
|
39
|
+
ColorInformation,
|
|
40
|
+
ColorPresentation,
|
|
41
|
+
FoldingRange,
|
|
42
|
+
DiagnosticRelatedInformation,
|
|
43
|
+
CodeAction,
|
|
44
|
+
SignatureHelpContext,
|
|
45
|
+
SemanticTokens,
|
|
46
|
+
InsertTextMode,
|
|
47
|
+
ChangeAnnotation,
|
|
48
|
+
InlayHintLabelPart,
|
|
49
|
+
} from '@difizen/vscode-languageserver-protocol';
|
|
50
|
+
import * as ls from '@difizen/vscode-languageserver-protocol';
|
|
51
|
+
import {
|
|
52
|
+
CompletionTriggerKind,
|
|
53
|
+
InsertTextFormat,
|
|
54
|
+
Diagnostic,
|
|
55
|
+
CompletionItemKind,
|
|
56
|
+
LocationLink,
|
|
57
|
+
DocumentHighlightKind,
|
|
58
|
+
CodeActionContext,
|
|
59
|
+
DiagnosticSeverity,
|
|
60
|
+
Command,
|
|
61
|
+
CodeLens,
|
|
62
|
+
DocumentLink,
|
|
63
|
+
MarkupContent,
|
|
64
|
+
FoldingRangeKind,
|
|
65
|
+
MarkupKind,
|
|
66
|
+
SymbolKind,
|
|
67
|
+
DocumentSymbol,
|
|
68
|
+
SignatureHelpTriggerKind,
|
|
69
|
+
AnnotatedTextEdit,
|
|
70
|
+
InlayHint,
|
|
71
|
+
} from '@difizen/vscode-languageserver-protocol';
|
|
72
|
+
|
|
73
|
+
import * as Is from './hostTypeUtil.js';
|
|
74
|
+
|
|
75
|
+
export type RecursivePartial<T> = {
|
|
76
|
+
[P in keyof T]?: RecursivePartial<T[P]>;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export interface ProtocolDocumentLink extends monaco.languages.ILink {
|
|
80
|
+
data?: unknown;
|
|
81
|
+
}
|
|
82
|
+
export namespace ProtocolDocumentLink {
|
|
83
|
+
export function is(item: any): item is ProtocolDocumentLink {
|
|
84
|
+
return !!item && 'data' in item;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ProtocolCodeLens extends monaco.languages.CodeLens {
|
|
89
|
+
data?: unknown;
|
|
90
|
+
}
|
|
91
|
+
export namespace ProtocolCodeLens {
|
|
92
|
+
export function is(item: any): item is ProtocolCodeLens {
|
|
93
|
+
return !!item && 'data' in item;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ProtocolCompletionItem extends monaco.languages.CompletionItem {
|
|
98
|
+
data?: unknown;
|
|
99
|
+
fromEdit?: boolean;
|
|
100
|
+
documentationFormat?: string;
|
|
101
|
+
originalItemKind?: CompletionItemKind;
|
|
102
|
+
deprecated?: boolean;
|
|
103
|
+
insertTextMode?: InsertTextMode;
|
|
104
|
+
}
|
|
105
|
+
export namespace ProtocolCompletionItem {
|
|
106
|
+
export function is(item: any): item is ProtocolCompletionItem {
|
|
107
|
+
return !!item && 'data' in item;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface ProtocolCodeAction extends monaco.languages.CodeAction {
|
|
112
|
+
data?: unknown;
|
|
113
|
+
}
|
|
114
|
+
export namespace ProtocolCodeAction {
|
|
115
|
+
export function is(item: any): item is ProtocolCodeAction {
|
|
116
|
+
return !!item && 'data' in item;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface ProtocolInlayHint extends monaco.languages.InlayHint {
|
|
121
|
+
data?: unknown;
|
|
122
|
+
}
|
|
123
|
+
export namespace ProtocolInlayHint {
|
|
124
|
+
export function is(item: any): item is ProtocolInlayHint {
|
|
125
|
+
return !!item && 'data' in item;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
type RangeReplace = { insert: monaco.IRange; replace: monaco.IRange };
|
|
130
|
+
|
|
131
|
+
function isRangeReplace(v: Partial<monaco.IRange> | RangeReplace): v is RangeReplace {
|
|
132
|
+
return (v as RangeReplace).insert !== undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export class MonacoToProtocolConverter {
|
|
136
|
+
public constructor(protected readonly _monaco: typeof monaco) {}
|
|
137
|
+
|
|
138
|
+
asPosition(lineNumber: undefined | null, column: undefined | null): {};
|
|
139
|
+
asPosition(lineNumber: number, column: undefined | null): Pick<Position, 'line'>;
|
|
140
|
+
asPosition(lineNumber: undefined | null, column: number): Pick<Position, 'character'>;
|
|
141
|
+
asPosition(lineNumber: number, column: number): Position;
|
|
142
|
+
asPosition(
|
|
143
|
+
lineNumber: number | undefined | null,
|
|
144
|
+
column: number | undefined | null,
|
|
145
|
+
): Partial<Position>;
|
|
146
|
+
asPosition(
|
|
147
|
+
lineNumber: number | undefined | null,
|
|
148
|
+
column: number | undefined | null,
|
|
149
|
+
): Partial<Position> {
|
|
150
|
+
const line =
|
|
151
|
+
lineNumber === undefined || lineNumber === null ? undefined : lineNumber - 1;
|
|
152
|
+
const character = column === undefined || column === null ? undefined : column - 1;
|
|
153
|
+
return {
|
|
154
|
+
line,
|
|
155
|
+
character,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
asRange(range: null): null;
|
|
160
|
+
asRange(range: undefined): undefined;
|
|
161
|
+
asRange(range: monaco.IRange): Range;
|
|
162
|
+
asRange(range: monaco.IRange | undefined): Range | undefined;
|
|
163
|
+
asRange(range: monaco.IRange | null): Range | null;
|
|
164
|
+
asRange(
|
|
165
|
+
range: monaco.IRange | { insert: monaco.IRange; replace: monaco.IRange },
|
|
166
|
+
): Range;
|
|
167
|
+
asRange(range: Partial<monaco.IRange>): RecursivePartial<Range>;
|
|
168
|
+
asRange(
|
|
169
|
+
range: Partial<monaco.IRange> | undefined,
|
|
170
|
+
): RecursivePartial<Range> | undefined;
|
|
171
|
+
asRange(range: Partial<monaco.IRange> | null): RecursivePartial<Range> | null;
|
|
172
|
+
asRange(
|
|
173
|
+
range: Partial<monaco.IRange> | undefined | null | RangeReplace,
|
|
174
|
+
): RecursivePartial<Range> | undefined | null {
|
|
175
|
+
if (range === undefined) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
if (range === null) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isRangeReplace(range)) {
|
|
183
|
+
return this.asRange(range.insert);
|
|
184
|
+
} else {
|
|
185
|
+
const start = this.asPosition(range.startLineNumber, range.startColumn);
|
|
186
|
+
const end = this.asPosition(range.endLineNumber, range.endColumn);
|
|
187
|
+
return {
|
|
188
|
+
start,
|
|
189
|
+
end,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
asLocation(item: monaco.languages.Location): Location;
|
|
195
|
+
asLocation(item: undefined | null): undefined;
|
|
196
|
+
asLocation(item: monaco.languages.Location | undefined | null): Location | undefined;
|
|
197
|
+
asLocation(item: monaco.languages.Location | undefined | null): Location | undefined {
|
|
198
|
+
if (!item) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
const uri = item.uri.toString();
|
|
202
|
+
const range = this.asRange(item.range);
|
|
203
|
+
return {
|
|
204
|
+
uri,
|
|
205
|
+
range,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
asTextDocumentIdentifier(
|
|
210
|
+
model: monaco.editor.IReadOnlyModel,
|
|
211
|
+
): TextDocumentIdentifier {
|
|
212
|
+
return {
|
|
213
|
+
uri: model.uri.toString(),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
asTextDocumentPositionParams(
|
|
218
|
+
model: monaco.editor.IReadOnlyModel,
|
|
219
|
+
position: monaco.Position,
|
|
220
|
+
): TextDocumentPositionParams {
|
|
221
|
+
return {
|
|
222
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
223
|
+
position: this.asPosition(position.lineNumber, position.column),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
asCompletionParams(
|
|
228
|
+
model: monaco.editor.IReadOnlyModel,
|
|
229
|
+
position: monaco.Position,
|
|
230
|
+
context: monaco.languages.CompletionContext,
|
|
231
|
+
): CompletionParams {
|
|
232
|
+
return Object.assign(this.asTextDocumentPositionParams(model, position), {
|
|
233
|
+
context: this.asCompletionContext(context),
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
asCompletionContext(context: monaco.languages.CompletionContext): CompletionContext {
|
|
238
|
+
return {
|
|
239
|
+
triggerKind: this.asCompletionTriggerKind(context.triggerKind),
|
|
240
|
+
triggerCharacter: context.triggerCharacter,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
asSignatureHelpContext(
|
|
245
|
+
context: monaco.languages.SignatureHelpContext,
|
|
246
|
+
): SignatureHelpContext {
|
|
247
|
+
return {
|
|
248
|
+
triggerKind: this.asSignatureHelpTriggerKind(context.triggerKind),
|
|
249
|
+
triggerCharacter: context.triggerCharacter,
|
|
250
|
+
isRetrigger: context.isRetrigger,
|
|
251
|
+
activeSignatureHelp: this.asSignatureHelp(context.activeSignatureHelp),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
asSignatureHelp(
|
|
256
|
+
signatureHelp: monaco.languages.SignatureHelp | undefined,
|
|
257
|
+
): SignatureHelp | undefined {
|
|
258
|
+
if (signatureHelp === undefined) {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
signatures: signatureHelp.signatures.map((signatureInfo) =>
|
|
263
|
+
this.asSignatureInformation(signatureInfo),
|
|
264
|
+
),
|
|
265
|
+
activeParameter: signatureHelp.activeParameter,
|
|
266
|
+
activeSignature: signatureHelp.activeSignature,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
asSignatureInformation(
|
|
271
|
+
signatureInformation: monaco.languages.SignatureInformation,
|
|
272
|
+
): SignatureInformation {
|
|
273
|
+
return {
|
|
274
|
+
documentation: this.asMarkupContent(signatureInformation.documentation),
|
|
275
|
+
label: signatureInformation.label,
|
|
276
|
+
parameters: signatureInformation.parameters.map((paramInfo) =>
|
|
277
|
+
this.asParameterInformation(paramInfo),
|
|
278
|
+
),
|
|
279
|
+
activeParameter: signatureInformation.activeParameter,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
asParameterInformation(
|
|
284
|
+
parameterInformation: monaco.languages.ParameterInformation,
|
|
285
|
+
): ParameterInformation {
|
|
286
|
+
return {
|
|
287
|
+
documentation: this.asMarkupContent(parameterInformation.documentation),
|
|
288
|
+
label: parameterInformation.label,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
asMarkupContent(
|
|
293
|
+
markupContent: string | monaco.IMarkdownString | undefined,
|
|
294
|
+
): string | MarkupContent | undefined {
|
|
295
|
+
if (markupContent === undefined) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
if (typeof markupContent === 'string') {
|
|
299
|
+
return markupContent;
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
kind: MarkupKind.Markdown,
|
|
303
|
+
value: markupContent.value,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
asSignatureHelpTriggerKind(
|
|
308
|
+
triggerKind: monaco.languages.SignatureHelpTriggerKind,
|
|
309
|
+
): SignatureHelpTriggerKind {
|
|
310
|
+
switch (triggerKind) {
|
|
311
|
+
case this._monaco.languages.SignatureHelpTriggerKind.ContentChange:
|
|
312
|
+
return SignatureHelpTriggerKind.ContentChange;
|
|
313
|
+
case this._monaco.languages.SignatureHelpTriggerKind.TriggerCharacter:
|
|
314
|
+
return SignatureHelpTriggerKind.TriggerCharacter;
|
|
315
|
+
default:
|
|
316
|
+
return SignatureHelpTriggerKind.Invoked;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
asCompletionTriggerKind(
|
|
321
|
+
triggerKind: monaco.languages.CompletionTriggerKind,
|
|
322
|
+
): CompletionTriggerKind {
|
|
323
|
+
switch (triggerKind) {
|
|
324
|
+
case this._monaco.languages.CompletionTriggerKind.TriggerCharacter:
|
|
325
|
+
return CompletionTriggerKind.TriggerCharacter;
|
|
326
|
+
case this._monaco.languages.CompletionTriggerKind.TriggerForIncompleteCompletions:
|
|
327
|
+
return CompletionTriggerKind.TriggerForIncompleteCompletions;
|
|
328
|
+
default:
|
|
329
|
+
return CompletionTriggerKind.Invoked;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
asCompletionItem(item: monaco.languages.CompletionItem): CompletionItem {
|
|
334
|
+
const result: CompletionItem = { label: item.label as string };
|
|
335
|
+
const protocolItem = ProtocolCompletionItem.is(item) ? item : undefined;
|
|
336
|
+
if (item.detail) {
|
|
337
|
+
result.detail = item.detail;
|
|
338
|
+
}
|
|
339
|
+
if (item.documentation) {
|
|
340
|
+
if (typeof item.documentation === 'string') {
|
|
341
|
+
result.documentation = item.documentation;
|
|
342
|
+
} else {
|
|
343
|
+
result.documentation = this.asDocumentation(
|
|
344
|
+
protocolItem?.documentationFormat ?? MarkupKind.Markdown,
|
|
345
|
+
item.documentation,
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (item.filterText) {
|
|
350
|
+
result.filterText = item.filterText;
|
|
351
|
+
}
|
|
352
|
+
this.fillPrimaryInsertText(result, item as ProtocolCompletionItem);
|
|
353
|
+
if (Is.isNumber(item.kind)) {
|
|
354
|
+
result.kind = this.asCompletionItemKind(
|
|
355
|
+
item.kind,
|
|
356
|
+
protocolItem && protocolItem.originalItemKind,
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
if (item.sortText) {
|
|
360
|
+
result.sortText = item.sortText;
|
|
361
|
+
}
|
|
362
|
+
if (item.additionalTextEdits) {
|
|
363
|
+
result.additionalTextEdits = this.asTextEdits(item.additionalTextEdits);
|
|
364
|
+
}
|
|
365
|
+
if (item.command) {
|
|
366
|
+
result.command = this.asCommand(item.command);
|
|
367
|
+
}
|
|
368
|
+
if (item.commitCharacters) {
|
|
369
|
+
result.commitCharacters = item.commitCharacters.slice();
|
|
370
|
+
}
|
|
371
|
+
if (item.command) {
|
|
372
|
+
result.command = this.asCommand(item.command);
|
|
373
|
+
}
|
|
374
|
+
if (item.preselect === true || item.preselect === false) {
|
|
375
|
+
result.preselect = item.preselect;
|
|
376
|
+
}
|
|
377
|
+
if (protocolItem) {
|
|
378
|
+
if (protocolItem.data !== undefined) {
|
|
379
|
+
result.data = protocolItem.data;
|
|
380
|
+
}
|
|
381
|
+
if (protocolItem.deprecated === true || protocolItem.deprecated === false) {
|
|
382
|
+
result.deprecated = protocolItem.deprecated;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (item.tags) {
|
|
386
|
+
result.tags = item.tags?.slice();
|
|
387
|
+
}
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
protected asCompletionItemKind(
|
|
392
|
+
value: monaco.languages.CompletionItemKind,
|
|
393
|
+
original: CompletionItemKind | undefined,
|
|
394
|
+
): CompletionItemKind {
|
|
395
|
+
if (original !== undefined) {
|
|
396
|
+
return original;
|
|
397
|
+
}
|
|
398
|
+
switch (value) {
|
|
399
|
+
case this._monaco.languages.CompletionItemKind.Method:
|
|
400
|
+
return CompletionItemKind.Method;
|
|
401
|
+
case this._monaco.languages.CompletionItemKind.Function:
|
|
402
|
+
return CompletionItemKind.Function;
|
|
403
|
+
case this._monaco.languages.CompletionItemKind.Constructor:
|
|
404
|
+
return CompletionItemKind.Constructor;
|
|
405
|
+
case this._monaco.languages.CompletionItemKind.Field:
|
|
406
|
+
return CompletionItemKind.Field;
|
|
407
|
+
case this._monaco.languages.CompletionItemKind.Variable:
|
|
408
|
+
return CompletionItemKind.Variable;
|
|
409
|
+
case this._monaco.languages.CompletionItemKind.Class:
|
|
410
|
+
return CompletionItemKind.Class;
|
|
411
|
+
case this._monaco.languages.CompletionItemKind.Struct:
|
|
412
|
+
return CompletionItemKind.Struct;
|
|
413
|
+
case this._monaco.languages.CompletionItemKind.Interface:
|
|
414
|
+
return CompletionItemKind.Interface;
|
|
415
|
+
case this._monaco.languages.CompletionItemKind.Module:
|
|
416
|
+
return CompletionItemKind.Module;
|
|
417
|
+
case this._monaco.languages.CompletionItemKind.Property:
|
|
418
|
+
return CompletionItemKind.Property;
|
|
419
|
+
case this._monaco.languages.CompletionItemKind.Event:
|
|
420
|
+
return CompletionItemKind.Event;
|
|
421
|
+
case this._monaco.languages.CompletionItemKind.Operator:
|
|
422
|
+
return CompletionItemKind.Operator;
|
|
423
|
+
case this._monaco.languages.CompletionItemKind.Unit:
|
|
424
|
+
return CompletionItemKind.Unit;
|
|
425
|
+
case this._monaco.languages.CompletionItemKind.Value:
|
|
426
|
+
return CompletionItemKind.Value;
|
|
427
|
+
case this._monaco.languages.CompletionItemKind.Constant:
|
|
428
|
+
return CompletionItemKind.Constant;
|
|
429
|
+
case this._monaco.languages.CompletionItemKind.Enum:
|
|
430
|
+
return CompletionItemKind.Enum;
|
|
431
|
+
case this._monaco.languages.CompletionItemKind.EnumMember:
|
|
432
|
+
return CompletionItemKind.EnumMember;
|
|
433
|
+
case this._monaco.languages.CompletionItemKind.Keyword:
|
|
434
|
+
return CompletionItemKind.Keyword;
|
|
435
|
+
case this._monaco.languages.CompletionItemKind.Text:
|
|
436
|
+
return CompletionItemKind.Text;
|
|
437
|
+
case this._monaco.languages.CompletionItemKind.Color:
|
|
438
|
+
return CompletionItemKind.Color;
|
|
439
|
+
case this._monaco.languages.CompletionItemKind.File:
|
|
440
|
+
return CompletionItemKind.File;
|
|
441
|
+
case this._monaco.languages.CompletionItemKind.Reference:
|
|
442
|
+
return CompletionItemKind.Reference;
|
|
443
|
+
case this._monaco.languages.CompletionItemKind.Customcolor:
|
|
444
|
+
return CompletionItemKind.Color;
|
|
445
|
+
case this._monaco.languages.CompletionItemKind.Folder:
|
|
446
|
+
return CompletionItemKind.Folder;
|
|
447
|
+
case this._monaco.languages.CompletionItemKind.TypeParameter:
|
|
448
|
+
return CompletionItemKind.TypeParameter;
|
|
449
|
+
case this._monaco.languages.CompletionItemKind.Snippet:
|
|
450
|
+
return CompletionItemKind.Snippet;
|
|
451
|
+
default:
|
|
452
|
+
return (value + 1) as CompletionItemKind;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
protected asDocumentation(
|
|
457
|
+
format: string,
|
|
458
|
+
documentation: string | monaco.IMarkdownString,
|
|
459
|
+
): string | MarkupContent {
|
|
460
|
+
switch (format) {
|
|
461
|
+
case MarkupKind.PlainText:
|
|
462
|
+
return { kind: format, value: documentation as string };
|
|
463
|
+
case MarkupKind.Markdown:
|
|
464
|
+
return { kind: format, value: (documentation as monaco.IMarkdownString).value };
|
|
465
|
+
default:
|
|
466
|
+
return `Unsupported Markup content received. Kind is: ${format}`;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
protected fillPrimaryInsertText(
|
|
471
|
+
target: CompletionItem,
|
|
472
|
+
source: ProtocolCompletionItem,
|
|
473
|
+
): void {
|
|
474
|
+
let format: InsertTextFormat = InsertTextFormat.PlainText;
|
|
475
|
+
let text: string | undefined;
|
|
476
|
+
let range: Range | undefined;
|
|
477
|
+
if (
|
|
478
|
+
source.insertTextRules !== undefined &&
|
|
479
|
+
(source.insertTextRules &
|
|
480
|
+
this._monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet) ===
|
|
481
|
+
0
|
|
482
|
+
) {
|
|
483
|
+
format = InsertTextFormat.Snippet;
|
|
484
|
+
text = source.insertText;
|
|
485
|
+
}
|
|
486
|
+
target.insertTextFormat = format;
|
|
487
|
+
|
|
488
|
+
text = source.insertText;
|
|
489
|
+
if (source.range) {
|
|
490
|
+
range = this.asRange(source.range);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
target.insertTextFormat = format;
|
|
494
|
+
if (source.fromEdit && text && range) {
|
|
495
|
+
target.textEdit = { newText: text, range: range };
|
|
496
|
+
} else {
|
|
497
|
+
target.insertText = text;
|
|
498
|
+
}
|
|
499
|
+
target.insertTextMode = source.insertTextMode;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
asTextEdit(edit: monaco.editor.ISingleEditOperation): TextEdit {
|
|
503
|
+
const range = this.asRange(edit.range)!;
|
|
504
|
+
return {
|
|
505
|
+
range,
|
|
506
|
+
newText: edit.text || '',
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
asTextEdits(items: monaco.editor.ISingleEditOperation[]): TextEdit[];
|
|
511
|
+
asTextEdits(items: undefined | null): undefined;
|
|
512
|
+
asTextEdits(
|
|
513
|
+
items: monaco.editor.ISingleEditOperation[] | undefined | null,
|
|
514
|
+
): TextEdit[] | undefined;
|
|
515
|
+
asTextEdits(
|
|
516
|
+
items: monaco.editor.ISingleEditOperation[] | undefined | null,
|
|
517
|
+
): TextEdit[] | undefined {
|
|
518
|
+
if (!items) {
|
|
519
|
+
return undefined;
|
|
520
|
+
}
|
|
521
|
+
return items.map((item) => this.asTextEdit(item));
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
asReferenceParams(
|
|
525
|
+
model: monaco.editor.IReadOnlyModel,
|
|
526
|
+
position: monaco.Position,
|
|
527
|
+
options: { includeDeclaration: boolean },
|
|
528
|
+
): ReferenceParams {
|
|
529
|
+
return {
|
|
530
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
531
|
+
position: this.asPosition(position.lineNumber, position.column),
|
|
532
|
+
context: { includeDeclaration: options.includeDeclaration },
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
asDocumentSymbolParams(model: monaco.editor.IReadOnlyModel): DocumentSymbolParams {
|
|
537
|
+
return {
|
|
538
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
asCodeLensParams(model: monaco.editor.IReadOnlyModel): CodeLensParams {
|
|
543
|
+
return {
|
|
544
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
asDiagnosticSeverity(value: monaco.MarkerSeverity): DiagnosticSeverity | undefined {
|
|
549
|
+
switch (value) {
|
|
550
|
+
case this._monaco.MarkerSeverity.Error:
|
|
551
|
+
return DiagnosticSeverity.Error;
|
|
552
|
+
case this._monaco.MarkerSeverity.Warning:
|
|
553
|
+
return DiagnosticSeverity.Warning;
|
|
554
|
+
case this._monaco.MarkerSeverity.Info:
|
|
555
|
+
return DiagnosticSeverity.Information;
|
|
556
|
+
case this._monaco.MarkerSeverity.Hint:
|
|
557
|
+
return DiagnosticSeverity.Hint;
|
|
558
|
+
}
|
|
559
|
+
return undefined;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
asDiagnostic(marker: monaco.editor.IMarkerData): Diagnostic {
|
|
563
|
+
const range = this.asRange(
|
|
564
|
+
new this._monaco.Range(
|
|
565
|
+
marker.startLineNumber,
|
|
566
|
+
marker.startColumn,
|
|
567
|
+
marker.endLineNumber,
|
|
568
|
+
marker.endColumn,
|
|
569
|
+
),
|
|
570
|
+
);
|
|
571
|
+
const severity = this.asDiagnosticSeverity(marker.severity);
|
|
572
|
+
const diag = Diagnostic.create(
|
|
573
|
+
range,
|
|
574
|
+
marker.message,
|
|
575
|
+
severity,
|
|
576
|
+
marker.code as string,
|
|
577
|
+
marker.source,
|
|
578
|
+
);
|
|
579
|
+
return diag;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
asDiagnostics(markers: monaco.editor.IMarkerData[]): Diagnostic[] {
|
|
583
|
+
if (markers === void 0 || markers === null) {
|
|
584
|
+
return markers;
|
|
585
|
+
}
|
|
586
|
+
return markers.map((marker) => this.asDiagnostic(marker));
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
asCodeActionContext(
|
|
590
|
+
context: monaco.languages.CodeActionContext,
|
|
591
|
+
diagnostics: Diagnostic[],
|
|
592
|
+
): CodeActionContext {
|
|
593
|
+
if (context === void 0 || context === null) {
|
|
594
|
+
return context;
|
|
595
|
+
}
|
|
596
|
+
return CodeActionContext.create(
|
|
597
|
+
diagnostics,
|
|
598
|
+
Is.isString(context.only) ? [context.only] : undefined,
|
|
599
|
+
context.trigger,
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
asCodeActionParams(
|
|
604
|
+
model: monaco.editor.IReadOnlyModel,
|
|
605
|
+
range: monaco.Range,
|
|
606
|
+
context: monaco.languages.CodeActionContext,
|
|
607
|
+
diagnostics: Diagnostic[],
|
|
608
|
+
): CodeActionParams {
|
|
609
|
+
return {
|
|
610
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
611
|
+
range: this.asRange(range),
|
|
612
|
+
context: this.asCodeActionContext(context, diagnostics),
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
asCommand(item: monaco.languages.Command | undefined | null): Command | undefined {
|
|
617
|
+
if (item) {
|
|
618
|
+
const args = item.arguments || [];
|
|
619
|
+
return Command.create(item.title, item.id, ...args);
|
|
620
|
+
}
|
|
621
|
+
return undefined;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
asCodeLens(item: monaco.languages.CodeLens): CodeLens {
|
|
625
|
+
const result = CodeLens.create(this.asRange(item.range));
|
|
626
|
+
if (item.command) {
|
|
627
|
+
result.command = this.asCommand(item.command);
|
|
628
|
+
}
|
|
629
|
+
if (ProtocolCodeLens.is(item)) {
|
|
630
|
+
if (item.data) {
|
|
631
|
+
result.data = item.data;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
return result;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
asFormattingOptions(options: monaco.languages.FormattingOptions): FormattingOptions {
|
|
638
|
+
return { tabSize: options.tabSize, insertSpaces: options.insertSpaces };
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
asDocumentFormattingParams(
|
|
642
|
+
model: monaco.editor.IReadOnlyModel,
|
|
643
|
+
options: monaco.languages.FormattingOptions,
|
|
644
|
+
): DocumentFormattingParams {
|
|
645
|
+
return {
|
|
646
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
647
|
+
options: this.asFormattingOptions(options),
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
asDocumentRangeFormattingParams(
|
|
652
|
+
model: monaco.editor.IReadOnlyModel,
|
|
653
|
+
range: monaco.Range,
|
|
654
|
+
options: monaco.languages.FormattingOptions,
|
|
655
|
+
): DocumentRangeFormattingParams {
|
|
656
|
+
return {
|
|
657
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
658
|
+
range: this.asRange(range),
|
|
659
|
+
options: this.asFormattingOptions(options),
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
asDocumentOnTypeFormattingParams(
|
|
664
|
+
model: monaco.editor.IReadOnlyModel,
|
|
665
|
+
position: monaco.IPosition,
|
|
666
|
+
ch: string,
|
|
667
|
+
options: monaco.languages.FormattingOptions,
|
|
668
|
+
): DocumentOnTypeFormattingParams {
|
|
669
|
+
return {
|
|
670
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
671
|
+
position: this.asPosition(position.lineNumber, position.column),
|
|
672
|
+
ch,
|
|
673
|
+
options: this.asFormattingOptions(options),
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
asRenameParams(
|
|
678
|
+
model: monaco.editor.IReadOnlyModel,
|
|
679
|
+
position: monaco.IPosition,
|
|
680
|
+
newName: string,
|
|
681
|
+
): RenameParams {
|
|
682
|
+
return {
|
|
683
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
684
|
+
position: this.asPosition(position.lineNumber, position.column),
|
|
685
|
+
newName,
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
asDocumentLinkParams(model: monaco.editor.IReadOnlyModel): DocumentLinkParams {
|
|
690
|
+
return {
|
|
691
|
+
textDocument: this.asTextDocumentIdentifier(model),
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
asDocumentLink(item: monaco.languages.ILink): DocumentLink {
|
|
696
|
+
const result = DocumentLink.create(this.asRange(item.range));
|
|
697
|
+
if (item.url) {
|
|
698
|
+
result.target = typeof item.url === 'string' ? item.url : item.url.toString();
|
|
699
|
+
}
|
|
700
|
+
if (ProtocolDocumentLink.is(item) && item.data) {
|
|
701
|
+
result.data = item.data;
|
|
702
|
+
}
|
|
703
|
+
if (item.tooltip) {
|
|
704
|
+
result.tooltip = item.tooltip;
|
|
705
|
+
}
|
|
706
|
+
return result;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
asCodeAction(item: monaco.languages.CodeAction): CodeAction {
|
|
710
|
+
const result: CodeAction = { title: item.title };
|
|
711
|
+
const protocolCodeAction = ProtocolCodeAction.is(item) ? item : undefined;
|
|
712
|
+
if (Is.isNumber(item.kind)) {
|
|
713
|
+
result.kind = item.kind;
|
|
714
|
+
}
|
|
715
|
+
if (item.diagnostics) {
|
|
716
|
+
result.diagnostics = this.asDiagnostics(item.diagnostics);
|
|
717
|
+
}
|
|
718
|
+
if (item.edit) {
|
|
719
|
+
throw new Error(
|
|
720
|
+
`VS Code code actions can only be converted to a protocol code action without an edit.`,
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
if (item.command) {
|
|
724
|
+
result.command = this.asCommand(item.command);
|
|
725
|
+
}
|
|
726
|
+
if (item.isPreferred !== undefined) {
|
|
727
|
+
result.isPreferred = item.isPreferred;
|
|
728
|
+
}
|
|
729
|
+
if (item.disabled) {
|
|
730
|
+
result.disabled = { reason: item.disabled };
|
|
731
|
+
}
|
|
732
|
+
if (protocolCodeAction) {
|
|
733
|
+
if (protocolCodeAction.data !== undefined) {
|
|
734
|
+
result.data = protocolCodeAction.data;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return result;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
asInlayHintLabelPart(part: monaco.languages.InlayHintLabelPart): InlayHintLabelPart {
|
|
741
|
+
return {
|
|
742
|
+
value: part.label,
|
|
743
|
+
command: this.asCommand(part.command),
|
|
744
|
+
location: this.asLocation(part.location),
|
|
745
|
+
tooltip: this.asMarkupContent(part.tooltip),
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
asInlayHintLabel(
|
|
750
|
+
label: string | monaco.languages.InlayHintLabelPart[],
|
|
751
|
+
): string | InlayHintLabelPart[] {
|
|
752
|
+
if (Array.isArray(label)) {
|
|
753
|
+
return label.map((part) => this.asInlayHintLabelPart(part));
|
|
754
|
+
}
|
|
755
|
+
return label;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
asInlayHint(item: monaco.languages.InlayHint): InlayHint {
|
|
759
|
+
const result = InlayHint.create(
|
|
760
|
+
this.asPosition(item.position.lineNumber, item.position.column),
|
|
761
|
+
this.asInlayHintLabel(item.label),
|
|
762
|
+
item.kind,
|
|
763
|
+
);
|
|
764
|
+
if (ProtocolInlayHint.is(item)) {
|
|
765
|
+
if (item.data) {
|
|
766
|
+
result.data = item.data;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
return result;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
export class ProtocolToMonacoConverter {
|
|
774
|
+
public constructor(protected readonly _monaco: typeof monaco) {}
|
|
775
|
+
|
|
776
|
+
asResourceEdits(
|
|
777
|
+
resource: monaco.Uri,
|
|
778
|
+
edits: (TextEdit | AnnotatedTextEdit)[],
|
|
779
|
+
asMetadata: (
|
|
780
|
+
annotation: ls.ChangeAnnotationIdentifier | undefined,
|
|
781
|
+
) => monaco.languages.WorkspaceEditMetadata | undefined,
|
|
782
|
+
modelVersionId?: number,
|
|
783
|
+
): monaco.languages.IWorkspaceTextEdit[] {
|
|
784
|
+
return edits.map((edit) => ({
|
|
785
|
+
resource: resource,
|
|
786
|
+
textEdit: this.asTextEdit(edit),
|
|
787
|
+
versionId: modelVersionId,
|
|
788
|
+
metadata: AnnotatedTextEdit.is(edit) ? asMetadata(edit.annotationId) : undefined,
|
|
789
|
+
}));
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
asWorkspaceEditMetadata(
|
|
793
|
+
changeAnnotation: ChangeAnnotation,
|
|
794
|
+
): monaco.languages.WorkspaceEditMetadata {
|
|
795
|
+
return {
|
|
796
|
+
needsConfirmation: changeAnnotation.needsConfirmation === true,
|
|
797
|
+
label: changeAnnotation.label,
|
|
798
|
+
description: changeAnnotation.description,
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
asWorkspaceEdit(item: WorkspaceEdit): monaco.languages.WorkspaceEdit;
|
|
803
|
+
asWorkspaceEdit(item: undefined | null): undefined;
|
|
804
|
+
asWorkspaceEdit(
|
|
805
|
+
item: WorkspaceEdit | undefined | null,
|
|
806
|
+
): monaco.languages.WorkspaceEdit | undefined;
|
|
807
|
+
asWorkspaceEdit(
|
|
808
|
+
item: WorkspaceEdit | undefined | null,
|
|
809
|
+
): monaco.languages.WorkspaceEdit | undefined {
|
|
810
|
+
if (!item) {
|
|
811
|
+
return undefined;
|
|
812
|
+
}
|
|
813
|
+
const sharedMetadata: Map<string, monaco.languages.WorkspaceEditMetadata> =
|
|
814
|
+
new Map();
|
|
815
|
+
if (item.changeAnnotations !== undefined) {
|
|
816
|
+
for (const key of Object.keys(item.changeAnnotations)) {
|
|
817
|
+
const metaData = this.asWorkspaceEditMetadata(item.changeAnnotations[key]);
|
|
818
|
+
sharedMetadata.set(key, metaData);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
const asMetadata = (
|
|
822
|
+
annotation: ls.ChangeAnnotationIdentifier | undefined,
|
|
823
|
+
): monaco.languages.WorkspaceEditMetadata | undefined => {
|
|
824
|
+
if (annotation === undefined) {
|
|
825
|
+
return undefined;
|
|
826
|
+
} else {
|
|
827
|
+
return sharedMetadata.get(annotation);
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
const edits: (
|
|
831
|
+
| monaco.languages.IWorkspaceTextEdit
|
|
832
|
+
| monaco.languages.IWorkspaceFileEdit
|
|
833
|
+
)[] = [];
|
|
834
|
+
if (item.documentChanges) {
|
|
835
|
+
item.documentChanges.forEach((change) => {
|
|
836
|
+
if (ls.CreateFile.is(change)) {
|
|
837
|
+
edits.push(<monaco.languages.IWorkspaceFileEdit>{
|
|
838
|
+
newUri: this._monaco.Uri.parse(change.uri),
|
|
839
|
+
options: change.options,
|
|
840
|
+
metadata: asMetadata(change.annotationId),
|
|
841
|
+
});
|
|
842
|
+
} else if (ls.RenameFile.is(change)) {
|
|
843
|
+
edits.push(<monaco.languages.IWorkspaceFileEdit>{
|
|
844
|
+
oldUri: this._monaco.Uri.parse(change.oldUri),
|
|
845
|
+
newUri: this._monaco.Uri.parse(change.newUri),
|
|
846
|
+
options: change.options,
|
|
847
|
+
metadata: asMetadata(change.annotationId),
|
|
848
|
+
});
|
|
849
|
+
} else if (ls.DeleteFile.is(change)) {
|
|
850
|
+
edits.push(<monaco.languages.IWorkspaceFileEdit>{
|
|
851
|
+
oldUri: this._monaco.Uri.parse(change.uri),
|
|
852
|
+
options: change.options,
|
|
853
|
+
metadata: asMetadata(change.annotationId),
|
|
854
|
+
});
|
|
855
|
+
} else if (ls.TextDocumentEdit.is(change)) {
|
|
856
|
+
const resource = this._monaco.Uri.parse(change.textDocument.uri);
|
|
857
|
+
const version =
|
|
858
|
+
typeof change.textDocument.version === 'number'
|
|
859
|
+
? change.textDocument.version
|
|
860
|
+
: undefined;
|
|
861
|
+
edits.push(
|
|
862
|
+
...this.asResourceEdits(resource, change.edits, asMetadata, version),
|
|
863
|
+
);
|
|
864
|
+
} else {
|
|
865
|
+
console.error(
|
|
866
|
+
`Unknown workspace edit change received:\n${JSON.stringify(change, undefined, 4)}`,
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
} else if (item.changes) {
|
|
871
|
+
for (const key of Object.keys(item.changes)) {
|
|
872
|
+
const resource = this._monaco.Uri.parse(key);
|
|
873
|
+
edits.push(...this.asResourceEdits(resource, item.changes[key], asMetadata));
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
return {
|
|
877
|
+
edits,
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
asTextEdit(edit: TextEdit): monaco.languages.TextEdit;
|
|
882
|
+
asTextEdit(edit: undefined | null): undefined;
|
|
883
|
+
asTextEdit(edit: TextEdit | undefined | null): undefined;
|
|
884
|
+
asTextEdit(edit: TextEdit | undefined | null): monaco.languages.TextEdit | undefined {
|
|
885
|
+
if (!edit) {
|
|
886
|
+
return undefined;
|
|
887
|
+
}
|
|
888
|
+
const range = this.asRange(edit.range)!;
|
|
889
|
+
return {
|
|
890
|
+
range,
|
|
891
|
+
text: edit.newText,
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
asTextEdits(items: TextEdit[]): monaco.languages.TextEdit[];
|
|
896
|
+
asTextEdits(items: undefined | null): undefined;
|
|
897
|
+
asTextEdits(
|
|
898
|
+
items: TextEdit[] | undefined | null,
|
|
899
|
+
): monaco.languages.TextEdit[] | undefined;
|
|
900
|
+
asTextEdits(
|
|
901
|
+
items: TextEdit[] | undefined | null,
|
|
902
|
+
): monaco.languages.TextEdit[] | undefined {
|
|
903
|
+
if (!items) {
|
|
904
|
+
return undefined;
|
|
905
|
+
}
|
|
906
|
+
return items.map((item) => this.asTextEdit(item));
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
asCodeLens(item: CodeLens): monaco.languages.CodeLens;
|
|
910
|
+
asCodeLens(item: undefined | null): undefined;
|
|
911
|
+
asCodeLens(item: CodeLens | undefined | null): monaco.languages.CodeLens | undefined;
|
|
912
|
+
asCodeLens(item: CodeLens | undefined | null): monaco.languages.CodeLens | undefined {
|
|
913
|
+
if (!item) {
|
|
914
|
+
return undefined;
|
|
915
|
+
}
|
|
916
|
+
const range = this.asRange(item.range);
|
|
917
|
+
const result = <ProtocolCodeLens>{ range };
|
|
918
|
+
if (item.command) {
|
|
919
|
+
result.command = this.asCommand(item.command);
|
|
920
|
+
}
|
|
921
|
+
if (item.data !== void 0 && item.data !== null) {
|
|
922
|
+
result.data = item.data;
|
|
923
|
+
}
|
|
924
|
+
return result;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
asCodeLensList(items: CodeLens[]): monaco.languages.CodeLensList;
|
|
928
|
+
asCodeLensList(items: undefined | null): undefined;
|
|
929
|
+
asCodeLensList(
|
|
930
|
+
items: CodeLens[] | undefined | null,
|
|
931
|
+
): monaco.languages.CodeLensList | undefined;
|
|
932
|
+
asCodeLensList(
|
|
933
|
+
items: CodeLens[] | undefined | null,
|
|
934
|
+
): monaco.languages.CodeLensList | undefined {
|
|
935
|
+
if (!items) {
|
|
936
|
+
return undefined;
|
|
937
|
+
}
|
|
938
|
+
return {
|
|
939
|
+
lenses: items.map((codeLens) => this.asCodeLens(codeLens)),
|
|
940
|
+
dispose: () => {},
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
asCodeActionList(actions: (Command | CodeAction)[]): monaco.languages.CodeActionList {
|
|
945
|
+
return {
|
|
946
|
+
actions: actions.map((action) => this.asCodeAction(action)),
|
|
947
|
+
dispose: () => {},
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
asCodeAction(item: Command | CodeAction): ProtocolCodeAction {
|
|
952
|
+
if (Command.is(item)) {
|
|
953
|
+
return {
|
|
954
|
+
command: {
|
|
955
|
+
id: item.command,
|
|
956
|
+
title: item.title,
|
|
957
|
+
arguments: item.arguments,
|
|
958
|
+
},
|
|
959
|
+
title: item.title,
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
return {
|
|
963
|
+
title: item.title,
|
|
964
|
+
command: this.asCommand(item.command),
|
|
965
|
+
edit: this.asWorkspaceEdit(item.edit),
|
|
966
|
+
diagnostics: this.asDiagnostics(item.diagnostics),
|
|
967
|
+
kind: item.kind,
|
|
968
|
+
disabled: item.disabled ? item.disabled.reason : undefined,
|
|
969
|
+
isPreferred: item.isPreferred,
|
|
970
|
+
data: item.data,
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
asCommand(command: Command): monaco.languages.Command;
|
|
975
|
+
asCommand(command: undefined): undefined;
|
|
976
|
+
asCommand(command: Command | undefined): monaco.languages.Command | undefined;
|
|
977
|
+
asCommand(command: Command | undefined): monaco.languages.Command | undefined {
|
|
978
|
+
if (!command) {
|
|
979
|
+
return undefined;
|
|
980
|
+
}
|
|
981
|
+
return {
|
|
982
|
+
id: command.command,
|
|
983
|
+
title: command.title,
|
|
984
|
+
arguments: command.arguments,
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
asDocumentSymbol(value: DocumentSymbol): monaco.languages.DocumentSymbol {
|
|
989
|
+
const children =
|
|
990
|
+
value.children && value.children.map((c) => this.asDocumentSymbol(c));
|
|
991
|
+
return {
|
|
992
|
+
name: value.name,
|
|
993
|
+
detail: value.detail || '',
|
|
994
|
+
kind: this.asSymbolKind(value.kind),
|
|
995
|
+
tags: value.tags || [],
|
|
996
|
+
range: this.asRange(value.range),
|
|
997
|
+
selectionRange: this.asRange(value.selectionRange),
|
|
998
|
+
children,
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
asDocumentSymbols(
|
|
1003
|
+
values: SymbolInformation[] | DocumentSymbol[],
|
|
1004
|
+
): monaco.languages.DocumentSymbol[] {
|
|
1005
|
+
if (DocumentSymbol.is(values[0])) {
|
|
1006
|
+
return (values as DocumentSymbol[]).map((s) => this.asDocumentSymbol(s));
|
|
1007
|
+
}
|
|
1008
|
+
return this.asSymbolInformations(values as SymbolInformation[]);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
asSymbolInformations(
|
|
1012
|
+
values: SymbolInformation[],
|
|
1013
|
+
uri?: monaco.Uri,
|
|
1014
|
+
): monaco.languages.DocumentSymbol[];
|
|
1015
|
+
asSymbolInformations(values: undefined | null, uri?: monaco.Uri): undefined;
|
|
1016
|
+
asSymbolInformations(
|
|
1017
|
+
values: SymbolInformation[] | undefined | null,
|
|
1018
|
+
uri?: monaco.Uri,
|
|
1019
|
+
): monaco.languages.DocumentSymbol[] | undefined;
|
|
1020
|
+
asSymbolInformations(
|
|
1021
|
+
values: SymbolInformation[] | undefined | null,
|
|
1022
|
+
uri?: monaco.Uri,
|
|
1023
|
+
): monaco.languages.DocumentSymbol[] | undefined {
|
|
1024
|
+
if (!values) {
|
|
1025
|
+
return undefined;
|
|
1026
|
+
}
|
|
1027
|
+
return values.map((information) => this.asSymbolInformation(information, uri));
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
asSymbolInformation(
|
|
1031
|
+
item: SymbolInformation,
|
|
1032
|
+
uri?: monaco.Uri,
|
|
1033
|
+
): monaco.languages.DocumentSymbol {
|
|
1034
|
+
const location = this.asLocation(
|
|
1035
|
+
uri ? { ...item.location, uri: uri.toString() } : item.location,
|
|
1036
|
+
);
|
|
1037
|
+
return {
|
|
1038
|
+
name: item.name,
|
|
1039
|
+
detail: '',
|
|
1040
|
+
containerName: item.containerName,
|
|
1041
|
+
kind: this.asSymbolKind(item.kind),
|
|
1042
|
+
tags: item.tags || [],
|
|
1043
|
+
range: location.range,
|
|
1044
|
+
selectionRange: location.range,
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
asSymbolKind(item: SymbolKind): monaco.languages.SymbolKind {
|
|
1049
|
+
if (item <= SymbolKind.TypeParameter) {
|
|
1050
|
+
// Symbol kind is one based in the protocol and zero based in code.
|
|
1051
|
+
return item - 1;
|
|
1052
|
+
}
|
|
1053
|
+
return this._monaco.languages.SymbolKind.Property;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
asDocumentHighlights(
|
|
1057
|
+
values: DocumentHighlight[],
|
|
1058
|
+
): monaco.languages.DocumentHighlight[];
|
|
1059
|
+
asDocumentHighlights(values: undefined | null): undefined;
|
|
1060
|
+
asDocumentHighlights(
|
|
1061
|
+
values: DocumentHighlight[] | undefined | null,
|
|
1062
|
+
): monaco.languages.DocumentHighlight[] | undefined;
|
|
1063
|
+
asDocumentHighlights(
|
|
1064
|
+
values: DocumentHighlight[] | undefined | null,
|
|
1065
|
+
): monaco.languages.DocumentHighlight[] | undefined {
|
|
1066
|
+
if (!values) {
|
|
1067
|
+
return undefined;
|
|
1068
|
+
}
|
|
1069
|
+
return values.map((item) => this.asDocumentHighlight(item));
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
asDocumentHighlight(item: DocumentHighlight): monaco.languages.DocumentHighlight {
|
|
1073
|
+
const range = this.asRange(item.range)!;
|
|
1074
|
+
const kind = Is.isNumber(item.kind)
|
|
1075
|
+
? this.asDocumentHighlightKind(item.kind)
|
|
1076
|
+
: undefined!;
|
|
1077
|
+
return { range, kind };
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
asDocumentHighlightKind(item: number): monaco.languages.DocumentHighlightKind {
|
|
1081
|
+
switch (item) {
|
|
1082
|
+
case DocumentHighlightKind.Text:
|
|
1083
|
+
return this._monaco.languages.DocumentHighlightKind.Text;
|
|
1084
|
+
case DocumentHighlightKind.Read:
|
|
1085
|
+
return this._monaco.languages.DocumentHighlightKind.Read;
|
|
1086
|
+
case DocumentHighlightKind.Write:
|
|
1087
|
+
return this._monaco.languages.DocumentHighlightKind.Write;
|
|
1088
|
+
}
|
|
1089
|
+
return this._monaco.languages.DocumentHighlightKind.Text;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
asReferences(values: Location[]): monaco.languages.Location[];
|
|
1093
|
+
asReferences(values: undefined | null): monaco.languages.Location[] | undefined;
|
|
1094
|
+
asReferences(
|
|
1095
|
+
values: Location[] | undefined | null,
|
|
1096
|
+
): monaco.languages.Location[] | undefined;
|
|
1097
|
+
asReferences(
|
|
1098
|
+
values: Location[] | undefined | null,
|
|
1099
|
+
): monaco.languages.Location[] | undefined {
|
|
1100
|
+
if (!values) {
|
|
1101
|
+
return undefined;
|
|
1102
|
+
}
|
|
1103
|
+
return values.map((location) => this.asLocation(location));
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
asDefinitionResult(item: Definition): monaco.languages.Definition;
|
|
1107
|
+
asDefinitionResult(item: DefinitionLink[]): monaco.languages.Definition;
|
|
1108
|
+
asDefinitionResult(item: undefined | null): undefined;
|
|
1109
|
+
asDefinitionResult(
|
|
1110
|
+
item: Definition | DefinitionLink[] | undefined | null,
|
|
1111
|
+
): monaco.languages.Definition | undefined;
|
|
1112
|
+
asDefinitionResult(
|
|
1113
|
+
item: Definition | DefinitionLink[] | undefined | null,
|
|
1114
|
+
): monaco.languages.Definition | undefined {
|
|
1115
|
+
if (!item) {
|
|
1116
|
+
return undefined;
|
|
1117
|
+
}
|
|
1118
|
+
if (Array.isArray(item)) {
|
|
1119
|
+
if (item.length === 0) {
|
|
1120
|
+
return undefined;
|
|
1121
|
+
} else if (LocationLink.is(item[0])) {
|
|
1122
|
+
const links: LocationLink[] = item as LocationLink[];
|
|
1123
|
+
return links.map((location) => this.asLocationLink(location));
|
|
1124
|
+
} else {
|
|
1125
|
+
const locations: Location[] = item as Location[];
|
|
1126
|
+
return locations.map((location) => this.asLocation(location));
|
|
1127
|
+
}
|
|
1128
|
+
} else {
|
|
1129
|
+
return this.asLocation(item);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
asLocation(item: Location): monaco.languages.Location;
|
|
1134
|
+
asLocation(item: undefined | null): undefined;
|
|
1135
|
+
asLocation(item: Location | undefined | null): monaco.languages.Location | undefined;
|
|
1136
|
+
asLocation(item: Location | undefined | null): monaco.languages.Location | undefined {
|
|
1137
|
+
if (!item) {
|
|
1138
|
+
return undefined;
|
|
1139
|
+
}
|
|
1140
|
+
const uri = this._monaco.Uri.parse(item.uri);
|
|
1141
|
+
const range = this.asRange(item.range)!;
|
|
1142
|
+
return {
|
|
1143
|
+
uri,
|
|
1144
|
+
range,
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
asLocationLink(item: undefined | null): undefined;
|
|
1149
|
+
asLocationLink(item: ls.LocationLink): monaco.languages.LocationLink;
|
|
1150
|
+
asLocationLink(
|
|
1151
|
+
item: ls.LocationLink | undefined | null,
|
|
1152
|
+
): monaco.languages.LocationLink | undefined {
|
|
1153
|
+
if (!item) {
|
|
1154
|
+
return undefined;
|
|
1155
|
+
}
|
|
1156
|
+
const result: monaco.languages.LocationLink = {
|
|
1157
|
+
uri: this._monaco.Uri.parse(item.targetUri),
|
|
1158
|
+
range: this.asRange(item.targetSelectionRange)!, // See issue: https://github.com/Microsoft/vscode/issues/58649
|
|
1159
|
+
originSelectionRange: this.asRange(item.originSelectionRange),
|
|
1160
|
+
targetSelectionRange: this.asRange(item.targetSelectionRange),
|
|
1161
|
+
};
|
|
1162
|
+
if (!result.targetSelectionRange) {
|
|
1163
|
+
throw new Error(`targetSelectionRange must not be undefined or null`);
|
|
1164
|
+
}
|
|
1165
|
+
return result;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
asSignatureHelpResult(item: undefined | null): undefined;
|
|
1169
|
+
asSignatureHelpResult(item: SignatureHelp): monaco.languages.SignatureHelpResult;
|
|
1170
|
+
asSignatureHelpResult(
|
|
1171
|
+
item: SignatureHelp | undefined | null,
|
|
1172
|
+
): monaco.languages.SignatureHelpResult | undefined;
|
|
1173
|
+
asSignatureHelpResult(
|
|
1174
|
+
item: SignatureHelp | undefined | null,
|
|
1175
|
+
): monaco.languages.SignatureHelpResult | undefined {
|
|
1176
|
+
if (!item) {
|
|
1177
|
+
return undefined;
|
|
1178
|
+
}
|
|
1179
|
+
const result = <monaco.languages.SignatureHelp>{};
|
|
1180
|
+
if (Is.isNumber(item.activeSignature)) {
|
|
1181
|
+
result.activeSignature = item.activeSignature;
|
|
1182
|
+
} else {
|
|
1183
|
+
// activeSignature was optional in the past
|
|
1184
|
+
result.activeSignature = 0;
|
|
1185
|
+
}
|
|
1186
|
+
if (Is.isNumber(item.activeParameter)) {
|
|
1187
|
+
result.activeParameter = item.activeParameter;
|
|
1188
|
+
} else {
|
|
1189
|
+
// activeParameter was optional in the past
|
|
1190
|
+
result.activeParameter = 0;
|
|
1191
|
+
}
|
|
1192
|
+
if (item.signatures) {
|
|
1193
|
+
result.signatures = this.asSignatureInformations(item.signatures);
|
|
1194
|
+
} else {
|
|
1195
|
+
result.signatures = [];
|
|
1196
|
+
}
|
|
1197
|
+
return {
|
|
1198
|
+
value: result,
|
|
1199
|
+
dispose: () => {},
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
asSignatureInformations(
|
|
1204
|
+
items: SignatureInformation[],
|
|
1205
|
+
): monaco.languages.SignatureInformation[] {
|
|
1206
|
+
return items.map((item) => this.asSignatureInformation(item));
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
asSignatureInformation(
|
|
1210
|
+
item: SignatureInformation,
|
|
1211
|
+
): monaco.languages.SignatureInformation {
|
|
1212
|
+
const result = <monaco.languages.SignatureInformation>{ label: item.label };
|
|
1213
|
+
if (item.documentation) {
|
|
1214
|
+
result.documentation = this.asDocumentation(item.documentation);
|
|
1215
|
+
}
|
|
1216
|
+
if (item.parameters) {
|
|
1217
|
+
result.parameters = this.asParameterInformations(item.parameters);
|
|
1218
|
+
} else {
|
|
1219
|
+
result.parameters = [];
|
|
1220
|
+
}
|
|
1221
|
+
if (item.activeParameter) {
|
|
1222
|
+
result.activeParameter = item.activeParameter;
|
|
1223
|
+
}
|
|
1224
|
+
return result;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
asParameterInformations(
|
|
1228
|
+
item: ParameterInformation[],
|
|
1229
|
+
): monaco.languages.ParameterInformation[] {
|
|
1230
|
+
return item.map((item) => this.asParameterInformation(item));
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
asParameterInformation(
|
|
1234
|
+
item: ParameterInformation,
|
|
1235
|
+
): monaco.languages.ParameterInformation {
|
|
1236
|
+
const result = <monaco.languages.ParameterInformation>{ label: item.label };
|
|
1237
|
+
if (item.documentation) {
|
|
1238
|
+
result.documentation = this.asDocumentation(item.documentation);
|
|
1239
|
+
}
|
|
1240
|
+
return result;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
asHover(hover: Hover): monaco.languages.Hover;
|
|
1244
|
+
asHover(hover: undefined | null): undefined;
|
|
1245
|
+
asHover(hover: Hover | undefined | null): monaco.languages.Hover | undefined;
|
|
1246
|
+
asHover(hover: Hover | undefined | null): monaco.languages.Hover | undefined {
|
|
1247
|
+
if (!hover) {
|
|
1248
|
+
return undefined;
|
|
1249
|
+
}
|
|
1250
|
+
return {
|
|
1251
|
+
contents: this.asHoverContent(hover.contents),
|
|
1252
|
+
range: this.asRange(hover.range),
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
asHoverContent(
|
|
1257
|
+
contents: MarkedString | MarkedString[] | MarkupContent,
|
|
1258
|
+
): monaco.IMarkdownString[] {
|
|
1259
|
+
if (Array.isArray(contents)) {
|
|
1260
|
+
return contents.map((content) => this.asMarkdownString(content));
|
|
1261
|
+
}
|
|
1262
|
+
return [this.asMarkdownString(contents)];
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
asDocumentation(value: string | MarkupContent): string | monaco.IMarkdownString {
|
|
1266
|
+
if (Is.isString(value)) {
|
|
1267
|
+
return value;
|
|
1268
|
+
}
|
|
1269
|
+
if (value.kind === MarkupKind.PlainText) {
|
|
1270
|
+
return value.value;
|
|
1271
|
+
}
|
|
1272
|
+
return this.asMarkdownString(value);
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
asMarkdownString(content: MarkedString | MarkupContent): monaco.IMarkdownString {
|
|
1276
|
+
if (MarkupContent.is(content)) {
|
|
1277
|
+
return {
|
|
1278
|
+
value: content.value,
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
if (Is.isString(content)) {
|
|
1282
|
+
return { value: content };
|
|
1283
|
+
}
|
|
1284
|
+
const { language, value } = content;
|
|
1285
|
+
return {
|
|
1286
|
+
value: '```' + language + '\n' + value + '\n```',
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
asSeverity(severity?: ls.DiagnosticSeverity): monaco.MarkerSeverity {
|
|
1291
|
+
if (severity === 1) {
|
|
1292
|
+
return this._monaco.MarkerSeverity.Error;
|
|
1293
|
+
}
|
|
1294
|
+
if (severity === 2) {
|
|
1295
|
+
return this._monaco.MarkerSeverity.Warning;
|
|
1296
|
+
}
|
|
1297
|
+
if (severity === 3) {
|
|
1298
|
+
return this._monaco.MarkerSeverity.Info;
|
|
1299
|
+
}
|
|
1300
|
+
return this._monaco.MarkerSeverity.Hint;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
asDiagnostics(diagnostics: undefined): undefined;
|
|
1304
|
+
asDiagnostics(diagnostics: Diagnostic[]): monaco.editor.IMarkerData[];
|
|
1305
|
+
asDiagnostics(
|
|
1306
|
+
diagnostics: Diagnostic[] | undefined,
|
|
1307
|
+
): monaco.editor.IMarkerData[] | undefined;
|
|
1308
|
+
asDiagnostics(
|
|
1309
|
+
diagnostics: Diagnostic[] | undefined,
|
|
1310
|
+
): monaco.editor.IMarkerData[] | undefined {
|
|
1311
|
+
if (!diagnostics) {
|
|
1312
|
+
return undefined;
|
|
1313
|
+
}
|
|
1314
|
+
return diagnostics.map((diagnostic) => this.asDiagnostic(diagnostic));
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
asDiagnostic(diagnostic: Diagnostic): monaco.editor.IMarkerData {
|
|
1318
|
+
return {
|
|
1319
|
+
code:
|
|
1320
|
+
typeof diagnostic.code === 'number'
|
|
1321
|
+
? diagnostic.code.toString()
|
|
1322
|
+
: diagnostic.code,
|
|
1323
|
+
severity: this.asSeverity(diagnostic.severity),
|
|
1324
|
+
message: diagnostic.message,
|
|
1325
|
+
source: diagnostic.source,
|
|
1326
|
+
startLineNumber: diagnostic.range.start.line + 1,
|
|
1327
|
+
startColumn: diagnostic.range.start.character + 1,
|
|
1328
|
+
endLineNumber: diagnostic.range.end.line + 1,
|
|
1329
|
+
endColumn: diagnostic.range.end.character + 1,
|
|
1330
|
+
relatedInformation: this.asRelatedInformations(diagnostic.relatedInformation),
|
|
1331
|
+
tags: diagnostic.tags,
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
asRelatedInformations(
|
|
1336
|
+
relatedInformation?: DiagnosticRelatedInformation[],
|
|
1337
|
+
): monaco.editor.IRelatedInformation[] | undefined {
|
|
1338
|
+
if (!relatedInformation) {
|
|
1339
|
+
return undefined;
|
|
1340
|
+
}
|
|
1341
|
+
return relatedInformation.map((item) => this.asRelatedInformation(item));
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
asRelatedInformation(
|
|
1345
|
+
relatedInformation: DiagnosticRelatedInformation,
|
|
1346
|
+
): monaco.editor.IRelatedInformation {
|
|
1347
|
+
return {
|
|
1348
|
+
resource: this._monaco.Uri.parse(relatedInformation.location.uri),
|
|
1349
|
+
startLineNumber: relatedInformation.location.range.start.line + 1,
|
|
1350
|
+
startColumn: relatedInformation.location.range.start.character + 1,
|
|
1351
|
+
endLineNumber: relatedInformation.location.range.end.line + 1,
|
|
1352
|
+
endColumn: relatedInformation.location.range.end.character + 1,
|
|
1353
|
+
message: relatedInformation.message,
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
asCompletionResult(
|
|
1358
|
+
result: CompletionItem[] | CompletionList | null | undefined,
|
|
1359
|
+
defaultMonacoRange: monaco.IRange,
|
|
1360
|
+
): monaco.languages.CompletionList {
|
|
1361
|
+
if (!result) {
|
|
1362
|
+
return {
|
|
1363
|
+
incomplete: false,
|
|
1364
|
+
suggestions: [],
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
if (Array.isArray(result)) {
|
|
1368
|
+
const suggestions = result.map((item) =>
|
|
1369
|
+
this.asCompletionItem(item, defaultMonacoRange, defaultRange),
|
|
1370
|
+
);
|
|
1371
|
+
return {
|
|
1372
|
+
incomplete: false,
|
|
1373
|
+
suggestions,
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
const defaultRange = this.getCompletionItemDefaultRange(result);
|
|
1377
|
+
return {
|
|
1378
|
+
incomplete: result.isIncomplete,
|
|
1379
|
+
suggestions: result.items.map((item) =>
|
|
1380
|
+
this.asCompletionItem(
|
|
1381
|
+
item,
|
|
1382
|
+
defaultMonacoRange,
|
|
1383
|
+
defaultRange,
|
|
1384
|
+
result.itemDefaults,
|
|
1385
|
+
),
|
|
1386
|
+
),
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
asCompletionItem(
|
|
1391
|
+
item: CompletionItem,
|
|
1392
|
+
defaultMonacoRange: monaco.IRange | RangeReplace,
|
|
1393
|
+
defaultRange?: monaco.IRange | RangeReplace,
|
|
1394
|
+
itemDefaults?: CompletionList['itemDefaults'],
|
|
1395
|
+
): ProtocolCompletionItem {
|
|
1396
|
+
const result = <ProtocolCompletionItem>{ label: this.asCompletionItemLabel(item) };
|
|
1397
|
+
if (item.detail) {
|
|
1398
|
+
result.detail = item.detail;
|
|
1399
|
+
}
|
|
1400
|
+
if (item.documentation) {
|
|
1401
|
+
result.documentation = this.asDocumentation(item.documentation);
|
|
1402
|
+
result.documentationFormat = Is.isString(item.documentation)
|
|
1403
|
+
? undefined
|
|
1404
|
+
: item.documentation.kind;
|
|
1405
|
+
}
|
|
1406
|
+
if (item.filterText) {
|
|
1407
|
+
result.filterText = item.filterText;
|
|
1408
|
+
}
|
|
1409
|
+
const insertText = this.asCompletionInsertText(
|
|
1410
|
+
item,
|
|
1411
|
+
defaultRange,
|
|
1412
|
+
itemDefaults?.insertTextFormat,
|
|
1413
|
+
);
|
|
1414
|
+
result.insertText = insertText.insertText;
|
|
1415
|
+
result.range = insertText.range ?? defaultMonacoRange;
|
|
1416
|
+
result.fromEdit = insertText.fromEdit;
|
|
1417
|
+
if (insertText.isSnippet) {
|
|
1418
|
+
result.insertTextRules =
|
|
1419
|
+
this._monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
|
1420
|
+
}
|
|
1421
|
+
if (Is.isNumber(item.kind)) {
|
|
1422
|
+
const [itemKind, original] = this.asCompletionItemKind(item.kind);
|
|
1423
|
+
result.kind = itemKind;
|
|
1424
|
+
if (original) {
|
|
1425
|
+
result.originalItemKind = original;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
if (item.sortText) {
|
|
1429
|
+
result.sortText = item.sortText;
|
|
1430
|
+
}
|
|
1431
|
+
if (item.additionalTextEdits) {
|
|
1432
|
+
result.additionalTextEdits = this.asTextEdits(item.additionalTextEdits);
|
|
1433
|
+
}
|
|
1434
|
+
if (Is.isStringArray(item.commitCharacters)) {
|
|
1435
|
+
result.commitCharacters = item.commitCharacters.slice();
|
|
1436
|
+
}
|
|
1437
|
+
if (item.command) {
|
|
1438
|
+
result.command = this.asCommand(item.command);
|
|
1439
|
+
}
|
|
1440
|
+
if (item.deprecated === true || item.deprecated === false) {
|
|
1441
|
+
result.deprecated = item.deprecated;
|
|
1442
|
+
}
|
|
1443
|
+
if (item.preselect === true || item.preselect === false) {
|
|
1444
|
+
result.preselect = item.preselect;
|
|
1445
|
+
}
|
|
1446
|
+
const data = item.data ?? itemDefaults?.data;
|
|
1447
|
+
if (data !== undefined) {
|
|
1448
|
+
result.data = data;
|
|
1449
|
+
}
|
|
1450
|
+
if (item.deprecated === true || item.deprecated === false) {
|
|
1451
|
+
result.deprecated = item.deprecated;
|
|
1452
|
+
}
|
|
1453
|
+
const insertTextMode = item.insertTextMode ?? itemDefaults?.insertTextMode;
|
|
1454
|
+
if (insertTextMode) {
|
|
1455
|
+
result.insertTextMode = insertTextMode;
|
|
1456
|
+
}
|
|
1457
|
+
if (item.tags) {
|
|
1458
|
+
result.tags = item.tags;
|
|
1459
|
+
}
|
|
1460
|
+
return result;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
getCompletionItemDefaultRange(
|
|
1464
|
+
list: CompletionList,
|
|
1465
|
+
): monaco.Range | RangeReplace | undefined {
|
|
1466
|
+
const rangeDefaults = list.itemDefaults?.editRange;
|
|
1467
|
+
return ls.Range.is(rangeDefaults)
|
|
1468
|
+
? this.asRange(rangeDefaults)
|
|
1469
|
+
: rangeDefaults !== undefined
|
|
1470
|
+
? {
|
|
1471
|
+
insert: this.asRange(rangeDefaults.insert),
|
|
1472
|
+
replace: this.asRange(rangeDefaults.replace),
|
|
1473
|
+
}
|
|
1474
|
+
: undefined;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
asCompletionItemLabel(
|
|
1478
|
+
item: ls.CompletionItem,
|
|
1479
|
+
): monaco.languages.CompletionItemLabel | string {
|
|
1480
|
+
if (ls.CompletionItemLabelDetails.is(item.labelDetails)) {
|
|
1481
|
+
return {
|
|
1482
|
+
label: item.label,
|
|
1483
|
+
detail: item.labelDetails.detail,
|
|
1484
|
+
description: item.labelDetails.description,
|
|
1485
|
+
};
|
|
1486
|
+
} else {
|
|
1487
|
+
return item.label;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
asCompletionItemKind(
|
|
1492
|
+
value: CompletionItemKind,
|
|
1493
|
+
): [monaco.languages.CompletionItemKind, CompletionItemKind | undefined] {
|
|
1494
|
+
if (CompletionItemKind.Text <= value && value <= CompletionItemKind.TypeParameter) {
|
|
1495
|
+
switch (value) {
|
|
1496
|
+
case CompletionItemKind.Text:
|
|
1497
|
+
return [this._monaco.languages.CompletionItemKind.Text, undefined];
|
|
1498
|
+
case CompletionItemKind.Method:
|
|
1499
|
+
return [this._monaco.languages.CompletionItemKind.Method, undefined];
|
|
1500
|
+
case CompletionItemKind.Function:
|
|
1501
|
+
return [this._monaco.languages.CompletionItemKind.Function, undefined];
|
|
1502
|
+
case CompletionItemKind.Constructor:
|
|
1503
|
+
return [this._monaco.languages.CompletionItemKind.Constructor, undefined];
|
|
1504
|
+
case CompletionItemKind.Field:
|
|
1505
|
+
return [this._monaco.languages.CompletionItemKind.Field, undefined];
|
|
1506
|
+
case CompletionItemKind.Variable:
|
|
1507
|
+
return [this._monaco.languages.CompletionItemKind.Variable, undefined];
|
|
1508
|
+
case CompletionItemKind.Class:
|
|
1509
|
+
return [this._monaco.languages.CompletionItemKind.Class, undefined];
|
|
1510
|
+
case CompletionItemKind.Interface:
|
|
1511
|
+
return [this._monaco.languages.CompletionItemKind.Interface, undefined];
|
|
1512
|
+
case CompletionItemKind.Module:
|
|
1513
|
+
return [this._monaco.languages.CompletionItemKind.Module, undefined];
|
|
1514
|
+
case CompletionItemKind.Property:
|
|
1515
|
+
return [this._monaco.languages.CompletionItemKind.Property, undefined];
|
|
1516
|
+
case CompletionItemKind.Unit:
|
|
1517
|
+
return [this._monaco.languages.CompletionItemKind.Unit, undefined];
|
|
1518
|
+
case CompletionItemKind.Value:
|
|
1519
|
+
return [this._monaco.languages.CompletionItemKind.Value, undefined];
|
|
1520
|
+
case CompletionItemKind.Enum:
|
|
1521
|
+
return [this._monaco.languages.CompletionItemKind.Enum, undefined];
|
|
1522
|
+
case CompletionItemKind.Keyword:
|
|
1523
|
+
return [this._monaco.languages.CompletionItemKind.Keyword, undefined];
|
|
1524
|
+
case CompletionItemKind.Snippet:
|
|
1525
|
+
return [this._monaco.languages.CompletionItemKind.Snippet, undefined];
|
|
1526
|
+
case CompletionItemKind.Color:
|
|
1527
|
+
return [this._monaco.languages.CompletionItemKind.Color, undefined];
|
|
1528
|
+
case CompletionItemKind.File:
|
|
1529
|
+
return [this._monaco.languages.CompletionItemKind.File, undefined];
|
|
1530
|
+
case CompletionItemKind.Reference:
|
|
1531
|
+
return [this._monaco.languages.CompletionItemKind.Reference, undefined];
|
|
1532
|
+
case CompletionItemKind.Folder:
|
|
1533
|
+
return [this._monaco.languages.CompletionItemKind.Folder, undefined];
|
|
1534
|
+
case CompletionItemKind.EnumMember:
|
|
1535
|
+
return [this._monaco.languages.CompletionItemKind.EnumMember, undefined];
|
|
1536
|
+
case CompletionItemKind.Constant:
|
|
1537
|
+
return [this._monaco.languages.CompletionItemKind.Constant, undefined];
|
|
1538
|
+
case CompletionItemKind.Struct:
|
|
1539
|
+
return [this._monaco.languages.CompletionItemKind.Struct, undefined];
|
|
1540
|
+
case CompletionItemKind.Event:
|
|
1541
|
+
return [this._monaco.languages.CompletionItemKind.Event, undefined];
|
|
1542
|
+
case CompletionItemKind.Operator:
|
|
1543
|
+
return [this._monaco.languages.CompletionItemKind.Operator, undefined];
|
|
1544
|
+
case CompletionItemKind.TypeParameter:
|
|
1545
|
+
return [this._monaco.languages.CompletionItemKind.TypeParameter, undefined];
|
|
1546
|
+
default:
|
|
1547
|
+
return [value - 1, undefined];
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
return [CompletionItemKind.Text, value];
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
asCompletionInsertText(
|
|
1554
|
+
item: CompletionItem,
|
|
1555
|
+
defaultRange?: monaco.IRange | RangeReplace,
|
|
1556
|
+
defaultInsertTextFormat?: InsertTextFormat,
|
|
1557
|
+
): {
|
|
1558
|
+
insertText: string;
|
|
1559
|
+
range?: monaco.IRange | RangeReplace;
|
|
1560
|
+
fromEdit: boolean;
|
|
1561
|
+
isSnippet: boolean;
|
|
1562
|
+
} {
|
|
1563
|
+
const insertTextFormat = item.insertTextFormat ?? defaultInsertTextFormat;
|
|
1564
|
+
|
|
1565
|
+
const isSnippet = insertTextFormat === InsertTextFormat.Snippet;
|
|
1566
|
+
if (item.textEdit !== undefined || defaultRange !== undefined) {
|
|
1567
|
+
const [range, newText] =
|
|
1568
|
+
item.textEdit !== undefined
|
|
1569
|
+
? this.getCompletionRangeAndText(item.textEdit)
|
|
1570
|
+
: [defaultRange, item.textEditText ?? item.label];
|
|
1571
|
+
|
|
1572
|
+
return { insertText: newText, range: range, fromEdit: true, isSnippet };
|
|
1573
|
+
} else if (item.insertText) {
|
|
1574
|
+
return {
|
|
1575
|
+
isSnippet,
|
|
1576
|
+
insertText: item.insertText,
|
|
1577
|
+
fromEdit: false,
|
|
1578
|
+
range: defaultRange,
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
return {
|
|
1582
|
+
insertText: item.label,
|
|
1583
|
+
range: defaultRange,
|
|
1584
|
+
fromEdit: false,
|
|
1585
|
+
isSnippet: false,
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
getCompletionRangeAndText(
|
|
1590
|
+
value: ls.TextEdit | ls.InsertReplaceEdit,
|
|
1591
|
+
): [monaco.Range | RangeReplace, string] {
|
|
1592
|
+
if (ls.InsertReplaceEdit.is(value)) {
|
|
1593
|
+
return [
|
|
1594
|
+
{ insert: this.asRange(value.insert), replace: this.asRange(value.replace) },
|
|
1595
|
+
value.newText,
|
|
1596
|
+
];
|
|
1597
|
+
} else {
|
|
1598
|
+
return [this.asRange(value.range), value.newText];
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
asDocumentLinks(documentLinks: DocumentLink[]): monaco.languages.ILinksList {
|
|
1603
|
+
const links = documentLinks.map((link) => this.asDocumentLink(link));
|
|
1604
|
+
return { links };
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
asDocumentLink(documentLink: DocumentLink): ProtocolDocumentLink {
|
|
1608
|
+
return {
|
|
1609
|
+
range: this.asRange(documentLink.range),
|
|
1610
|
+
url: documentLink.target,
|
|
1611
|
+
data: documentLink.data,
|
|
1612
|
+
tooltip: documentLink.tooltip,
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
asRange(range: null): null;
|
|
1617
|
+
asRange(range: undefined): undefined;
|
|
1618
|
+
asRange(range: Range): monaco.Range;
|
|
1619
|
+
asRange(range: Range | undefined): monaco.Range | undefined;
|
|
1620
|
+
asRange(range: Range | null): monaco.Range | null;
|
|
1621
|
+
asRange(range: RecursivePartial<Range>): Partial<monaco.IRange>;
|
|
1622
|
+
asRange(
|
|
1623
|
+
range: RecursivePartial<Range> | undefined,
|
|
1624
|
+
): monaco.Range | Partial<monaco.IRange> | undefined;
|
|
1625
|
+
asRange(
|
|
1626
|
+
range: RecursivePartial<Range> | null,
|
|
1627
|
+
): monaco.Range | Partial<monaco.IRange> | null;
|
|
1628
|
+
asRange(
|
|
1629
|
+
range: RecursivePartial<Range> | undefined | null,
|
|
1630
|
+
): monaco.Range | Partial<monaco.IRange> | undefined | null {
|
|
1631
|
+
if (range === undefined) {
|
|
1632
|
+
return undefined;
|
|
1633
|
+
}
|
|
1634
|
+
if (range === null) {
|
|
1635
|
+
return null;
|
|
1636
|
+
}
|
|
1637
|
+
const start = this.asPosition(range.start);
|
|
1638
|
+
const end = this.asPosition(range.end);
|
|
1639
|
+
if (
|
|
1640
|
+
start instanceof this._monaco.Position &&
|
|
1641
|
+
end instanceof this._monaco.Position
|
|
1642
|
+
) {
|
|
1643
|
+
return new this._monaco.Range(
|
|
1644
|
+
start.lineNumber,
|
|
1645
|
+
start.column,
|
|
1646
|
+
end.lineNumber,
|
|
1647
|
+
end.column,
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
const startLineNumber =
|
|
1651
|
+
!start || start.lineNumber === undefined ? undefined : start.lineNumber;
|
|
1652
|
+
const startColumn = !start || start.column === undefined ? undefined : start.column;
|
|
1653
|
+
const endLineNumber =
|
|
1654
|
+
!end || end.lineNumber === undefined ? undefined : end.lineNumber;
|
|
1655
|
+
const endColumn = !end || end.column === undefined ? undefined : end.column;
|
|
1656
|
+
return { startLineNumber, startColumn, endLineNumber, endColumn };
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
asPosition(position: null): null;
|
|
1660
|
+
asPosition(position: undefined): undefined;
|
|
1661
|
+
asPosition(position: Position): monaco.Position;
|
|
1662
|
+
asPosition(position: Position | undefined): monaco.Position | undefined;
|
|
1663
|
+
asPosition(position: Position | null): monaco.Position | null;
|
|
1664
|
+
asPosition(position: Partial<Position>): Partial<monaco.IPosition>;
|
|
1665
|
+
asPosition(
|
|
1666
|
+
position: Partial<Position> | undefined,
|
|
1667
|
+
): monaco.Position | Partial<monaco.IPosition> | undefined;
|
|
1668
|
+
asPosition(
|
|
1669
|
+
position: Partial<Position> | null,
|
|
1670
|
+
): monaco.Position | Partial<monaco.IPosition> | null;
|
|
1671
|
+
asPosition(
|
|
1672
|
+
position: Partial<Position> | undefined | null,
|
|
1673
|
+
): monaco.Position | Partial<monaco.IPosition> | undefined | null {
|
|
1674
|
+
if (position === undefined) {
|
|
1675
|
+
return undefined;
|
|
1676
|
+
}
|
|
1677
|
+
if (position === null) {
|
|
1678
|
+
return null;
|
|
1679
|
+
}
|
|
1680
|
+
const { line, character } = position;
|
|
1681
|
+
const lineNumber = line === undefined ? undefined : line + 1;
|
|
1682
|
+
const column = character === undefined ? undefined : character + 1;
|
|
1683
|
+
if (lineNumber !== undefined && column !== undefined) {
|
|
1684
|
+
return new this._monaco.Position(lineNumber, column);
|
|
1685
|
+
}
|
|
1686
|
+
return { lineNumber, column };
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
asColorInformations(items: ColorInformation[]): monaco.languages.IColorInformation[] {
|
|
1690
|
+
return items.map((item) => this.asColorInformation(item));
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
asColorInformation(item: ColorInformation): monaco.languages.IColorInformation {
|
|
1694
|
+
return {
|
|
1695
|
+
range: this.asRange(item.range),
|
|
1696
|
+
color: item.color,
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
asColorPresentations(
|
|
1701
|
+
items: ColorPresentation[],
|
|
1702
|
+
): monaco.languages.IColorPresentation[] {
|
|
1703
|
+
return items.map((item) => this.asColorPresentation(item));
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
asColorPresentation(item: ColorPresentation): monaco.languages.IColorPresentation {
|
|
1707
|
+
return {
|
|
1708
|
+
label: item.label,
|
|
1709
|
+
textEdit: this.asTextEdit(item.textEdit),
|
|
1710
|
+
additionalTextEdits: this.asTextEdits(item.additionalTextEdits),
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
asFoldingRanges(items: undefined | null): undefined | null;
|
|
1715
|
+
asFoldingRanges(items: FoldingRange[]): monaco.languages.FoldingRange[];
|
|
1716
|
+
asFoldingRanges(
|
|
1717
|
+
items: FoldingRange[] | undefined | null,
|
|
1718
|
+
): monaco.languages.FoldingRange[] | undefined | null {
|
|
1719
|
+
if (!items) {
|
|
1720
|
+
return items;
|
|
1721
|
+
}
|
|
1722
|
+
return items.map((item) => this.asFoldingRange(item));
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
asFoldingRange(item: FoldingRange): monaco.languages.FoldingRange {
|
|
1726
|
+
return {
|
|
1727
|
+
start: item.startLine + 1,
|
|
1728
|
+
end: item.endLine + 1,
|
|
1729
|
+
kind: this.asFoldingRangeKind(item.kind),
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
asFoldingRangeKind(kind?: string): monaco.languages.FoldingRangeKind | undefined {
|
|
1734
|
+
if (kind) {
|
|
1735
|
+
switch (kind) {
|
|
1736
|
+
case FoldingRangeKind.Comment:
|
|
1737
|
+
return this._monaco.languages.FoldingRangeKind.Comment;
|
|
1738
|
+
case FoldingRangeKind.Imports:
|
|
1739
|
+
return this._monaco.languages.FoldingRangeKind.Imports;
|
|
1740
|
+
case FoldingRangeKind.Region:
|
|
1741
|
+
return this._monaco.languages.FoldingRangeKind.Region;
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
return undefined;
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
asSemanticTokens(semanticTokens: SemanticTokens): monaco.languages.SemanticTokens {
|
|
1748
|
+
return {
|
|
1749
|
+
resultId: semanticTokens.resultId,
|
|
1750
|
+
data: Uint32Array.from(semanticTokens.data),
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
asInlayHintLabelPart(part: InlayHintLabelPart): monaco.languages.InlayHintLabelPart {
|
|
1755
|
+
return {
|
|
1756
|
+
label: part.value,
|
|
1757
|
+
command: this.asCommand(part.command),
|
|
1758
|
+
location: this.asLocation(part.location),
|
|
1759
|
+
tooltip: part.tooltip && this.asMarkdownString(part.tooltip),
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
asInlayHintLabel(
|
|
1764
|
+
label: string | InlayHintLabelPart[],
|
|
1765
|
+
): string | monaco.languages.InlayHintLabelPart[] {
|
|
1766
|
+
if (Array.isArray(label)) {
|
|
1767
|
+
return label.map((part) => this.asInlayHintLabelPart(part));
|
|
1768
|
+
}
|
|
1769
|
+
return label;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
asInlayHint(inlayHint: InlayHint): ProtocolInlayHint {
|
|
1773
|
+
return {
|
|
1774
|
+
data: inlayHint.data,
|
|
1775
|
+
label: this.asInlayHintLabel(inlayHint.label),
|
|
1776
|
+
position: this.asPosition(inlayHint.position),
|
|
1777
|
+
kind: inlayHint.kind,
|
|
1778
|
+
paddingLeft: inlayHint.paddingLeft,
|
|
1779
|
+
paddingRight: inlayHint.paddingRight,
|
|
1780
|
+
tooltip: inlayHint.tooltip && this.asMarkdownString(inlayHint.tooltip),
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
asInlayHintList(items: InlayHint[]): monaco.languages.InlayHintList;
|
|
1785
|
+
asInlayHintList(items: undefined | null): undefined;
|
|
1786
|
+
asInlayHintList(
|
|
1787
|
+
items: InlayHint[] | undefined | null,
|
|
1788
|
+
): monaco.languages.InlayHintList | undefined;
|
|
1789
|
+
asInlayHintList(
|
|
1790
|
+
items: InlayHint[] | undefined | null,
|
|
1791
|
+
): monaco.languages.InlayHintList | undefined {
|
|
1792
|
+
if (!items) {
|
|
1793
|
+
return undefined;
|
|
1794
|
+
}
|
|
1795
|
+
return {
|
|
1796
|
+
hints: items.map((hint) => this.asInlayHint(hint)),
|
|
1797
|
+
dispose: () => {},
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
}
|