Skip to content

Commit c41769e

Browse files
authored
Refactoring all-the-icons functions (#4588)
1 parent 5991c60 commit c41769e

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

lsp-headerline.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ caching purposes.")
157157
lsp-headerline-arrow
158158
(setq lsp-headerline-arrow (let ((all-the-icons-scale-factor 1.0)
159159
(all-the-icons-default-adjust 0))
160-
(lsp-icons-all-the-icons-material-icon
160+
(lsp-icons-all-the-icons-icon
161+
'material
161162
"chevron_right"
162163
'lsp-headerline-breadcrumb-separator-face
163164
">"

lsp-icons.el

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@
3232
:type 'boolean
3333
:group 'lsp-icons)
3434

35-
(declare-function all-the-icons-material "ext:all-the-icons" t t)
35+
(defcustom lsp-modeline-code-action-icons-enable t
36+
"If non-nil, icons support is enabled for modeline-code-action"
37+
:type 'boolean
38+
:group 'lsp-icons)
39+
3640
(declare-function lsp-treemacs-symbol-icon "ext:lsp-treemacs" (kind))
3741
(declare-function lsp-treemacs-get-icon "ext:lsp-treemacs" (icon-name))
3842

3943
(defun lsp-icons--enabled-for-feature (feature)
4044
"Check if icons support is enabled for FEATURE."
4145
(cond
4246
((eq feature 'headerline-breadcrumb) lsp-headerline-breadcrumb-icons-enable)
47+
((eq feature 'modeline-code-action) lsp-modeline-code-action-icons-enable)
4348
(t t)))
4449

4550
(defun lsp-icons--fix-image-background (image)
@@ -79,16 +84,17 @@ if its enabled."
7984
(lsp-icons--fix-image-background
8085
(lsp-treemacs-symbol-icon kind))))
8186

82-
(defun lsp-icons-all-the-icons-material-icon (icon-name face fallback &optional feature)
83-
"Get a material icon from all-the-icons by ICON-NAME using FACE.
87+
(defun lsp-icons-all-the-icons-icon (icon-set icon-name face fallback &optional feature &rest args)
88+
"Get icon ICON-NAME from `all-the-icons' ICON-SET using FACE.
89+
If ARGS is provided, it's a plist passed directly to the `all-the-icons' function.
8490
Fallback to FALLBACK string if not found or not available.
8591
FEATURE is the feature that will use the icon which we should check
8692
if its enabled."
87-
(if (and (functionp 'all-the-icons-material)
88-
(lsp-icons--enabled-for-feature feature))
89-
(all-the-icons-material icon-name
90-
:face face)
91-
(propertize fallback 'face face)))
93+
(let ((icon-set-fn (intern-soft (concat "all-the-icons-" (symbol-name icon-set)))))
94+
(if (and (fboundp icon-set-fn)
95+
(lsp-icons--enabled-for-feature feature))
96+
(apply icon-set-fn icon-name :face face args)
97+
(propertize fallback 'face face))))
9298

9399
(lsp-consistency-check lsp-icons)
94100

lsp-modeline.el

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
;;; Code:
2323

2424
(require 'lsp-mode)
25+
(require 'lsp-icons)
2526

2627
(defgroup lsp-modeline nil
2728
"LSP support for modeline"
@@ -71,7 +72,6 @@
7172
(const :tag "All Projects" :global))
7273
:package-version '(lsp-mode . "6.3"))
7374

74-
(declare-function all-the-icons-octicon "ext:all-the-icons" t t)
7575
(declare-function lsp-treemacs-errors-list "ext:lsp-treemacs" t)
7676

7777

@@ -86,14 +86,6 @@
8686
'lsp-modeline-code-actions-preferred-face
8787
'lsp-modeline-code-actions-face))
8888

89-
(defun lsp-modeline--code-actions-icon (face)
90-
"Build the icon for modeline code actions using FACE."
91-
(if (require 'all-the-icons nil t)
92-
(all-the-icons-octicon "light-bulb"
93-
:face face
94-
:v-adjust -0.0575)
95-
(propertize lsp-modeline-code-action-fallback-icon 'face face)))
96-
9789
(defun lsp-modeline--code-action-name (actions preferred-code-action-title)
9890
"Return the code action name from ACTIONS and PREFERRED-CODE-ACTION-TITLE."
9991
(or preferred-code-action-title
@@ -116,7 +108,13 @@
116108
(mapconcat
117109
(lambda (segment)
118110
(pcase segment
119-
('icon (lsp-modeline--code-actions-icon face))
111+
('icon (lsp-icons-all-the-icons-icon
112+
'octicon
113+
"light-bulb"
114+
face
115+
lsp-modeline-code-action-fallback-icon
116+
'modeline-code-action
117+
:v-adjust -0.0575))
120118
('name (propertize (lsp-modeline--code-action-name actions preferred-code-action)
121119
'face face))
122120
('count (propertize (number-to-string (seq-length actions))

0 commit comments

Comments
 (0)