unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: "João Távora" <joaotavora@gmail.com>
Cc: Danny Freeman <danny@dfreeman.email>,
	 Dmitry Gutov <dgutov@yandex.ru>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: Eglot, project.el, and python virtual environments
Date: Sun, 20 Nov 2022 23:54:21 -0800	[thread overview]
Message-ID: <87bkp0vj2q.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <87zgcml7g7.fsf@gmail.com> ("João Távora"'s message of "Sun, 20 Nov 2022 01:51:04 +0000")

João Távora <joaotavora@gmail.com> writes:

> Danny Freeman <danny@dfreeman.email> writes:
>
>> Dmitry Gutov <dgutov@yandex.ru> writes:
>>
>>> Then your solution should work okay, but it also means it belongs
>>> to the category of Eglot hacks (as
>>> opposed to project.el hacks).
>>
>> It is absolutely an Eglot hack :)
>
> I don't consider this a hack at all.  Not only does it work okay, it's
> how supposed to work.

[...]

>> (defun eglot--find-lsp-root (dir)
>>   (when-let ((root (and eglot-root-marker
>>                         eglot-lsp-context
>>                         (locate-dominating-file dir eglot-root-marker))))
>>     (cons 'transient root)))
>>
>> (add-hook 'project-find-functions #'eglot--find-lsp-root)
>
>
> I think the code above is fine, but it belongs in the user's
> configuration.  In fact, it belongs in the manual, in a section similar
> to what used to be section called "Handling Quirkly Servers" in the old
> README.
>
> This code doesn't belong in Eglot.  Eglot is designed as thin layer
> making different Emacs facilities communicate with LSP servers.  Eglot's
> user interaction is mostly for LSP basics such as connect/disconnect and
> Eglot's user preferences deal with LSP in its generality.  Baking
> project definition facilities into Eglot would bloat it and I don't want
> that.
>
> Are we worried that users will find it hard to apply snippets such as
> Danny's?  My experience with libraries such as Yasnippet, SLY and Eglot
> tells me otherwise: if robust simple Lisp snippets such as the one above
> are easy to find, users have no trouble applying them.  But if we really
> must have a point-and-click interactive interface for programming-averse
> programmers :-) , then we can also remember that Eglot is also an
> Elisp-level API for major-modes to take advantage of.
>
> ... Which means that if the problem here is both LSP and Python-specific
> a .venv specific version of the above snippet could well live in
> python.el.

From the point of view of an end-consumer of all this, I agree that
customization on my end is inevitable, and not a bad thing. I don't
expect that an automatic solution to Python virtual envs, in particular,
will ever be found: they are a mess, and there are several packages in
ELPA/MELPA just for dealing with them.

I spent some time looking at eglot.el and project.el, and was mostly
surprised to find how little they need to know about each other.
Really, Eglot only uses projects very lightly, to group managed buffers
together under one `eglot-lsp-server' instance (I don't know if the
actual external processes need to know which/how many buffers they're
involved with).

Other than that, it doesn't seem to matter at all that project.el and
eglot.el might have different opinions about what project any given file
buffer might belong to.

So yes, Danny's "hack" seems quite sufficient.

The only remaining question is finding the right LSP executable. In my
Python venv case, that's done by using one of the aforementioned
packages -- there's no guarantee that the virtual environment will be
under "./.venv", it could be somewhere else entirely. The packages
generally work by hacking exec-path, so that Eglot's `executable-find'
call finds the right Python LSP executable.

A little care needs to be taken that the environment is "activated"
before the call to `eglot', but it's not that tricky. I don't think
anything more should be done to help with this particular Python case
(besides some documentation).

But maybe something could be done for finding LSP executables in the
more general case. I can imagine that for saner languages, simply
customizing a different executable path (perhaps passing it different
command-line arguments) would be sufficient. All I could think of was
the possibility that the project structure returned by our custom
project-finding function could contain information about the LSP
executable. So instead of just

(cons 'transient dir)

We could return something like

(cons 'transient dir
      'eglot-lsp-program-overrides
         '((python-mode . ("~/proj/.venv/bin/python/pylsp"))))

Where the provided sexp is used as a mask on `eglot-server-programs'.

project.el is pretty vague about the structure of a project, so it's
hard to know exactly how that value should be injected. But with this
setup the user could either use 'transient directly, or first call some
other project-finding function, and then figure out how to stick this
information in there in a useful way. Then `eglot--guess-contact' could
check for it there.

Just a suggestion!

Thanks to all for the discussion,
Eric




  parent reply	other threads:[~2022-11-21  7:54 UTC|newest]

Thread overview: 139+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 18:37 Eglot, project.el, and python virtual environments Eric Abrahamsen
2022-11-16 22:24 ` Danny Freeman
2022-11-16 22:53   ` Eric Abrahamsen
2022-11-17 13:41     ` Danny Freeman
2022-11-17 18:06       ` Eric Abrahamsen
2022-11-17 18:48         ` Yuan Fu
2022-11-17 22:21       ` Tim Cross
2022-11-18  2:38         ` Phil Sainty
2022-11-18  7:43           ` Eli Zaretskii
2022-11-18 13:55             ` Danny Freeman
2022-11-18 15:22               ` Eli Zaretskii
2022-11-18 15:53                 ` Danny Freeman
2022-11-18 19:36               ` Eric Abrahamsen
2022-11-18 15:06             ` Stefan Monnier
2022-11-18 15:17               ` Eli Zaretskii
2022-11-18 15:28                 ` Stefan Monnier
2022-11-19  1:12             ` Dmitry Gutov
2022-11-19  7:42               ` Eli Zaretskii
2022-11-19 13:06                 ` Dmitry Gutov
2022-11-19 13:14                   ` Eli Zaretskii
2022-11-18 18:31   ` João Távora
2022-11-19  1:13     ` Dmitry Gutov
2022-11-19  1:56       ` João Távora
2022-11-19 15:23         ` Dmitry Gutov
2022-11-19 19:17           ` Danny Freeman
2022-11-19 19:49             ` Dmitry Gutov
2022-11-19 21:22               ` Danny Freeman
2022-11-20  1:51                 ` João Távora
2022-11-20 15:36                   ` Dmitry Gutov
2022-11-20 20:35                     ` João Távora
2022-11-20 22:05                       ` Dmitry Gutov
2022-11-21 13:45                         ` João Távora
2022-11-22 15:48                           ` Dmitry Gutov
2022-11-22 21:12                             ` Stefan Monnier
2022-11-22 21:34                               ` João Távora
2022-11-22 22:00                                 ` Dmitry Gutov
2022-11-22 23:23                                   ` João Távora
2022-11-23  0:03                                     ` Dmitry Gutov
2022-11-23 13:57                                       ` Subprojects in project.el (Was: Eglot, project.el, and python virtual environments) João Távora
2022-11-23 20:33                                         ` João Távora
2022-11-24  2:49                                           ` Dmitry Gutov
2022-11-24  8:42                                             ` João Távora
2022-11-24 22:17                                               ` Dmitry Gutov
2022-11-25 19:56                                                 ` Subprojects in project.el João Távora
2022-11-25 22:33                                                   ` Dmitry Gutov
2022-11-26  0:00                                                     ` João Távora
2022-11-26  1:57                                                       ` Dmitry Gutov
2022-11-26  9:23                                                         ` João Távora
2022-11-26 13:34                                                           ` Dmitry Gutov
2022-11-26 19:36                                                             ` João Távora
2022-11-26  2:01                                                       ` Dmitry Gutov
2022-11-26  9:24                                                         ` João Távora
2022-11-24  2:51                                           ` Subprojects in project.el (Was: Eglot, project.el, and python virtual environments) Dmitry Gutov
2022-11-24  6:23                                           ` Eli Zaretskii
2022-11-24  9:01                                             ` João Távora
2022-11-24 22:11                                             ` Dmitry Gutov
2022-11-25  7:30                                               ` Eli Zaretskii
2022-11-25 17:24                                                 ` Dmitry Gutov
2022-11-25 19:45                                                   ` Eli Zaretskii
2022-11-25 21:57                                                     ` Dmitry Gutov
2022-11-25 23:55                                                       ` Subprojects in project.el João Távora
2022-11-28  0:41                                                         ` Dmitry Gutov
2022-11-26  7:26                                                       ` Subprojects in project.el (Was: Eglot, project.el, and python virtual environments) Eli Zaretskii
2022-12-02  1:32                                                         ` Dmitry Gutov
2022-12-02 14:16                                                           ` Eli Zaretskii
2022-12-02 15:08                                                             ` Dmitry Gutov
2022-12-02 15:37                                                               ` Dmitry Gutov
2022-12-02 15:44                                                               ` Subprojects in project.el Stefan Monnier
2022-12-02 23:26                                                                 ` João Távora
2022-12-06 14:36                                                           ` Subprojects in project.el (Was: Eglot, project.el, and python virtual environments) João Távora
2022-11-24  3:01                                         ` Dmitry Gutov
2022-11-24  8:50                                           ` João Távora
2022-11-24 22:46                                             ` Tim Cross
2022-11-24 23:38                                               ` Dmitry Gutov
2022-11-25  7:07                                                 ` Bozhidar Batsov
2022-11-25 14:58                                                   ` Subprojects in project.el Stefan Monnier
2022-11-25 22:29                                                     ` Dmitry Gutov
2022-11-26  2:59                                                       ` Stefan Monnier
2022-11-26 12:30                                                         ` Dmitry Gutov
2022-11-26 17:32                                                           ` Stefan Monnier
2022-11-27  0:25                                                             ` Dmitry Gutov
2022-11-25 20:32                                                 ` João Távora
2022-11-28  4:10                                                 ` Subprojects in project.el (Was: Eglot, project.el, and python virtual environments) Tim Cross
2022-11-28 17:21                                                   ` Dmitry Gutov
2022-11-29  9:56                                                     ` Subprojects in project.el João Távora
2022-11-29 18:40                                                       ` Dmitry Gutov
2022-11-29 22:21                                                         ` João Távora
2022-11-30  0:39                                                           ` Dmitry Gutov
2022-11-30  0:54                                                             ` João Távora
2022-11-30  0:57                                                               ` Dmitry Gutov
2022-11-30  1:18                                                                 ` João Távora
2022-12-02 22:47                                                                 ` Richard Stallman
2022-12-02 23:46                                                                   ` Dmitry Gutov
2022-12-03  7:09                                                                     ` Eli Zaretskii
2022-11-24 22:58                                             ` Subprojects in project.el (Was: Eglot, project.el, and python virtual environments) Dmitry Gutov
2022-11-25  2:38                                               ` Subprojects in project.el Stefan Monnier
2022-11-25 20:23                                                 ` João Távora
2022-11-25 22:23                                                 ` Dmitry Gutov
2022-11-25  7:42                                               ` Juri Linkov
2022-11-25 20:27                                                 ` Dmitry Gutov
2022-11-25 23:47                                                   ` João Távora
2022-11-25 23:58                                                     ` Dmitry Gutov
2022-11-26  0:46                                                       ` João Távora
2022-11-26  2:07                                                         ` Dmitry Gutov
2022-11-25 20:16                                               ` João Távora
2022-11-25 22:44                                                 ` Dmitry Gutov
2022-11-26  0:37                                                   ` João Távora
2022-11-26  2:05                                                     ` Dmitry Gutov
2022-11-26  9:42                                                       ` João Távora
2022-11-26 12:38                                                         ` Dmitry Gutov
2022-11-29 10:03                                                           ` João Távora
2022-11-29 10:17                                                           ` João Távora
2022-11-29 19:07                                                             ` Dmitry Gutov
2022-11-29 22:52                                                               ` João Távora
2022-11-30  1:10                                                                 ` Dmitry Gutov
2022-11-27 19:25                                                 ` Juri Linkov
2022-11-27 21:43                                                   ` Dmitry Gutov
2022-11-22 23:53                                 ` "Backend completion style" as a first-class library. Re: Eglot, project.el, and python virtual environments João Távora
2022-11-23  1:45                                   ` Stefan Monnier
2022-11-25 13:16                                     ` João Távora
2022-11-22 21:40                             ` João Távora
2022-11-22 22:13                               ` Dmitry Gutov
2022-11-22 23:33                                 ` João Távora
2022-11-21 20:58                     ` Augusto Stoffel
2022-11-23  3:37                       ` Dmitry Gutov
2022-11-20 16:37                   ` João Távora
2022-11-21  7:54                   ` Eric Abrahamsen [this message]
2022-11-21 13:36                     ` João Távora
2022-11-21 15:41                       ` Alfred M. Szmidt
2022-11-21 16:49                         ` Eli Zaretskii
2022-11-21 16:49                       ` Eric Abrahamsen
2022-11-21 20:54                     ` Augusto Stoffel
2022-11-19 23:25           ` João Távora
2022-11-19 23:40             ` Dmitry Gutov
2022-11-16 23:18 ` Philip Kaludercic
2022-11-17  1:14   ` Eric Abrahamsen
2022-11-17  6:47 ` North Year
2022-11-17 18:09   ` Eric Abrahamsen
2022-11-19 22:36 ` Stephen Leake

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=87bkp0vj2q.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=danny@dfreeman.email \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).