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

Feature/lsp UI sideline disabled preferred actions #545

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions lsp-ui-sideline.el
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,29 @@ Push sideline overlays on `lsp-ui-sideline--ovs'."
(propertize " " 'display (lsp-ui-sideline--code-actions-make-image))
(propertize " " 'display '(space :width 0.3))))))

(defface lsp-ui-sideline-disabled-code-action-face
'((t :inherit lsp-disabled-code-action-face))
"Faced used to show disabled code actions in the sideline.")

(defface lsp-ui-sideline-preferred-code-action-face
'((t :inherit lsp-preferred-code-action-face))
"Face used to show preferred code actions in the sideline.")

(defcustom lsp-ui-sideline-show-disabled-code-actions t
"Whether disabled code actions should be shown.
They cannot be executed."
:type 'boolean
:group 'lsp-ui-sideline)

(defun lsp-ui-sideline--code-actions (actions bol eol)
"Show code ACTIONS."
(let ((inhibit-modification-hooks t))
(when lsp-ui-sideline-actions-kind-regex
(setq actions (seq-filter (-lambda ((&CodeAction :kind?))
(or (not kind?)
(s-match lsp-ui-sideline-actions-kind-regex kind?)))
(setq actions (seq-filter (-lambda ((&CodeAction :kind? :disabled?))
(and (or (not disabled?)
lsp-ui-sideline-show-disabled-code-actions)
(or (not kind?)
(s-match lsp-ui-sideline-actions-kind-regex kind?))))
actions)))
(setq lsp-ui-sideline--code-actions actions)
(lsp-ui-sideline--delete-kind 'actions)
Expand All @@ -489,8 +505,14 @@ Push sideline overlays on `lsp-ui-sideline--ovs'."
(lsp-execute-code-action action))))
map))
(len (length title))
((&CodeAction :disabled? :is-preferred?) action)
(title (progn (add-face-text-property 0 len 'lsp-ui-sideline-global nil title)
(add-face-text-property 0 len 'lsp-ui-sideline-code-action nil title)
(when is-preferred?
(add-face-text-property 0 len 'lsp-ui-sideline-preferred-code-action-face nil title))
(when disabled?
(add-face-text-property 0 len 'lsp-ui-sideline-disabled-code-action-face nil title)
(add-text-properties 0 len `(help-echo ,(lsp:code-action-disabled-reason disabled?)) title))
(add-text-properties 0 len `(keymap ,keymap mouse-face highlight) title)
title))
(string (concat (propertize " " 'display `(space :align-to (- right-fringe ,(lsp-ui-sideline--align (+ len (length image)) margin))))
Expand Down