GNU bug report logs - #60570
29.0.60; Eglot+pyright freeze Emacs when edit a single file in Home director

Previous Next

Package: emacs;

Reported by: Eason Huang <aqua0210 <at> foxmail.com>

Date: Thu, 5 Jan 2023 08:59:02 UTC

Severity: normal

Found in version 29.0.60

To reply to this bug, email your comments to 60570 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#60570; Package emacs. (Thu, 05 Jan 2023 08:59:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eason Huang <aqua0210 <at> foxmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 05 Jan 2023 08:59:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Eason Huang <aqua0210 <at> foxmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.60;
 Eglot+pyright freeze Emacs when edit a single file in Home director
Date: Thu, 05 Jan 2023 16:57:16 +0800
Hi Emacs dev team,

I use Emacs 29 with eglot + pyright, Eglot will freeze Emacs when editing
a single test.py file.

Steps to reproduce:
On macOS, only pyright is installed on the system
1. install pyright
```
$ sudo npm install -g pyright
$ pyright --version
pyright 1.1.286

```
2. C-x C-f ~/test.py Open a python file and I just want to test some simple code.
3. M-x eglot At this point, Emacs freezes and the find program takes up 99% of the
system's resources. Finally, you has to force quit Emacs.

I guess this is because Eglot will delegate project.el to search the entire
`~/` directory by the program `find`.

If I use git to manage my test.py file, the issue is gone.

I am using Emacs 29 with commit:
https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=2569ede9c496bb060e0b88428cb541088aaba1f9

--
Eason Huang


In GNU Emacs 29.0.60 (build 1, x86_64-apple-darwin22.2.0, NS
 appkit-2299.30 Version 13.1 (Build 22C65)) of 2023-01-02 built on
 macbook
Windowing system distributor 'Apple', version 10.3.2299
System Description:  macOS 13.1

Configured using:
 'configure --with-native-compilation=aot 'CPPFLAGS=-I/opt/local/include
 -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'
 'LDFLAGS=-L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-rpath
 /opt/local/lib/gcc12
 -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
 -arch x86_64''

Configured features:
ACL GIF GLIB GMP GNUTLS JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM ZLIB

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Python

Minor modes in effect:
  eglot--managed-mode: t
  flymake-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny rfc822
mml mml-sec epa derived epg rfc6068 epg-config gnus-util mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
files-x find-dired dired dired-loaddefs grep time-date eglot
external-completion array filenotify jsonrpc ert pp ewoc debug backtrace
find-func xref flymake-proc flymake thingatpt compile
text-property-search url-util url-parse auth-source eieio eieio-core
password-cache json map url-vars imenu vc-svn python project byte-opt
pcase treesit comint ansi-osc ring cl-loaddefs comp comp-cstr warnings
icons subr-x rx cl-seq cl-macs gv cl-extra help-mode bytecomp
byte-compile cl-lib ansi-color rmc iso-transl tooltip cconv eldoc paren
electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads kqueue cocoa ns lcms2
multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 139166 11475)
 (symbols 48 11664 0)
 (strings 32 35088 1771)
 (string-bytes 1 1137571)
 (vectors 16 26979)
 (vector-slots 8 519329 21535)
 (floats 8 53 23)
 (intervals 56 269 0)
 (buffers 984 16))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60570; Package emacs. (Thu, 05 Jan 2023 21:39:01 GMT) Full text and rfc822 format available.

Message #8 received at 60570 <at> debbugs.gnu.org (full text, mbox):

From: João Távora <joaotavora <at> gmail.com>
To: 60570 <at> debbugs.gnu.org, Dmitry Gutov <dgutov <at> yandex.ru>,
 aqua0210 <at> foxmail.com
Subject: Re: 29.0.60; Eglot+pyright freeze Emacs when edit a single file in
 Home director
Date: Thu, 5 Jan 2023 21:38:40 +0000
[Message part 1 (text/plain, inline)]
Eason,

Eglot is asking project.el to tell it which files belong to a
project. I believe project.el uses find as a last-ditch effort, if
finds no other method to answer.

I'm afraid there can be no good solution to your problem, because by
invoking any project-aware operation on ~/test.py (and Eglot counts as
project-aware functionality) and in the absence of, say, a ~/.git you
are effectively telling `project.el` that your whole home directory is a
gigantic project, and there is no good way to determine the files in
that project but to use find.

You could:

1. configure your language server to not request project-wide file
   watching from the LSP client in certain directories (including the
   $HOME directory).  See your language server's documentation for this
   effect

2. Tell project.el via its interfaces (project-find-functions) that the
   "project" you store in your $HOME is composed of a relatively small and
   manageable set of files.

3. A very simple means -- but not the only means -- to do the above is to
   type `git init` in your $HOME directory.

4. Read project.el's documentation (and ask its maintainers) for other
   means to use project-find-functions to declare that a project exists
   in $HOME but does not include the full contents of your home
   directory as its files.

