all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: Xref/tags/lsp possible bug
@ 2022-04-25 10:01 Alessandro Bertulli
  2022-04-25 20:05 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 10+ messages in thread
From: Alessandro Bertulli @ 2022-04-25 10:01 UTC (permalink / raw)
  To: dgutov; +Cc: help-gnu-emacs

Thanks Dmitry!

> AFAIK it's a limitation of the LSP protocol: it's unable to perform
> completion on all symbol names globally. Nor is it able, in general, to
> find a symbol by name (it needs a location of an existing reference in
> some file). So that affects how lsp-mode's Xref integration works (and
> Eglot's).

Indeed, you're right, I opened an issue on lsp-mode's GitHub and the
maintainer (Ivan) kindly answered me. I report here its answer, in case
it is useful to someone:

"In lsp protocol, there is no convenient method to list the symbols.
We do some hacks using document symbols to provide some handling when
the method is invoked like that C-u M-x xref-find-definitions(or with
(setq xref-prompt-for-identifier t)) but that is not really what the
xref wants. This feature of xref is designed with tags in mind and it
does not fit well with lsp protocol. Thus we have created lsp-find-*
set of functions to make the difference between lsp and xref more
evident."

Okay, it's not a real problem, but I wonder why is it, though. I
suppose LSP does have a sort of symbol table kept in memory, so I
think it wouldn't be a big problem to allow the user to query it. I
suppose it's something that can be added in a future specification.

As a side note, reading your answer to Eli: yes, I got the hint it
could be a problem of Xref, that's a part of why I asked here (being
Xref a part of Emacs, or at least GNU Elpa).

Anyway, thank you all for your support!

Alessandro


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: Xref/tags/lsp possible bug
@ 2022-04-23 15:28 Alessandro Bertulli
  0 siblings, 0 replies; 10+ messages in thread
From: Alessandro Bertulli @ 2022-04-23 15:28 UTC (permalink / raw)
  To: eliz; +Cc: help-gnu-emacs

> Every major mode needs to set up its Xref support.  It sounds to me
> that what you experience are the differences in the major modes you
> use in each case.

Thanks, that makes sense. I'll try asking on the lsp-mode
support/mailing list. Thanks a lot, especially for the speed in
answering!


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Xref/tags/lsp possible bug
@ 2022-04-23 12:17 Alessandro Bertulli
  2022-04-23 12:52 ` Eli Zaretskii
  2022-04-25  1:32 ` Dmitry Gutov
  0 siblings, 2 replies; 10+ messages in thread
From: Alessandro Bertulli @ 2022-04-23 12:17 UTC (permalink / raw)
  To: help-gnu-emacs

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)


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-04-26  1:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-25 10:01 Xref/tags/lsp possible bug Alessandro Bertulli
2022-04-25 20:05 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-04-25 20:29   ` Dmitry Gutov
2022-04-25 21:48     ` Stefan Monnier
2022-04-26  1:41       ` Dmitry Gutov
  -- strict thread matches above, loose matches on Subject: below --
2022-04-23 15:28 Alessandro Bertulli
2022-04-23 12:17 Alessandro Bertulli
2022-04-23 12:52 ` Eli Zaretskii
2022-04-24 23:06   ` Dmitry Gutov
2022-04-25  1:32 ` Dmitry Gutov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.