lsp-mode icon indicating copy to clipboard operation
lsp-mode copied to clipboard

Provide function to execute code lens similar to lsp-execute-code-action

Open muirdm opened this issue 5 years ago • 13 comments

Apologies if I missed something, but there I couldn't find a way to execute code lens commands other than clicking on the code lens overlay text. gopls has some lenses such as "run this test" or "enable compiler detail diagnostics" where the lens text's only purpose is to allow you to run the command on the server. It would be useful to have completing read pop up with available lenses, similar to lsp-execute-code-action.

muirdm avatar Aug 15 '20 22:08 muirdm

I think this is possible, but I wonder how the best way to find the lenses, I mean, should we search at the current line? search in the "function" scope? the visible buffer? For a "Run this test' lens, searching by the "function" scope would be better, but for a "enable compiler detail diagnostics", showing lens on the visible buffer maybe would be better.

ericdallo avatar Aug 15 '20 22:08 ericdallo

I don't really have good understanding of code lens use cases in general, but I might start with something like:

  1. If active region, choose code lenses that start or end within region.
  2. Otherwise, list all code lenses but sort them so the the ones "closest" to point come first.

muirdm avatar Aug 16 '20 03:08 muirdm

There is lsp-avy-lens.

yyoncho avatar Aug 16 '20 04:08 yyoncho

There is lsp-avy-lens.

Is that good enough for you?

yyoncho avatar Aug 27 '20 16:08 yyoncho

There is lsp-avy-lens.

Is that good enough for you?

That only shows lenses currently visible in the buffer, right? I want something that shows all the available lenses in the file.

muirdm avatar Aug 27 '20 16:08 muirdm

Yes. The non-visible lenses might not be resolved so showing all lenses in the file is not an option.

yyoncho avatar Aug 27 '20 16:08 yyoncho

The non-visible lenses might not be resolved so showing all lenses in the file is not an option.

I thought the code lens response includes all lenses for the file. Isn't that enough to show a list of all lenses (that are relevant to point) and let the user select one in a completing read?

muirdm avatar Aug 27 '20 16:08 muirdm

There is https://microsoft.github.io/language-server-protocol/specification#codeLens_resolve which as to be called when the server hasn't populated the lens data.

yyoncho avatar Aug 27 '20 16:08 yyoncho

Don't code actions and completion items have the same thing? We show lists of those before resolving them.

muirdm avatar Aug 27 '20 17:08 muirdm

No, they don't. Consider References <Count> lenses. The heavy part is calculating the lens label. While for completion item the heavy part is not the label but calculating the additional text edits, docs, etc.

Also, in general, the completing-read won't work since you can have a lens with the same text on top of the line with the same content. In this case, you won't be able to differentiate the lens while in reality when clicking on them they will return different results. If we include the line number, it won't be fine for invisible lenses.

E. g.

<lens>
public void foo(
    ... long list of parameters)
{ 
}

<lens>
public void foo(
    ... another long list of parameters )
{ 
}

yyoncho avatar Aug 27 '20 17:08 yyoncho

Ah, I didn't realize the lens names can require resolving. Thanks.

Anyway, I still thing there should be a non-visual way to invoke lenses. If there is a code lens on my current line, I don't want to have to click or use avy to run it. I want a "traditional" Emacs command to view/execute it with a single key bind if possible.

muirdm avatar Aug 27 '20 17:08 muirdm

The last one seems like to be doable. Something like M-x lsp-lens-execute which will accept directional param. It will use completing-read in case there more than one lenses grouped on one line.

yyoncho avatar Aug 27 '20 17:08 yyoncho

Any particular interest to solve this or someone working one currently? That's something I've missing in lsp.

ryukinix avatar Dec 03 '24 02:12 ryukinix