help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Set eglot to use project config in subdirectory


From: Eric Abrahamsen
Subject: Re: Set eglot to use project config in subdirectory
Date: Tue, 01 Aug 2023 12:26:15 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

Marc <marcc0000@pm.me> writes:

> Hi!
>
> I am working with a typescript project with the following structure:
>
> root/package.json
> root/services/service1/package.json 
> root/services/service2/package.json
>
> Essentially, the git repo is initialized at root and then there are a
> bunch of subprojects within the repository with their own project setup.
>
> I noticed that when I edit a file in service1 for eglot, it's using the
> package.json (I.e the project config) from the root folder and therefore 
> complaining about
> outdated dependencies and I suspect it might also have something to do
> with my emacs freezing when doing file edits.
>
> Is there any way to set so if I'm editing service1, it uses the project
> configuration for that service?
>
> I'm using eglot together with projectile if that matters.

I use project.el, not projectile, but maybe the following will help get
you started:

(defun my-find-eglot-project (dir)
  (when (and (bound-and-true-p eglot-lsp-context)
             (string-match-p "my/special/project/" dir))
    (when-let ((root (locate-dominating-file dir ".venv")))
      (cons 'transient root))))

(add-hook 'project-find-functions #'my-find-eglot-project)

You can see this is set up for an analogous situation to yours, just
with Python subprojects instead of Node.

To be perfectly honest I've already forgotten the exact chain of events
here, I think it's something like when Eglot is trying to decide which
files "belong" to a certain LSP server, it uses project.el to collect
those files, and this function basically lies to Eglot about where the
root of the current project is. I don't know how hard this would be to
adapt to Projectile.

Good luck,
Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]