Avoid sending unhandled LSP requests to JSON language server

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-03-03 13:39:40 -08:00
parent 0582c557e3
commit 81627a0f14
2 changed files with 32 additions and 1 deletions

View file

@ -1322,6 +1322,7 @@ impl Project {
cx: &mut ModelContext<Self>,
) -> Task<Result<Vec<DocumentHighlight>>> {
let position = position.to_point_utf16(buffer.read(cx));
self.request_lsp(buffer.clone(), GetDocumentHighlights { position }, cx)
}
@ -1724,6 +1725,17 @@ impl Project {
return Task::ready(Ok(Default::default()));
}
if !lang_server
.capabilities()
.borrow()
.as_ref()
.map_or(false, |capabilities| {
capabilities.code_action_provider.is_some()
})
{
return Task::ready(Ok(Default::default()));
}
let lsp_range = lsp::Range::new(
range.start.to_point_utf16(buffer).to_lsp_position(),
range.end.to_point_utf16(buffer).to_lsp_position(),
@ -2251,6 +2263,17 @@ impl Project {
if let Some((file, language_server)) = file.zip(buffer.language_server().cloned()) {
let lsp_params = request.to_lsp(&file.abs_path(cx), cx);
return cx.spawn(|this, cx| async move {
if !language_server
.capabilities()
.borrow()
.as_ref()
.map_or(false, |capabilities| {
request.check_capabilities(capabilities)
})
{
return Ok(Default::default());
}
let response = language_server
.request::<R::LspRequest>(lsp_params)
.await