5. Stop opening Python scripts in your $HOME *and* auto-activating Eglot
   in them.  You may be auto-activating Eglot with eglot-ensure, but this
   is not recommended precisely because it carries with risks like this.

6. Request to project.el's maintainer that project.el interrupt up its
   very slow `find`-based search and returns only subset of results.

7. Request that Eglot honour the keyword didChangeWatchFiles when it is
   included in eglot-ignored-server-capabilities.  If you then also
   change your configuration to do this _only_ in certain directories
   (for example by utilizing directory-local variables or writing a
   slightly complicated whook), this would mitigate your problem. We
   can probably do this in eglot.el, but I don't see this as priority
   because of the burden on the user and it only solves the problem for
   Eglot, not all other project.el-using functionality.

I recommend restricting your use of eglot-ensure. It's very overrated
functionality. M-x eglot will probably only need to be typed once
or twice in a typical Emacs session.

You can also, possibly, "unfreeze" your emacs by using C-g or a killall
find issued from the console.

João
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60570; Package emacs. (Fri, 06 Jan 2023 06:18:01 GMT) Full text and rfc822 format available.

Message #11 received at 60570 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: João Távora <joaotavora <at> gmail.com>
Cc: aqua0210 <at> foxmail.com, 60570 <at> debbugs.gnu.org,
 Dmitry Gutov <dgutov <at> yandex.ru>
Subject: Re: bug#60570: 29.0.60; Eglot+pyright freeze Emacs when edit a 
 single file in Home director
Date: Thu, 5 Jan 2023 23:17:41 -0700
João Távora <joaotavora <at> gmail.com> writes:

> 5. Stop opening Python scripts in your $HOME *and* auto-activating Eglot
>    in them.  You may be auto-activating Eglot with eglot-ensure, but this
>    is not recommended precisely because it carries with risks like this.
[...]
>
> I recommend restricting your use of eglot-ensure. It's very overrated
> functionality. M-x eglot will probably only need to be typed once 
> or twice in a typical Emacs session.

I use a custom function eglot-soft-ensure which only enables eglot if
there is already a LSP server running for the current project. This way
eglot doesn’t auto-start in which files that I don’t want it to start.

(defun eglot-soft-ensure ()
  "Turn on eglot when there is an exising server for the current project."
  (require 'eglot)
  (when-let* ((project (project-current))
              (eglot-server (gethash project eglot--servers-by-project)))
    (eglot-ensure)))

Yuan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60570; Package emacs. (Fri, 06 Jan 2023 10:30:02 GMT) Full text and rfc822 format available.

Message #14 received at 60570 <at> debbugs.gnu.org (full text, mbox):

From: João Távora <joaotavora <at> gmail.com>
To: Yuan Fu <casouri <at> gmail.com>
Cc: Eason Huang <aqua0210 <at> foxmail.com>, 60570 <at> debbugs.gnu.org,
 Dmitry Gutov <dgutov <at> yandex.ru>
Subject: Re: bug#60570: 29.0.60; Eglot+pyright freeze Emacs when edit a single
 file in Home director
Date: Fri, 6 Jan 2023 10:29:17 +0000
[Message part 1 (text/plain, inline)]
On Fri, Jan 6, 2023, 06:17 Yuan Fu <casouri <at> gmail.com> wrote:

> I use a custom function eglot-soft-ensure which only enables eglot if
> there is already a LSP server running for the current project. This way
> eglot doesn’t auto-start in which files that I don’t want it to start.
>
> (defun eglot-soft-ensure ()
>   "Turn on eglot when there is an exising server for the current project."
>   (require 'eglot)
>   (when-let* ((project (project-current))
>               (eglot-server (gethash project eglot--servers-by-project)))
>     (eglot-ensure)))

Hello Yuan,

I must me missing something, because I would say you can just
get rid of eglot-soft-ensure. I can't understand what it is adding
on top of the normal Eglot behaviour. From the manual:

"When you visit a file under the same project, whether an existing or a
new file, its buffer is automatically added to the set of buffers managed by
Eglot, and the server which supports the buffer’s major-mode is notified
about that. Thus, visiting a non-existent file
/home/joe/projects/fooey/lib/y.foo
in the above example will notify the server of the *.foo files’ language
that a new file was added to the project, even before the file appears
on disk. The special Eglot minor mode is also turned on automatically
in the buffer visiting the file."

https://joaotavora.github.io/eglot/#Eglot-and-Buffers

João
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60570; Package emacs. (Fri, 06 Jan 2023 13:38:02 GMT) Full text and rfc822 format available.

Message #17 received at 60570 <at> debbugs.gnu.org (full text, mbox):

From: Eason Huang <aqua0210 <at> foxmail.com>
To: João Távora <joaotavora <at> gmail.com>
Cc: 60570 <at> debbugs.gnu.org, Dmitry Gutov <dgutov <at> yandex.ru>
Subject: Re: bug#60570: 29.0.60; Eglot+pyright freeze Emacs when edit a
 single file in Home director
Date: Fri, 06 Jan 2023 21:36:52 +0800
João Távora <joaotavora <at> gmail.com> writes:

> Eason,
>
> Eglot is asking project.el to tell it which files belong to a
> project. I believe project.el uses find as a last-ditch effort, if
> finds no other method to answer.
>
> I'm afraid there can be no good solution to your problem, because by
> invoking any project-aware operation on ~/test.py (and Eglot counts as
> project-aware functionality) and in the absence of, say, a ~/.git you
> are effectively telling `project.el` that your whole home directory is a
> gigantic project, and there is no good way to determine the files in
> that project but to use find.

> You could:
>
> 1. configure your language server to not request project-wide file
>    watching from the LSP client in certain directories (including the
>    $HOME directory).  See your language server's documentation for this
>    effect

> 2. Tell project.el via its interfaces (project-find-functions) that the
>    "project" you store in your $HOME is composed of a relatively small and
>    manageable set of files.

> 3. A very simple means -- but not the only means -- to do the above is to
>    type `git init` in your $HOME directory.
>
> 4. Read project.el's documentation (and ask its maintainers) for other
>    means to use project-find-functions to declare that a project exists
>    in $HOME but does not include the full contents of your home
>    directory as its files.
>
> 5. Stop opening Python scripts in your $HOME *and* auto-activating Eglot
>    in them.  You may be auto-activating Eglot with eglot-ensure, but this
>    is not recommended precisely because it carries with risks like this.
>
> 6. Request to project.el's maintainer that project.el interrupt up its
>    very slow `find`-based search and returns only subset of results.
>
> 7. Request that Eglot honour the keyword didChangeWatchFiles when it is
>    included in eglot-ignored-server-capabilities.  If you then also
>    change your configuration to do this _only_ in certain directories
>    (for example by utilizing directory-local variables or writing a
>    slightly complicated whook), this would mitigate your problem. We
>    can probably do this in eglot.el, but I don't see this as priority
>    because of the burden on the user and it only solves the problem for
>    Eglot, not all other project.el-using functionality.
>
> I recommend restricting your use of eglot-ensure. It's very overrated
> functionality. M-x eglot will probably only need to be typed once
> or twice in a typical Emacs session.

Thanks for your detailed explanation and solutions.

I will aviod opening Python scripts in $HOME directory and use git to
manage my python project. For the single file, just put it in an empty
directory aslo works as expected.

I enjoy using M-x eglot and never use eglot-ensure.


> You can also, possibly, "unfreeze" your emacs by using C-g or a killall
> find issued from the console.
C-g sometimes can "unfreeze" Eamcs and stop the find program.


-- 
Eason Huang





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60570; Package emacs. (Sat, 07 Jan 2023 22:40:02 GMT) Full text and rfc822 format available.

Message #20 received at 60570 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: João Távora <joaotavora <at> gmail.com>
Cc: Eason Huang <aqua0210 <at> foxmail.com>, 60570 <at> debbugs.gnu.org,
 Dmitry Gutov <dgutov <at> yandex.ru>
Subject: Re: bug#60570: 29.0.60; Eglot+pyright freeze Emacs when edit a single
 file in Home director
Date: Sat, 7 Jan 2023 14:38:54 -0800

> On Jan 6, 2023, at 2:29 AM, João Távora <joaotavora <at> gmail.com> wrote:
> 
> On Fri, Jan 6, 2023, 06:17 Yuan Fu <casouri <at> gmail.com> wrote:
> 
> > I use a custom function eglot-soft-ensure which only enables eglot if
> > there is already a LSP server running for the current project. This way
> > eglot doesn’t auto-start in which files that I don’t want it to start.
> >
> > (defun eglot-soft-ensure ()
> >   "Turn on eglot when there is an exising server for the current project."
> >   (require 'eglot)
> >   (when-let* ((project (project-current))
> >               (eglot-server (gethash project eglot--servers-by-project)))
> >     (eglot-ensure)))
> 
> Hello Yuan,
> 
> I must me missing something, because I would say you can just 
> get rid of eglot-soft-ensure. I can't understand what it is adding 
> on top of the normal Eglot behaviour. From the manual:
> 
> "When you visit a file under the same project, whether an existing or a 
> new file, its buffer is automatically added to the set of buffers managed by
> Eglot, and the server which supports the buffer’s major-mode is notified 
> about that. Thus, visiting a non-existent file /home/joe/projects/fooey/lib/y.foo 
> in the above example will notify the server of the *.foo files’ language 
> that a new file was added to the project, even before the file appears 
> on disk. The special Eglot minor mode is also turned on automatically 
> in the buffer visiting the file."
> 
> https://joaotavora.github.io/eglot/#Eglot-and-Buffers

Oh! I must have done something wrong that prompted me to write eglot-soft-ensure. But I don’t remember :-) Sorry for the misinformation!

Yuan



This bug report was last modified 1 year and 102 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.