doomemacs / doomemacs

An Emacs framework for the stubborn martian hacker
MIT License
19.45k stars 3.06k forks source link

DoomEmacs Python Lsp not loading properly #7786

Open TBytes404 opened 7 months ago

TBytes404 commented 7 months ago

I confirm that...

Expected behavior

I’ve enabled lsp-mode and the python +lsp language support.

Current behavior

However, when I open a Python file, I encounter the following warning:

Error (python-mode-local-vars-hook): Error running hook "lsp!" because: (void-function lsp-deferred)

Additionally, I see the message:

File local-variables error: (doom-hook-error python-mode-local-vars-hook lsp! (void-function lsp-deferred))

Steps to reproduce

  1. enable lsp & (python +lsp).
  2. open a file with .py extension.

System Information

I’m using Emacs 29 with native-comp on MacOS Sonoma.

TBytes404 commented 7 months ago

I’m new to Emacs. Could you review this change and let me know if it might cause any issues? Should I create a pull request?

Solution:

Modify file: ~/.config/emacs/modules/lang/python/config.el line: 24

--- 24|    (add-hook 'python-mode-local-vars-hook #'lsp! 'append)
+++ 24|    (after! lsp!(add-hook 'python-mode-local-vars-hook #'lsp! 'append))

The (after! lsp!(...)) construct ensures that the hook is executed only after lsp-mode has been fully loaded.

Explanation:

In DoomEmacs, the lsp-deferred function, located in the file ~/.config/emacs/modules/tools/lsp/autoload/common.el at line 9 is used to lazily load lsp-mode.

By adding (after! lsp!(...)), we wait for lsp-mode to be available before executing the hook. This prevents the “void-function lsp-deferred” error.

hlissner commented 7 months ago

Errors about missing lsp-* functions usually mean you've forgotten to enable the :tools lsp module (or you forgot to run doom sync afterwards?). You did not include your M-x doom/info in your system information, so I can't say for sure.

The (after! lsp!(...)) construct ensures that the hook is executed only after lsp-mode has been fully loaded.

This is incorrect. That ensures that the enclosed code never runs at all, because lsp! is not a valid package.

TBytes404 commented 7 months ago
generated  Apr 05, 2024 22:21:46
system     MacOS 14.4.1 Darwin 23.4.0 arm64 ns
emacs      29.3 EMACSDIR=~/.config/emacs/
           EMACS=/opt/homebrew/Cellar/emacs-plus@29/29.3/Emacs.app/Contents/MacOS/Emacs
doom       3.0.0-pre PROFILE=_@0 HEAD -> master, origin/master, origin/HEAD ea4792ccd
           2024-04-01 13:47:12 -0400 ~/.config/doom/
shell      /bin/zsh
features   ACL GIF GLIB GMP GNUTLS JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP NOTIFY
           KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
           TREE_SITTER WEBP XIM ZLIB
traits     gui daemon server-running envvar-file custom-file
custom     tool-bar-mode size-indication-mode column-number-mode blink-cursor-mode
           magit-todos-insert-after connection-local-criteria-alist
           connection-local-profile-alist
modules    :config use-package :completion company vertico :ui doom doom-dashboard
           hl-todo modeline ophints (popup +defaults) (vc-gutter +pretty)
           vi-tilde-fringe workspaces :editor (evil +everywhere) file-templates fold
           (format +onsave) snippets :emacs dired electric undo vc :term vterm
           :checkers syntax :tools (eval +overlay) lookup (lsp +peek) magit :os macos
           :lang emacs-lisp markdown org (python +lsp +pyright) sh :config (default
           +bindings +smartparens)