massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-json / node_modules / vscode-languageserver / lib / common / server.js
1 "use strict";
2 /* --------------------------------------------------------------------------------------------
3  * Copyright (c) Microsoft Corporation. All rights reserved.
4  * Licensed under the MIT License. See License.txt in the project root for license information.
5  * ------------------------------------------------------------------------------------------ */
6 Object.defineProperty(exports, "__esModule", { value: true });
7 exports.createConnection = exports.combineFeatures = exports.combineLanguagesFeatures = exports.combineWorkspaceFeatures = exports.combineWindowFeatures = exports.combineClientFeatures = exports.combineTracerFeatures = exports.combineTelemetryFeatures = exports.combineConsoleFeatures = exports._LanguagesImpl = exports.BulkUnregistration = exports.BulkRegistration = exports.ErrorMessageTracker = exports.TextDocuments = void 0;
8 const vscode_languageserver_protocol_1 = require("vscode-languageserver-protocol");
9 const Is = require("./utils/is");
10 const UUID = require("./utils/uuid");
11 const progress_1 = require("./progress");
12 const configuration_1 = require("./configuration");
13 const workspaceFolders_1 = require("./workspaceFolders");
14 const callHierarchy_1 = require("./callHierarchy");
15 const semanticTokens_1 = require("./semanticTokens");
16 const showDocument_1 = require("./showDocument");
17 const fileOperations_1 = require("./fileOperations");
18 const linkedEditingRange_1 = require("./linkedEditingRange");
19 const moniker_1 = require("./moniker");
20 function null2Undefined(value) {
21     if (value === null) {
22         return undefined;
23     }
24     return value;
25 }
26 /**
27  * A manager for simple text documents
28  */
29 class TextDocuments {
30     /**
31      * Create a new text document manager.
32      */
33     constructor(configuration) {
34         this._documents = Object.create(null);
35         this._configuration = configuration;
36         this._onDidChangeContent = new vscode_languageserver_protocol_1.Emitter();
37         this._onDidOpen = new vscode_languageserver_protocol_1.Emitter();
38         this._onDidClose = new vscode_languageserver_protocol_1.Emitter();
39         this._onDidSave = new vscode_languageserver_protocol_1.Emitter();
40         this._onWillSave = new vscode_languageserver_protocol_1.Emitter();
41     }
42     /**
43      * An event that fires when a text document managed by this manager
44      * has been opened or the content changes.
45      */
46     get onDidChangeContent() {
47         return this._onDidChangeContent.event;
48     }
49     /**
50      * An event that fires when a text document managed by this manager
51      * has been opened.
52      */
53     get onDidOpen() {
54         return this._onDidOpen.event;
55     }
56     /**
57      * An event that fires when a text document managed by this manager
58      * will be saved.
59      */
60     get onWillSave() {
61         return this._onWillSave.event;
62     }
63     /**
64      * Sets a handler that will be called if a participant wants to provide
65      * edits during a text document save.
66      */
67     onWillSaveWaitUntil(handler) {
68         this._willSaveWaitUntil = handler;
69     }
70     /**
71      * An event that fires when a text document managed by this manager
72      * has been saved.
73      */
74     get onDidSave() {
75         return this._onDidSave.event;
76     }
77     /**
78      * An event that fires when a text document managed by this manager
79      * has been closed.
80      */
81     get onDidClose() {
82         return this._onDidClose.event;
83     }
84     /**
85      * Returns the document for the given URI. Returns undefined if
86      * the document is not managed by this instance.
87      *
88      * @param uri The text document's URI to retrieve.
89      * @return the text document or `undefined`.
90      */
91     get(uri) {
92         return this._documents[uri];
93     }
94     /**
95      * Returns all text documents managed by this instance.
96      *
97      * @return all text documents.
98      */
99     all() {
100         return Object.keys(this._documents).map(key => this._documents[key]);
101     }
102     /**
103      * Returns the URIs of all text documents managed by this instance.
104      *
105      * @return the URI's of all text documents.
106      */
107     keys() {
108         return Object.keys(this._documents);
109     }
110     /**
111      * Listens for `low level` notification on the given connection to
112      * update the text documents managed by this instance.
113      *
114      * Please note that the connection only provides handlers not an event model. Therefore
115      * listening on a connection will overwrite the following handlers on a connection:
116      * `onDidOpenTextDocument`, `onDidChangeTextDocument`, `onDidCloseTextDocument`,
117      * `onWillSaveTextDocument`, `onWillSaveTextDocumentWaitUntil` and `onDidSaveTextDocument`.
118      *
119      * Use the corresponding events on the TextDocuments instance instead.
120      *
121      * @param connection The connection to listen on.
122      */
123     listen(connection) {
124         connection.__textDocumentSync = vscode_languageserver_protocol_1.TextDocumentSyncKind.Full;
125         connection.onDidOpenTextDocument((event) => {
126             let td = event.textDocument;
127             let document = this._configuration.create(td.uri, td.languageId, td.version, td.text);
128             this._documents[td.uri] = document;
129             let toFire = Object.freeze({ document });
130             this._onDidOpen.fire(toFire);
131             this._onDidChangeContent.fire(toFire);
132         });
133         connection.onDidChangeTextDocument((event) => {
134             let td = event.textDocument;
135             let changes = event.contentChanges;
136             if (changes.length === 0) {
137                 return;
138             }
139             let document = this._documents[td.uri];
140             const { version } = td;
141             if (version === null || version === undefined) {
142                 throw new Error(`Received document change event for ${td.uri} without valid version identifier`);
143             }
144             document = this._configuration.update(document, changes, version);
145             this._documents[td.uri] = document;
146             this._onDidChangeContent.fire(Object.freeze({ document }));
147         });
148         connection.onDidCloseTextDocument((event) => {
149             let document = this._documents[event.textDocument.uri];
150             if (document) {
151                 delete this._documents[event.textDocument.uri];
152                 this._onDidClose.fire(Object.freeze({ document }));
153             }
154         });
155         connection.onWillSaveTextDocument((event) => {
156             let document = this._documents[event.textDocument.uri];
157             if (document) {
158                 this._onWillSave.fire(Object.freeze({ document, reason: event.reason }));
159             }
160         });
161         connection.onWillSaveTextDocumentWaitUntil((event, token) => {
162             let document = this._documents[event.textDocument.uri];
163             if (document && this._willSaveWaitUntil) {
164                 return this._willSaveWaitUntil(Object.freeze({ document, reason: event.reason }), token);
165             }
166             else {
167                 return [];
168             }
169         });
170         connection.onDidSaveTextDocument((event) => {
171             let document = this._documents[event.textDocument.uri];
172             if (document) {
173                 this._onDidSave.fire(Object.freeze({ document }));
174             }
175         });
176     }
177 }
178 exports.TextDocuments = TextDocuments;
179 /**
180  * Helps tracking error message. Equal occurrences of the same
181  * message are only stored once. This class is for example
182  * useful if text documents are validated in a loop and equal
183  * error message should be folded into one.
184  */
185 class ErrorMessageTracker {
186     constructor() {
187         this._messages = Object.create(null);
188     }
189     /**
190      * Add a message to the tracker.
191      *
192      * @param message The message to add.
193      */
194     add(message) {
195         let count = this._messages[message];
196         if (!count) {
197             count = 0;
198         }
199         count++;
200         this._messages[message] = count;
201     }
202     /**
203      * Send all tracked messages to the connection's window.
204      *
205      * @param connection The connection established between client and server.
206      */
207     sendErrors(connection) {
208         Object.keys(this._messages).forEach(message => {
209             connection.window.showErrorMessage(message);
210         });
211     }
212 }
213 exports.ErrorMessageTracker = ErrorMessageTracker;
214 class RemoteConsoleImpl {
215     constructor() {
216     }
217     rawAttach(connection) {
218         this._rawConnection = connection;
219     }
220     attach(connection) {
221         this._connection = connection;
222     }
223     get connection() {
224         if (!this._connection) {
225             throw new Error('Remote is not attached to a connection yet.');
226         }
227         return this._connection;
228     }
229     fillServerCapabilities(_capabilities) {
230     }
231     initialize(_capabilities) {
232     }
233     error(message) {
234         this.send(vscode_languageserver_protocol_1.MessageType.Error, message);
235     }
236     warn(message) {
237         this.send(vscode_languageserver_protocol_1.MessageType.Warning, message);
238     }
239     info(message) {
240         this.send(vscode_languageserver_protocol_1.MessageType.Info, message);
241     }
242     log(message) {
243         this.send(vscode_languageserver_protocol_1.MessageType.Log, message);
244     }
245     send(type, message) {
246         if (this._rawConnection) {
247             this._rawConnection.sendNotification(vscode_languageserver_protocol_1.LogMessageNotification.type, { type, message });
248         }
249     }
250 }
251 class _RemoteWindowImpl {
252     constructor() {
253     }
254     attach(connection) {
255         this._connection = connection;
256     }
257     get connection() {
258         if (!this._connection) {
259             throw new Error('Remote is not attached to a connection yet.');
260         }
261         return this._connection;
262     }
263     initialize(_capabilities) {
264     }
265     fillServerCapabilities(_capabilities) {
266     }
267     showErrorMessage(message, ...actions) {
268         let params = { type: vscode_languageserver_protocol_1.MessageType.Error, message, actions };
269         return this.connection.sendRequest(vscode_languageserver_protocol_1.ShowMessageRequest.type, params).then(null2Undefined);
270     }
271     showWarningMessage(message, ...actions) {
272         let params = { type: vscode_languageserver_protocol_1.MessageType.Warning, message, actions };
273         return this.connection.sendRequest(vscode_languageserver_protocol_1.ShowMessageRequest.type, params).then(null2Undefined);
274     }
275     showInformationMessage(message, ...actions) {
276         let params = { type: vscode_languageserver_protocol_1.MessageType.Info, message, actions };
277         return this.connection.sendRequest(vscode_languageserver_protocol_1.ShowMessageRequest.type, params).then(null2Undefined);
278     }
279 }
280 const RemoteWindowImpl = showDocument_1.ShowDocumentFeature(progress_1.ProgressFeature(_RemoteWindowImpl));
281 var BulkRegistration;
282 (function (BulkRegistration) {
283     /**
284      * Creates a new bulk registration.
285      * @return an empty bulk registration.
286      */
287     function create() {
288         return new BulkRegistrationImpl();
289     }
290     BulkRegistration.create = create;
291 })(BulkRegistration = exports.BulkRegistration || (exports.BulkRegistration = {}));
292 class BulkRegistrationImpl {
293     constructor() {
294         this._registrations = [];
295         this._registered = new Set();
296     }
297     add(type, registerOptions) {
298         const method = Is.string(type) ? type : type.method;
299         if (this._registered.has(method)) {
300             throw new Error(`${method} is already added to this registration`);
301         }
302         const id = UUID.generateUuid();
303         this._registrations.push({
304             id: id,
305             method: method,
306             registerOptions: registerOptions || {}
307         });
308         this._registered.add(method);
309     }
310     asRegistrationParams() {
311         return {
312             registrations: this._registrations
313         };
314     }
315 }
316 var BulkUnregistration;
317 (function (BulkUnregistration) {
318     function create() {
319         return new BulkUnregistrationImpl(undefined, []);
320     }
321     BulkUnregistration.create = create;
322 })(BulkUnregistration = exports.BulkUnregistration || (exports.BulkUnregistration = {}));
323 class BulkUnregistrationImpl {
324     constructor(_connection, unregistrations) {
325         this._connection = _connection;
326         this._unregistrations = new Map();
327         unregistrations.forEach(unregistration => {
328             this._unregistrations.set(unregistration.method, unregistration);
329         });
330     }
331     get isAttached() {
332         return !!this._connection;
333     }
334     attach(connection) {
335         this._connection = connection;
336     }
337     add(unregistration) {
338         this._unregistrations.set(unregistration.method, unregistration);
339     }
340     dispose() {
341         let unregistrations = [];
342         for (let unregistration of this._unregistrations.values()) {
343             unregistrations.push(unregistration);
344         }
345         let params = {
346             unregisterations: unregistrations
347         };
348         this._connection.sendRequest(vscode_languageserver_protocol_1.UnregistrationRequest.type, params).then(undefined, (_error) => {
349             this._connection.console.info(`Bulk unregistration failed.`);
350         });
351     }
352     disposeSingle(arg) {
353         const method = Is.string(arg) ? arg : arg.method;
354         const unregistration = this._unregistrations.get(method);
355         if (!unregistration) {
356             return false;
357         }
358         let params = {
359             unregisterations: [unregistration]
360         };
361         this._connection.sendRequest(vscode_languageserver_protocol_1.UnregistrationRequest.type, params).then(() => {
362             this._unregistrations.delete(method);
363         }, (_error) => {
364             this._connection.console.info(`Un-registering request handler for ${unregistration.id} failed.`);
365         });
366         return true;
367     }
368 }
369 class RemoteClientImpl {
370     attach(connection) {
371         this._connection = connection;
372     }
373     get connection() {
374         if (!this._connection) {
375             throw new Error('Remote is not attached to a connection yet.');
376         }
377         return this._connection;
378     }
379     initialize(_capabilities) {
380     }
381     fillServerCapabilities(_capabilities) {
382     }
383     register(typeOrRegistrations, registerOptionsOrType, registerOptions) {
384         if (typeOrRegistrations instanceof BulkRegistrationImpl) {
385             return this.registerMany(typeOrRegistrations);
386         }
387         else if (typeOrRegistrations instanceof BulkUnregistrationImpl) {
388             return this.registerSingle1(typeOrRegistrations, registerOptionsOrType, registerOptions);
389         }
390         else {
391             return this.registerSingle2(typeOrRegistrations, registerOptionsOrType);
392         }
393     }
394     registerSingle1(unregistration, type, registerOptions) {
395         const method = Is.string(type) ? type : type.method;
396         const id = UUID.generateUuid();
397         let params = {
398             registrations: [{ id, method, registerOptions: registerOptions || {} }]
399         };
400         if (!unregistration.isAttached) {
401             unregistration.attach(this.connection);
402         }
403         return this.connection.sendRequest(vscode_languageserver_protocol_1.RegistrationRequest.type, params).then((_result) => {
404             unregistration.add({ id: id, method: method });
405             return unregistration;
406         }, (_error) => {
407             this.connection.console.info(`Registering request handler for ${method} failed.`);
408             return Promise.reject(_error);
409         });
410     }
411     registerSingle2(type, registerOptions) {
412         const method = Is.string(type) ? type : type.method;
413         const id = UUID.generateUuid();
414         let params = {
415             registrations: [{ id, method, registerOptions: registerOptions || {} }]
416         };
417         return this.connection.sendRequest(vscode_languageserver_protocol_1.RegistrationRequest.type, params).then((_result) => {
418             return vscode_languageserver_protocol_1.Disposable.create(() => {
419                 this.unregisterSingle(id, method);
420             });
421         }, (_error) => {
422             this.connection.console.info(`Registering request handler for ${method} failed.`);
423             return Promise.reject(_error);
424         });
425     }
426     unregisterSingle(id, method) {
427         let params = {
428             unregisterations: [{ id, method }]
429         };
430         return this.connection.sendRequest(vscode_languageserver_protocol_1.UnregistrationRequest.type, params).then(undefined, (_error) => {
431             this.connection.console.info(`Un-registering request handler for ${id} failed.`);
432         });
433     }
434     registerMany(registrations) {
435         let params = registrations.asRegistrationParams();
436         return this.connection.sendRequest(vscode_languageserver_protocol_1.RegistrationRequest.type, params).then(() => {
437             return new BulkUnregistrationImpl(this._connection, params.registrations.map(registration => { return { id: registration.id, method: registration.method }; }));
438         }, (_error) => {
439             this.connection.console.info(`Bulk registration failed.`);
440             return Promise.reject(_error);
441         });
442     }
443 }
444 class _RemoteWorkspaceImpl {
445     constructor() {
446     }
447     attach(connection) {
448         this._connection = connection;
449     }
450     get connection() {
451         if (!this._connection) {
452             throw new Error('Remote is not attached to a connection yet.');
453         }
454         return this._connection;
455     }
456     initialize(_capabilities) {
457     }
458     fillServerCapabilities(_capabilities) {
459     }
460     applyEdit(paramOrEdit) {
461         function isApplyWorkspaceEditParams(value) {
462             return value && !!value.edit;
463         }
464         let params = isApplyWorkspaceEditParams(paramOrEdit) ? paramOrEdit : { edit: paramOrEdit };
465         return this.connection.sendRequest(vscode_languageserver_protocol_1.ApplyWorkspaceEditRequest.type, params);
466     }
467 }
468 const RemoteWorkspaceImpl = fileOperations_1.FileOperationsFeature(workspaceFolders_1.WorkspaceFoldersFeature(configuration_1.ConfigurationFeature(_RemoteWorkspaceImpl)));
469 class TracerImpl {
470     constructor() {
471         this._trace = vscode_languageserver_protocol_1.Trace.Off;
472     }
473     attach(connection) {
474         this._connection = connection;
475     }
476     get connection() {
477         if (!this._connection) {
478             throw new Error('Remote is not attached to a connection yet.');
479         }
480         return this._connection;
481     }
482     initialize(_capabilities) {
483     }
484     fillServerCapabilities(_capabilities) {
485     }
486     set trace(value) {
487         this._trace = value;
488     }
489     log(message, verbose) {
490         if (this._trace === vscode_languageserver_protocol_1.Trace.Off) {
491             return;
492         }
493         this.connection.sendNotification(vscode_languageserver_protocol_1.LogTraceNotification.type, {
494             message: message,
495             verbose: this._trace === vscode_languageserver_protocol_1.Trace.Verbose ? verbose : undefined
496         });
497     }
498 }
499 class TelemetryImpl {
500     constructor() {
501     }
502     attach(connection) {
503         this._connection = connection;
504     }
505     get connection() {
506         if (!this._connection) {
507             throw new Error('Remote is not attached to a connection yet.');
508         }
509         return this._connection;
510     }
511     initialize(_capabilities) {
512     }
513     fillServerCapabilities(_capabilities) {
514     }
515     logEvent(data) {
516         this.connection.sendNotification(vscode_languageserver_protocol_1.TelemetryEventNotification.type, data);
517     }
518 }
519 class _LanguagesImpl {
520     constructor() {
521     }
522     attach(connection) {
523         this._connection = connection;
524     }
525     get connection() {
526         if (!this._connection) {
527             throw new Error('Remote is not attached to a connection yet.');
528         }
529         return this._connection;
530     }
531     initialize(_capabilities) {
532     }
533     fillServerCapabilities(_capabilities) {
534     }
535     attachWorkDoneProgress(params) {
536         return progress_1.attachWorkDone(this.connection, params);
537     }
538     attachPartialResultProgress(_type, params) {
539         return progress_1.attachPartialResult(this.connection, params);
540     }
541 }
542 exports._LanguagesImpl = _LanguagesImpl;
543 const LanguagesImpl = moniker_1.MonikerFeature(linkedEditingRange_1.LinkedEditingRangeFeature(semanticTokens_1.SemanticTokensFeature(callHierarchy_1.CallHierarchyFeature(_LanguagesImpl))));
544 function combineConsoleFeatures(one, two) {
545     return function (Base) {
546         return two(one(Base));
547     };
548 }
549 exports.combineConsoleFeatures = combineConsoleFeatures;
550 function combineTelemetryFeatures(one, two) {
551     return function (Base) {
552         return two(one(Base));
553     };
554 }
555 exports.combineTelemetryFeatures = combineTelemetryFeatures;
556 function combineTracerFeatures(one, two) {
557     return function (Base) {
558         return two(one(Base));
559     };
560 }
561 exports.combineTracerFeatures = combineTracerFeatures;
562 function combineClientFeatures(one, two) {
563     return function (Base) {
564         return two(one(Base));
565     };
566 }
567 exports.combineClientFeatures = combineClientFeatures;
568 function combineWindowFeatures(one, two) {
569     return function (Base) {
570         return two(one(Base));
571     };
572 }
573 exports.combineWindowFeatures = combineWindowFeatures;
574 function combineWorkspaceFeatures(one, two) {
575     return function (Base) {
576         return two(one(Base));
577     };
578 }
579 exports.combineWorkspaceFeatures = combineWorkspaceFeatures;
580 function combineLanguagesFeatures(one, two) {
581     return function (Base) {
582         return two(one(Base));
583     };
584 }
585 exports.combineLanguagesFeatures = combineLanguagesFeatures;
586 function combineFeatures(one, two) {
587     function combine(one, two, func) {
588         if (one && two) {
589             return func(one, two);
590         }
591         else if (one) {
592             return one;
593         }
594         else {
595             return two;
596         }
597     }
598     let result = {
599         __brand: 'features',
600         console: combine(one.console, two.console, combineConsoleFeatures),
601         tracer: combine(one.tracer, two.tracer, combineTracerFeatures),
602         telemetry: combine(one.telemetry, two.telemetry, combineTelemetryFeatures),
603         client: combine(one.client, two.client, combineClientFeatures),
604         window: combine(one.window, two.window, combineWindowFeatures),
605         workspace: combine(one.workspace, two.workspace, combineWorkspaceFeatures)
606     };
607     return result;
608 }
609 exports.combineFeatures = combineFeatures;
610 function createConnection(connectionFactory, watchDog, factories) {
611     const logger = (factories && factories.console ? new (factories.console(RemoteConsoleImpl))() : new RemoteConsoleImpl());
612     const connection = connectionFactory(logger);
613     logger.rawAttach(connection);
614     const tracer = (factories && factories.tracer ? new (factories.tracer(TracerImpl))() : new TracerImpl());
615     const telemetry = (factories && factories.telemetry ? new (factories.telemetry(TelemetryImpl))() : new TelemetryImpl());
616     const client = (factories && factories.client ? new (factories.client(RemoteClientImpl))() : new RemoteClientImpl());
617     const remoteWindow = (factories && factories.window ? new (factories.window(RemoteWindowImpl))() : new RemoteWindowImpl());
618     const workspace = (factories && factories.workspace ? new (factories.workspace(RemoteWorkspaceImpl))() : new RemoteWorkspaceImpl());
619     const languages = (factories && factories.languages ? new (factories.languages(LanguagesImpl))() : new LanguagesImpl());
620     const allRemotes = [logger, tracer, telemetry, client, remoteWindow, workspace, languages];
621     function asPromise(value) {
622         if (value instanceof Promise) {
623             return value;
624         }
625         else if (Is.thenable(value)) {
626             return new Promise((resolve, reject) => {
627                 value.then((resolved) => resolve(resolved), (error) => reject(error));
628             });
629         }
630         else {
631             return Promise.resolve(value);
632         }
633     }
634     let shutdownHandler = undefined;
635     let initializeHandler = undefined;
636     let exitHandler = undefined;
637     let protocolConnection = {
638         listen: () => connection.listen(),
639         sendRequest: (type, ...params) => connection.sendRequest(Is.string(type) ? type : type.method, ...params),
640         onRequest: (type, handler) => connection.onRequest(type, handler),
641         sendNotification: (type, param) => {
642             const method = Is.string(type) ? type : type.method;
643             if (arguments.length === 1) {
644                 connection.sendNotification(method);
645             }
646             else {
647                 connection.sendNotification(method, param);
648             }
649         },
650         onNotification: (type, handler) => connection.onNotification(type, handler),
651         onProgress: connection.onProgress,
652         sendProgress: connection.sendProgress,
653         onInitialize: (handler) => initializeHandler = handler,
654         onInitialized: (handler) => connection.onNotification(vscode_languageserver_protocol_1.InitializedNotification.type, handler),
655         onShutdown: (handler) => shutdownHandler = handler,
656         onExit: (handler) => exitHandler = handler,
657         get console() { return logger; },
658         get telemetry() { return telemetry; },
659         get tracer() { return tracer; },
660         get client() { return client; },
661         get window() { return remoteWindow; },
662         get workspace() { return workspace; },
663         get languages() { return languages; },
664         onDidChangeConfiguration: (handler) => connection.onNotification(vscode_languageserver_protocol_1.DidChangeConfigurationNotification.type, handler),
665         onDidChangeWatchedFiles: (handler) => connection.onNotification(vscode_languageserver_protocol_1.DidChangeWatchedFilesNotification.type, handler),
666         __textDocumentSync: undefined,
667         onDidOpenTextDocument: (handler) => connection.onNotification(vscode_languageserver_protocol_1.DidOpenTextDocumentNotification.type, handler),
668         onDidChangeTextDocument: (handler) => connection.onNotification(vscode_languageserver_protocol_1.DidChangeTextDocumentNotification.type, handler),
669         onDidCloseTextDocument: (handler) => connection.onNotification(vscode_languageserver_protocol_1.DidCloseTextDocumentNotification.type, handler),
670         onWillSaveTextDocument: (handler) => connection.onNotification(vscode_languageserver_protocol_1.WillSaveTextDocumentNotification.type, handler),
671         onWillSaveTextDocumentWaitUntil: (handler) => connection.onRequest(vscode_languageserver_protocol_1.WillSaveTextDocumentWaitUntilRequest.type, handler),
672         onDidSaveTextDocument: (handler) => connection.onNotification(vscode_languageserver_protocol_1.DidSaveTextDocumentNotification.type, handler),
673         sendDiagnostics: (params) => connection.sendNotification(vscode_languageserver_protocol_1.PublishDiagnosticsNotification.type, params),
674         onHover: (handler) => connection.onRequest(vscode_languageserver_protocol_1.HoverRequest.type, (params, cancel) => {
675             return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
676         }),
677         onCompletion: (handler) => connection.onRequest(vscode_languageserver_protocol_1.CompletionRequest.type, (params, cancel) => {
678             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
679         }),
680         onCompletionResolve: (handler) => connection.onRequest(vscode_languageserver_protocol_1.CompletionResolveRequest.type, handler),
681         onSignatureHelp: (handler) => connection.onRequest(vscode_languageserver_protocol_1.SignatureHelpRequest.type, (params, cancel) => {
682             return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
683         }),
684         onDeclaration: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DeclarationRequest.type, (params, cancel) => {
685             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
686         }),
687         onDefinition: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DefinitionRequest.type, (params, cancel) => {
688             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
689         }),
690         onTypeDefinition: (handler) => connection.onRequest(vscode_languageserver_protocol_1.TypeDefinitionRequest.type, (params, cancel) => {
691             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
692         }),
693         onImplementation: (handler) => connection.onRequest(vscode_languageserver_protocol_1.ImplementationRequest.type, (params, cancel) => {
694             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
695         }),
696         onReferences: (handler) => connection.onRequest(vscode_languageserver_protocol_1.ReferencesRequest.type, (params, cancel) => {
697             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
698         }),
699         onDocumentHighlight: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentHighlightRequest.type, (params, cancel) => {
700             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
701         }),
702         onDocumentSymbol: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentSymbolRequest.type, (params, cancel) => {
703             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
704         }),
705         onWorkspaceSymbol: (handler) => connection.onRequest(vscode_languageserver_protocol_1.WorkspaceSymbolRequest.type, (params, cancel) => {
706             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
707         }),
708         onCodeAction: (handler) => connection.onRequest(vscode_languageserver_protocol_1.CodeActionRequest.type, (params, cancel) => {
709             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
710         }),
711         onCodeActionResolve: (handler) => connection.onRequest(vscode_languageserver_protocol_1.CodeActionResolveRequest.type, (params, cancel) => {
712             return handler(params, cancel);
713         }),
714         onCodeLens: (handler) => connection.onRequest(vscode_languageserver_protocol_1.CodeLensRequest.type, (params, cancel) => {
715             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
716         }),
717         onCodeLensResolve: (handler) => connection.onRequest(vscode_languageserver_protocol_1.CodeLensResolveRequest.type, (params, cancel) => {
718             return handler(params, cancel);
719         }),
720         onDocumentFormatting: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentFormattingRequest.type, (params, cancel) => {
721             return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
722         }),
723         onDocumentRangeFormatting: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentRangeFormattingRequest.type, (params, cancel) => {
724             return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
725         }),
726         onDocumentOnTypeFormatting: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentOnTypeFormattingRequest.type, (params, cancel) => {
727             return handler(params, cancel);
728         }),
729         onRenameRequest: (handler) => connection.onRequest(vscode_languageserver_protocol_1.RenameRequest.type, (params, cancel) => {
730             return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
731         }),
732         onPrepareRename: (handler) => connection.onRequest(vscode_languageserver_protocol_1.PrepareRenameRequest.type, (params, cancel) => {
733             return handler(params, cancel);
734         }),
735         onDocumentLinks: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentLinkRequest.type, (params, cancel) => {
736             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
737         }),
738         onDocumentLinkResolve: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentLinkResolveRequest.type, (params, cancel) => {
739             return handler(params, cancel);
740         }),
741         onDocumentColor: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentColorRequest.type, (params, cancel) => {
742             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
743         }),
744         onColorPresentation: (handler) => connection.onRequest(vscode_languageserver_protocol_1.ColorPresentationRequest.type, (params, cancel) => {
745             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
746         }),
747         onFoldingRanges: (handler) => connection.onRequest(vscode_languageserver_protocol_1.FoldingRangeRequest.type, (params, cancel) => {
748             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
749         }),
750         onSelectionRanges: (handler) => connection.onRequest(vscode_languageserver_protocol_1.SelectionRangeRequest.type, (params, cancel) => {
751             return handler(params, cancel, progress_1.attachWorkDone(connection, params), progress_1.attachPartialResult(connection, params));
752         }),
753         onExecuteCommand: (handler) => connection.onRequest(vscode_languageserver_protocol_1.ExecuteCommandRequest.type, (params, cancel) => {
754             return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
755         }),
756         dispose: () => connection.dispose()
757     };
758     for (let remote of allRemotes) {
759         remote.attach(protocolConnection);
760     }
761     connection.onRequest(vscode_languageserver_protocol_1.InitializeRequest.type, (params) => {
762         watchDog.initialize(params);
763         if (Is.string(params.trace)) {
764             tracer.trace = vscode_languageserver_protocol_1.Trace.fromString(params.trace);
765         }
766         for (let remote of allRemotes) {
767             remote.initialize(params.capabilities);
768         }
769         if (initializeHandler) {
770             let result = initializeHandler(params, new vscode_languageserver_protocol_1.CancellationTokenSource().token, progress_1.attachWorkDone(connection, params), undefined);
771             return asPromise(result).then((value) => {
772                 if (value instanceof vscode_languageserver_protocol_1.ResponseError) {
773                     return value;
774                 }
775                 let result = value;
776                 if (!result) {
777                     result = { capabilities: {} };
778                 }
779                 let capabilities = result.capabilities;
780                 if (!capabilities) {
781                     capabilities = {};
782                     result.capabilities = capabilities;
783                 }
784                 if (capabilities.textDocumentSync === undefined || capabilities.textDocumentSync === null) {
785                     capabilities.textDocumentSync = Is.number(protocolConnection.__textDocumentSync) ? protocolConnection.__textDocumentSync : vscode_languageserver_protocol_1.TextDocumentSyncKind.None;
786                 }
787                 else if (!Is.number(capabilities.textDocumentSync) && !Is.number(capabilities.textDocumentSync.change)) {
788                     capabilities.textDocumentSync.change = Is.number(protocolConnection.__textDocumentSync) ? protocolConnection.__textDocumentSync : vscode_languageserver_protocol_1.TextDocumentSyncKind.None;
789                 }
790                 for (let remote of allRemotes) {
791                     remote.fillServerCapabilities(capabilities);
792                 }
793                 return result;
794             });
795         }
796         else {
797             let result = { capabilities: { textDocumentSync: vscode_languageserver_protocol_1.TextDocumentSyncKind.None } };
798             for (let remote of allRemotes) {
799                 remote.fillServerCapabilities(result.capabilities);
800             }
801             return result;
802         }
803     });
804     connection.onRequest(vscode_languageserver_protocol_1.ShutdownRequest.type, () => {
805         watchDog.shutdownReceived = true;
806         if (shutdownHandler) {
807             return shutdownHandler(new vscode_languageserver_protocol_1.CancellationTokenSource().token);
808         }
809         else {
810             return undefined;
811         }
812     });
813     connection.onNotification(vscode_languageserver_protocol_1.ExitNotification.type, () => {
814         try {
815             if (exitHandler) {
816                 exitHandler();
817             }
818         }
819         finally {
820             if (watchDog.shutdownReceived) {
821                 watchDog.exit(0);
822             }
823             else {
824                 watchDog.exit(1);
825             }
826         }
827     });
828     connection.onNotification(vscode_languageserver_protocol_1.SetTraceNotification.type, (params) => {
829         tracer.trace = vscode_languageserver_protocol_1.Trace.fromString(params.value);
830     });
831     return protocolConnection;
832 }
833 exports.createConnection = createConnection;
834 //# sourceMappingURL=server.js.map