[Suggestion] Do not try to guess a root if lsp--suggest-project-root failed #3973
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, when
lsp-auto-guess-root
is set andlsp--suggest-project-root
fails to find a project root (which actually never happens because of #3972), we fall back tolsp-find-session-folder
.This PR introduces
lsp-guess-root-without-session
to not fall back tolsp-find-session-folder
and makelsp--suggest-project-root
authoritative, thus giving full control to the user. Note that it rarely makes sense to setlsp-guess-root-without-session
without settinglsp-auto-guess-root
.Alternatives considered:
lsp-auto-guess-root
to always make it authoritative (previous version of this PR). This is a breaking change.lsp-auto-guess-root
, in addition to the existingnil
andt
(which semantics remain unchanged), to makelsp--suggest-project-root
authoritative. Not clear what the value should be, and it could be considered a breaking change sincelsp-auto-guess-root
is documented as a boolean.To motivate why the user may want full control on the definition of a project root, let's consider the following working tree:
The projects of this working tree are:
foo@x
(directoryfoo
and languagex
) containsfoo/main.x
foo/bar@x
(directoryfoo/bar
and languagex
) containsfoo/bar/lib.x
foo@y
(directoryfoo
and languagey
) containsfoo/conf.y
andfoo/bar/conf.y
We can see here both the notion of nested projects (
foo@x
andfoo/bar@x
, see also #533) and overlapping projects (between languagex
andy
).With an empty session file and project/projectile not yet configured for language
y
, we can exhibit an inconsistency with the following operations:foo/bar/conf.y
and fail to find a project root with project/projectile. Falling back to the session file also fails. The file is correctly not connected to an LSP server (because project/projectile is not yet configured).foo/bar/lib.x
. We find a root with project/projectile (because it's configured for languagex
) and use it, namelyfoo/bar
. The file is correctly connected to an LSP server.foo/bar/conf.y
again. We fail again to find a project root using project/projectile. However, now the session file thinks thatfoo/bar
is a valid root and will use it. The file will connect to an LSP server with the wrong root.