help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Eglot code-action organise imports


From: sami
Subject: Eglot code-action organise imports
Date: Fri, 18 Nov 2022 09:42:47 +0100

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 via email to

[Prev in Thread] Current Thread [Next in Thread]