unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: sami@hamb.se
To: help-gnu-emacs@gnu.org
Subject: Eglot code-action organise imports
Date: Fri, 18 Nov 2022 09:42:47 +0100	[thread overview]
Message-ID: <25D6F830-1298-4B4F-AA9C-51173E5F2900@hamb.se> (raw)

Hi all,


I’m trying to get the code action of organize imports to work with before-save-hook. Specifically for go-mode.
I’ve been searching around and found a couple of issues later linking to a solution similar to this:

(defun sami/eglot-organize-imports ()
  (call-interactively 'eglot-code-action-organize-imports))
(defun sami/before-saving-go ()
  (add-hook 'before-save-hook #'eglot-format-buffer -10 t)
  (add-hook 'before-save-hook #'sami/eglot-organize-imports nil t))
(add-hook 'go-mode-hook #'sami/before-saving-go)

Problem seems to be, running the function “eglot-code-actions” and selecting “Organize imports” works fine, but running the stand-alone function of “eglot-code-action-organize-imports” does not yield anything.

Test case:
In any go file, add something like fmt.Println(“hello”) imports the package fmt automatically, deleting or commenting the line does not delete the imported package fmt.   “eglot-code-action-organize-imports” does not delete the imported package fmt. Running the function “eglot-code-actions” and selecting “Organize imports” DOES deletes the package fmt from imports.

There are no errors in *Messages* nor in *EGLOT (testing/(go-mode)) events* 

Br
Sami



                 reply	other threads:[~2022-11-18  8:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25D6F830-1298-4B4F-AA9C-51173E5F2900@hamb.se \
    --to=sami@hamb.se \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).