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) {
27 * A manager for simple text documents
31 * Create a new text document manager.
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();
43 * An event that fires when a text document managed by this manager
44 * has been opened or the content changes.
46 get onDidChangeContent() {
47 return this._onDidChangeContent.event;
50 * An event that fires when a text document managed by this manager
54 return this._onDidOpen.event;
57 * An event that fires when a text document managed by this manager
61 return this._onWillSave.event;
64 * Sets a handler that will be called if a participant wants to provide
65 * edits during a text document save.
67 onWillSaveWaitUntil(handler) {
68 this._willSaveWaitUntil = handler;
71 * An event that fires when a text document managed by this manager
75 return this._onDidSave.event;
78 * An event that fires when a text document managed by this manager
82 return this._onDidClose.event;
85 * Returns the document for the given URI. Returns undefined if
86 * the document is not managed by this instance.
88 * @param uri The text document's URI to retrieve.
89 * @return the text document or `undefined`.
92 return this._documents[uri];
95 * Returns all text documents managed by this instance.
97 * @return all text documents.
100 return Object.keys(this._documents).map(key => this._documents[key]);
103 * Returns the URIs of all text documents managed by this instance.
105 * @return the URI's of all text documents.
108 return Object.keys(this._documents);
111 * Listens for `low level` notification on the given connection to
112 * update the text documents managed by this instance.
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`.
119 * Use the corresponding events on the TextDocuments instance instead.
121 * @param connection The connection to listen on.
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);
133 connection.onDidChangeTextDocument((event) => {
134 let td = event.textDocument;
135 let changes = event.contentChanges;
136 if (changes.length === 0) {
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`);
144 document = this._configuration.update(document, changes, version);
145 this._documents[td.uri] = document;
146 this._onDidChangeContent.fire(Object.freeze({ document }));
148 connection.onDidCloseTextDocument((event) => {
149 let document = this._documents[event.textDocument.uri];
151 delete this._documents[event.textDocument.uri];
152 this._onDidClose.fire(Object.freeze({ document }));
155 connection.onWillSaveTextDocument((event) => {
156 let document = this._documents[event.textDocument.uri];
158 this._onWillSave.fire(Object.freeze({ document, reason: event.reason }));
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);
170 connection.onDidSaveTextDocument((event) => {
171 let document = this._documents[event.textDocument.uri];
173 this._onDidSave.fire(Object.freeze({ document }));
178 exports.TextDocuments = TextDocuments;
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.
185 class ErrorMessageTracker {
187 this._messages = Object.create(null);
190 * Add a message to the tracker.
192 * @param message The message to add.
195 let count = this._messages[message];
200 this._messages[message] = count;
203 * Send all tracked messages to the connection's window.
205 * @param connection The connection established between client and server.
207 sendErrors(connection) {
208 Object.keys(this._messages).forEach(message => {
209 connection.window.showErrorMessage(message);
213 exports.ErrorMessageTracker = ErrorMessageTracker;
214 class RemoteConsoleImpl {
217 rawAttach(connection) {
218 this._rawConnection = connection;
221 this._connection = connection;
224 if (!this._connection) {
225 throw new Error('Remote is not attached to a connection yet.');
227 return this._connection;
229 fillServerCapabilities(_capabilities) {
231 initialize(_capabilities) {
234 this.send(vscode_languageserver_protocol_1.MessageType.Error, message);
237 this.send(vscode_languageserver_protocol_1.MessageType.Warning, message);
240 this.send(vscode_languageserver_protocol_1.MessageType.Info, message);
243 this.send(vscode_languageserver_protocol_1.MessageType.Log, message);
245 send(type, message) {
246 if (this._rawConnection) {
247 this._rawConnection.sendNotification(vscode_languageserver_protocol_1.LogMessageNotification.type, { type, message });
251 class _RemoteWindowImpl {
255 this._connection = connection;
258 if (!this._connection) {
259 throw new Error('Remote is not attached to a connection yet.');
261 return this._connection;
263 initialize(_capabilities) {
265 fillServerCapabilities(_capabilities) {
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);
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);
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);
280 const RemoteWindowImpl = showDocument_1.ShowDocumentFeature(progress_1.ProgressFeature(_RemoteWindowImpl));
281 var BulkRegistration;
282 (function (BulkRegistration) {
284 * Creates a new bulk registration.
285 * @return an empty bulk registration.
288 return new BulkRegistrationImpl();
290 BulkRegistration.create = create;
291 })(BulkRegistration = exports.BulkRegistration || (exports.BulkRegistration = {}));
292 class BulkRegistrationImpl {
294 this._registrations = [];
295 this._registered = new Set();
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`);
302 const id = UUID.generateUuid();
303 this._registrations.push({
306 registerOptions: registerOptions || {}
308 this._registered.add(method);
310 asRegistrationParams() {
312 registrations: this._registrations
316 var BulkUnregistration;
317 (function (BulkUnregistration) {
319 return new BulkUnregistrationImpl(undefined, []);
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);
332 return !!this._connection;
335 this._connection = connection;
337 add(unregistration) {
338 this._unregistrations.set(unregistration.method, unregistration);
341 let unregistrations = [];
342 for (let unregistration of this._unregistrations.values()) {
343 unregistrations.push(unregistration);
346 unregisterations: unregistrations
348 this._connection.sendRequest(vscode_languageserver_protocol_1.UnregistrationRequest.type, params).then(undefined, (_error) => {
349 this._connection.console.info(`Bulk unregistration failed.`);
353 const method = Is.string(arg) ? arg : arg.method;
354 const unregistration = this._unregistrations.get(method);
355 if (!unregistration) {
359 unregisterations: [unregistration]
361 this._connection.sendRequest(vscode_languageserver_protocol_1.UnregistrationRequest.type, params).then(() => {
362 this._unregistrations.delete(method);
364 this._connection.console.info(`Un-registering request handler for ${unregistration.id} failed.`);
369 class RemoteClientImpl {
371 this._connection = connection;
374 if (!this._connection) {
375 throw new Error('Remote is not attached to a connection yet.');
377 return this._connection;
379 initialize(_capabilities) {
381 fillServerCapabilities(_capabilities) {
383 register(typeOrRegistrations, registerOptionsOrType, registerOptions) {
384 if (typeOrRegistrations instanceof BulkRegistrationImpl) {
385 return this.registerMany(typeOrRegistrations);
387 else if (typeOrRegistrations instanceof BulkUnregistrationImpl) {
388 return this.registerSingle1(typeOrRegistrations, registerOptionsOrType, registerOptions);
391 return this.registerSingle2(typeOrRegistrations, registerOptionsOrType);
394 registerSingle1(unregistration, type, registerOptions) {
395 const method = Is.string(type) ? type : type.method;
396 const id = UUID.generateUuid();
398 registrations: [{ id, method, registerOptions: registerOptions || {} }]
400 if (!unregistration.isAttached) {
401 unregistration.attach(this.connection);
403 return this.connection.sendRequest(vscode_languageserver_protocol_1.RegistrationRequest.type, params).then((_result) => {
404 unregistration.add({ id: id, method: method });
405 return unregistration;
407 this.connection.console.info(`Registering request handler for ${method} failed.`);
408 return Promise.reject(_error);
411 registerSingle2(type, registerOptions) {
412 const method = Is.string(type) ? type : type.method;
413 const id = UUID.generateUuid();
415 registrations: [{ id, method, registerOptions: registerOptions || {} }]
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);
422 this.connection.console.info(`Registering request handler for ${method} failed.`);
423 return Promise.reject(_error);
426 unregisterSingle(id, method) {
428 unregisterations: [{ id, method }]
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.`);
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 }; }));
439 this.connection.console.info(`Bulk registration failed.`);
440 return Promise.reject(_error);
444 class _RemoteWorkspaceImpl {
448 this._connection = connection;
451 if (!this._connection) {
452 throw new Error('Remote is not attached to a connection yet.');
454 return this._connection;
456 initialize(_capabilities) {
458 fillServerCapabilities(_capabilities) {
460 applyEdit(paramOrEdit) {
461 function isApplyWorkspaceEditParams(value) {
462 return value && !!value.edit;
464 let params = isApplyWorkspaceEditParams(paramOrEdit) ? paramOrEdit : { edit: paramOrEdit };
465 return this.connection.sendRequest(vscode_languageserver_protocol_1.ApplyWorkspaceEditRequest.type, params);
468 const RemoteWorkspaceImpl = fileOperations_1.FileOperationsFeature(workspaceFolders_1.WorkspaceFoldersFeature(configuration_1.ConfigurationFeature(_RemoteWorkspaceImpl)));
471 this._trace = vscode_languageserver_protocol_1.Trace.Off;
474 this._connection = connection;
477 if (!this._connection) {
478 throw new Error('Remote is not attached to a connection yet.');
480 return this._connection;
482 initialize(_capabilities) {
484 fillServerCapabilities(_capabilities) {
489 log(message, verbose) {
490 if (this._trace === vscode_languageserver_protocol_1.Trace.Off) {
493 this.connection.sendNotification(vscode_languageserver_protocol_1.LogTraceNotification.type, {
495 verbose: this._trace === vscode_languageserver_protocol_1.Trace.Verbose ? verbose : undefined
499 class TelemetryImpl {
503 this._connection = connection;
506 if (!this._connection) {
507 throw new Error('Remote is not attached to a connection yet.');
509 return this._connection;
511 initialize(_capabilities) {
513 fillServerCapabilities(_capabilities) {
516 this.connection.sendNotification(vscode_languageserver_protocol_1.TelemetryEventNotification.type, data);
519 class _LanguagesImpl {
523 this._connection = connection;
526 if (!this._connection) {
527 throw new Error('Remote is not attached to a connection yet.');
529 return this._connection;
531 initialize(_capabilities) {
533 fillServerCapabilities(_capabilities) {
535 attachWorkDoneProgress(params) {
536 return progress_1.attachWorkDone(this.connection, params);
538 attachPartialResultProgress(_type, params) {
539 return progress_1.attachPartialResult(this.connection, params);
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));
549 exports.combineConsoleFeatures = combineConsoleFeatures;
550 function combineTelemetryFeatures(one, two) {
551 return function (Base) {
552 return two(one(Base));
555 exports.combineTelemetryFeatures = combineTelemetryFeatures;
556 function combineTracerFeatures(one, two) {
557 return function (Base) {
558 return two(one(Base));
561 exports.combineTracerFeatures = combineTracerFeatures;
562 function combineClientFeatures(one, two) {
563 return function (Base) {
564 return two(one(Base));
567 exports.combineClientFeatures = combineClientFeatures;
568 function combineWindowFeatures(one, two) {
569 return function (Base) {
570 return two(one(Base));
573 exports.combineWindowFeatures = combineWindowFeatures;
574 function combineWorkspaceFeatures(one, two) {
575 return function (Base) {
576 return two(one(Base));
579 exports.combineWorkspaceFeatures = combineWorkspaceFeatures;
580 function combineLanguagesFeatures(one, two) {
581 return function (Base) {
582 return two(one(Base));
585 exports.combineLanguagesFeatures = combineLanguagesFeatures;
586 function combineFeatures(one, two) {
587 function combine(one, two, func) {
589 return func(one, two);
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)
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) {
625 else if (Is.thenable(value)) {
626 return new Promise((resolve, reject) => {
627 value.then((resolved) => resolve(resolved), (error) => reject(error));
631 return Promise.resolve(value);
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);
647 connection.sendNotification(method, param);
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);
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));
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);
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));
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));
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));
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));
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));
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));
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));
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));
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));
711 onCodeActionResolve: (handler) => connection.onRequest(vscode_languageserver_protocol_1.CodeActionResolveRequest.type, (params, cancel) => {
712 return handler(params, cancel);
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));
717 onCodeLensResolve: (handler) => connection.onRequest(vscode_languageserver_protocol_1.CodeLensResolveRequest.type, (params, cancel) => {
718 return handler(params, cancel);
720 onDocumentFormatting: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentFormattingRequest.type, (params, cancel) => {
721 return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
723 onDocumentRangeFormatting: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentRangeFormattingRequest.type, (params, cancel) => {
724 return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
726 onDocumentOnTypeFormatting: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentOnTypeFormattingRequest.type, (params, cancel) => {
727 return handler(params, cancel);
729 onRenameRequest: (handler) => connection.onRequest(vscode_languageserver_protocol_1.RenameRequest.type, (params, cancel) => {
730 return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
732 onPrepareRename: (handler) => connection.onRequest(vscode_languageserver_protocol_1.PrepareRenameRequest.type, (params, cancel) => {
733 return handler(params, cancel);
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));
738 onDocumentLinkResolve: (handler) => connection.onRequest(vscode_languageserver_protocol_1.DocumentLinkResolveRequest.type, (params, cancel) => {
739 return handler(params, cancel);
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));
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));
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));
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));
753 onExecuteCommand: (handler) => connection.onRequest(vscode_languageserver_protocol_1.ExecuteCommandRequest.type, (params, cancel) => {
754 return handler(params, cancel, progress_1.attachWorkDone(connection, params), undefined);
756 dispose: () => connection.dispose()
758 for (let remote of allRemotes) {
759 remote.attach(protocolConnection);
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);
766 for (let remote of allRemotes) {
767 remote.initialize(params.capabilities);
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) {
777 result = { capabilities: {} };
779 let capabilities = result.capabilities;
782 result.capabilities = capabilities;
784 if (capabilities.textDocumentSync === undefined || capabilities.textDocumentSync === null) {
785 capabilities.textDocumentSync = Is.number(protocolConnection.__textDocumentSync) ? protocolConnection.__textDocumentSync : vscode_languageserver_protocol_1.TextDocumentSyncKind.None;
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;
790 for (let remote of allRemotes) {
791 remote.fillServerCapabilities(capabilities);
797 let result = { capabilities: { textDocumentSync: vscode_languageserver_protocol_1.TextDocumentSyncKind.None } };
798 for (let remote of allRemotes) {
799 remote.fillServerCapabilities(result.capabilities);
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);
813 connection.onNotification(vscode_languageserver_protocol_1.ExitNotification.type, () => {
820 if (watchDog.shutdownReceived) {
828 connection.onNotification(vscode_languageserver_protocol_1.SetTraceNotification.type, (params) => {
829 tracer.trace = vscode_languageserver_protocol_1.Trace.fromString(params.value);
831 return protocolConnection;
833 exports.createConnection = createConnection;
834 //# sourceMappingURL=server.js.map