From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.devel Subject: Re: Eglot, project.el, and python virtual environments Date: Fri, 18 Nov 2022 11:36:22 -0800 Message-ID: <874juwvyvd.fsf@ericabrahamsen.net> References: <87zgcq68zp.fsf@ericabrahamsen.net> <878rkale3l.fsf@dfreeman.email> <87v8nezf2k.fsf@ericabrahamsen.net> <87o7t5k7sv.fsf@dfreeman.email> <86mt8p4221.fsf@gmail.com> <4cc918a053771a5e1c440cb4b458f3ed@webmail.orcon.net.nz> <838rk8d7xb.fsf@gnu.org> <87k03swcye.fsf@dfreeman.email> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38714"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , Phil Sainty , Dmitry Gutov , theophilusx@gmail.com, emacs-devel@gnu.org, =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= To: Danny Freeman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 18 20:37:02 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ow7Ac-0009sB-Bm for ged-emacs-devel@m.gmane-mx.org; Fri, 18 Nov 2022 20:37:02 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ow7AC-0007j5-9r; Fri, 18 Nov 2022 14:36:36 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ow7AA-0007in-TV for emacs-devel@gnu.org; Fri, 18 Nov 2022 14:36:35 -0500 Original-Received: from mail.ericabrahamsen.net ([52.70.2.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ow7A9-0002ke-2e; Fri, 18 Nov 2022 14:36:34 -0500 Original-Received: from localhost (c-71-197-232-41.hsd1.wa.comcast.net [71.197.232.41]) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id 6F0A8FA167; Fri, 18 Nov 2022 19:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericabrahamsen.net; s=mail; t=1668800184; bh=XbphLhZ37rb43cYQDRJuJBwPNW3WfjCkTRdCPEosJ18=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=mu6i6UWtHbsmuw1UUiWEf6q3oYWQ8QkOgx8pmvJSxXIVyS2V4Uc2AXvh4pDURS/VT WswKNfMruy2TE5HA4b7cyIZXs/G/cBjXTYCyW58tHqCct2VlB22bN3hZugR22NRono xxSHcNN2hGKivGrSyNnIXsFEyXEUffjr6D3fXg/8= In-Reply-To: <87k03swcye.fsf@dfreeman.email> (Danny Freeman's message of "Fri, 18 Nov 2022 08:55:35 -0500") Received-SPF: pass client-ip=52.70.2.18; envelope-from=eric@ericabrahamsen.net; helo=mail.ericabrahamsen.net X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300120 Archived-At: Danny Freeman writes: > Eli Zaretskii writes: > >> I think this turns the table for no good reason. I see no reason to >> add complex new abstractions to project.el just because we have an >> issue with configuring Eglot in the use case presented in this thread. >> >> Let me remind you that Eglot already supports a kind of "sub-project": >> it uses the same LSP server only for those source files in a project >> that share the same major mode. So parts of a project that use a >> different PL are already considered to be a "sub-project", and Eglot >> does that without any help from project.el. >> >> Given that this feature already exists, a proposal to add a >> "sub-project" notion to project.el should describe at least several >> use cases of such "sub-projects" where the separate "sub-projects" >> share the same programming language. If the situation with python-env >> is the only one we find reasonable, IMO adding "sub-projects" to >> project.el is an unjustified complication. > > I think that most monorepo projects fall into this category. That is a > large version controlled repository with multiple sub projects in it. > Sometimes the subprojects are written in different languages. Usually > there are sub folders of the monorepo project that act as sub projects. > I ran into one at work yesterday, but I'm not sure what I would have > project.el do differently there. I preferred it's behavior actually. > >> I suggest to look at this as an Eglot issue, not a project.el issue. >> What is requested here is an ability to tell Eglot which directories >> should share the same LSP server and which ones should have separate >> servers. It shouldn't be hard to have a buffer-local variable to tell >> Eglot that, or a function that accepts a buffer and returns a value >> that Eglot can use for this decision. All we need is a way to tell >> Eglot which directories to communicate to the LSP server as those >> which it should watch, and when to start another instance of the LSP >> server even though one is already up and running for this project and >> major mode. Let's not complicate project.el for a problem that >> doesn't belong to it. > > Is this not exactly what `eglot-lsp-context` is for? Using my example > from earlier in the thread is what I suspect is the "right way" to solve > this: > > ``` > (defun project-find-virtualenv-for-eglot (dir) > (when eglot-lsp-context > (let ((root (locate-dominating-file dir ".virtualenv"))) > (when root > (cons 'transient root))))) > > (add-hook 'project-find-functions #'project-find-virtualenv-for-eglot) > ``` > > It can be made more targeted by checking the value of directory if > necessary. (I could also a use when-let) > > It is an obscure way to solve this problem. I only know about it from my > time spent with eglot's source. Not every user will have that > experience. How could we make that better? I agree that this seems like the most likely point of customization -- and also agree that if this approach gets "blessed" somehow it could probably be made more obvious, if only through documentation. I wonder if the same entry point could be used for language server short-circuiting: for instance, the transient project structure could contain a sexp that's used to mask the value of `eglot-server-programs', to point Eglot at different programs. It looks like that value would get cached for later use. Anyway, I haven't looked at Eglot closely enough to suggest anything more than that. I'll try to read through the library this weekend. Eric