"use strict"; /* -------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DeclarationFeature = void 0; const vscode_1 = require("vscode"); const vscode_languageserver_protocol_1 = require("vscode-languageserver-protocol"); const client_1 = require("./client"); function ensure(target, key) { if (target[key] === void 0) { target[key] = {}; } return target[key]; } class DeclarationFeature extends client_1.TextDocumentFeature { constructor(client) { super(client, vscode_languageserver_protocol_1.DeclarationRequest.type); } fillClientCapabilities(capabilities) { const declarationSupport = ensure(ensure(capabilities, 'textDocument'), 'declaration'); declarationSupport.dynamicRegistration = true; declarationSupport.linkSupport = true; } initialize(capabilities, documentSelector) { const [id, options] = this.getRegistration(documentSelector, capabilities.declarationProvider); if (!id || !options) { return; } this.register({ id: id, registerOptions: options }); } registerLanguageProvider(options) { const provider = { provideDeclaration: (document, position, token) => { const client = this._client; const provideDeclaration = (document, position, token) => { return client.sendRequest(vscode_languageserver_protocol_1.DeclarationRequest.type, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position), token).then(client.protocol2CodeConverter.asDeclarationResult, (error) => { return client.handleFailedRequest(vscode_languageserver_protocol_1.DeclarationRequest.type, error, null); }); }; const middleware = client.clientOptions.middleware; return middleware.provideDeclaration ? middleware.provideDeclaration(document, position, token, provideDeclaration) : provideDeclaration(document, position, token); } }; return [vscode_1.languages.registerDeclarationProvider(options.documentSelector, provider), provider]; } } exports.DeclarationFeature = DeclarationFeature; //# sourceMappingURL=declaration.js.map