Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #393: eglot-completing-read #393

Merged
merged 2 commits into from
Jan 2, 2020

Conversation

theothornhill
Copy link
Collaborator

This is a first try on the completion-read function. Highly inspired from lsp-mode, maybe this is something we can use?

@theothornhill theothornhill changed the title Close #386: allow for auto code-action when only one action Close #389: eglot-completing-read Dec 31, 2019
@joaotavora
Copy link
Owner

@theothornhill this is not exempt from copyright paperwork, because:

  1. It is not a "tiny" or "trivial" patch
  2. It is "highly inspired" by lsp-mode, which means it might be a derivative work.

Probably 2 is not a problem since Yasnippet also has that implementation, much earlier than lsp-mode and it is simple enough (and Yasnippet is the FSF's already).

Anyway, I will review this when I have time.

@theothornhill
Copy link
Collaborator Author

theothornhill commented Dec 31, 2019

I understand. I will clean up the PR, and let you have a look. FYI, the implementation inside eglot-code-actions is more of a proof-of-concept. It is a very simple implementation still

theothornhill added a commit to theothornhill/eglot that referenced this pull request Dec 31, 2019
* eglot.el (eglot-code-actions): Remove code related to tmm
* eglot.el (eglot--completing-read): Adds implementation for
completing-read
theothornhill added a commit to theothornhill/eglot that referenced this pull request Dec 31, 2019
* eglot.el (eglot-code-actions): Remove code related to tmm
* eglot.el (eglot--completing-read): Adds implementation for
completing-read
theothornhill added a commit to theothornhill/eglot that referenced this pull request Dec 31, 2019
* eglot.el (eglot-code-actions): Remove code related to tmm
* eglot.el (eglot--completing-read): Adds implementation for
completing-read
theothornhill added a commit to theothornhill/eglot that referenced this pull request Dec 31, 2019
* eglot.el (eglot-code-actions): Remove code related to tmm
* eglot.el (eglot--completing-read): Adds implementation for
completing-read
@theothornhill
Copy link
Collaborator Author

which means it might be a derivative work.

Inspiration is mostly the last line though, and it seems like a quite general thing, but I don’t know much about these things

@theothornhill theothornhill changed the title Close #389: eglot-completing-read Close #393: eglot-completing-read Dec 31, 2019
@theothornhill
Copy link
Collaborator Author

I added an extra commit with some more refactorings and functionality. I feel this helps readability of eglot-code-actions, yet unsure if deviates too much from current coding style

@theothornhill theothornhill force-pushed the eglot-completing-read branch from 62bf1bc to 9eafdd3 Compare January 1, 2020 11:00
@joaotavora
Copy link
Owner

joaotavora commented Jan 1, 2020

@theothornhill before you go further, let me tell you that even before that newest commit this sounds like a lot of code to solve a problem that I don't really remember any more: you want to select LSP code actions in text mode exclusively, right?

@theothornhill
Copy link
Collaborator Author

Well, this commit allows us to use the completion framework of choice to select and navigate code actions. Right now we have to use tmm, but I believe we should be able to use ido/helm/ivy/vanilla. All of them hook into completing-read.

As far as a lot of code goes, it’s mostly extracted from the existing function. It can easily be added back.

I believe we could change this so that it only works for completing code actions, but I think some sort of lsp-response-completing-read would simplify a lot of the code in Eglot

@joaotavora
Copy link
Owner

but I think some sort of lsp-response-completing-read would simplify a lot of the code in Eglot

What other code besides LSP code-action selections?

@theothornhill
Copy link
Collaborator Author

I think workspace allows for returning available workspaces, and I assume it is returned through jsonrpc, and as such could benefit from creating alist and completing them. Not sure if it is implemented yet in eglot though

@theothornhill
Copy link
Collaborator Author

I like the minimalism of eglot - it’s why I use it. However I think normal completing read offers equivalent functionality to tmm, but in addition gives people who use ivy/helm a unified experience

@joaotavora
Copy link
Owner

joaotavora commented Jan 1, 2020

I'm OK with adding completing-read somewhere in the code, but you seem to be touching too much, and I don't see a use for it outside LSP code actions. I can't get a server to trigger code actions right now (all I have handy is clangd and pyls), so I can't show you what I absolutely suspect is a much simpler implementation for this, like this

diff --git a/eglot.el b/eglot.el
index 4c0160a..fd43ce2 100644
--- a/eglot.el
+++ b/eglot.el
@@ -2461,12 +2461,10 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp."
          (menu `("Eglot code actions:" ("dummy" ,@menu-items)))
          (action (if (listp last-nonmenu-event)
                      (x-popup-menu last-nonmenu-event menu)
-                   (let ((never-mind (gensym)) retval)
-                     (setcdr (cadr menu)
-                             (cons `("never mind..." . ,never-mind) (cdadr menu)))
-                     (if (eq (setq retval (tmm-prompt menu)) never-mind)
-                         (keyboard-quit)
-                       retval)))))
+                   ;; maybe missing a `cdr' or `cadr' or sth like that here
+                   (assoc (completing-read "[eglot] Action? "
+                                           menu-items nil 'required)
+                          menu-items))))
     (eglot--dcase action
         (((Command) command arguments)
          (eglot-execute-command server (intern command) arguments))

@joaotavora
Copy link
Owner

Can you start from that implementation and test?

theothornhill added a commit to theothornhill/eglot that referenced this pull request Jan 1, 2020
* eglot.el (eglot-code-actions): Remove code related to tmm
and add completing-read
@theothornhill theothornhill force-pushed the eglot-completing-read branch from 9eafdd3 to 99cda7d Compare January 1, 2020 19:09
@theothornhill
Copy link
Collaborator Author

theothornhill commented Jan 1, 2020

Can you start from that implementation and test?

This version should work fine for completing-read of code actions

eglot.el Outdated Show resolved Hide resolved
* eglot.el (eglot-code-actions): Remove code related to tmm
and add completing-read
@joaotavora joaotavora merged commit 4496657 into joaotavora:master Jan 2, 2020
@joaotavora
Copy link
Owner

Thanks! Now if you additionally also think that auto-confirming a single option is a good idea, work on a separate pull request for that, according to what we already discussed.

@nemethf
Copy link
Collaborator

nemethf commented Jan 2, 2020

It was possible to select a non-default action with just one keystroke with the old tmm-based solution. This is now more complicated with the new completing-read version with its default settings. Is there a completion package that provides easy selection? (I haven't tried all of them.) Thank you.

@nemethf
Copy link
Collaborator

nemethf commented Jan 2, 2020

Hm. Or is it possible to use tmm as a completing-read function?

@joaotavora
Copy link
Owner

Is there a completion package that provides easy selection? (I haven't tried all of them.)

I haven't tried them, but Ivy and Helm are pretty popular options. I personally use fido-mode in the Emacs 27 branch, you can convince to add, say, numbered shortcuts to it :-)

@joaotavora
Copy link
Owner

Hm. Or is it possible to use tmm as a completing-read function?

That would be interesting, I think.

@nemethf
Copy link
Collaborator

nemethf commented Jan 2, 2020

Thanks. I've unfortunately accumulated a decent backlog, but I'm going to look at it.

@theothornhill theothornhill deleted the eglot-completing-read branch January 2, 2020 13:17
@nemethf
Copy link
Collaborator

nemethf commented Jan 18, 2020

Hm. Or is it possible to use tmm as a completing-read function?

That would be interesting, I think.

It wasn't possible out of the box, but I took a stab at it: https://github.com/nemethf/single-key-completion

I'd like to test it with Eglot. Do you happen to know an example where the server returns more than one code-action? Thanks.

@theothornhill
Copy link
Collaborator Author

theothornhill commented Jan 18, 2020

Using typescript-language-server and create-react-app, you can try to create a new class/hook, then import to App.js. Usually gives me import as a code action and move to new file. Not sure how minimal you would consider this to be, but I believe it’s reproducible at least :)

Typescript-language-server gives a lot of code actions all over, so should be easy enough to get it

bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 18, 2022
See also joaotavora/eglot#386.

* eglot.el (eglot-code-actions): Replace tmm with completing-read

Copyright-paperwork-exempt: yes
Co-authored-by: João Távora <[email protected]>
bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 19, 2022
See also joaotavora/eglot#386.

* eglot.el (eglot-code-actions): Replace tmm with completing-read

Copyright-paperwork-exempt: yes
Co-authored-by: João Távora <[email protected]>
bhankas pushed a commit to bhankas/emacs that referenced this pull request Sep 19, 2022
See also #386.

* eglot.el (eglot-code-actions): Replace tmm with completing-read

Copyright-paperwork-exempt: yes
Co-authored-by: João Távora <[email protected]>

#393: joaotavora/eglot#393
#386: joaotavora/eglot#386
jollaitbot pushed a commit to sailfishos-mirror/emacs that referenced this pull request Oct 12, 2022
See also joaotavora/eglot#386.

* eglot.el (eglot-code-actions): Replace tmm with completing-read

Copyright-paperwork-exempt: yes
Co-authored-by: João Távora <[email protected]>
GitHub-reference: close joaotavora/eglot#393
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants