Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use file-truename in lsp-f-canonical #3325

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lsp-diagnostics.el
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ See https://github.com/emacs-lsp/lsp-mode."
(defun lsp-diagnostics--flymake-update-diagnostics ()
"Report new diagnostics to flymake."
(funcall lsp-diagnostics--flymake-report-fn
(-some->> (lsp-diagnostics t)
(gethash (lsp--fix-path-casing buffer-file-name))
(-some->> (lsp--get-buffer-diagnostics)
(--map (-let* (((&Diagnostic :message :severity?
:range (range &as &Range
:start (&Position :line start-line :character)
Expand Down
54 changes: 32 additions & 22 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ FORMAT and ARGS i the same as for `message'."

(defun lsp-f-canonical (file-name)
"Return the canonical FILE-NAME, without a trailing slash."
(directory-file-name (expand-file-name file-name)))
(directory-file-name file-name))

(defalias 'lsp-canonical-file-name 'lsp-f-canonical)

Expand All @@ -1259,8 +1259,8 @@ Symlinks are not followed."
(when (and (f-exists? path-a)
(f-exists? path-b))
(equal
(lsp-f-canonical (directory-file-name (f-expand path-a)))
(lsp-f-canonical (directory-file-name (f-expand path-b))))))
(lsp-f-canonical (f-expand path-a))
(lsp-f-canonical (f-expand path-b)))))

(defun lsp-f-parent (path)
"Return the parent directory to PATH.
Expand Down Expand Up @@ -3816,17 +3816,19 @@ If any filters, checks if it applies for PATH."

(defun lsp--suggest-project-root ()
"Get project root."
(or
(when (featurep 'projectile) (condition-case nil
(projectile-project-root)
(error nil)))
(when (featurep 'project)
(when-let ((project (project-current)))
(if (fboundp 'project-root)
(project-root project)
(car (with-no-warnings
(project-roots project))))))
default-directory))
(-> (or
(when (featurep 'projectile) (condition-case nil
(projectile-project-root)
(error nil)))
(when (featurep 'project)
(when-let ((project (project-current)))
(if (fboundp 'project-root)
(project-root project)
(car (with-no-warnings
(project-roots project))))))
default-directory)
(lsp-f-canonical)
(expand-file-name)))

(defun lsp--read-from-file (file)
"Read FILE content."
Expand Down Expand Up @@ -4965,10 +4967,11 @@ identifier and the position respectively."

(defun lsp--get-buffer-diagnostics ()
"Return buffer diagnostics."
(gethash (or
(plist-get lsp--virtual-buffer :buffer-file-name)
(lsp--fix-path-casing (buffer-file-name)))
(lsp-diagnostics t)))
(let* ((file (or (plist-get lsp--virtual-buffer :buffer-file-name)
(lsp--fix-path-casing (buffer-file-name))))
(diags (lsp-diagnostics t)))
(or (gethash (lsp--fix-path-casing file) diags)
(gethash (lsp--fix-path-casing (lsp-file-truename file)) diags))))

(defun lsp-cur-line-diagnostics ()
"Return any diagnostics that apply to the current line."
Expand Down Expand Up @@ -8712,13 +8715,13 @@ Select action: "

(defun lsp-find-session-folder (session file-name)
"Look in the current SESSION for folder containing FILE-NAME."
(let ((file-name-canonical (lsp-f-canonical file-name)))
(let ((file (lsp-f-canonical file-name)))
(->> session
(lsp-session-folders)
(--filter (and (lsp--files-same-host it file-name-canonical)
(or (lsp-f-same? it file-name-canonical)
(--filter (and (lsp--files-same-host it file)
(or (lsp-f-same? it file)
(and (f-dir? it)
(lsp-f-ancestor-of? it file-name-canonical)))))
(lsp-f-ancestor-of? it file)))))
(--max-by (> (length it)
(length other))))))

Expand Down Expand Up @@ -8746,6 +8749,7 @@ Select action: "
(when lsp-auto-guess-root
(lsp--suggest-project-root))
(lsp-find-session-folder session file-name)
(lsp-find-session-folder session (lsp-file-truename file-name))
(unless lsp-auto-guess-root
(when-let ((root-folder (lsp--find-root-interactively session)))
(if (or (not (f-equal? root-folder (expand-file-name "~/")))
Expand Down Expand Up @@ -9024,6 +9028,12 @@ This avoids overloading the server with many files when starting Emacs."
lsp-file-truename-cache))))
,@body)
(fset 'file-truename old-fn))))

(defun lsp-file-truename (file-name)
(or (gethash file-name lsp-file-truename-cache)
(puthash file-name (file-truename file-name)
lsp-file-truename-cache)))



(defun lsp-virtual-buffer-call (key &rest args)
Expand Down