-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
avoid overloading ls with completion resolve requests #10539
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ use crate::{ | |
file_operations::FileOperationsInterest, | ||
find_lsp_workspace, jsonrpc, | ||
transport::{Payload, Transport}, | ||
Call, Error, OffsetEncoding, Result, | ||
Call, Error, LanguageServerId, OffsetEncoding, Result, | ||
}; | ||
|
||
use helix_core::{find_workspace, syntax::LanguageServerFeature, ChangeSet, Rope}; | ||
|
@@ -46,7 +46,7 @@ fn workspace_for_uri(uri: lsp::Url) -> WorkspaceFolder { | |
|
||
#[derive(Debug)] | ||
pub struct Client { | ||
id: usize, | ||
id: LanguageServerId, | ||
name: String, | ||
_process: Child, | ||
server_tx: UnboundedSender<Payload>, | ||
|
@@ -179,10 +179,14 @@ impl Client { | |
server_environment: HashMap<String, String>, | ||
root_path: PathBuf, | ||
root_uri: Option<lsp::Url>, | ||
id: usize, | ||
id: LanguageServerId, | ||
name: String, | ||
req_timeout: u64, | ||
) -> Result<(Self, UnboundedReceiver<(usize, Call)>, Arc<Notify>)> { | ||
) -> Result<( | ||
Self, | ||
UnboundedReceiver<(LanguageServerId, Call)>, | ||
Arc<Notify>, | ||
)> { | ||
// Resolve path to the binary | ||
let cmd = helix_stdx::env::which(cmd)?; | ||
|
||
|
@@ -234,7 +238,7 @@ impl Client { | |
&self.name | ||
} | ||
|
||
pub fn id(&self) -> usize { | ||
pub fn id(&self) -> LanguageServerId { | ||
self.id | ||
} | ||
|
||
|
@@ -393,6 +397,16 @@ impl Client { | |
&self, | ||
params: R::Params, | ||
) -> impl Future<Output = Result<Value>> | ||
where | ||
R::Params: serde::Serialize, | ||
{ | ||
self.call_with_ref::<R>(¶ms) | ||
} | ||
|
||
fn call_with_ref<R: lsp::request::Request>( | ||
&self, | ||
params: &R::Params, | ||
) -> impl Future<Output = Result<Value>> | ||
where | ||
R::Params: serde::Serialize, | ||
{ | ||
|
@@ -401,7 +415,7 @@ impl Client { | |
|
||
fn call_with_timeout<R: lsp::request::Request>( | ||
&self, | ||
params: R::Params, | ||
params: &R::Params, | ||
timeout_secs: u64, | ||
) -> impl Future<Output = Result<Value>> | ||
where | ||
|
@@ -410,17 +424,16 @@ impl Client { | |
let server_tx = self.server_tx.clone(); | ||
let id = self.next_request_id(); | ||
|
||
let params = serde_json::to_value(params); | ||
async move { | ||
use std::time::Duration; | ||
use tokio::time::timeout; | ||
|
||
let params = serde_json::to_value(params)?; | ||
|
||
let request = jsonrpc::MethodCall { | ||
jsonrpc: Some(jsonrpc::Version::V2), | ||
id: id.clone(), | ||
method: R::METHOD.to_string(), | ||
params: Self::value_into_params(params), | ||
params: Self::value_into_params(params?), | ||
}; | ||
|
||
let (tx, mut rx) = channel::<Result<Value>>(1); | ||
|
@@ -737,7 +750,7 @@ impl Client { | |
new_uri: url_from_path(new_path)?, | ||
}]; | ||
let request = self.call_with_timeout::<lsp::request::WillRenameFiles>( | ||
lsp::RenameFilesParams { files }, | ||
&lsp::RenameFilesParams { files }, | ||
5, | ||
); | ||
|
||
|
@@ -1022,21 +1035,10 @@ impl Client { | |
|
||
pub fn resolve_completion_item( | ||
&self, | ||
completion_item: lsp::CompletionItem, | ||
) -> Option<impl Future<Output = Result<lsp::CompletionItem>>> { | ||
let capabilities = self.capabilities.get().unwrap(); | ||
|
||
// Return early if the server does not support resolving completion items. | ||
match capabilities.completion_provider { | ||
Some(lsp::CompletionOptions { | ||
resolve_provider: Some(true), | ||
.. | ||
}) => (), | ||
_ => return None, | ||
} | ||
|
||
let res = self.call::<lsp::request::ResolveCompletionItem>(completion_item); | ||
Some(async move { Ok(serde_json::from_value(res.await?)?) }) | ||
completion_item: &lsp::CompletionItem, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah nice, I remember thinking there was an unnecessary clone in completion resolving because of the type here lacking a ref 👍 |
||
) -> impl Future<Output = Result<lsp::CompletionItem>> { | ||
let res = self.call_with_ref::<lsp::request::ResolveCompletionItem>(completion_item); | ||
async move { Ok(serde_json::from_value(res.await?)?) } | ||
} | ||
|
||
pub fn resolve_code_action( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this will be useful when introducing spell checking diagnostics