Skip to content

Commit

Permalink
Execute commands in code lenses when clicked
Browse files Browse the repository at this point in the history
References #460
  • Loading branch information
Gert-dev committed Sep 3, 2019
1 parent f5fcbcf commit f269561
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
15 changes: 9 additions & 6 deletions lib/CodeLensManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
19 changes: 15 additions & 4 deletions lib/SerenataClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)', {
Expand Down

0 comments on commit f269561

Please sign in to comment.