Skip to content

Commit 903b790

Browse files
authored
When auto-configure is enabled, remove hooks for disabled options (#3078)
* When auto-configure is enabled, remove hooks for disabled options When `lsp-auto-configure' is enabled, hooks are automatically added to `lsp-configure-hook' for any options which are enabled. However, if any of those options are later disabled, the hooks were not removed from `lsp-configure-hook`; therefore the corresponding behaviour did not get disabled. So add the relevant `remove-hook' calls when options are not enabled. Partial fix for #2525. * Call lsp--auto-configure from lsp-configure-buffer Currently `lsp' is the only thing calling `lsp--auto-configure', which means that auto-configuration only activates when `lsp-mode' called, rather than when a buffer needs to be configured. If we consider the following flow: 1. An option `lsp-headerline-breadcrumb-enable' (say) is set to `t'. 2. `lsp-mode` is called, triggering `lsp--auto-configure', which in turn executes: (add-hook 'lsp-configure-hook 'lsp-headerline-breadcrumb-mode) 3. `lsp-headerline-breadcrumb-enable' is set to `nil'. 4. Another buffer is opened. 5. At this point, `lsp-headerline-breadcrumb-mode' is still in `lsp-configure-hook', therefore, the breadcrumb headerline will be activated even though the option is disabled. Clearly this is undesirable, as reported in #2525. So call `lsp--auto-configure` from `lsp-configure-buffer', so that any hooks which need to be removed will get removed. Fixes #2525.
1 parent 03f6270 commit 903b790

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

lsp-mode.el

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,6 +4050,8 @@ yet."
40504050
(lsp--cur-workspace (list lsp--cur-workspace))))
40514051
lsp--cur-workspace)
40524052
(when lsp-auto-configure
4053+
(lsp--auto-configure)
4054+
40534055
(when (and lsp-enable-text-document-color
40544056
(lsp-feature? "textDocument/documentColor"))
40554057
(add-hook 'lsp-on-change-hook #'lsp--document-color nil t))
@@ -7369,18 +7371,24 @@ returns the command to execute."
73697371
(when (functionp 'lsp-ui-mode)
73707372
(lsp-ui-mode))
73717373

7372-
(when lsp-headerline-breadcrumb-enable
7373-
(add-hook 'lsp-configure-hook 'lsp-headerline-breadcrumb-mode))
7374-
(when lsp-modeline-code-actions-enable
7375-
(add-hook 'lsp-configure-hook 'lsp-modeline-code-actions-mode))
7376-
(when lsp-modeline-diagnostics-enable
7377-
(add-hook 'lsp-configure-hook 'lsp-modeline-diagnostics-mode))
7378-
(when lsp-modeline-workspace-status-enable
7379-
(add-hook 'lsp-configure-hook 'lsp-modeline-workspace-status-mode))
7380-
(when lsp-lens-enable
7381-
(add-hook 'lsp-configure-hook 'lsp-lens--enable))
7382-
(when lsp-semantic-tokens-enable
7383-
(add-hook 'lsp-configure-hook 'lsp-semantic-tokens--enable))
7374+
(if lsp-headerline-breadcrumb-enable
7375+
(add-hook 'lsp-configure-hook 'lsp-headerline-breadcrumb-mode)
7376+
(remove-hook 'lsp-configure-hook 'lsp-headerline-breadcrumb-mode))
7377+
(if lsp-modeline-code-actions-enable
7378+
(add-hook 'lsp-configure-hook 'lsp-modeline-code-actions-mode)
7379+
(remove-hook 'lsp-configure-hook 'lsp-modeline-code-actions-mode))
7380+
(if lsp-modeline-diagnostics-enable
7381+
(add-hook 'lsp-configure-hook 'lsp-modeline-diagnostics-mode)
7382+
(remove-hook 'lsp-configure-hook 'lsp-modeline-diagnostics-mode))
7383+
(if lsp-modeline-workspace-status-enable
7384+
(add-hook 'lsp-configure-hook 'lsp-modeline-workspace-status-mode)
7385+
(remove-hook 'lsp-configure-hook 'lsp-modeline-workspace-status-mode))
7386+
(if lsp-lens-enable
7387+
(add-hook 'lsp-configure-hook 'lsp-lens--enable)
7388+
(remove-hook 'lsp-configure-hook 'lsp-lens--enable))
7389+
(if lsp-semantic-tokens-enable
7390+
(add-hook 'lsp-configure-hook 'lsp-semantic-tokens--enable)
7391+
(remove-hook 'lsp-configure-hook 'lsp-semantic-tokens--enable))
73847392

73857393
;; yas-snippet config
73867394
(setq-local yas-inhibit-overlay-modification-protection t))

0 commit comments

Comments
 (0)