emacs-lsp / lsp-ui

UI integrations for lsp-mode
https://emacs-lsp.github.io/lsp-ui
GNU General Public License v3.0
1.04k stars 141 forks source link

flycheck doesn't work when editing thru symlink #119

Closed jackkamm closed 6 years ago

jackkamm commented 6 years ago

lsp-ui-flycheck has problems when editing a file through a symlink.

In particular, syntax errors within the buffer are not highlighted by flycheck; furthermore functions such as flycheck-list-errors, flycheck-next-error, etc. will not find any errors.

However, calling lsp-ui-flycheck-list works fine, and will correctly find errors/warnings and list them in the sidebar.

I believe the issue is in the function lsp-ui-flycheck--start within lsp-ui-flycheck.el, around line 169:

(defun lsp-ui-flycheck--start (checker callback)
  ;; ...skipping a few lines here...
  (let ((errors))
    (dolist (diag (gethash buffer-file-name lsp--diagnostics)) ;<--ISSUE HERE
      (push (flycheck-error-new
      ;; ...more lines below...

replacing buffer-file-name with (file-truename buffer-filename) fixed the issue in my case.

sebastiencs commented 6 years ago

Thank you ! I've pushed a fix

aquarichy commented 11 months ago

This bug may have returned.

If I create a minimal environment in a fresh image, with just emacs, lsp-mode, lsp-ui, lsp-pyright, and flycheck installed, if I access a .py file from its real path, flycheck errors are shown as highlighted in the buffer. If I access it through a symlinked directory, I get the behaviour above. lsp-ui-flycheck-list sees my errors, but they aren't indicated otherwise.

Minimal .emacs:

;; ---- Package Management (package.el, melpa) ----
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

;; From: https://emacs-lsp.github.io/lsp-mode/page/installation/
(use-package lsp-mode
  :init
  ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
  (setq lsp-keymap-prefix "C-c l")
  :hook (;; replace XXX-mode with concrete major-mode(e. g. python-mode)
         (python-mode . lsp)
         ;; if you want which-key integration
         (lsp-mode . lsp-enable-which-key-integration))
  :commands lsp)

(use-package lsp-ui :commands lsp-ui-mode)

;; From: https://emacs-lsp.github.io/lsp-pyright/
(use-package lsp-pyright
  :ensure t
  :hook (python-mode . (lambda ()
                          (require 'lsp-pyright)
                          (lsp))))  ; or lsp-deferred