@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,819 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
* ------------------------------------------------------------------------------------------ */
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
ClientCapabilities,
|
|
8
|
+
DidChangeTextDocumentParams,
|
|
9
|
+
DidCloseTextDocumentParams,
|
|
10
|
+
DidOpenTextDocumentParams,
|
|
11
|
+
DidSaveTextDocumentParams,
|
|
12
|
+
DocumentSelector,
|
|
13
|
+
ProtocolNotificationType,
|
|
14
|
+
RegistrationType,
|
|
15
|
+
SaveOptions,
|
|
16
|
+
ServerCapabilities,
|
|
17
|
+
TextDocumentChangeRegistrationOptions,
|
|
18
|
+
TextDocumentRegistrationOptions,
|
|
19
|
+
TextDocumentSaveRegistrationOptions,
|
|
20
|
+
TextDocumentSyncOptions,
|
|
21
|
+
WillSaveTextDocumentParams,
|
|
22
|
+
} from '@difizen/vscode-languageserver-protocol';
|
|
23
|
+
import {
|
|
24
|
+
DidChangeTextDocumentNotification,
|
|
25
|
+
DidCloseTextDocumentNotification,
|
|
26
|
+
DidOpenTextDocumentNotification,
|
|
27
|
+
DidSaveTextDocumentNotification,
|
|
28
|
+
TextDocumentSyncKind,
|
|
29
|
+
WillSaveTextDocumentNotification,
|
|
30
|
+
WillSaveTextDocumentWaitUntilRequest,
|
|
31
|
+
} from '@difizen/vscode-languageserver-protocol';
|
|
32
|
+
import type {
|
|
33
|
+
TextDocument,
|
|
34
|
+
TextDocumentChangeEvent,
|
|
35
|
+
TextDocumentWillSaveEvent,
|
|
36
|
+
TextEdit as VTextEdit,
|
|
37
|
+
DocumentSelector as VDocumentSelector,
|
|
38
|
+
Event,
|
|
39
|
+
Disposable,
|
|
40
|
+
} from 'vscode';
|
|
41
|
+
|
|
42
|
+
import type {
|
|
43
|
+
FeatureClient,
|
|
44
|
+
DynamicFeature,
|
|
45
|
+
NextSignature,
|
|
46
|
+
TextDocumentSendFeature,
|
|
47
|
+
NotifyingFeature,
|
|
48
|
+
RegistrationData,
|
|
49
|
+
NotificationSendEvent,
|
|
50
|
+
} from './features.js';
|
|
51
|
+
import {
|
|
52
|
+
TextDocumentEventFeature,
|
|
53
|
+
ensure,
|
|
54
|
+
DynamicDocumentFeature,
|
|
55
|
+
} from './features.js';
|
|
56
|
+
import * as UUID from './utils/uuid.js';
|
|
57
|
+
import {
|
|
58
|
+
workspace as Workspace,
|
|
59
|
+
languages as Languages,
|
|
60
|
+
EventEmitter,
|
|
61
|
+
} from './vscodeAdaptor/vscodeAdaptor.js';
|
|
62
|
+
|
|
63
|
+
export interface TextDocumentSynchronizationMiddleware {
|
|
64
|
+
didOpen?: NextSignature<TextDocument, Promise<void>>;
|
|
65
|
+
didChange?: NextSignature<TextDocumentChangeEvent, Promise<void>>;
|
|
66
|
+
willSave?: NextSignature<TextDocumentWillSaveEvent, Promise<void>>;
|
|
67
|
+
willSaveWaitUntil?: NextSignature<TextDocumentWillSaveEvent, Thenable<VTextEdit[]>>;
|
|
68
|
+
didSave?: NextSignature<TextDocument, Promise<void>>;
|
|
69
|
+
didClose?: NextSignature<TextDocument, Promise<void>>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface DidOpenTextDocumentFeatureShape
|
|
73
|
+
extends DynamicFeature<TextDocumentRegistrationOptions>,
|
|
74
|
+
TextDocumentSendFeature<(textDocument: TextDocument) => Promise<void>>,
|
|
75
|
+
NotifyingFeature<DidOpenTextDocumentParams> {
|
|
76
|
+
openDocuments: Iterable<TextDocument>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type ResolvedTextDocumentSyncCapabilities = {
|
|
80
|
+
resolvedTextDocumentSync?: TextDocumentSyncOptions;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export class DidOpenTextDocumentFeature
|
|
84
|
+
extends TextDocumentEventFeature<
|
|
85
|
+
DidOpenTextDocumentParams,
|
|
86
|
+
TextDocument,
|
|
87
|
+
TextDocumentSynchronizationMiddleware
|
|
88
|
+
>
|
|
89
|
+
implements DidOpenTextDocumentFeatureShape
|
|
90
|
+
{
|
|
91
|
+
private readonly _syncedDocuments: Map<string, TextDocument>;
|
|
92
|
+
|
|
93
|
+
constructor(
|
|
94
|
+
client: FeatureClient<TextDocumentSynchronizationMiddleware>,
|
|
95
|
+
syncedDocuments: Map<string, TextDocument>,
|
|
96
|
+
) {
|
|
97
|
+
super(
|
|
98
|
+
client,
|
|
99
|
+
Workspace.onDidOpenTextDocument,
|
|
100
|
+
DidOpenTextDocumentNotification.type,
|
|
101
|
+
() => client.middleware.didOpen,
|
|
102
|
+
(textDocument) =>
|
|
103
|
+
client.code2ProtocolConverter.asOpenTextDocumentParams(textDocument),
|
|
104
|
+
(data) => data,
|
|
105
|
+
TextDocumentEventFeature.textDocumentFilter,
|
|
106
|
+
);
|
|
107
|
+
this._syncedDocuments = syncedDocuments;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public get openDocuments(): IterableIterator<TextDocument> {
|
|
111
|
+
return this._syncedDocuments.values();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public fillClientCapabilities(capabilities: ClientCapabilities): void {
|
|
115
|
+
ensure(
|
|
116
|
+
ensure(capabilities, 'textDocument')!,
|
|
117
|
+
'synchronization',
|
|
118
|
+
)!.dynamicRegistration = true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public initialize(
|
|
122
|
+
capabilities: ServerCapabilities,
|
|
123
|
+
documentSelector: DocumentSelector,
|
|
124
|
+
): void {
|
|
125
|
+
const textDocumentSyncOptions = (
|
|
126
|
+
capabilities as ResolvedTextDocumentSyncCapabilities
|
|
127
|
+
).resolvedTextDocumentSync;
|
|
128
|
+
if (
|
|
129
|
+
documentSelector &&
|
|
130
|
+
textDocumentSyncOptions &&
|
|
131
|
+
textDocumentSyncOptions.openClose
|
|
132
|
+
) {
|
|
133
|
+
this.register({
|
|
134
|
+
id: UUID.generateUuid(),
|
|
135
|
+
registerOptions: { documentSelector: documentSelector },
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public get registrationType(): RegistrationType<TextDocumentRegistrationOptions> {
|
|
141
|
+
return DidOpenTextDocumentNotification.type;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public override register(
|
|
145
|
+
data: RegistrationData<TextDocumentRegistrationOptions>,
|
|
146
|
+
): void {
|
|
147
|
+
super.register(data);
|
|
148
|
+
if (!data.registerOptions.documentSelector) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const documentSelector = this._client.protocol2CodeConverter.asDocumentSelector(
|
|
152
|
+
data.registerOptions.documentSelector,
|
|
153
|
+
);
|
|
154
|
+
Workspace.textDocuments.forEach((textDocument) => {
|
|
155
|
+
const uri: string = textDocument.uri.toString();
|
|
156
|
+
if (this._syncedDocuments.has(uri)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (
|
|
160
|
+
Languages.match(documentSelector, textDocument) > 0 &&
|
|
161
|
+
!this._client.hasDedicatedTextSynchronizationFeature(textDocument)
|
|
162
|
+
) {
|
|
163
|
+
const middleware = this._client.middleware;
|
|
164
|
+
const didOpen = (textDocument: TextDocument): Promise<void> => {
|
|
165
|
+
return this._client.sendNotification(
|
|
166
|
+
this._type,
|
|
167
|
+
this._createParams(textDocument),
|
|
168
|
+
);
|
|
169
|
+
};
|
|
170
|
+
(middleware.didOpen
|
|
171
|
+
? middleware.didOpen(textDocument, didOpen)
|
|
172
|
+
: didOpen(textDocument)
|
|
173
|
+
).catch((error) => {
|
|
174
|
+
this._client.error(
|
|
175
|
+
`Sending document notification ${this._type.method} failed`,
|
|
176
|
+
error,
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
this._syncedDocuments.set(uri, textDocument);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
protected getTextDocument(data: TextDocument): TextDocument {
|
|
185
|
+
return data;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
protected override notificationSent(
|
|
189
|
+
textDocument: TextDocument,
|
|
190
|
+
type: ProtocolNotificationType<
|
|
191
|
+
DidOpenTextDocumentParams,
|
|
192
|
+
TextDocumentRegistrationOptions
|
|
193
|
+
>,
|
|
194
|
+
params: DidOpenTextDocumentParams,
|
|
195
|
+
): void {
|
|
196
|
+
this._syncedDocuments.set(textDocument.uri.toString(), textDocument);
|
|
197
|
+
super.notificationSent(textDocument, type, params);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface DidCloseTextDocumentFeatureShape
|
|
202
|
+
extends DynamicFeature<TextDocumentRegistrationOptions>,
|
|
203
|
+
TextDocumentSendFeature<(textDocument: TextDocument) => Promise<void>>,
|
|
204
|
+
NotifyingFeature<DidCloseTextDocumentParams> {}
|
|
205
|
+
|
|
206
|
+
export class DidCloseTextDocumentFeature
|
|
207
|
+
extends TextDocumentEventFeature<
|
|
208
|
+
DidCloseTextDocumentParams,
|
|
209
|
+
TextDocument,
|
|
210
|
+
TextDocumentSynchronizationMiddleware
|
|
211
|
+
>
|
|
212
|
+
implements DidCloseTextDocumentFeatureShape
|
|
213
|
+
{
|
|
214
|
+
private readonly _syncedDocuments: Map<string, TextDocument>;
|
|
215
|
+
private readonly _pendingTextDocumentChanges: Map<string, TextDocument>;
|
|
216
|
+
|
|
217
|
+
constructor(
|
|
218
|
+
client: FeatureClient<TextDocumentSynchronizationMiddleware>,
|
|
219
|
+
syncedDocuments: Map<string, TextDocument>,
|
|
220
|
+
pendingTextDocumentChanges: Map<string, TextDocument>,
|
|
221
|
+
) {
|
|
222
|
+
super(
|
|
223
|
+
client,
|
|
224
|
+
Workspace.onDidCloseTextDocument,
|
|
225
|
+
DidCloseTextDocumentNotification.type,
|
|
226
|
+
() => client.middleware.didClose,
|
|
227
|
+
(textDocument) =>
|
|
228
|
+
client.code2ProtocolConverter.asCloseTextDocumentParams(textDocument),
|
|
229
|
+
(data) => data,
|
|
230
|
+
TextDocumentEventFeature.textDocumentFilter,
|
|
231
|
+
);
|
|
232
|
+
this._syncedDocuments = syncedDocuments;
|
|
233
|
+
this._pendingTextDocumentChanges = pendingTextDocumentChanges;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public get registrationType(): RegistrationType<TextDocumentRegistrationOptions> {
|
|
237
|
+
return DidCloseTextDocumentNotification.type;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public fillClientCapabilities(capabilities: ClientCapabilities): void {
|
|
241
|
+
ensure(
|
|
242
|
+
ensure(capabilities, 'textDocument')!,
|
|
243
|
+
'synchronization',
|
|
244
|
+
)!.dynamicRegistration = true;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public initialize(
|
|
248
|
+
capabilities: ServerCapabilities,
|
|
249
|
+
documentSelector: DocumentSelector,
|
|
250
|
+
): void {
|
|
251
|
+
const textDocumentSyncOptions = (
|
|
252
|
+
capabilities as ResolvedTextDocumentSyncCapabilities
|
|
253
|
+
).resolvedTextDocumentSync;
|
|
254
|
+
if (
|
|
255
|
+
documentSelector &&
|
|
256
|
+
textDocumentSyncOptions &&
|
|
257
|
+
textDocumentSyncOptions.openClose
|
|
258
|
+
) {
|
|
259
|
+
this.register({
|
|
260
|
+
id: UUID.generateUuid(),
|
|
261
|
+
registerOptions: { documentSelector: documentSelector },
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
protected override async callback(data: TextDocument): Promise<void> {
|
|
267
|
+
await super.callback(data);
|
|
268
|
+
this._pendingTextDocumentChanges.delete(data.uri.toString());
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
protected getTextDocument(data: TextDocument): TextDocument {
|
|
272
|
+
return data;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
protected override notificationSent(
|
|
276
|
+
textDocument: TextDocument,
|
|
277
|
+
type: ProtocolNotificationType<
|
|
278
|
+
DidCloseTextDocumentParams,
|
|
279
|
+
TextDocumentRegistrationOptions
|
|
280
|
+
>,
|
|
281
|
+
params: DidCloseTextDocumentParams,
|
|
282
|
+
): void {
|
|
283
|
+
this._syncedDocuments.delete(textDocument.uri.toString());
|
|
284
|
+
super.notificationSent(textDocument, type, params);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public override unregister(id: string): void {
|
|
288
|
+
const selector = this._selectors.get(id)!;
|
|
289
|
+
// The super call removed the selector from the map
|
|
290
|
+
// of selectors.
|
|
291
|
+
super.unregister(id);
|
|
292
|
+
const selectors = this._selectors.values();
|
|
293
|
+
this._syncedDocuments.forEach((textDocument) => {
|
|
294
|
+
if (
|
|
295
|
+
Languages.match(selector, textDocument) > 0 &&
|
|
296
|
+
!this._selectorFilter!(selectors, textDocument) &&
|
|
297
|
+
!this._client.hasDedicatedTextSynchronizationFeature(textDocument)
|
|
298
|
+
) {
|
|
299
|
+
const middleware = this._client.middleware;
|
|
300
|
+
const didClose = (textDocument: TextDocument): Promise<void> => {
|
|
301
|
+
return this._client.sendNotification(
|
|
302
|
+
this._type,
|
|
303
|
+
this._createParams(textDocument),
|
|
304
|
+
);
|
|
305
|
+
};
|
|
306
|
+
this._syncedDocuments.delete(textDocument.uri.toString());
|
|
307
|
+
(middleware.didClose
|
|
308
|
+
? middleware.didClose(textDocument, didClose)
|
|
309
|
+
: didClose(textDocument)
|
|
310
|
+
).catch((error) => {
|
|
311
|
+
this._client.error(
|
|
312
|
+
`Sending document notification ${this._type.method} failed`,
|
|
313
|
+
error,
|
|
314
|
+
);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
interface DidChangeTextDocumentData {
|
|
322
|
+
syncKind: 0 | 1 | 2;
|
|
323
|
+
documentSelector: VDocumentSelector;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface DidChangeTextDocumentFeatureShape
|
|
327
|
+
extends DynamicFeature<TextDocumentChangeRegistrationOptions>,
|
|
328
|
+
TextDocumentSendFeature<(event: TextDocumentChangeEvent) => Promise<void>>,
|
|
329
|
+
NotifyingFeature<DidChangeTextDocumentParams> {}
|
|
330
|
+
|
|
331
|
+
export class DidChangeTextDocumentFeature
|
|
332
|
+
extends DynamicDocumentFeature<
|
|
333
|
+
TextDocumentChangeRegistrationOptions,
|
|
334
|
+
TextDocumentSynchronizationMiddleware
|
|
335
|
+
>
|
|
336
|
+
implements DidChangeTextDocumentFeatureShape
|
|
337
|
+
{
|
|
338
|
+
private _listener: Disposable | undefined;
|
|
339
|
+
private readonly _changeData: Map<string, DidChangeTextDocumentData>;
|
|
340
|
+
private readonly _onNotificationSent: EventEmitter<
|
|
341
|
+
NotificationSendEvent<DidChangeTextDocumentParams>
|
|
342
|
+
>;
|
|
343
|
+
private readonly _onPendingChangeAdded: EventEmitter<void>;
|
|
344
|
+
private readonly _pendingTextDocumentChanges: Map<string, TextDocument>;
|
|
345
|
+
private _syncKind: TextDocumentSyncKind;
|
|
346
|
+
|
|
347
|
+
constructor(
|
|
348
|
+
client: FeatureClient<TextDocumentSynchronizationMiddleware>,
|
|
349
|
+
pendingTextDocumentChanges: Map<string, TextDocument>,
|
|
350
|
+
) {
|
|
351
|
+
super(client);
|
|
352
|
+
this._changeData = new Map<string, DidChangeTextDocumentData>();
|
|
353
|
+
this._onNotificationSent = new EventEmitter();
|
|
354
|
+
this._onPendingChangeAdded = new EventEmitter();
|
|
355
|
+
this._pendingTextDocumentChanges = pendingTextDocumentChanges;
|
|
356
|
+
this._syncKind = TextDocumentSyncKind.None;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
public get onNotificationSent(): Event<
|
|
360
|
+
NotificationSendEvent<DidChangeTextDocumentParams>
|
|
361
|
+
> {
|
|
362
|
+
return this._onNotificationSent.event;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
public get onPendingChangeAdded(): Event<void> {
|
|
366
|
+
return this._onPendingChangeAdded.event;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
public get syncKind(): TextDocumentSyncKind {
|
|
370
|
+
return this._syncKind;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
public get registrationType(): RegistrationType<TextDocumentChangeRegistrationOptions> {
|
|
374
|
+
return DidChangeTextDocumentNotification.type;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
public fillClientCapabilities(capabilities: ClientCapabilities): void {
|
|
378
|
+
ensure(
|
|
379
|
+
ensure(capabilities, 'textDocument')!,
|
|
380
|
+
'synchronization',
|
|
381
|
+
)!.dynamicRegistration = true;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
public initialize(
|
|
385
|
+
capabilities: ServerCapabilities,
|
|
386
|
+
documentSelector: DocumentSelector,
|
|
387
|
+
): void {
|
|
388
|
+
const textDocumentSyncOptions = (
|
|
389
|
+
capabilities as ResolvedTextDocumentSyncCapabilities
|
|
390
|
+
).resolvedTextDocumentSync;
|
|
391
|
+
if (
|
|
392
|
+
documentSelector &&
|
|
393
|
+
textDocumentSyncOptions &&
|
|
394
|
+
textDocumentSyncOptions.change !== undefined &&
|
|
395
|
+
textDocumentSyncOptions.change !== TextDocumentSyncKind.None
|
|
396
|
+
) {
|
|
397
|
+
this.register({
|
|
398
|
+
id: UUID.generateUuid(),
|
|
399
|
+
registerOptions: Object.assign(
|
|
400
|
+
{},
|
|
401
|
+
{ documentSelector: documentSelector },
|
|
402
|
+
{ syncKind: textDocumentSyncOptions.change },
|
|
403
|
+
),
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
public register(data: RegistrationData<TextDocumentChangeRegistrationOptions>): void {
|
|
409
|
+
if (!data.registerOptions.documentSelector) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (!this._listener) {
|
|
413
|
+
this._listener = Workspace.onDidChangeTextDocument(this.callback, this);
|
|
414
|
+
}
|
|
415
|
+
this._changeData.set(data.id, {
|
|
416
|
+
syncKind: data.registerOptions.syncKind,
|
|
417
|
+
documentSelector: this._client.protocol2CodeConverter.asDocumentSelector(
|
|
418
|
+
data.registerOptions.documentSelector,
|
|
419
|
+
),
|
|
420
|
+
});
|
|
421
|
+
this.updateSyncKind(data.registerOptions.syncKind);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
public *getDocumentSelectors(): IterableIterator<VDocumentSelector> {
|
|
425
|
+
for (const data of this._changeData.values()) {
|
|
426
|
+
yield data.documentSelector;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
private async callback(event: TextDocumentChangeEvent): Promise<void> {
|
|
431
|
+
// Text document changes are send for dirty changes as well. We don't
|
|
432
|
+
// have dirty / un-dirty events in the LSP so we ignore content changes
|
|
433
|
+
// with length zero.
|
|
434
|
+
if (event.contentChanges.length === 0) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// We need to capture the URI and version here since they might change on the text document
|
|
439
|
+
// until we reach did `didChange` call since the middleware support async execution.
|
|
440
|
+
const uri = event.document.uri;
|
|
441
|
+
const version = event.document.version;
|
|
442
|
+
|
|
443
|
+
const promises: Promise<void>[] = [];
|
|
444
|
+
for (const changeData of this._changeData.values()) {
|
|
445
|
+
if (
|
|
446
|
+
Languages.match(changeData.documentSelector, event.document) > 0 &&
|
|
447
|
+
!this._client.hasDedicatedTextSynchronizationFeature(event.document)
|
|
448
|
+
) {
|
|
449
|
+
const middleware = this._client.middleware;
|
|
450
|
+
if (changeData.syncKind === TextDocumentSyncKind.Incremental) {
|
|
451
|
+
const didChange = async (event: TextDocumentChangeEvent): Promise<void> => {
|
|
452
|
+
const params =
|
|
453
|
+
this._client.code2ProtocolConverter.asChangeTextDocumentParams(
|
|
454
|
+
event,
|
|
455
|
+
uri,
|
|
456
|
+
version,
|
|
457
|
+
);
|
|
458
|
+
await this._client.sendNotification(
|
|
459
|
+
DidChangeTextDocumentNotification.type,
|
|
460
|
+
params,
|
|
461
|
+
);
|
|
462
|
+
this.notificationSent(
|
|
463
|
+
event.document,
|
|
464
|
+
DidChangeTextDocumentNotification.type,
|
|
465
|
+
params,
|
|
466
|
+
);
|
|
467
|
+
};
|
|
468
|
+
promises.push(
|
|
469
|
+
middleware.didChange
|
|
470
|
+
? middleware.didChange(event, (event) => didChange(event))
|
|
471
|
+
: didChange(event),
|
|
472
|
+
);
|
|
473
|
+
} else if (changeData.syncKind === TextDocumentSyncKind.Full) {
|
|
474
|
+
const didChange = async (event: TextDocumentChangeEvent): Promise<void> => {
|
|
475
|
+
const eventUri: string = event.document.uri.toString();
|
|
476
|
+
this._pendingTextDocumentChanges.set(eventUri, event.document);
|
|
477
|
+
this._onPendingChangeAdded.fire();
|
|
478
|
+
};
|
|
479
|
+
promises.push(
|
|
480
|
+
middleware.didChange
|
|
481
|
+
? middleware.didChange(event, (event) => didChange(event))
|
|
482
|
+
: didChange(event),
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return Promise.all(promises).then(undefined, (error) => {
|
|
488
|
+
this._client.error(
|
|
489
|
+
`Sending document notification ${DidChangeTextDocumentNotification.type.method} failed`,
|
|
490
|
+
error,
|
|
491
|
+
);
|
|
492
|
+
throw error;
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
public notificationSent(
|
|
497
|
+
textDocument: TextDocument,
|
|
498
|
+
type: ProtocolNotificationType<
|
|
499
|
+
DidChangeTextDocumentParams,
|
|
500
|
+
TextDocumentRegistrationOptions
|
|
501
|
+
>,
|
|
502
|
+
params: DidChangeTextDocumentParams,
|
|
503
|
+
): void {
|
|
504
|
+
this._onNotificationSent.fire({ textDocument, type, params });
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
public unregister(id: string): void {
|
|
508
|
+
this._changeData.delete(id);
|
|
509
|
+
if (this._changeData.size === 0) {
|
|
510
|
+
if (this._listener) {
|
|
511
|
+
this._listener.dispose();
|
|
512
|
+
this._listener = undefined;
|
|
513
|
+
}
|
|
514
|
+
this._syncKind = TextDocumentSyncKind.None;
|
|
515
|
+
} else {
|
|
516
|
+
this._syncKind = TextDocumentSyncKind.None as TextDocumentSyncKind;
|
|
517
|
+
for (const changeData of this._changeData.values()) {
|
|
518
|
+
this.updateSyncKind(changeData.syncKind);
|
|
519
|
+
if (this._syncKind === TextDocumentSyncKind.Full) {
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
public clear = (): void => {
|
|
527
|
+
this._pendingTextDocumentChanges.clear();
|
|
528
|
+
this._changeData.clear();
|
|
529
|
+
this._syncKind = TextDocumentSyncKind.None;
|
|
530
|
+
if (this._listener) {
|
|
531
|
+
this._listener.dispose();
|
|
532
|
+
this._listener = undefined;
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
public getPendingDocumentChanges(excludes: Set<string>): TextDocument[] {
|
|
537
|
+
if (this._pendingTextDocumentChanges.size === 0) {
|
|
538
|
+
return [];
|
|
539
|
+
}
|
|
540
|
+
let result: TextDocument[];
|
|
541
|
+
if (excludes.size === 0) {
|
|
542
|
+
result = Array.from(this._pendingTextDocumentChanges.values());
|
|
543
|
+
this._pendingTextDocumentChanges.clear();
|
|
544
|
+
} else {
|
|
545
|
+
result = [];
|
|
546
|
+
for (const entry of this._pendingTextDocumentChanges) {
|
|
547
|
+
if (!excludes.has(entry[0])) {
|
|
548
|
+
result.push(entry[1]);
|
|
549
|
+
this._pendingTextDocumentChanges.delete(entry[0]);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return result;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
public getProvider(
|
|
557
|
+
document: TextDocument,
|
|
558
|
+
): { send: (event: TextDocumentChangeEvent) => Promise<void> } | undefined {
|
|
559
|
+
for (const changeData of this._changeData.values()) {
|
|
560
|
+
if (Languages.match(changeData.documentSelector, document) > 0) {
|
|
561
|
+
return {
|
|
562
|
+
send: (event: TextDocumentChangeEvent): Promise<void> => {
|
|
563
|
+
return this.callback(event);
|
|
564
|
+
},
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return undefined;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
private updateSyncKind(syncKind: TextDocumentSyncKind): void {
|
|
572
|
+
if (this._syncKind === TextDocumentSyncKind.Full) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
switch (syncKind) {
|
|
576
|
+
case TextDocumentSyncKind.Full:
|
|
577
|
+
this._syncKind = syncKind;
|
|
578
|
+
break;
|
|
579
|
+
case TextDocumentSyncKind.Incremental:
|
|
580
|
+
if (this._syncKind === TextDocumentSyncKind.None) {
|
|
581
|
+
this._syncKind = TextDocumentSyncKind.Incremental;
|
|
582
|
+
}
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export class WillSaveFeature extends TextDocumentEventFeature<
|
|
589
|
+
WillSaveTextDocumentParams,
|
|
590
|
+
TextDocumentWillSaveEvent,
|
|
591
|
+
TextDocumentSynchronizationMiddleware
|
|
592
|
+
> {
|
|
593
|
+
constructor(client: FeatureClient<TextDocumentSynchronizationMiddleware>) {
|
|
594
|
+
super(
|
|
595
|
+
client,
|
|
596
|
+
Workspace.onWillSaveTextDocument,
|
|
597
|
+
WillSaveTextDocumentNotification.type,
|
|
598
|
+
() => client.middleware.willSave,
|
|
599
|
+
(willSaveEvent) =>
|
|
600
|
+
client.code2ProtocolConverter.asWillSaveTextDocumentParams(willSaveEvent),
|
|
601
|
+
(event) => event.document,
|
|
602
|
+
(selectors, willSaveEvent) =>
|
|
603
|
+
TextDocumentEventFeature.textDocumentFilter(selectors, willSaveEvent.document),
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
public get registrationType(): RegistrationType<TextDocumentRegistrationOptions> {
|
|
608
|
+
return WillSaveTextDocumentNotification.type;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
public fillClientCapabilities(capabilities: ClientCapabilities): void {
|
|
612
|
+
const value = ensure(ensure(capabilities, 'textDocument')!, 'synchronization')!;
|
|
613
|
+
value.willSave = true;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
public initialize(
|
|
617
|
+
capabilities: ServerCapabilities,
|
|
618
|
+
documentSelector: DocumentSelector,
|
|
619
|
+
): void {
|
|
620
|
+
const textDocumentSyncOptions = (
|
|
621
|
+
capabilities as ResolvedTextDocumentSyncCapabilities
|
|
622
|
+
).resolvedTextDocumentSync;
|
|
623
|
+
if (
|
|
624
|
+
documentSelector &&
|
|
625
|
+
textDocumentSyncOptions &&
|
|
626
|
+
textDocumentSyncOptions.willSave
|
|
627
|
+
) {
|
|
628
|
+
this.register({
|
|
629
|
+
id: UUID.generateUuid(),
|
|
630
|
+
registerOptions: { documentSelector: documentSelector },
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
protected getTextDocument(data: TextDocumentWillSaveEvent): TextDocument {
|
|
636
|
+
return data.document;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
export class WillSaveWaitUntilFeature extends DynamicDocumentFeature<
|
|
641
|
+
TextDocumentRegistrationOptions,
|
|
642
|
+
TextDocumentSynchronizationMiddleware
|
|
643
|
+
> {
|
|
644
|
+
private _listener: Disposable | undefined;
|
|
645
|
+
private readonly _selectors: Map<string, VDocumentSelector>;
|
|
646
|
+
|
|
647
|
+
constructor(client: FeatureClient<TextDocumentSynchronizationMiddleware>) {
|
|
648
|
+
super(client);
|
|
649
|
+
this._selectors = new Map<string, VDocumentSelector>();
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
protected getDocumentSelectors(): IterableIterator<VDocumentSelector> {
|
|
653
|
+
return this._selectors.values();
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
public get registrationType(): RegistrationType<TextDocumentRegistrationOptions> {
|
|
657
|
+
return WillSaveTextDocumentWaitUntilRequest.type;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
public fillClientCapabilities(capabilities: ClientCapabilities): void {
|
|
661
|
+
const value = ensure(ensure(capabilities, 'textDocument')!, 'synchronization')!;
|
|
662
|
+
value.willSaveWaitUntil = true;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
public initialize(
|
|
666
|
+
capabilities: ServerCapabilities,
|
|
667
|
+
documentSelector: DocumentSelector,
|
|
668
|
+
): void {
|
|
669
|
+
const textDocumentSyncOptions = (
|
|
670
|
+
capabilities as ResolvedTextDocumentSyncCapabilities
|
|
671
|
+
).resolvedTextDocumentSync;
|
|
672
|
+
if (
|
|
673
|
+
documentSelector &&
|
|
674
|
+
textDocumentSyncOptions &&
|
|
675
|
+
textDocumentSyncOptions.willSaveWaitUntil
|
|
676
|
+
) {
|
|
677
|
+
this.register({
|
|
678
|
+
id: UUID.generateUuid(),
|
|
679
|
+
registerOptions: { documentSelector: documentSelector },
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
public register(data: RegistrationData<TextDocumentRegistrationOptions>): void {
|
|
685
|
+
if (!data.registerOptions.documentSelector) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (!this._listener) {
|
|
689
|
+
this._listener = Workspace.onWillSaveTextDocument(this.callback, this);
|
|
690
|
+
}
|
|
691
|
+
this._selectors.set(
|
|
692
|
+
data.id,
|
|
693
|
+
this._client.protocol2CodeConverter.asDocumentSelector(
|
|
694
|
+
data.registerOptions.documentSelector,
|
|
695
|
+
),
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
private callback(event: TextDocumentWillSaveEvent): void {
|
|
700
|
+
if (
|
|
701
|
+
TextDocumentEventFeature.textDocumentFilter(
|
|
702
|
+
this._selectors.values(),
|
|
703
|
+
event.document,
|
|
704
|
+
) &&
|
|
705
|
+
!this._client.hasDedicatedTextSynchronizationFeature(event.document)
|
|
706
|
+
) {
|
|
707
|
+
const middleware = this._client.middleware;
|
|
708
|
+
const willSaveWaitUntil = (
|
|
709
|
+
event: TextDocumentWillSaveEvent,
|
|
710
|
+
): Thenable<VTextEdit[]> => {
|
|
711
|
+
return this._client
|
|
712
|
+
.sendRequest(
|
|
713
|
+
WillSaveTextDocumentWaitUntilRequest.type,
|
|
714
|
+
this._client.code2ProtocolConverter.asWillSaveTextDocumentParams(event),
|
|
715
|
+
)
|
|
716
|
+
.then(async (edits) => {
|
|
717
|
+
const vEdits = await this._client.protocol2CodeConverter.asTextEdits(edits);
|
|
718
|
+
return vEdits === undefined ? [] : vEdits;
|
|
719
|
+
});
|
|
720
|
+
};
|
|
721
|
+
event.waitUntil(
|
|
722
|
+
middleware.willSaveWaitUntil
|
|
723
|
+
? middleware.willSaveWaitUntil(event, willSaveWaitUntil)
|
|
724
|
+
: willSaveWaitUntil(event),
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
public unregister(id: string): void {
|
|
730
|
+
this._selectors.delete(id);
|
|
731
|
+
if (this._selectors.size === 0 && this._listener) {
|
|
732
|
+
this._listener.dispose();
|
|
733
|
+
this._listener = undefined;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
public clear(): void {
|
|
738
|
+
this._selectors.clear();
|
|
739
|
+
if (this._listener) {
|
|
740
|
+
this._listener.dispose();
|
|
741
|
+
this._listener = undefined;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
export interface DidSaveTextDocumentFeatureShape
|
|
747
|
+
extends DynamicFeature<TextDocumentRegistrationOptions>,
|
|
748
|
+
TextDocumentSendFeature<(textDocument: TextDocument) => Promise<void>>,
|
|
749
|
+
NotifyingFeature<DidSaveTextDocumentParams> {}
|
|
750
|
+
|
|
751
|
+
export class DidSaveTextDocumentFeature
|
|
752
|
+
extends TextDocumentEventFeature<
|
|
753
|
+
DidSaveTextDocumentParams,
|
|
754
|
+
TextDocument,
|
|
755
|
+
TextDocumentSynchronizationMiddleware
|
|
756
|
+
>
|
|
757
|
+
implements DidSaveTextDocumentFeatureShape
|
|
758
|
+
{
|
|
759
|
+
private _includeText: boolean;
|
|
760
|
+
|
|
761
|
+
constructor(client: FeatureClient<TextDocumentSynchronizationMiddleware>) {
|
|
762
|
+
super(
|
|
763
|
+
client,
|
|
764
|
+
Workspace.onDidSaveTextDocument,
|
|
765
|
+
DidSaveTextDocumentNotification.type,
|
|
766
|
+
() => client.middleware.didSave,
|
|
767
|
+
(textDocument) =>
|
|
768
|
+
client.code2ProtocolConverter.asSaveTextDocumentParams(
|
|
769
|
+
textDocument,
|
|
770
|
+
this._includeText,
|
|
771
|
+
),
|
|
772
|
+
(data) => data,
|
|
773
|
+
TextDocumentEventFeature.textDocumentFilter,
|
|
774
|
+
);
|
|
775
|
+
this._includeText = false;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
public get registrationType(): RegistrationType<TextDocumentSaveRegistrationOptions> {
|
|
779
|
+
return DidSaveTextDocumentNotification.type;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
public fillClientCapabilities(capabilities: ClientCapabilities): void {
|
|
783
|
+
ensure(ensure(capabilities, 'textDocument')!, 'synchronization')!.didSave = true;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
public initialize(
|
|
787
|
+
capabilities: ServerCapabilities,
|
|
788
|
+
documentSelector: DocumentSelector,
|
|
789
|
+
): void {
|
|
790
|
+
const textDocumentSyncOptions = (
|
|
791
|
+
capabilities as ResolvedTextDocumentSyncCapabilities
|
|
792
|
+
).resolvedTextDocumentSync;
|
|
793
|
+
if (documentSelector && textDocumentSyncOptions && textDocumentSyncOptions.save) {
|
|
794
|
+
const saveOptions: SaveOptions =
|
|
795
|
+
typeof textDocumentSyncOptions.save === 'boolean'
|
|
796
|
+
? { includeText: false }
|
|
797
|
+
: { includeText: !!textDocumentSyncOptions.save.includeText };
|
|
798
|
+
this.register({
|
|
799
|
+
id: UUID.generateUuid(),
|
|
800
|
+
registerOptions: Object.assign(
|
|
801
|
+
{},
|
|
802
|
+
{ documentSelector: documentSelector },
|
|
803
|
+
saveOptions,
|
|
804
|
+
),
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
public override register(
|
|
810
|
+
data: RegistrationData<TextDocumentSaveRegistrationOptions>,
|
|
811
|
+
): void {
|
|
812
|
+
this._includeText = !!data.registerOptions.includeText;
|
|
813
|
+
super.register(data);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
protected getTextDocument(data: TextDocument): TextDocument {
|
|
817
|
+
return data;
|
|
818
|
+
}
|
|
819
|
+
}
|