:documentation "Map (DIR -> (WATCH ID1 ID2...)) for `didChangeWatchedFiles'."
:initform (make-hash-table :test #'equal) :accessor eglot--file-watches)
(managed-buffers
- :documentation "Map (PATH -> BUFFER) for buffers managed by server."
- :initform (make-hash-table :test #'equal)
+ :initform nil
+ :documentation "List of buffers managed by server."
:accessor eglot--managed-buffers)
(saved-initargs
:documentation "Saved initargs for reconnection purposes."
(defun eglot-path-to-uri (path)
"Convert PATH, a file name, to LSP URI string and return it."
- (let ((expanded-path (expand-file-name path)))
+ (let ((truepath (file-truename path)))
(if (and (url-type (url-generic-parse-url path))
;; It might be MS Windows path which includes a drive
;; letter that looks like a URL scheme (bug#59338)
(not (and (eq system-type 'windows-nt)
- (file-name-absolute-p expanded-path))))
+ (file-name-absolute-p truepath))))
;; Path is already a URI, so forward it to the LSP server
;; untouched. The server should be able to handle it, since
;; it provided this URI to clients in the first place.
(concat "file://"
;; Add a leading "/" for local MS Windows-style paths.
(if (and (eq system-type 'windows-nt)
- (not (file-remote-p expanded-path)))
+ (not (file-remote-p truepath)))
"/")
(url-hexify-string
;; Again watch out for trampy paths.
- (directory-file-name (file-local-name expanded-path))
+ (directory-file-name (file-local-name truepath))
eglot--uri-path-allowed-chars)))))
(defun eglot-range-region (range &optional markers)
(defun eglot--on-shutdown (server)
"Called by jsonrpc.el when SERVER is already dead."
;; Turn off `eglot--managed-mode' where appropriate.
- (dolist (buffer (map-values (eglot--managed-buffers server)))
+ (dolist (buffer (eglot--managed-buffers server))
(let (;; Avoid duplicate shutdowns (github#389)
(eglot-autoshutdown nil))
(eglot--when-live-buffer buffer (eglot--managed-mode-off))))
(add-hook 'eldoc-documentation-functions #'eglot-signature-eldoc-function
nil t)
(eldoc-mode 1))
-
- (let ((buffer (current-buffer)))
- (puthash (expand-file-name (buffer-file-name buffer))
- buffer
- (eglot--managed-buffers (eglot-current-server)))))
+ (cl-pushnew (current-buffer) (eglot--managed-buffers (eglot-current-server))))
(t
(when eglot--track-changes
(track-changes-unregister eglot--track-changes)
(let ((server eglot--cached-server))
(setq eglot--cached-server nil)
(when server
- (remhash (expand-file-name (buffer-file-name (current-buffer)))
- (eglot--managed-buffers server))
+ (setf (eglot--managed-buffers server)
+ (delq (current-buffer) (eglot--managed-buffers server)))
(when (and eglot-autoshutdown
- (null (map-values (eglot--managed-buffers server))))
+ (null (eglot--managed-buffers server)))
(eglot-shutdown server)))))))
(defun eglot--managed-mode-off ()
(remhash token (eglot--progress-reporters server))))))))))
(cl-defmethod eglot-handle-notification
- (server (_method (eql textDocument/publishDiagnostics)) &key uri diagnostics
+ (_server (_method (eql textDocument/publishDiagnostics)) &key uri diagnostics
&allow-other-keys) ; FIXME: doesn't respect `eglot-strict-mode'
"Handle notification publishDiagnostics."
(cl-flet ((eglot--diag-type (sev)
(mess (source code message)
(concat source (and code (format " [%s]" code)) ": " message)))
(if-let* ((path (expand-file-name (eglot-uri-to-path uri)))
- (buffer (gethash path (eglot--managed-buffers server))))
+ (buffer (find-buffer-visiting path)))
(with-current-buffer buffer
(cl-loop
initially
Try to visit the target file for a richer summary line."
(pcase-let*
((file (eglot-uri-to-path uri))
- (visiting (or (gethash file (eglot--managed-buffers (eglot-current-server)))
+ (visiting (or (find-buffer-visiting file)
(gethash uri eglot--temp-location-buffers)))
(collect (lambda ()
(eglot--widening
(with-current-buffer (get-buffer-create "*EGLOT proposed server changes*")
(buffer-disable-undo (current-buffer))
(let ((inhibit-read-only t)
- (target (current-buffer))
- (managed-buffers (eglot--managed-buffers (eglot-current-server))))
+ (target (current-buffer)))
(diff-mode)
(erase-buffer)
(pcase-dolist (`(,path ,edits ,_) prepared)
(with-temp-buffer
(let* ((diff (current-buffer))
- (existing-buf (gethash path (gethash path managed-buffers)))
+ (existing-buf (find-buffer-visiting path))
(existing-buf-label (prin1-to-string existing-buf)))
(with-temp-buffer
(if existing-buf
(eglot--dbind ((VersionedTextDocumentIdentifier) uri version)
textDocument
(list (eglot-uri-to-path uri) edits version)))
- documentChanges))
- (managed-buffers (eglot--managed-buffers (eglot-current-server))))
+ documentChanges)))
(unless (and changes documentChanges)
;; We don't want double edits, and some servers send both
;; changes and documentChanges. This unless ensures that we
(cl-loop for (uri edits) on changes by #'cddr
do (push (list (eglot-uri-to-path uri) edits) prepared)))
(cl-flet ((notevery-visited-p ()
- (cl-notevery (lambda (p) (gethash p managed-buffers))
+ (cl-notevery #'find-buffer-visiting
(mapcar #'car prepared)))
(accept-p ()
(y-or-n-p