emacs-lsp / lsp-python-ms

lsp-mode :heart: Microsoft's python language server
https://emacs-lsp.github.io/lsp-python-ms
BSD 3-Clause "New" or "Revised" License
190 stars 41 forks source link

server crashes if lsp-python-ms-parse-dot-env-enabled #147

Closed rileyrg closed 3 years ago

rileyrg commented 3 years ago

I'm using a pyenv 3.9.2 set up now with no local .venv, .env.
(1) The server isnt automatically installed - I need to manually run the install command lsp-install-server and select mspyls (2) Server falls over if lsp-python-ms-parse-dot-env-enabled` is true.

My working setup:-

       (use-package lsp-python-ms
         :custom
         (lsp-python-ms-auto-install-server t)
         (lsp-python-ms-parse-dot-env-enabled nil)
         :config
         (require 'lsp-python-ms)
         :hook (python-mode . (lambda ()
                                (lsp-deferred))))

When lsp-python-ms-parse-dot-env-enabled is set to t I get the backtrace attached. Snippet:-

Debugger entered--Lisp error: (wrong-type-argument stringp nil) file-name-as-directory(nil) (f-join (file-name-as-directory root) ".env") (let ((envvar (or envvar "PYTHONPATH")) (file (f-join (file-name-as-directory root) ".env")) (rx (concat "^[:blank:]" envvar "[:blank:]=[:blank:]")) val) (if (and (f-exists\? file) (f-file\? file) (f-readable\? file)) (progn (let ((temp-buffer (generate-new-buffer " temp"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents file) (keep-lines rx ... ...) (if ... ...)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))))) lsp-python-ms--parse-dot-env(nil) (progn (lsp-python-ms--parse-dot-env workspace-root)) (if lsp-python-ms-parse-dot-env-enabled (progn (lsp-python-ms--parse-dot-env workspace-root))) (let ((workspace-root (if workspace (progn (or (and (memq ... cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list ... workspace))) (aref workspace 4)) (lsp-python-ms--workspace-root)))) (if lsp-python-ms-parse-dot-env-enabled (progn (lsp-python-ms--parse-dot-env workspace-root))) (let* ((--cl-rest-- (lsp-python-ms--get-python-ver-and-syspath workspace-root)) (pyver (if (= (length --cl-rest--) 3) (car-safe (prog1 --cl-rest-- (setq --cl-rest-- ...))) (signal 'wrong-number-of-arguments (list '... (length --cl-rest--))))) (pysyspath (car-safe (prog1 --cl-rest-- (setq --cl-rest-- (cdr --cl-rest--))))) (pyintpath (car --cl-rest--))) (list ':interpreter (list ':properties (list ':InterpreterPath pyintpath ':UseDefaultDatabase t ':Version pyver)) ':displayOptions '(:preferredFormat "markdown" :trimDocumentationLines :json-false :maxDocumentationLineLength 0 :trimDocumentationText :json-false :maxDocumentationTextLength 0) ':searchPaths (vconcat lsp-python-ms-extra-paths pysyspath) ':analysisUpdates t ':asyncStartup t ':logLevel lsp-python-ms-log-level ':typeStubSearchPaths (vector (expand-file-name (f-join lsp-python-ms-dir "Typeshed")))))) lsp-python-ms--extra-init-params()

backtrace.txt

EDIT:

I did some debugging and the issue is that lsp-python-ms--extra-init-params calls lsp-python-ms--workspace-root (since no workspace passed in) which in turn calls lsp-workspace-root which returns nil despite it being a projectile project.

This is with lsp auto guess root set to t :- when nil it says the project is blacklisted (its not).

LSP :: main.py not in project or it is blacklisted.

There is a .projectile in the directory.

Modifying lsp-python-ms--workspace-root to use lsp--suggest-project-root solved the issue but I have no idea of the knock on effects. Bottom line is lsp-workspace root doesn't use lsp-auto-guess-root to correctly spot a projectile root and that in combination with the lsp-python-ms--workspace-root "cond" statement (it returns the nil returned by lsp-worskapce root) means it fails to identify the project root.