[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Xref/tags/lsp possible bug
From: |
Alessandro Bertulli |
Subject: |
Xref/tags/lsp possible bug |
Date: |
Sat, 23 Apr 2022 14:17:03 +0200 |
Hi all!
I just stumbled upon a very strange behavior of Emacs, I don't know if
it is a bug or an error of my configuration. Basically, I noticed two
things:
- First, when using LSP modes (both lsp-mode and eglot), the command
xref-find-definitions only acts on the symbol under point. I
explain: usually, in vanilla Emacs (emacs -q) if point is on a
whitespace/not on a symbol, invoking the command (bound to M-.) will
prompt you for an identifier to search for. However, when LSP is
active, it directly searches for an empty symbol, for example
reporting something similar to: "Symbol not found" (not the double
space, which makes me think it searches for a symbol named ""). As I
said, this happend both for lsp-mode and eglot, so maybe is a
problem of xref?
- Second, and minor: while I was investigating, I noticed that,
depending on the loaded packages, when giving M-., xref sometimes
asks for the symbol to search, sometimes it asks the TAGS table
first. What package can be the problem?
Do you think it is a bug of Emacs? Do you know a way to resolve?
Thanks to all!
############
I report some useful infos:
Emacs version: This is GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu, GTK+
Version 3.24.33, cairo version 1.17.6) of 2022-04-20
lsp-mode version: 20220422.2059
xref version: 1.4.1
##########
Steps to reproduce:
-First bug:
- launch emacs -q
- go on an C++ file
- on a whitespace, give M-.. The prompt says "Find definition of: "
- close and restart with the provided file (emacs -q --load file,
see end of the mail)
- go on the same C++ file
- launch lsp-mode (M-x lsp)
- on the same whitespace, give M-. The minibuffer says "Unable to
find symbol in current document" (note the bouble space). In
*Messages* buffer, the error is reported perfized with the string
"user-error: ".
- give M-x lsp-find-definition on the same whitespace. The minibuffer
says: "LSP :: Not found for: " (note the space at the end).
-Second bug:
- launch emacs -q
- go on a C++ file
- on a whitespace, give M-. The prompt says "Find definitions of: "
- close and restart with provided file (emacs -q --load file)
- go on the same C++ file
- on the same whitespace, give M-. The prompt says "Visit tags table
(default TAGS): "
- go on an elisp file, do the same, the prompt says "Find definitions of: "
#############
Test init file
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages
'(helpful transient-dwim ivy projectile eglot magit lsp-ui flycheck
which-key yasnippet-snippets yasnippet lsp-mode company))
)
;;--------------
;; Enable MELPA
;;-------------
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired. See
`package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do
this.
;;(add-to-list 'package-archives '("melpa-stable" . "
https://stable.melpa.org/packages/") t)
(package-initialize)
(setq pkg-list '(helpful transient-dwim ivy projectile eglot magit lsp-ui
flycheck which-key yasnippet-snippets yasnippet lsp-mode company))
(mapc (lambda (pkg)
(unless (package-installed-p pkg)
(package-install pkg))
(require pkg))
pkg-list)
;;------------
;; Various
;;-------------
(setq confirm-kill-emacs #'y-or-n-p)
(tool-bar-mode 0)
(global-flycheck-mode)
(setq sentence-end-double-space nil)
(show-paren-mode)
;;--------------
;; Help - transient-dwim
;;--------------
(which-key-mode 1)
(global-set-key (kbd "C-M-SPC") #'which-key-show-major-mode)
(global-set-key (kbd "M-=") 'transient-dwim-dispatch)
;; Helpful ---------------
(global-set-key (kbd "C-h f") #'helpful-callable)
(global-set-key (kbd "C-h v") #'helpful-variable)
(global-set-key (kbd "C-h k") #'helpful-key)
(global-set-key (kbd "C-h M-.") #'helpful-at-point)
;;------------
;; Ivy
;;----------
(ivy-mode 1)
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")
;;-----------------
;; YASnippet
;;-----------------
(require 'yasnippet)
(yas-reload-all)
(yas-global-mode)
;;--------------
;;Projectile
;;-------------------
(require 'projectile)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(projectile-mode +1)
;;------------------
;; Eglot
;;------------------
(require 'eglot)
;;use flychech instead of flymake
(add-to-list 'eglot-stay-out-of 'flymake)
;;suggested by the repo
(define-key eglot-mode-map (kbd "C-c r") 'eglot-rename)
(define-key eglot-mode-map (kbd "C-c o")
'eglot-code-action-organize-imports)
(define-key eglot-mode-map (kbd "C-c h") 'eldoc)
;;----------------
;; Language Server Protocol
;;--------------
(require 'lsp-mode)
;; apparently, this must be done before loading in any way lsp-mode
(setq lsp-keymap-prefix "C-c l")
(define-key lsp-mode-map (kbd "C-c l") lsp-command-map)
;; this must be called after to let which-key see the new prefix, think
(add-hook 'lsp-mode-hook 'lsp-enable-which-key-integration)
(define-key lsp-mode-map (kbd "M-RET") 'lsp-execute-code-action)
;;suggested by lsp-java doc
(setq lsp-completion-enable-additional-text-edit nil)
;;copied from https://emacs-lsp.github.io/lsp-mode/tutorials/CPP-guide/
;;probably is better
(with-eval-after-load 'lsp-mode
(add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration)
(yas-global-mode))
;; lsp-mode is not activated by default in the c++-hook so that
;; the second bug can also be reproduced.
;; However, if needed, uncomment this line
;; (add-hook 'c++-mode-hook 'lsp)
;;---------------
;; lsp-ui
;;--------------
(eval-after-load 'lsp
(eval-after-load 'lsp-ui
(setq lsp-ui-sideline-show-hover t)
))
;;-------------------
;; Company (should be called after lsp-mode?)
;;------------------
(add-hook 'prog-mode-hook 'company-mode)
(define-key prog-mode-map (kbd "C-M-i") 'company-complete)
(eval-after-load 'comapny '(define-key company-mode-map (kbd "<C-tab>")
'company-complete))
(eval-after-load 'company '(define-key company-active-map (kbd "<tab>")
'company-complete))
(eval-after-load 'company '(add-to-list 'company-backends 'company-capf))
(setq company-minimum-prefix-length 1)
(run-hooks 'after-init-hook)
- Xref/tags/lsp possible bug,
Alessandro Bertulli <=