emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.75k stars 872 forks source link

Renamed/deleted directories wrongly persist in LSP session #3019

Open betaprior opened 3 years ago

betaprior commented 3 years ago

Thank you for the bug report

Bug description

After renaming a directory containing the source file, LSP throws errors on startup:

Error processing message (file-missing "Opening directory" "No such file or directory" <OLD_DEFUNCT_PATH>).

This path shows up when I do M-x lsp-describe-session and there appears to be no way of deleting it. Elsewhere on the internet, it is suggested to delete the session cache file and restart Emacs ([https://www.baozi.technology/spacemacs-fixing-lsp-mode-whining-about-not-finding-your-directory](see here)), but surely you don't expect users to restart emacs after doing some minor file operations!

Steps to reproduce

Consider a simple python project with a single file, edited w/ the help of LSP, e.g. /tmp/foo/main.py. Close the file, then in a terminal mv foo bar, and open /tmp/bar/main.py. LSP will complain about the missing file.

Expected behavior

Defunct/missing directories to be cleaned up automatically, or at least offer the user the option of removing the defunct directory from whatever session cache it is stored in.

Which Language Server did you use?

lsp-python with pyright

OS

Linux

Error callstack

Debugger entered--Lisp error: (file-missing "Opening directory" "No such file or directory" "/home/leo/projects/ledgerdomain/sandbox/docuseal-f...")
  directory-files("/home/leo/projects/ledgerdomain/sandbox/docuseal-f...")
  (-filter #'(lambda (path) (lsp--path-is-watchable-directory path dir ignored-directories)) (directory-files dir))
  (-map #'(lambda (path) (lsp--all-watchable-directories (f-join dir path) ignored-directories)) (-filter #'(lambda (path) (lsp--path-is-watchable-directory path dir ignored-directories)) (directory-files dir)))
  (apply #'nconc (list dir) (-map #'(lambda (path) (lsp--all-watchable-directories (f-join dir path) ignored-directories)) (-filter #'(lambda (path) (lsp--path-is-watchable-directory path dir ignored-directories)) (directory-files dir))))
  (let* ((dir (if (f-symlink\? dir) (file-truename dir) dir))) (apply #'nconc (list dir) (-map #'(lambda (path) (lsp--all-watchable-directories (f-join dir path) ignored-directories)) (-filter #'(lambda (path) (lsp--path-is-watchable-directory path dir ignored-directories)) (directory-files dir)))))
  lsp--all-watchable-directories("/home/leo/projects/ledgerdomain/sandbox/docuseal-f..." ("[/\\\\]\\.git\\'" "[/\\\\]\\.github\\'" "[/\\\\]\\.circleci\\'" "[/\\\\]\\.hg\\'" "[/\\\\]\\.bzr\\'" "[/\\\\]_darcs\\'" "[/\\\\]\\.svn\\'" "[/\\\\]_FOSSIL_\\'" "[/\\\\]\\.idea\\'" "[/\\\\]\\.ensime_cache\\'" "[/\\\\]\\.eunit\\'" "[/\\\\]node_modules" "[/\\\\]\\.fslckout\\'" "[/\\\\]\\.tox\\'" "[/\\\\]dist\\'" "[/\\\\]dist-newstyle\\'" "[/\\\\]\\.stack-work\\'" "[/\\\\]\\.bloop\\'" "[/\\\\]\\.metals\\'" "[/\\\\]target\\'" "[/\\\\]\\.ccls-cache\\'" "[/\\\\]\\.vscode\\'" "[/\\\\]\\.deps\\'" "[/\\\\]build-aux\\'" "[/\\\\]autom4te.cache\\'" "[/\\\\]\\.reference\\'" "[/\\\\]\\.lsp\\'" "[/\\\\]\\.clj-kondo\\'" "[/\\\\]\\.shadow-cljs\\'" "[/\\\\]\\.babel_cache\\'" "[/\\\\]\\.cpcache\\'" "[/\\\\]bin/Debug\\'" "[/\\\\]obj\\'" "[/\\\\]_opam\\'" "[/\\\\]_build\\'" "[/\\\\]\\.direnv\\'"))
  (let* ((dir (if (f-symlink\? dir) (file-truename dir) dir)) (watch (or watch (make-lsp-watch :root-directory dir))) (dirs-to-watch (lsp--all-watchable-directories dir ignored-directories))) (lsp-log "Creating watchers for following %s folders:\n  %s" (length dirs-to-watch) (s-join "\n  " dirs-to-watch)) (if (or (not warn-big-repo\?) (not lsp-file-watch-threshold) (let ((number-of-directories (length dirs-to-watch))) (or (< number-of-directories lsp-file-watch-threshold) (condition-case _err (lsp--ask-about-watching-big-repo number-of-directories dir) ('quit))))) (progn (let ((--dolist-tail-- dirs-to-watch)) (while --dolist-tail-- (let ((current-dir ...)) (condition-case err (progn ...) (error ...) (file-missing ...)) (setq --dolist-tail-- (cdr --dolist-tail--))))))) watch)
  lsp-watch-root-folder("/home/leo/projects/ledgerdomain/sandbox/docuseal-f..." #f(compiled-function (&rest args2) #<bytecode 0x1580852fb9d9>) ("[/\\\\]flycheck_[^/\\\\]+\\'" "[/\\\\]\\.#[^/\\\\]+\\'" "[/\\\\][^/\\\\]+~\\'") ("[/\\\\]\\.git\\'" "[/\\\\]\\.github\\'" "[/\\\\]\\.circleci\\'" "[/\\\\]\\.hg\\'" "[/\\\\]\\.bzr\\'" "[/\\\\]_darcs\\'" "[/\\\\]\\.svn\\'" "[/\\\\]_FOSSIL_\\'" "[/\\\\]\\.idea\\'" "[/\\\\]\\.ensime_cache\\'" "[/\\\\]\\.eunit\\'" "[/\\\\]node_modules" "[/\\\\]\\.fslckout\\'" "[/\\\\]\\.tox\\'" "[/\\\\]dist\\'" "[/\\\\]dist-newstyle\\'" "[/\\\\]\\.stack-work\\'" "[/\\\\]\\.bloop\\'" "[/\\\\]\\.metals\\'" "[/\\\\]target\\'" "[/\\\\]\\.ccls-cache\\'" "[/\\\\]\\.vscode\\'" "[/\\\\]\\.deps\\'" "[/\\\\]build-aux\\'" "[/\\\\]autom4te.cache\\'" "[/\\\\]\\.reference\\'" "[/\\\\]\\.lsp\\'" "[/\\\\]\\.clj-kondo\\'" "[/\\\\]\\.shadow-cljs\\'" "[/\\\\]\\.babel_cache\\'" "[/\\\\]\\.cpcache\\'" "[/\\\\]bin/Debug\\'" "[/\\\\]obj\\'" "[/\\\\]_opam\\'" "[/\\\\]_build\\'" "[/\\\\]\\.direnv\\'") #s(lsp-watch :descriptors #<hash-table equal 0/65 0x158085c6b279> :root-directory "/home/leo/projects/ledgerdomain/sandbox/docuseal-f...") t)
  (let* ((watch (make-lsp-watch :root-directory folder)) (ignored-things (lsp--get-ignored-regexes-for-workspace-root folder)) (ignored-files-regex-list (car ignored-things)) (ignored-directories-regex-list (car (cdr ignored-things)))) (puthash folder watch created-watches) (lsp-watch-root-folder (file-truename folder) (-partial #'lsp--file-process-event (lsp-session) folder) ignored-files-regex-list ignored-directories-regex-list watch t))
  (let ((folder (car --dolist-tail--))) (let* ((watch (make-lsp-watch :root-directory folder)) (ignored-things (lsp--get-ignored-regexes-for-workspace-root folder)) (ignored-files-regex-list (car ignored-things)) (ignored-directories-regex-list (car (cdr ignored-things)))) (puthash folder watch created-watches) (lsp-watch-root-folder (file-truename folder) (-partial #'lsp--file-process-event (lsp-session) folder) ignored-files-regex-list ignored-directories-regex-list watch t)) (setq --dolist-tail-- (cdr --dolist-tail--)))
  (while --dolist-tail-- (let ((folder (car --dolist-tail--))) (let* ((watch (make-lsp-watch :root-directory folder)) (ignored-things (lsp--get-ignored-regexes-for-workspace-root folder)) (ignored-files-regex-list (car ignored-things)) (ignored-directories-regex-list (car (cdr ignored-things)))) (puthash folder watch created-watches) (lsp-watch-root-folder (file-truename folder) (-partial #'lsp--file-process-event (lsp-session) folder) ignored-files-regex-list ignored-directories-regex-list watch t)) (setq --dolist-tail-- (cdr --dolist-tail--))))
  (let ((--dolist-tail-- root-folders)) (while --dolist-tail-- (let ((folder (car --dolist-tail--))) (let* ((watch (make-lsp-watch :root-directory folder)) (ignored-things (lsp--get-ignored-regexes-for-workspace-root folder)) (ignored-files-regex-list (car ignored-things)) (ignored-directories-regex-list (car (cdr ignored-things)))) (puthash folder watch created-watches) (lsp-watch-root-folder (file-truename folder) (-partial #'lsp--file-process-event (lsp-session) folder) ignored-files-regex-list ignored-directories-regex-list watch t)) (setq --dolist-tail-- (cdr --dolist-tail--)))))
  (let* ((created-watches (lsp-session-watches (lsp-session))) (root-folders (cl-set-difference (lsp-find-roots-for-workspace lsp--cur-workspace (lsp-session)) (ht-keys created-watches)))) (let ((--dolist-tail-- root-folders)) (while --dolist-tail-- (let ((folder (car --dolist-tail--))) (let* ((watch (make-lsp-watch :root-directory folder)) (ignored-things (lsp--get-ignored-regexes-for-workspace-root folder)) (ignored-files-regex-list (car ignored-things)) (ignored-directories-regex-list (car ...))) (puthash folder watch created-watches) (lsp-watch-root-folder (file-truename folder) (-partial #'lsp--file-process-event (lsp-session) folder) ignored-files-regex-list ignored-directories-regex-list watch t)) (setq --dolist-tail-- (cdr --dolist-tail--))))))
  (progn (let* ((created-watches (lsp-session-watches (lsp-session))) (root-folders (cl-set-difference (lsp-find-roots-for-workspace lsp--cur-workspace (lsp-session)) (ht-keys created-watches)))) (let ((--dolist-tail-- root-folders)) (while --dolist-tail-- (let ((folder (car --dolist-tail--))) (let* ((watch ...) (ignored-things ...) (ignored-files-regex-list ...) (ignored-directories-regex-list ...)) (puthash folder watch created-watches) (lsp-watch-root-folder (file-truename folder) (-partial ... ... folder) ignored-files-regex-list ignored-directories-regex-list watch t)) (setq --dolist-tail-- (cdr --dolist-tail--)))))))
  (if (and lsp-enable-file-watchers (equal method "workspace/didChangeWatchedFiles")) (progn (let* ((created-watches (lsp-session-watches (lsp-session))) (root-folders (cl-set-difference (lsp-find-roots-for-workspace lsp--cur-workspace (lsp-session)) (ht-keys created-watches)))) (let ((--dolist-tail-- root-folders)) (while --dolist-tail-- (let ((folder ...)) (let* (... ... ... ...) (puthash folder watch created-watches) (lsp-watch-root-folder ... ... ignored-files-regex-list ignored-directories-regex-list watch t)) (setq --dolist-tail-- (cdr --dolist-tail--))))))))
  (let* ((method (gethash "method" input0)) (id (gethash "id" input0)) (register-options\? (gethash "registerOptions" input0))) (if (and lsp-enable-file-watchers (equal method "workspace/didChangeWatchedFiles")) (progn (let* ((created-watches (lsp-session-watches (lsp-session))) (root-folders (cl-set-difference (lsp-find-roots-for-workspace lsp--cur-workspace ...) (ht-keys created-watches)))) (let ((--dolist-tail-- root-folders)) (while --dolist-tail-- (let (...) (let* ... ... ...) (setq --dolist-tail-- ...))))))) (let* ((v (record 'lsp--registered-capability id method register-options\?))) (progn (or (and (memq (type-of lsp--cur-workspace) cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list 'lsp--workspace lsp--cur-workspace))) (let* ((v lsp--cur-workspace)) (aset v 3 (cons v (aref v 3)))))))
  lsp--server-register-capability(#<hash-table equal 3/3 0x1580873b60d1>)
  mapc(lsp--server-register-capability [#<hash-table equal 3/3 0x1580873b60d1>])
  (cond ((setq handler (gethash method (progn (or (and (memq ... cl-struct-lsp--client-tags) t) (signal 'wrong-type-argument (list ... client))) (aref client 7)) nil)) (funcall handler workspace params)) ((setq handler (gethash method (progn (or (and (memq ... cl-struct-lsp--client-tags) t) (signal 'wrong-type-argument (list ... client))) (aref client 29)) nil)) (funcall handler workspace params (-partial #'lsp--send-request-response workspace recv-time request)) 'delay-response) ((equal method "client/registerCapability") (mapc #'lsp--server-register-capability (lsp:registration-params-registrations params)) (mapc #'(lambda (buf) (if (lsp-buffer-live-p buf) (progn (let* ... ...)))) buffers) nil) ((equal method "window/showMessageRequest") (let ((choice (lsp--window-log-message-request params))) (list ':title choice))) ((equal method "client/unregisterCapability") (mapc #'lsp--server-unregister-capability (lsp:unregistration-params-unregisterations params)) (mapc #'(lambda (buf) (if (lsp-buffer-live-p buf) (progn (let* ... ...)))) buffers) nil) ((equal method "workspace/applyEdit") (list :applied (condition-case err (prog1 t (lsp--apply-workspace-edit (lsp:apply-workspace-edit-params-edit params) 'server-requested)) (error (lsp--error "Failed to apply edits with message %s" (error-message-string err)) :json-false)))) ((equal method "workspace/configuration") (let ((lsp--cur-workspace workspace)) (let* ((buf (and t (car buffers)))) (if buf (let* ((wcb ...)) (if wcb (let ... ...) (save-current-buffer ... ...))) (let ((temp-buffer ...)) (save-current-buffer (set-buffer temp-buffer) (unwind-protect ... ...))))))) ((equal method "workspace/workspaceFolders") (let ((folders (or (gethash (let ... ...) (let ... ...)) (let (...) (progn ... ...))))) (apply #'vector (-map #'(lambda (folder) (list :uri ...)) (-distinct folders))))) ((equal method "window/workDoneProgress/create") nil) (t (lsp-warn "Unknown request method: %s" method) nil))
  (let* ((recv-time (current-time)) (client (progn (or (and (memq (type-of workspace) cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list 'lsp--workspace workspace))) (aref workspace 5))) (buffers (progn (or (and (memq (type-of workspace) cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list 'lsp--workspace workspace))) (aref workspace 9))) (handler nil) (response (cond ((setq handler (gethash method (progn ... ...) nil)) (funcall handler workspace params)) ((setq handler (gethash method (progn ... ...) nil)) (funcall handler workspace params (-partial #'lsp--send-request-response workspace recv-time request)) 'delay-response) ((equal method "client/registerCapability") (mapc #'lsp--server-register-capability (lsp:registration-params-registrations params)) (mapc #'(lambda ... ...) buffers) nil) ((equal method "window/showMessageRequest") (let ((choice ...)) (list ':title choice))) ((equal method "client/unregisterCapability") (mapc #'lsp--server-unregister-capability (lsp:unregistration-params-unregisterations params)) (mapc #'(lambda ... ...) buffers) nil) ((equal method "workspace/applyEdit") (list :applied (condition-case err (prog1 t ...) (error ... :json-false)))) ((equal method "workspace/configuration") (let ((lsp--cur-workspace workspace)) (let* (...) (if buf ... ...)))) ((equal method "workspace/workspaceFolders") (let ((folders ...)) (apply #'vector (-map ... ...)))) ((equal method "window/workDoneProgress/create") nil) (t (lsp-warn "Unknown request method: %s" method) nil)))) (if (eq response 'delay-response) nil (lsp--send-request-response workspace recv-time request response)))
  (let* ((workspace input0) (request input1) (params (gethash "params" request)) (method (gethash "method" request))) (let* ((recv-time (current-time)) (client (progn (or (and (memq ... cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list ... workspace))) (aref workspace 5))) (buffers (progn (or (and (memq ... cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list ... workspace))) (aref workspace 9))) (handler nil) (response (cond ((setq handler (gethash method ... nil)) (funcall handler workspace params)) ((setq handler (gethash method ... nil)) (funcall handler workspace params (-partial ... workspace recv-time request)) 'delay-response) ((equal method "client/registerCapability") (mapc #'lsp--server-register-capability (lsp:registration-params-registrations params)) (mapc #'... buffers) nil) ((equal method "window/showMessageRequest") (let (...) (list ... choice))) ((equal method "client/unregisterCapability") (mapc #'lsp--server-unregister-capability (lsp:unregistration-params-unregisterations params)) (mapc #'... buffers) nil) ((equal method "workspace/applyEdit") (list :applied (condition-case err ... ...))) ((equal method "workspace/configuration") (let (...) (let* ... ...))) ((equal method "workspace/workspaceFolders") (let (...) (apply ... ...))) ((equal method "window/workDoneProgress/create") nil) (t (lsp-warn "Unknown request method: %s" method) nil)))) (if (eq response 'delay-response) nil (lsp--send-request-response workspace recv-time request response))))
  lsp--on-request(#s(lsp--workspace :ewoc nil :server-capabilities #<hash-table equal 14/14 0x158084f42355> :registered-server-capabilities (#s(lsp--registered-capability :id "f5c66e09-6856-4be4-9217-11e0160f7087" :method "workspace/didChangeWorkspaceFolders" :options #<hash-table equal 0/1 0x158085f16101>)) :root "/home/leo/projects/ledgerdomain/sandbox/docuseal-f..." :client #s(lsp--client :language-id nil :add-on? nil :new-connection (:connect (closure ((test-command) (command closure (t) nil (cons ... lsp-pyright-langserver-command-args)) view-inhibit-help-message cl-struct-lsp--log-entry-tags cl-struct-lsp-session-tags cl-struct-lsp--workspace-tags cl-struct-lsp--registered-capability-tags lsp-mode-menu cl-struct-lsp--folding-range-tags cl-struct-lsp-watch-tags cl-struct-lsp--client-tags lsp--log-lines dap-ui-menu-items dap-auto-configure-mode t) (filter sentinel name environment-fn) (let ((final-command ...) (process-name ...) (process-environment ...)) (let* (... ...) (set-process-query-on-exit-flag proc nil) (set-process-query-on-exit-flag ... nil) (save-current-buffer ... ...) (cons proc proc)))) :test\? (closure ((test-command) (command closure (t) nil (cons ... lsp-pyright-langserver-command-args)) view-inhibit-help-message cl-struct-lsp--log-entry-tags cl-struct-lsp-session-tags cl-struct-lsp--workspace-tags cl-struct-lsp--registered-capability-tags lsp-mode-menu cl-struct-lsp--folding-range-tags cl-struct-lsp-watch-tags cl-struct-lsp--client-tags lsp--log-lines dap-ui-menu-items dap-auto-configure-mode t) nil (lsp-server-present\? (lsp-resolve-final-function command)))) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 3/65 0x1580856724f9> :request-handlers #<hash-table equal 0/65 0x158085672621> :response-handlers #<hash-table eql 613/730 0x158086214c65> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x158086214c85> :action-handlers #<hash-table equal 0/65 0x158083df65b1> :major-modes (python-mode) :activation-fn nil :priority 3 :server-id pyright :multi-root t :initialization-options nil :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn (closure (t) (workspace) (let ((lsp--cur-workspace workspace)) (lsp--set-configuration (make-hash-table :test 'equal)))) :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x158083df65d1> :download-server-fn (closure (t) (_client callback error-callback _update\?) (lsp-package-ensure 'pyright callback error-callback)) :download-in-progress? nil :buffers nil) :host-root nil :proc #<process pyright> :cmd-proc #<process pyright> :buffers (#<buffer main.py<2>>) :semantic-tokens-faces nil :semantic-tokens-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x158085fa3081> :watches #<hash-table equal 0/65 0x158085fa3359> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 0/65 0x158085fa33fd> :work-done-tokens #<hash-table equal 0/65 0x158085284ef9>) #<hash-table equal 4/4 0x1580873b6045>)
  (cond ((eq val 'response) (progn (or id (cl--assertion-failed 'id)) nil) (let* ((--dash-source-638-- (gethash id (progn (or ... ...) (aref client 8)))) (callback (car-safe (prog1 --dash-source-638-- (setq --dash-source-638-- ...)))) (method (prog1 (car (cdr --dash-source-638--)) (setq --dash-source-638-- (nthcdr 2 --dash-source-638--)))) (before-send (car (cdr --dash-source-638--)))) (if lsp-print-io (progn (lsp--log-entry-new (lsp--make-log-entry method id data 'incoming-resp (/ ... 1000)) workspace))) (if callback (progn (funcall callback (lsp:json-response-result json-data)) (remhash id (progn (or ... ...) (aref client 8))))))) ((eq val 'response-error) (progn (or id (cl--assertion-failed 'id)) nil) (let* ((--dash-source-640-- (cdr (gethash id (progn ... ...)))) (callback (car-safe (prog1 --dash-source-640-- (setq --dash-source-640-- ...)))) (method (car-safe (prog1 --dash-source-640-- (setq --dash-source-640-- ...)))) (before-send (car (cdr --dash-source-640--)))) (if lsp-print-io (progn (lsp--log-entry-new (lsp--make-log-entry method id (lsp:json-response-error-error json-data) 'incoming-resp (/ ... 1000)) workspace))) (if callback (progn (funcall callback (lsp:json-response-error-error json-data)) (remhash id (progn (or ... ...) (aref client 8))))))) ((eq val 'notification) (lsp--on-notification workspace json-data)) ((eq val 'request) (lsp--on-request workspace json-data)) (t nil))
  (let* ((val (lsp--get-message-type json-data))) (cond ((eq val 'response) (progn (or id (cl--assertion-failed 'id)) nil) (let* ((--dash-source-638-- (gethash id (progn ... ...))) (callback (car-safe (prog1 --dash-source-638-- ...))) (method (prog1 (car ...) (setq --dash-source-638-- ...))) (before-send (car (cdr --dash-source-638--)))) (if lsp-print-io (progn (lsp--log-entry-new (lsp--make-log-entry method id data ... ...) workspace))) (if callback (progn (funcall callback (lsp:json-response-result json-data)) (remhash id (progn ... ...)))))) ((eq val 'response-error) (progn (or id (cl--assertion-failed 'id)) nil) (let* ((--dash-source-640-- (cdr (gethash id ...))) (callback (car-safe (prog1 --dash-source-640-- ...))) (method (car-safe (prog1 --dash-source-640-- ...))) (before-send (car (cdr --dash-source-640--)))) (if lsp-print-io (progn (lsp--log-entry-new (lsp--make-log-entry method id ... ... ...) workspace))) (if callback (progn (funcall callback (lsp:json-response-error-error json-data)) (remhash id (progn ... ...)))))) ((eq val 'notification) (lsp--on-notification workspace json-data)) ((eq val 'request) (lsp--on-request workspace json-data)) (t nil)))
  (let* ((client (progn (or (and (memq (type-of workspace) cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list 'lsp--workspace workspace))) (aref workspace 5))) (id (let ((it (lsp:json-response-id json-data))) (if it (progn (if (stringp it) (string-to-number it) it))))) (data (lsp:json-response-result json-data))) (let* ((val (lsp--get-message-type json-data))) (cond ((eq val 'response) (progn (or id (cl--assertion-failed 'id)) nil) (let* ((--dash-source-638-- (gethash id ...)) (callback (car-safe ...)) (method (prog1 ... ...)) (before-send (car ...))) (if lsp-print-io (progn (lsp--log-entry-new ... workspace))) (if callback (progn (funcall callback ...) (remhash id ...))))) ((eq val 'response-error) (progn (or id (cl--assertion-failed 'id)) nil) (let* ((--dash-source-640-- (cdr ...)) (callback (car-safe ...)) (method (car-safe ...)) (before-send (car ...))) (if lsp-print-io (progn (lsp--log-entry-new ... workspace))) (if callback (progn (funcall callback ...) (remhash id ...))))) ((eq val 'notification) (lsp--on-notification workspace json-data)) ((eq val 'request) (lsp--on-request workspace json-data)) (t nil))))
  (let ((lsp--cur-workspace workspace)) (let* ((client (progn (or (and (memq ... cl-struct-lsp--workspace-tags) t) (signal 'wrong-type-argument (list ... workspace))) (aref workspace 5))) (id (let ((it (lsp:json-response-id json-data))) (if it (progn (if ... ... it))))) (data (lsp:json-response-result json-data))) (let* ((val (lsp--get-message-type json-data))) (cond ((eq val 'response) (progn (or id (cl--assertion-failed ...)) nil) (let* ((--dash-source-638-- ...) (callback ...) (method ...) (before-send ...)) (if lsp-print-io (progn ...)) (if callback (progn ... ...)))) ((eq val 'response-error) (progn (or id (cl--assertion-failed ...)) nil) (let* ((--dash-source-640-- ...) (callback ...) (method ...) (before-send ...)) (if lsp-print-io (progn ...)) (if callback (progn ... ...)))) ((eq val 'notification) (lsp--on-notification workspace json-data)) ((eq val 'request) (lsp--on-request workspace json-data)) (t nil)))))
  (condition-case err (let ((lsp--cur-workspace workspace)) (let* ((client (progn (or (and ... t) (signal ... ...)) (aref workspace 5))) (id (let ((it ...)) (if it (progn ...)))) (data (lsp:json-response-result json-data))) (let* ((val (lsp--get-message-type json-data))) (cond ((eq val 'response) (progn (or id ...) nil) (let* (... ... ... ...) (if lsp-print-io ...) (if callback ...))) ((eq val 'response-error) (progn (or id ...) nil) (let* (... ... ... ...) (if lsp-print-io ...) (if callback ...))) ((eq val 'notification) (lsp--on-notification workspace json-data)) ((eq val 'request) (lsp--on-request workspace json-data)) (t nil))))) ((debug error) (message "Error processing message %S." err) nil))
  lsp--parser-on-message(#<hash-table equal 4/4 0x1580873b6045> #s(lsp--workspace :ewoc nil :server-capabilities #<hash-table equal 14/14 0x158084f42355> :registered-server-capabilities (#s(lsp--registered-capability :id "f5c66e09-6856-4be4-9217-11e0160f7087" :method "workspace/didChangeWorkspaceFolders" :options #<hash-table equal 0/1 0x158085f16101>)) :root "/home/leo/projects/ledgerdomain/sandbox/docuseal-f..." :client #s(lsp--client :language-id nil :add-on? nil :new-connection (:connect (closure ((test-command) (command closure (t) nil (cons ... lsp-pyright-langserver-command-args)) view-inhibit-help-message cl-struct-lsp--log-entry-tags cl-struct-lsp-session-tags cl-struct-lsp--workspace-tags cl-struct-lsp--registered-capability-tags lsp-mode-menu cl-struct-lsp--folding-range-tags cl-struct-lsp-watch-tags cl-struct-lsp--client-tags lsp--log-lines dap-ui-menu-items dap-auto-configure-mode t) (filter sentinel name environment-fn) (let ((final-command ...) (process-name ...) (process-environment ...)) (let* (... ...) (set-process-query-on-exit-flag proc nil) (set-process-query-on-exit-flag ... nil) (save-current-buffer ... ...) (cons proc proc)))) :test\? (closure ((test-command) (command closure (t) nil (cons ... lsp-pyright-langserver-command-args)) view-inhibit-help-message cl-struct-lsp--log-entry-tags cl-struct-lsp-session-tags cl-struct-lsp--workspace-tags cl-struct-lsp--registered-capability-tags lsp-mode-menu cl-struct-lsp--folding-range-tags cl-struct-lsp-watch-tags cl-struct-lsp--client-tags lsp--log-lines dap-ui-menu-items dap-auto-configure-mode t) nil (lsp-server-present\? (lsp-resolve-final-function command)))) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 3/65 0x1580856724f9> :request-handlers #<hash-table equal 0/65 0x158085672621> :response-handlers #<hash-table eql 613/730 0x158086214c65> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x158086214c85> :action-handlers #<hash-table equal 0/65 0x158083df65b1> :major-modes (python-mode) :activation-fn nil :priority 3 :server-id pyright :multi-root t :initialization-options nil :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn (closure (t) (workspace) (let ((lsp--cur-workspace workspace)) (lsp--set-configuration (make-hash-table :test 'equal)))) :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x158083df65d1> :download-server-fn (closure (t) (_client callback error-callback _update\?) (lsp-package-ensure 'pyright callback error-callback)) :download-in-progress? nil :buffers nil) :host-root nil :proc #<process pyright> :cmd-proc #<process pyright> :buffers (#<buffer main.py<2>>) :semantic-tokens-faces nil :semantic-tokens-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x158085fa3081> :watches #<hash-table equal 0/65 0x158085fa3359> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 0/65 0x158085fa33fd> :work-done-tokens #<hash-table equal 0/65 0x158085284ef9>))
  (progn (lsp--parser-on-message (condition-case err (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (apply ... ...) (decode-coding-region ... ... ...) (goto-char ...) (json-parse-buffer :object-type ... :null-object nil :false-object nil)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))) (error (lsp-warn "Failed to parse the following chunk:\n'''\n%s\n'''\nwi..." (concat leftovers input) err))) workspace))
  (if (>= chunk-length left-to-receive) (progn (lsp--parser-on-message (condition-case err (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn ... ... ... ...) (and ... ...)))) (error (lsp-warn "Failed to parse the following chunk:\n'''\n%s\n'''\nwi..." (concat leftovers input) err))) workspace)))
  (let* ((chunk-length (string-bytes chunk)) (left-to-receive (- body-length body-received)) (this-body (if (< left-to-receive chunk-length) (prog1 (substring-no-properties chunk 0 left-to-receive) (setq chunk (substring-no-properties chunk left-to-receive))) (prog1 chunk (setq chunk nil)))) (body-bytes (string-bytes this-body))) (setq body (cons this-body body)) (setq body-received (+ body-received body-bytes)) (if (>= chunk-length left-to-receive) (progn (lsp--parser-on-message (condition-case err (let ((temp-buffer ...)) (save-current-buffer (set-buffer temp-buffer) (unwind-protect ... ...))) (error (lsp-warn "Failed to parse the following chunk:\n'''\n%s\n'''\nwi..." (concat leftovers input) err))) workspace))))
  (if (not body-length) (let* ((body-sep-pos (and t (string-match-p "\15\n\15\n" chunk)))) (if body-sep-pos (progn (setq body-length (lsp--get-body-length (mapcar #'lsp--parse-header (split-string ... "\15\n")))) (setq body-received 0) (setq leftovers nil) (setq chunk (substring-no-properties chunk (+ body-sep-pos 4)))) (progn (setq leftovers chunk) (setq chunk nil)))) (let* ((chunk-length (string-bytes chunk)) (left-to-receive (- body-length body-received)) (this-body (if (< left-to-receive chunk-length) (prog1 (substring-no-properties chunk 0 left-to-receive) (setq chunk (substring-no-properties chunk left-to-receive))) (prog1 chunk (setq chunk nil)))) (body-bytes (string-bytes this-body))) (setq body (cons this-body body)) (setq body-received (+ body-received body-bytes)) (if (>= chunk-length left-to-receive) (progn (lsp--parser-on-message (condition-case err (let (...) (save-current-buffer ... ...)) (error (lsp-warn "Failed to parse the following chunk:\n'''\n%s\n'''\nwi..." ... err))) workspace)))))
  (while (not (s-blank\? chunk)) (if (not body-length) (let* ((body-sep-pos (and t (string-match-p "\15\n\15\n" chunk)))) (if body-sep-pos (progn (setq body-length (lsp--get-body-length (mapcar ... ...))) (setq body-received 0) (setq leftovers nil) (setq chunk (substring-no-properties chunk (+ body-sep-pos 4)))) (progn (setq leftovers chunk) (setq chunk nil)))) (let* ((chunk-length (string-bytes chunk)) (left-to-receive (- body-length body-received)) (this-body (if (< left-to-receive chunk-length) (prog1 (substring-no-properties chunk 0 left-to-receive) (setq chunk ...)) (prog1 chunk (setq chunk nil)))) (body-bytes (string-bytes this-body))) (setq body (cons this-body body)) (setq body-received (+ body-received body-bytes)) (if (>= chunk-length left-to-receive) (progn (lsp--parser-on-message (condition-case err (let ... ...) (error ...)) workspace))))))
  (closure ((chunk . "Content-Length: 183\15\n\15\n{\"jsonrpc\":\"2...") (body) (body-length) (leftovers) (body-received) (workspace . #s(lsp--workspace :ewoc nil :server-capabilities #<hash-table equal 14/14 0x158084f42355> :registered-server-capabilities (...) :root "/home/leo/projects/ledgerdomain/sand..." :client #s(lsp--client :language-id nil :add-on? nil :new-connection ... :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 3/65 0x1580856724f9> :request-handlers #<hash-table equal 0/65 0x158085672621> :response-handlers #<hash-table eql 613/730 0x158086214c65> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x158086214c85> :action-handlers #<hash-table equal 0/65 0x158083df65b1> :major-modes ... :activation-fn nil :priority 3 :server-id pyright :multi-root t :initialization-options nil :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn ... :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x158083df65d1> :download-server-fn ... :download-in-progress? nil :buffers nil) :host-root nil :proc #<process pyright> :cmd-proc #<process pyright> :buffers (#<buffer main.py<2>>) :semantic-tokens-faces nil :semantic-tokens-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x158085fa3081> :watches #<hash-table equal 0/65 0x158085fa3359> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 0/65 0x158085fa33fd> :work-done-tokens #<hash-table equal 0/65 0x158085284ef9>)) view-inhibit-help-message cl-struct-lsp--log-entry-tags cl-struct-lsp-session-tags cl-struct-lsp--workspace-tags cl-struct-lsp--registered-capability-tags lsp-mode-menu cl-struct-lsp--folding-range-tags cl-struct-lsp-watch-tags cl-struct-lsp--client-tags lsp--log-lines dap-ui-menu-items dap-auto-configure-mode t) (_proc input) (setq chunk (if (s-blank\? leftovers) input (concat leftovers input))) (while (not (s-blank\? chunk)) (if (not body-length) (let* (...) (if body-sep-pos ... ...)) (let* (... ... ... ...) (setq body ...) (setq body-received ...) (if ... ...)))))(#<process pyright> "Content-Length: 204\15\n\15\n{\"jsonrpc\":\"2.0\",\"id\":0,\"me...")

Anything else?

No response

pradyparanjpe commented 2 years ago

I am having a similar problem.

On a similar platform: Spacemacs (devel), lsp-python with pyright on Linux (fedora-34)

Question As a temporary workaround, is there a way to manually erase the bad entry? (or simply all entries?)

yyoncho commented 2 years ago

lsp-workspace-folders-remove

offbyone commented 2 years ago

How does one invoke that effectively? In this case I have several project roots missing, so do I have to go through them and clean them up?

yyoncho commented 2 years ago

Or delete lsp-session-file before starting emacd

offbyone commented 2 years ago

I worked around this myself:

(defun offby1/lsp-workspace-remove-missing-projects ()
  (interactive)
  (dolist (dead-project (seq-filter (lambda (x) (not (file-directory-p x))) (lsp-session-folders (lsp-session))))
    (lsp-workspace-folders-remove dead-project)))
skyler544 commented 2 years ago

Question As a temporary workaround, is there a way to manually erase the bad entry? (or simply all entries?)

Using lsp-workspace-folders-remove for this wasn't possible in my case as the bad entry wasn't available there. Instead, I was able to remove that entry by checking the value of lsp-session-file and then, with emacs and lsp closed, manually editing that file to remove the bad entry.