| 855 | } |
| 856 | |
| 857 | class DidChangeTextDocumentFeature implements DynamicFeature<TextDocumentChangeRegistrationOptions> { |
| 858 | |
| 859 | private _listener: Disposable | undefined; |
| 860 | private _changeData: Map<string, DidChangeTextDocumentData> = new Map<string, DidChangeTextDocumentData>(); |
| 861 | private _forcingDelivery: boolean = false; |
| 862 | private _changeDelayer: { uri: string; delayer: Delayer<void> } | undefined; |
| 863 | |
| 864 | constructor(private _client: BaseLanguageClient) { |
| 865 | } |
| 866 | |
| 867 | public get messages(): typeof DidChangeTextDocumentNotification.type { |
| 868 | return DidChangeTextDocumentNotification.type; |
| 869 | } |
| 870 | |
| 871 | public fillClientCapabilities(capabilities: ClientCapabilities): void { |
| 872 | ensure(ensure(capabilities, 'textDocument')!, 'synchronization')!.dynamicRegistration = true; |
| 873 | } |
| 874 | |
| 875 | public initialize(capabilities: ServerCapabilities, documentSelector: DocumentSelector): void { |
| 876 | let textDocumentSyncOptions = (capabilities as ResolvedTextDocumentSyncCapabilities).resolvedTextDocumentSync; |
| 877 | if (documentSelector && textDocumentSyncOptions && textDocumentSyncOptions.change !== void 0 && textDocumentSyncOptions.change !== TextDocumentSyncKind.None) { |
| 878 | this.register(this.messages, |
| 879 | { |
| 880 | id: UUID.generateUuid(), |
| 881 | registerOptions: Object.assign({}, { documentSelector: documentSelector }, { syncKind: textDocumentSyncOptions.change }) |
| 882 | } |
| 883 | ); |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | public register(_message: RPCMessageType, data: RegistrationData<TextDocumentChangeRegistrationOptions>): void { |
| 888 | if (!data.registerOptions.documentSelector) { |
| 889 | return; |
| 890 | } |
| 891 | if (!this._listener) { |
| 892 | this._listener = Workspace.onDidChangeTextDocument(this.callback, this); |
| 893 | } |
| 894 | this._changeData.set( |
| 895 | data.id, |
| 896 | { |
| 897 | documentSelector: data.registerOptions.documentSelector, |
| 898 | syncKind: data.registerOptions.syncKind |
| 899 | } |
| 900 | ); |
| 901 | } |
| 902 | |
| 903 | private callback(event: TextDocumentChangeEvent): void { |
| 904 | for (const changeData of this._changeData.values()) { |
| 905 | if (Languages.match(changeData.documentSelector, event.document)) { |
| 906 | let middleware = this._client.clientOptions.middleware!; |
| 907 | if (changeData.syncKind === TextDocumentSyncKind.Incremental) { |
| 908 | let params = this._client.code2ProtocolConverter.asChangeTextDocumentParams(event); |
| 909 | if (middleware.didChange) { |
| 910 | middleware.didChange(event, () => this._client.sendNotification(DidChangeTextDocumentNotification.type, params)); |
| 911 | } else { |
| 912 | this._client.sendNotification(DidChangeTextDocumentNotification.type, params); |
| 913 | } |
| 914 | } else if (changeData.syncKind === TextDocumentSyncKind.Full) { |
nothing calls this directly
no outgoing calls
no test coverage detected