Subject: bug#64608: 29.0.90; Eglot: reuse server when visiting external files

From: Filippo Argiolas <[email-masked]>
Date: Sat, 15 Jul 2023 09:30:47 +0200

Il giorno ven 14 lug 2023 alle ore 16:00 João Távora
<[email-masked]> 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