GNU bug report logs - #64608
29.0.90; Eglot: reuse server when visiting external files

Previous Next

Package: emacs;

Reported by: Filippo Argiolas <filippo.argiolas <at> gmail.com>

Date: Fri, 14 Jul 2023 07:33:02 UTC

Severity: normal

Found in version 29.0.90

To reply to this bug, email your comments to 64608 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#64608; Package emacs. (Fri, 14 Jul 2023 07:33:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Filippo Argiolas <filippo.argiolas <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 14 Jul 2023 07:33:03 GMT) Full text and rfc822 format available.

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

From: Filippo Argiolas <filippo.argiolas <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.90; Eglot: reuse server when visiting external files
Date: Fri, 14 Jul 2023 07:51:28 +0200
Hi,

I'm working on a couple of projects each with their main root and all
sharing some common code in an external root dir.

Each project has a compile_commands.json that knows how to compile the
external shared code. External root has no compile db and doesn't know
how to compile itself.

Eglot currently allows me to jump to external files using xref while
keeping the current active running server by setting
eglot-extend-to-xref.

Project.el allows me to visit external files using project-or-external-
functions by defining project-external-roots on my custom backend or
project-vc-external-roots-functions with the default backend.

It would be great if I configure Eglot to not switch to a new server
when visiting an external file in a similar way it does with xref.

Any pointer to achieve something like this with current project.el and
eglot code would also be great. Maybe with a custom project backend?


Best regards,
Filippo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64608; Package emacs. (Fri, 14 Jul 2023 10:39:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Filippo Argiolas <filippo.argiolas <at> gmail.com>,
 João Távora <joaotavora <at> gmail.com>
Cc: 64608 <at> debbugs.gnu.org
Subject: Re: bug#64608: 29.0.90;
 Eglot: reuse server when visiting external files
Date: Fri, 14 Jul 2023 13:38:49 +0300
> From: Filippo Argiolas <filippo.argiolas <at> gmail.com>
> Date: Fri, 14 Jul 2023 07:51:28 +0200
> 
> Hi,
> 
> I'm working on a couple of projects each with their main root and all
> sharing some common code in an external root dir.
> 
> Each project has a compile_commands.json that knows how to compile the
> external shared code. External root has no compile db and doesn't know
> how to compile itself.
> 
> Eglot currently allows me to jump to external files using xref while
> keeping the current active running server by setting
> eglot-extend-to-xref.
> 
> Project.el allows me to visit external files using project-or-external-
> functions by defining project-external-roots on my custom backend or
> project-vc-external-roots-functions with the default backend.
> 
> It would be great if I configure Eglot to not switch to a new server
> when visiting an external file in a similar way it does with xref.
> 
> Any pointer to achieve something like this with current project.el and
> eglot code would also be great. Maybe with a custom project backend?

Sorry, I don't understand: AFAIU Eglot reuses the same server for all
the buffers under the same major-mode, so you should already have what
you want?  Or what am I missing?

Adding João to this discussion.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64608; Package emacs. (Fri, 14 Jul 2023 14:01:02 GMT) Full text and rfc822 format available.

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

From: João Távora <joaotavora <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 64608 <at> debbugs.gnu.org, Filippo Argiolas <filippo.argiolas <at> gmail.com>
Subject: Re: bug#64608: 29.0.90;
 Eglot: reuse server when visiting external files
Date: Fri, 14 Jul 2023 15:00:34 +0100
[Message part 1 (text/plain, inline)]
On Fri, Jul 14, 2023, 11:38 Eli Zaretskii <eliz <at> gnu.org> wrote:

> >
> > Any pointer to achieve something like this with current project.el and
> > eglot code would also be great. Maybe with a custom project backend?
>
> Sorry, I don't understand: AFAIU Eglot reuses the same server for all
> the buffers under the same major-mode, so you should already have what
> you want?  Or what am I missing?
>

Not really like that Eli. Within the set of all the buffers in the major
mode, subsets are defined for every project, i.e. return value of
project-current. Broadly, that pair {major-mode , project} is the
discriminator that determines Eglot's choice of server instance to manage a
given buffer. The exception is buffers visited by eglot-extend-to-xref. I
believe this is explained in the manual. If it's not clear, we should
improve it.

Fillipo, to fully understand your use case and what's missing I need you to
create a structural example of those related projects, closely
representative of the real one, pack it as a zip or a reference to a Git
repository, in a way that I can experience the same limitation you are
experiencing myself. Is the server you are using Clangd? If so, say the
version.

In summary, please follow the seven steps outlined in
https://joaotavora.github.io/eglot/#Troubleshooting-Eglot, else it's going
to be hard to help you.

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

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64608; Package emacs. (Fri, 14 Jul 2023 14:16:02 GMT) Full text and rfc822 format available.

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

From: Filippo Argiolas <filippo.argiolas <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 64608 <at> debbugs.gnu.org,
 João Távora <joaotavora <at> gmail.com>
Subject: Re: bug#64608: 29.0.90;
 Eglot: reuse server when visiting external files
Date: Fri, 14 Jul 2023 15:55:50 +0200
[Message part 1 (text/plain, inline)]
Il ven 14 lug 2023, 12:38 Eli Zaretskii <eliz <at> gnu.org> ha scritto:

> > From: Filippo Argiolas <filippo.argiolas <at> gmail.com>
> > Date: Fri, 14 Jul 2023 07:51:28 +0200
> >
> > Hi,
> >
> > I'm working on a couple of projects each with their main root and all
> > sharing some common code in an external root dir.
> >
> > Each project has a compile_commands.json that knows how to compile the
> > external shared code. External root has no compile db and doesn't know
> > how to compile itself.
> >
> > Eglot currently allows me to jump to external files using xref while
> > keeping the current active running server by setting
> > eglot-extend-to-xref.
> >
> > Project.el allows me to visit external files using project-or-external-
> > functions by defining project-external-roots on my custom backend or
> > project-vc-external-roots-functions with the default backend.
> >
> > It would be great if I configure Eglot to not switch to a new server
> > when visiting an external file in a similar way it does with xref.
> >
> > Any pointer to achieve something like this with current project.el and
> > eglot code would also be great. Maybe with a custom project backend?
>
> Sorry, I don't understand: AFAIU Eglot reuses the same server for all
> the buffers under the same major-mode, so you should already have what
> you want?  Or what am I missing?
>
> Adding João to this discussion.
>

I could be misusing the word server here, what I'm seeing is a clangd
instance for each project. Each with its own hidden stdout/stderr buffer.
Not sure if they're actually different processes, far from the laptop at
the moment and cannot check, but I guess so.

When I visit a file in a new project it starts a new clangd instance
associated to its root dir and its compile db if it exists. All buffers
from the same project share the same instance. Not sure what happens with
different major modes as I'm using c-mode only.

What I'd like is to reuse the same instance and the same compile db if I'm
visiting an external file from project-or-external- functions.

Filippo
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64608; Package emacs. (Sat, 15 Jul 2023 09:45:02 GMT) Full text and rfc822 format available.

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

From: Filippo Argiolas <filippo.argiolas <at> gmail.com>
To: João Távora <joaotavora <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 64608 <at> debbugs.gnu.org
Subject: Re: bug#64608: 29.0.90;
 Eglot: reuse server when visiting external files
Date: Sat, 15 Jul 2023 09:30:47 +0200
Il giorno ven 14 lug 2023 alle ore 16:00 João Távora
<joaotavora <at> gmail.com> ha scritto:
> Fillipo, to fully understand your use case and what's missing I need you to create a structural example of those related projects, closely representative of the real one, pack it as a zip or a reference to a Git repository, in a way that I can experience the same limitation you are experiencing myself. Is the server you are using Clangd? If so, say the version.

I tried to setup a minimal work dir to show you what I'd like to obtain.

https://people.freedesktop.org/~fargiolas/eglot-external-test-case.tar.gz

It's configured (compile db and dir locals) to be unpacked inside /tmp/

Inside you will find three dirs:
- foo and bar are normal projects
- ext contains shared code that can be compiled only when paired with
one or the other project.

ext is is added as an external root to each of the projects with .dir-locals.el
foo and bar include compile_commands.json that build both the project
and the external code. Each project builds the external code
differently (e.g. by setting different defines).

Only relevant settings in init.el are:
(add-hook 'c-mode-hook 'eglot-ensure)
(setq eglot-extend-to-xref t)

emacs 29.0.90
clangd 6.0.6

With eglot-extend-to-xref I can jump from foo/main.c into ext
functions while keeping the same active clangd server (eglot:foo in
the modeline).
If I open foo/main.c and then visit ext/ext.c with
project-or-external-find-file or project-or-external-find-regexp it
switches to a new clangd instance (eglot:ext in the modeline) as it
detects ext/ as its own project.

What I'd like is to keep the same clangd instance if I'm visiting and
external file in a similar way that xref does.
Is it something achievable in current eglot? may be something I should
configure about workspaces?

Thanks!
Filippo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#64608; Package emacs. (Sat, 15 Jul 2023 09:45:03 GMT) Full text and rfc822 format available.

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

From: Filippo Argiolas <filippo.argiolas <at> gmail.com>
To: João Távora <joaotavora <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 64608 <at> debbugs.gnu.org
Subject: Re: bug#64608: 29.0.90;
 Eglot: reuse server when visiting external files
Date: Sat, 15 Jul 2023 09:32:20 +0200
Il giorno sab 15 lug 2023 alle ore 09:30 Filippo Argiolas
<filippo.argiolas <at> gmail.com> ha scritto:
> emacs 29.0.90
> clangd 6.0.6

clangd 16.0.6, sorry for the typo




This bug report was last modified 293 days ago.

Previous Next


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