disable automatic lsp project import prompt by default

now to import / initialize a new lsp workspace/project, a file needs
to be opened from the workspace/project directory, and `M-x lsp` needs
to be manually run, which will trigger the project import prompt

existing lsp workspaces/projects will still open automatically,
triggering the lsp to load for them, etc.
This commit is contained in:
Gered 2024-12-11 17:48:22 -05:00
parent 28d6f2feb4
commit bc7c2b053f

View file

@ -14,14 +14,24 @@
(treesit-auto-add-to-auto-mode-alist 'all)
(global-treesit-auto-mode))
;; This should be used for any hooks instead of `lsp`. Doing so makes it so that
;; LSP will not be loaded automatically unless the file is already part of a
;; pre-configured workspace/project/session. There will be no automatic prompt when
;; a file is opened from a directory that is not part of an existing workspace.
;; To initialize a new workspace/project/session, use `M-x lsp`.
(defun lsp-non-interactive ()
(require 'lsp)
(when (lsp-workspace-root)
(lsp)))
(defun gered/enable-lsp ()
(interactive)
(add-hook 'prog-mode-hook 'lsp)
(add-hook 'prog-mode-hook 'lsp-non-interactive)
(message "Adding lsp hook to prog-modes"))
(defun gered/disable-lsp ()
(interactive)
(remove-hook 'prog-mode-hook 'lsp)
(remove-hook 'prog-mode-hook 'lsp-non-interactive)
(message "Removing lsp hook from prog-modes"))
(use-package lsp-mode
@ -29,7 +39,7 @@
:init
(setq lsp-keymap-prefix "M-z")
:hook
((prog-mode . lsp)
((prog-mode . lsp-non-interactive)
(lsp-mode . lsp-enable-which-key-integration))
:config
(setq lsp-enable-on-type-formatting nil)