When opening a Java file of a project previously attached to lsp-mode and the language server, the modeline as well as the error buffer called up with s-l g e show errors of all projects I ever attached to the language server.

Is it possible to avoid this? As long as I don't open a Java file from some other project, I would prefer to work as if the project of the file I am looking at is the only project I have.

To elaborate: my preferred setup would be to have separate emacs processes taking care each of one project at a time. Despite editing or viewing source code in several projects, seeing something like 3 warnings in the modeline when its actually zero for the project I am focusing on whereas the 3 are from another project I am only skimming the source code of is distracting and confusing.

  • Well, one way to solve this might be adding an add-advice with :around parameter (you can see an example here) to lsp-mode and lsp functions, where you'd simply avoid calling the original function if an lsp-server is running and its project dir does not accord to the file you're opening. That said,there may be an easier way. E.g. Idk what do you mean "projects attached", is that some built-in functional in lsp-mode? I usually use .dir-locals.els for projects where I want lsp to run automatically.
    – Hi-Angel
    Commented Mar 10 at 17:32
  • re "projects attached": Afaiu, opening a .java file triggers start of the eclipse language server which then looks at its workspace directory (~/.emacs.d/workspace by default) where to either create or find metadata for the project of the opened Java file. If there is metadata from other Java projects, they are all opened and "processed", including sending errors/warnings found to the emacs lsp client. So maybe it is more of an eclipse language server thing I am trying to avoid here :-/ I might look more closely at what s-l F r remove folder does, but that would be a manual step each time.
    – Harald
    Commented Mar 11 at 8:30
  • Yeah, okay, it's just that for me opening a .java file does not trigger lsp-mode, so no servers is being started. In general, for me lsp-mode only starts automatically when there's a .dir-locals.el file at the top dir of the project that explicitly runs (lsp). So I presume you have some local settings that trigger lsp-mode upon opening the file. By any chance, do you use Doom Emacs? They provide a lot of pre-configured things, so it might just be part of their customization.
    – Hi-Angel
    Commented Mar 11 at 9:21

1 Answer 1


This is what the OP wants:

the modeline as well as the error buffer called up with s-l g e show errors of all projects I ever attached to the language server. Is it possible to avoid this?

This is what I found: https://github.com/emacs-lsp/lsp-mode/discussions/3095 . It says:

Let say you have java projects A/B. Typically, when you open a file from one of them, both of them will be sent to the server (this is how multi-root works).

(My emphasis.) So the behavior is intended and it does not seem to be customizable :-)

Anyway the above link is a good read as a background for what "workspace" and "session" mean for lsp-mode.

  • Unless I am missing something, this doesn't seem to answer OP's question. OP wants to have separate Emacs processes handle separate projects. So the expected answer would come down to "don't enable lsp-mode upon opening a .java file if Emacs already has java lsp server running for another project, which this file does not belong to". The problem you referred to simply does not exist in that workflow, because for a newly opened file to be sent to a running lsp-server, lsp-mode needs to be enabled in the buffer. If it wasn't enabled in the buffer, then it's never sent to the running server
    – Hi-Angel
    Commented Mar 11 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.