UNPKG

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