From: Yuri Khan <yuri.v.khan@gmail.com>
To: "Sébastien Gendre" <seb@k-7.ch>
Cc: Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
Subject: Re: Dev workflow in Emacs with containers
Date: Sun, 1 Dec 2024 16:41:24 +0700 [thread overview]
Message-ID: <CAP_d_8XHzntd4Fws8qix0HiMHNnr19CiC=w3FRYqQnayGBkuWA@mail.gmail.com> (raw)
In-Reply-To: <874j3oa8gm.fsf@k-7.ch>
On Sun, 1 Dec 2024 at 01:21, Sébastien Gendre <seb@k-7.ch> wrote:
> Seems a good way to do it.
>
> I haven't think about the language server.
> How do you configure the container ?
I install the language server in the same image that is used for
building. This way, it has access to the same version of the standard
library as the compiler does.
If the project is set up to use system-packaged libraries, I install
them in the same image.
I bind-mount the sources and vendored third-party libraries. This way,
I do not need to rebuild the image whenever they change.
All this taken together ensures that (1) the language server sees the
same sources and libraries that the compiler sees, and (2) I don’t
need to install the same libraries on my host machine, which would
defeat the point of dockerization.
Another thing to look out for is where the language server caches its
data. This should also be bind-mounted so that it persists between
sessions.
> > Where practical, I prefer to mount my volumes at the same paths in the
> > container as locally, this simplifies the mapping a lot. But in some
> > cases I hook ‘compilation-filter’ to a function that replaces
> > prefixes.
>
> I'm very curious about your compilation filter. Can you share it ?
As I said, mounting in matching paths is a lot simpler.
Suppose I have the project root at /home/me/work/project on the host,
but I mount it at /mnt/project in the container.
The compiler will report its messages with the file names starting
with /mnt/project. Then when I instruct Emacs to go to the error
location, it will not find the file. It may ask me for assistance.
So I have this somewhere in my load-path:
;; yk-compile.el
(defvar yk-compilation-filter-alist nil
"List of (REGEXP REPLACEMENT) to apply to compilation messages.")
(defun yk-compilation-filter ()
"Apply replacements to compilation messages."
(save-excursion
(pcase-dolist (`(,regexp ,replacement) yk-compilation-filter-alist)
(goto-char compilation-filter-start)
(beginning-of-line)
(while (re-search-forward regexp nil t)
(replace-match replacement nil nil)))))
(provide 'yk-compile)
(this is probably not the most efficient way to do it, but it works for me).
In the project root, I have a .dir-locals.el that sets up the
replacements for this project:
((nil . ((yk-compilation-filter-alist
. (("/mnt/project/" "/home/me/work/project/"))))))
(Now that I think about it, I could probably achieve a similar effect
using the ‘compilation-transform-file-match-alist’ variable, except
that it only helps with the issue of *jumping* to error location and
not solving the *display* of file paths.)
Additionally, with sources mounted in a path different from the host,
the language server will also talk in terms of container paths. It
will expect paths starting with ‘/mnt/project’ in the
textDocument/didOpen notifications, and report that path in its
textDocument/references responses. clangd happens to have a path
mapping feature which is specified in its command line.
My only motivation for mounting the sources in a path different from
the host is that I want to have multiple working copies of the project
on the host, so that I could work with multiple feature branches at
the same time; and mounting them in the same place in the container
allows me to speed up compilation using ccache. If compilation time is
not an issue, I much prefer the ease of transparent paths.
prev parent reply other threads:[~2024-12-01 9:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 14:32 Dev workflow in Emacs with containers Sébastien Gendre
2024-11-29 17:32 ` Yuri Khan
2024-11-29 18:20 ` Leo Butler
2024-11-30 10:44 ` Yuri Khan
2024-11-30 18:21 ` Sébastien Gendre
2024-12-01 9:41 ` Yuri Khan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAP_d_8XHzntd4Fws8qix0HiMHNnr19CiC=w3FRYqQnayGBkuWA@mail.gmail.com' \
--to=yuri.v.khan@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=seb@k-7.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).