Update default implementation of LspAdapter::check_if_user_installed(...)
with generic functionality that can be overridden if needed
#10397
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.
The previous default implementation for the trait method was a no-op (it always returned
None
), but the concrete implementations for the few languages that supported it were more or less copy/paste boilerplate.To avoid a circular dependency between the
language
andproject
crates, this PR introduces theLspBinaryConfigProvider
trait that allows for a DI-like approach to getting the user's LSP override configs out of the LSP Adapter Delegate.Through this approach, we can make the default implementation of the trait method apply to all LSP Adapters by using the
LspAdapter::name(...)
method to provide the key in to the config map.LSP Adapter implementations still have the ability to implement the trait method explicitly in the event that the generalized logic is not sufficient for detecting and bootstrapping the LSP binary. An example could be cases where the
PATH
fallback still needs specific CLI flags/options, as the default logic passes no arguments. Thegopls
adapter is one such case where the concrete implementation is more-or-less the same but needs flags for the CLI.The small number of existing explicit implementations have not been changed. This should make it easier to use local installs of LSPs for users with constrained connectivity without needing to wait for all of the various language adapters already in place to support overrides explicitly.
I think in practice the primary entry point here is going to be using the config file overrides; I feel like the automagic
PATH
overrides could lead to a lot of unexpected behavior for users, especially when CLI args are involved, and so it might be prudent to have the generalized version only provide an override from the config file. Adapter implementations can then choose to implement thePATH
fallback logic if they want. Another option would be adding another trait method toLspAdapter
such asdefault_args()
akin toname()
that would be used with thePATH
fallback.Probably worth discussing, and I can revise the PR easily.
Related Issues:
$PATH
#4978Release Notes:
LspAdapter::check_if_user_installed(...)
to enable detecting local LSP binaries for all LspAdapter implementations