[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#927749: marked as done (elpa-lsp-mode: Race condition in lsp-mode when using imenu and session restore)



Your message dated Thu, 30 Jan 2020 17:51:05 +0000
with message-id <E1ixDy5-0005DY-6M@fasolo.debian.org>
and subject line Bug#927749: fixed in lsp-mode 6.2.1-1
has caused the Debian Bug report #927749,
regarding elpa-lsp-mode: Race condition in lsp-mode when using imenu and session restore
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
927749: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=927749
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Package: elpa-lsp-mode
Version: 6.0-1
Severity: normal
Tags: patch

There is a race condition possibly leading to an error when lsp-mode is used
with imenu and session restore. See the upstream bug report for more details:
  https://github.com/emacs-lsp/lsp-mode/issues/784

The author helped in getting a patch for version 6.0 as included in Debian
Buster. The packet lsp-ui also need a small patch, I'll file another bug for
that.



-- System Information:
Debian Release: buster/sid
  APT prefers testing
  APT policy: (990, 'testing'), (50, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.19.0-4-amd64 (SMP w/8 CPU cores)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US:us (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages elpa-lsp-mode depends on:
ii  elpa-dash             2.14.1+dfsg-1
ii  elpa-dash-functional  1.2.0+dfsg-5
ii  elpa-f                0.20.0-1
ii  elpa-ht               2.2-2
ii  elpa-spinner          1.7.3-1
ii  emacsen-common        3.0.4

Versions of packages elpa-lsp-mode recommends:
ii  emacs              1:26.1+1-3.2
ii  emacs-gtk [emacs]  1:26.1+1-3.2

elpa-lsp-mode suggests no packages.

-- no debconf information
--- lsp-mode.el.orig	2019-01-21 21:56:43.000000000 +0100
+++ lsp-mode.el	2019-04-22 19:17:56.714357377 +0200
@@ -473,6 +473,16 @@
 
 (defvar lsp--tcp-port 10000)
 
+(defvar-local lsp--document-symbols nil
+  "The latest document symbols.")
+
+(defvar-local lsp--document-symbols-request-async nil
+  "If non-nil, request document symbols asynchronously.")
+
+(defvar-local lsp--document-symbols-tick -1
+  "The value of `buffer-chars-modified-tick' when document
+  symbols were last retrieved.")
+
 (cl-defgeneric lsp-execute-command (server command arguments)
   "Ask SERVER to execute COMMAND with ARGUMENTS.")
 
@@ -1674,6 +1684,9 @@
          (kind (if (hash-table-p sync) (gethash "change" sync) sync)))
     (setq lsp--server-sync-method (or lsp-document-sync-method
                                       (alist-get kind lsp--sync-methods))))
+  (when (and lsp-auto-configure (lsp--capability "documentSymbolProvider"))
+    (lsp-enable-imenu))
+
   (run-hooks 'lsp-after-open-hook))
 
 (define-inline lsp--text-document-identifier ()
@@ -2591,8 +2604,38 @@
                 'def-params td-params)))
 
 (defun lsp--get-document-symbols ()
-  (lsp-request "textDocument/documentSymbol"
-               `(:textDocument ,(lsp--text-document-identifier))))
+  "Get document symbols.
+
+If the buffer has not been modified since symbols were last
+retrieved, simply return the latest result.
+
+Else, if the request was initiated by Imenu updating its menu-bar
+entry, perform it asynchronously; i.e., give Imenu the latest
+result and then force a refresh when a new one is available.
+
+Else (e.g., due to intereactive use of `imenu' or `xref'),
+perform the request synchronously."
+  (if (= (buffer-chars-modified-tick) lsp--document-symbols-tick)
+      lsp--document-symbols
+    (let ((method "textDocument/documentSymbol")
+	      (params `(:textDocument ,(lsp--text-document-identifier)))
+	      (tick (buffer-chars-modified-tick)))
+      (if (not lsp--document-symbols-request-async)
+	      (prog1
+	          (setq lsp--document-symbols (lsp-request method params))
+	        (setq lsp--document-symbols-tick tick))
+	    (lsp-request-async method params
+			               (lambda (document-symbols)
+			                 (setq lsp--document-symbols document-symbols
+				                   lsp--document-symbols-tick tick)
+			                 (lsp--imenu-refresh))
+			               :mode 'alive)
+	    lsp--document-symbols))))
+
+(advice-add 'imenu-update-menubar :around
+	        (lambda (oldfun &rest r)
+	          (let ((lsp--document-symbols-request-async t))
+		        (apply oldfun r))))
 
 (defun lsp--xref-backend () 'xref-lsp)
 
@@ -3173,9 +3216,14 @@
          (result (compare-strings name1 0 (length name1) name2 0 (length name2))))
     (if (numberp result) result 0)))
 
+(defun lsp--imenu-refresh ()
+  "Force Imenu to refresh itself."
+  (imenu--menubar-select imenu--rescan-item))
+
 (defun lsp-enable-imenu ()
   "Use lsp-imenu for the current buffer."
-  (setq-local imenu-create-index-function #'lsp--imenu-create-index))
+  (setq-local imenu-create-index-function #'lsp--imenu-create-index)
+  (lsp--imenu-refresh))
 
 (defun lsp-resolve-final-function (command)
   "Resolve final function COMMAND."
@@ -3304,8 +3352,6 @@
     (lsp-ui-flycheck-enable t)
     (flycheck-mode 1)))
 
-  (lsp-enable-imenu)
-
   (when (functionp 'company-lsp)
     (company-mode 1)
     (setq-local company-backends '(company-lsp))

--- End Message ---
--- Begin Message ---
Source: lsp-mode
Source-Version: 6.2.1-1

We believe that the bug you reported is fixed in the latest version of
lsp-mode, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 927749@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Thomas Koch <thomas@koch.ro> (supplier of updated lsp-mode package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@ftp-master.debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Thu, 30 Jan 2020 17:12:59 +0000
Source: lsp-mode
Architecture: source
Version: 6.2.1-1
Distribution: unstable
Urgency: medium
Maintainer: Debian Emacsen team <debian-emacsen@lists.debian.org>
Changed-By: Thomas Koch <thomas@koch.ro>
Closes: 927749
Changes:
 lsp-mode (6.2.1-1) unstable; urgency=medium
 .
   * update Standards-Version 4.3.0->4.4.1, no changes
   * update debhelper 11->12, use debhelper-compat
   * new upstream version (Closes: 927749)
Checksums-Sha1:
 99a3fc9aa9f8305c80b614a0b10b20c09a35833d 2032 lsp-mode_6.2.1-1.dsc
 e875dea2118ab020d7ffd005aa6bbf178c845166 2352264 lsp-mode_6.2.1.orig.tar.xz
 11520d4bd1fe7f6a4bb31bff9604e43151321fdf 4344 lsp-mode_6.2.1-1.debian.tar.xz
 d4e114c171453829934be6e7752f0f34862e17d1 7772 lsp-mode_6.2.1-1_source.buildinfo
Checksums-Sha256:
 799c5d8023480b3b9917cbb533cd6b906a36e264034ad8031f16e2c39b61eff2 2032 lsp-mode_6.2.1-1.dsc
 9547917a6a6395a9096065b516e15c7492c636df3554dfeefad0ca867080d01b 2352264 lsp-mode_6.2.1.orig.tar.xz
 83f1dc6bed36df28c8e55c17a6a176795cfbc4527eba3b7b19b9558bb2f90479 4344 lsp-mode_6.2.1-1.debian.tar.xz
 0e57a30fb729f7c2693886b1316097097893f3239e2ae8399965ebd635c46031 7772 lsp-mode_6.2.1-1_source.buildinfo
Files:
 5b809263b261c6add8b9110e04c42727 2032 lisp optional lsp-mode_6.2.1-1.dsc
 322f6d0505bfe8fc3abd362a913337e7 2352264 lisp optional lsp-mode_6.2.1.orig.tar.xz
 5c7ae944c0e31e9382e8d98415da4cfd 4344 lisp optional lsp-mode_6.2.1-1.debian.tar.xz
 2b206565d119e472b1a0c75a2a12c622 7772 lisp optional lsp-mode_6.2.1-1_source.buildinfo

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEdgQCBVl/ppbxMTvKB/xIkQQrploFAl4zEvAACgkQB/xIkQQr
ploMvQ//eBFtXUeI44a0CodN06EjpuRxM+OR6MyqusFvtO83nqYbhM59UIwKxor6
PDcWsBiSNmuRQIAdEtQLsEqT/W24u5habpccK90UHyXKg0Bvk31UI9Wb/oezQ/L+
upgnXl1W2VadNm+J8l3S2saStdqaniRNa6W0MrtFim6K3vxUWmHnmRTMevV3TxaH
WhO4rrhwfkkr0zvnZaoWpaZF1C27kTLYhbI8VrdKrLJnXkJ4IMpg9p943qniYnz+
wf2GyRJ95CbzHHzX6HBHmeoWIiG5r1tgvWedHnNZcZuLYQm6r1AQVVFtrlVtvJ8w
lqr+x7L4k1OlW6EovtcUg08AxEDrRfAe3xQt6aT5KUHP5XIHDGfBGJxEeh+qIHlb
W2Ecf9OzJsjExpA97BTvP7cX7Vtj1PEOGeXW6cPoLX12Ks9G3n7Pmf/cIS8WIoIC
nyBCm55sGig/wS36RK3dTwW/+4GEJlcB+8tbZmAIg0CmmTlAd93yBVN2rUixCI3b
ngiZXFUWj8PUZStY9NeMMJYSYxeZYUiidQ9TqXIdNRZnwChdQmRhJY2qWrUxtuPH
ZpHitJMIZKy0ge4992JiGVCNWmpoqNF/D8lTICCvfRNi0WD/iroAzqx4I0JvqejO
LglinMTm0E9p1ZCT9/G5pWw6YzLOoPoY1i9WM6FLL0VzgkcrUSY=
=+oXG
-----END PGP SIGNATURE-----

--- End Message ---

Reply to: