Use true async and add code actions prefix. - #5
Conversation
|
I've tried your branch but the code action doesn't seem to work. 🤔 |
It's now fixed. |
| (advice-remove 'y-or-n-p #'always))) | ||
|
|
||
| (defvar-local sideline-eglot--ht-candidates nil | ||
| (defvar sideline-eglot--ht-candidates nil |
There was a problem hiding this comment.
Would this work with all buffers since this is no longer a local variable?
There was a problem hiding this comment.
I've tested it on 2 buffers with different language server and it works well for me, it hasn't given me any incovenience.
There was a problem hiding this comment.
also this is the only way i found to make this works because async json apparently works in a temp buffer.
|
This is the working patch for me. diff --git a/sideline-eglot.el b/sideline-eglot.el
index 2d803ef..8266d99 100644
--- a/sideline-eglot.el
+++ b/sideline-eglot.el
@@ -60,39 +60,38 @@ This can be used to insert, for example, an unicode character: 💡"
,@body
(advice-remove 'y-or-n-p #'always)))
-(defvar sideline-eglot--ht-candidates nil
+(defvar-local sideline-eglot--ht-candidates nil
"Holds candidates.")
-(defvar sideline-eglot--callback)
-
(defun sideline-eglot--async-candidates (callback &rest _)
"Request eglot's CALLBACK candidates."
- (setq sideline-eglot--callback callback)
- (jsonrpc-async-request
- (eglot-current-server)
- :textDocument/codeAction
- (list :textDocument (eglot--TextDocumentIdentifier)
- :range (list :start (eglot--pos-to-lsp-position (point))
- :end (eglot--pos-to-lsp-position nil))
- :context
- `(:diagnostics
- [,@(cl-loop for diag in (flymake-diagnostics (point) nil)
- when (cdr (assoc 'eglot-lsp-diag
- (eglot--diag-data diag)))
- collect it)]))
- :success-fn
- (lambda (resp)
- (let ((actions (append resp nil)))
- (if sideline-eglot--ht-candidates
- (ht-clear sideline-eglot--ht-candidates)
- (setq sideline-eglot--ht-candidates (ht-create)))
- (dolist (row actions)
- (ht-set sideline-eglot--ht-candidates
- (concat sideline-eglot-code-actions-prefix
- (cl-getf row :title))
- row))
- (funcall sideline-eglot--callback (ht-keys sideline-eglot--ht-candidates))))
- :deferred :textDocument/codeAction))
+ (let ((buffer (current-buffer)))
+ (jsonrpc-async-request
+ (eglot-current-server)
+ :textDocument/codeAction
+ (list :textDocument (eglot--TextDocumentIdentifier)
+ :range (list :start (eglot--pos-to-lsp-position (point))
+ :end (eglot--pos-to-lsp-position nil))
+ :context
+ `(:diagnostics
+ [,@(cl-loop for diag in (flymake-diagnostics (point) nil)
+ when (cdr (assoc 'eglot-lsp-diag
+ (eglot--diag-data diag)))
+ collect it)]))
+ :success-fn
+ (lambda (resp)
+ (sideline--with-buffer buffer
+ (let ((actions (append resp nil)))
+ (if sideline-eglot--ht-candidates
+ (ht-clear sideline-eglot--ht-candidates)
+ (setq sideline-eglot--ht-candidates (ht-create)))
+ (dolist (row actions)
+ (ht-set sideline-eglot--ht-candidates
+ (concat sideline-eglot-code-actions-prefix
+ (cl-getf row :title))
+ row))
+ (funcall callback (ht-keys sideline-eglot--ht-candidates)))))
+ :deferred :textDocument/codeAction)))
;;;###autoload
(defun sideline-eglot (command)
@@ -110,9 +109,9 @@ Argument COMMAND is required in sideline backend."
(command (cl-getf matching-code-action :command))
(server (eglot-current-server)))
(sideline-eglot--inhibit-timeout
- (eglot-execute-command server
- (cl-getf command :command)
- (cl-getf command :arguments))))))))
+ (eglot-execute-command server
+ (cl-getf command :command)
+ (cl-getf command :arguments))))))))
(provide 'sideline-eglot)
;;; sideline-eglot.el ends here |
| (concat sideline-eglot-code-actions-prefix | ||
| (cl-getf row :title)) | ||
| row)) | ||
| (funcall sideline-eglot--callback (ht-keys sideline-eglot--ht-candidates)))) |
There was a problem hiding this comment.
In the lambda, you will lose buffer local variables sideline-eglot--callback and sideline-eglot--ht-candidates since you are inside the *temp* buffer.
Thanks! it works to me too, i'm updating this patch. |
|
Thank you! |
Based on joaotavora comments (#3).
This adds true async and code action prefix from sideline-lsp.