diff --git a/lib/CodeLensManager.js b/lib/CodeLensManager.js index d6a645cd..a0730233 100644 --- a/lib/CodeLensManager.js +++ b/lib/CodeLensManager.js @@ -15,26 +15,27 @@ class CodeLensManager constructor() { this.markers = {}; this.annotations = {}; - this.service = null; } /** * @param {TextEditor} editor * @param {Array} codeLenses + * @param {Callable} executeCommandHandler */ - process(editor, codeLenses) { + process(editor, codeLenses, executeCommandHandler) { this.removeMarkers(editor); codeLenses.forEach((codeLens) => { - this.processOne(editor, codeLens); + this.processOne(editor, codeLens, executeCommandHandler); }); } /** * @param {TextEditor} editor * @param {Object} codeLens + * @param {Callable} executeCommandHandler */ - processOne(editor, codeLens) { + processOne(editor, codeLens, executeCommandHandler) { if (!codeLens.command) { // To support this, one would have to send a resolve request and show some sort of placeholder beforehand, // as we wouldn't know what title to show yet. @@ -59,8 +60,10 @@ class CodeLensManager anchorElement.classList.add('badge-small'); anchorElement.href = '#'; anchorElement.addEventListener('click', () => { - // TODO: To fix too long hover line, place anchor inside div and give div the nbsp's. - console.log("TODO: Execute command via server ", codeLens.command); + executeCommandHandler({ + command: codeLens.command.command, + arguments: codeLens.command.arguments, + }); }); // Markers are glued against the gutter by default, make sure they are indented to the level of the code. diff --git a/lib/SerenataClient.js b/lib/SerenataClient.js index 9e99366b..5b923a0c 100644 --- a/lib/SerenataClient.js +++ b/lib/SerenataClient.js @@ -188,6 +188,7 @@ class SerenataClient extends AutoLanguageClient this.connection = connection; + connection.onCustom('serenata/openTextDocument', this.onOpenTextDocument.bind(this)); connection.onCustom('serenata/didProgressIndexing', this.onDidProgressIndexing.bind(this)); if (this.container.getConfiguration().get('refactoring.enable')) { @@ -235,10 +236,11 @@ class SerenataClient extends AutoLanguageClient const codeLenses = await this.codeLens(editor); - // provider.activate(this.getLegacyServiceShim()); - // range: convert_1.default.lsRangeToAtomRange(codeLens.range), - - this.container.getCodeLensManager().process(editor, codeLenses); + this.container.getCodeLensManager().process( + editor, + codeLenses, + this.connection.executeCommand.bind(this.connection) + ); } async codeLens(editor) { @@ -410,6 +412,15 @@ class SerenataClient extends AutoLanguageClient }); } + onOpenTextDocument(parameters) { + const {Convert} = require('atom-languageclient'); + + atom.workspace.open(Convert.uriToPath(parameters.uri), { + initialLine: parameters.position.line, + searchAllPanes: true, + }); + } + onDidProgressIndexing(data) { if (!this.indexingProgressBusyMessage) { this.indexingProgressBusyMessage = this.busySignalService.reportBusy('Indexing (scanning)', {