From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#70408: 30.0.50; Eglot and Project integration Date: Tue, 16 Apr 2024 18:02:10 +0200 Message-ID: <3i7r7yspjdbjtlyrc6ry3vi4rbsxvm52axyehk3dn4ykjltndh@aqizn4e6dflm> References: <87o7aas3sk.fsf.ref@aol.com> <87o7aas3sk.fsf@aol.com> <86le5djzz2.fsf@gnu.org> <8cfba95b-fedd-4b5f-9778-d656601006d1@gutov.dev> Reply-To: Ergus Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29998"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Dmitry Gutov , Eli Zaretskii , 70408@debbugs.gnu.org To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 16 18:03:20 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1rwlHE-0007Xj-AC for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 16 Apr 2024 18:03:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwlGo-0005Sd-Gb; Tue, 16 Apr 2024 12:02:54 -0400 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 1rwlGm-0005Qv-MU for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2024 12:02:52 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwlGm-0008Gp-9q for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2024 12:02:52 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rwlGx-0000Iv-Ip for bug-gnu-emacs@gnu.org; Tue, 16 Apr 2024 12:03:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ergus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Apr 2024 16:03:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70408 X-GNU-PR-Package: emacs Original-Received: via spool by 70408-submit@debbugs.gnu.org id=B70408.1713283365970 (code B ref 70408); Tue, 16 Apr 2024 16:03:03 +0000 Original-Received: (at 70408) by debbugs.gnu.org; 16 Apr 2024 16:02:45 +0000 Original-Received: from localhost ([127.0.0.1]:44663 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rwlGa-0000Ew-VT for submit@debbugs.gnu.org; Tue, 16 Apr 2024 12:02:44 -0400 Original-Received: from sonic311-14.consmr.mail.bf2.yahoo.com ([74.6.131.124]:38966) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rwlGW-0000Df-6s for 70408@debbugs.gnu.org; Tue, 16 Apr 2024 12:02:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1713283338; bh=i0VWL7wRFPBJNcgwAVU5UZKVhatzH+M1R4Vn7PS44F4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject:Reply-To; b=HHDPITqoKNY6+wYJMxfBfWJBko/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hy2VfGkAEVwMvMjQluyd7FArhhBzDMu6OLNbNbT qOtysQXd1dr.wd9uKx636w4mLr39WRowzhzvkofjnGVAj5BHfP0DcL5p2IIurpUiosv8bJ50ElPH kp4LgOnckkSzWervab7IvgQPJ4de7KtNDT7xANt8iJuHn3AvlNmWTJ0X8aQQMblVhI86imQoEMrT GF_EPgBmmG1.Dc6vjmDRJRYy_RG0w6vmcRe_zvY8anwU1P6hzMl2JVCKHBqKvDFskbm_FUDWX1UC 5wx3qks59QWoYmnpxnRieGgrHJwKWEA8zVd0dXW8JO40N1ckhH3STsd4Vs5HKENSxmwYvRyuFD4X SaWgrPKQfpJhOMc4IIRNAv31RYYGJMV7GnuUDa7PV9SDTJA_GqmwZGG9_a5Oc6jOLSJ_ULCVkvr4 C9PMI2MLJ2.t_n5RHie8I44KSnZ0BDwjscVfBXqC037jj7MA1qtJXdHeFGtEdN1k1GQjc1vRRglr ul6dkSki2ca8ARTOhGtCRZokXv6KeNX6NKr9JClLKiP7DIcPenVNwsk0vg4AJob4hSS9J2qXxLZF _1KVOrEWlEykxHBBYSsaiKHMLmV3B4DtFFpnDN_fBE X-Sonic-MF: X-Sonic-ID: eb0c9abc-d5f2-4ce7-b367-0b260b20435a Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.bf2.yahoo.com with HTTP; Tue, 16 Apr 2024 16:02:18 +0000 Original-Received: by hermes--production-ir2-7b99fc9bb6-9sm2s (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 82b03ee34769c2254398d3d2aadbf6b8; Tue, 16 Apr 2024 16:02:12 +0000 (UTC) Content-Disposition: inline In-Reply-To: X-Mailer: WebService/1.1.22205 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:283439 Archived-At: On Tue, Apr 16, 2024 at 02:51:10PM +0100, João Távora wrote: >On Tue, Apr 16, 2024 at 1:56 PM Dmitry Gutov wrote: > >> IIUC Ergus's request is primarily about a situation where an >> "out-of-tree" build is used. Meaning, the directory for build artefacts >> is not a subdirectory of the project root, but -- apparently -- some >> sibling directory of it (e.g. "../build"). So it's somewhat atypical, >> although I suppose the solution from the link above might work with it too. > >Ah, I know about that. That's where compile-commands.json is generated >by CMake. But using that './build' as the project root passed via LSP >to clangd >(and likely any other server) will most likely fail: that's not the >project root >and it doesn't have any versioned source files (only auto-generated ones). > >Because of this, C++ projects usually have sth like: > > ln -sf build/compile_commands.json compile_commands.json > >as a build step. > >Alternatively, you invoke clangd with `--compile-commands-dir=build`. >I don't think there's anything project.el or Eglot can do or should do >about this case. > What my POC workaround does is basically call a hook that updates `eglot-workspace-configuration` as a root's directory-local variable the first time project-current is called within a project. ``` (defun project-multi--set-eglot (plist) "Set the eglot variables in root's PLIST when possible." (when-let* ((compile-dir (project-extra-info (project-current) :compile-dir)) (file-exists-p (expand-file-name "compile_commands.json" compile-dir))) (let* ((symvars (intern (format "eglot-multi--%s" compile-dir))) (eglot-complete (project-multi--merge-plist ;; merge with new values (bound-and-true-p eglot-workspace-configuration) `(:clangd (:initializationOptions (:compilationDatabasePath ,compile-dir)))))) ;; set the dir local variables, they will apply automatically to ;; all buffers open in the future within the project root (dir-locals-set-class-variables symvars `((nil . ((eglot-workspace-configuration . ,eglot-complete))))) (dir-locals-set-directory-class (project-root (project-current)) symvars) ;; set the variable manually in all the already opened buffers ;; TODO: JAM check if the variable is not already set in the other buffers?? ;; Probably override only the value instead of replacing the whole variable? (mapc (lambda (buffer) (with-current-buffer buffer (setq-local eglot-workspace-configuration eglot-complete))) (project-buffers (project-current)))))) ``` project-multi--merge-plist is just a hack function to merge the eglot-workspace-configuration value without overriding the existing sub-values if already set (in case the user sets some sub-values in the dir locals then those takes precedence) Then this restarts eglot IIUC this is equivalent to call `--compile-commands-dir=build` and at the moment is working for me. >> This bug is split off from an emacs-devel discussion, where I posted a >> draft solution of mine: >> https://lists.gnu.org/archive/html/emacs-devel/2024-04/msg00279.html >> I'm curious for any feedback - like would that be good enough for this >> and related cases, or maybe if someone has an even simpler approach in mind. > >I'll pass, but wish you luck. I've stated in the past that I think >project.el should >allow subprojects inside larger projects, and let users of >project-current (direct >or indirect) specify if they're interesting in the innermost, >outermost, or intermediate >projects when searching for projects to act on, via a combination of prefix >arguments, arguments, customized special variables or let-bound special >variables. > At the moment I assume the outer most only; which is the simpler one to setup and implement woth the current project.el support. The main goal I have is OOSC, not nested projects. >João