Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Do not try to guess a root if lsp--suggest-project-root failed #3973

Merged
merged 3 commits into from
Apr 23, 2023

Conversation

ia0
Copy link
Contributor

@ia0 ia0 commented Feb 25, 2023

Currently, when lsp-auto-guess-root is set and lsp--suggest-project-root fails to find a project root (which actually never happens because of #3972), we fall back to lsp-find-session-folder.

This PR introduces lsp-guess-root-without-session to not fall back to lsp-find-session-folder and make lsp--suggest-project-root authoritative, thus giving full control to the user. Note that it rarely makes sense to set lsp-guess-root-without-session without setting lsp-auto-guess-root.

Alternatives considered:

  • Change the behavior of lsp-auto-guess-root to always make it authoritative (previous version of this PR). This is a breaking change.
  • Add a value to lsp-auto-guess-root, in addition to the existing nil and t (which semantics remain unchanged), to make lsp--suggest-project-root authoritative. Not clear what the value should be, and it could be considered a breaking change since lsp-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:

foo/conf.y
foo/main.x
foo/bar/conf.y
foo/bar/lib.x

The projects of this working tree are:

  • foo@x (directory foo and language x) contains foo/main.x
  • foo/bar@x (directory foo/bar and language x) contains foo/bar/lib.x
  • foo@y (directory foo and language y) contains foo/conf.y and foo/bar/conf.y

We can see here both the notion of nested projects (foo@x and foo/bar@x, see also #533) and overlapping projects (between language x and y).

With an empty session file and project/projectile not yet configured for language y, we can exhibit an inconsistency with the following operations:

  • Open 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).
  • Close the file.
  • Open foo/bar/lib.x. We find a root with project/projectile (because it's configured for language x) and use it, namely foo/bar. The file is correctly connected to an LSP server.
  • Close the file.
  • Open foo/bar/conf.y again. We fail again to find a project root using project/projectile. However, now the session file thinks that foo/bar is a valid root and will use it. The file will connect to an LSP server with the wrong root.

…failed

Currently, when `lsp-auto-guess-root` is set and `lsp--suggest-project-root`
fails to find a project root, we fall back to `lsp-find-session-folder`.

This PR makes `lsp--suggest-project-root` authoritative when
`lsp-auto-guess-root` is set, thus giving full control to the user.
@yyoncho yyoncho merged commit 99b812e into emacs-lsp:master Apr 23, 2023
@ia0 ia0 deleted the auto_guess branch April 24, 2023 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants