Add validation in LspCommand::to_lsp + check for inverted ranges (#22731)

#22690 logged errors and flipped the range in this case. Instead it
brings more visibility to the issue to return errors.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-01-06 15:00:36 -07:00 committed by GitHub
parent 1c223d8940
commit 141393232e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 134 additions and 162 deletions

View file

@ -1,4 +1,4 @@
use crate::{lsp_command::LspCommand, lsp_store::LspStore};
use crate::{lsp_command::LspCommand, lsp_store::LspStore, make_text_document_identifier};
use anyhow::{Context, Result};
use async_trait::async_trait;
use gpui::{AppContext, AsyncAppContext, Model};
@ -53,13 +53,11 @@ impl LspCommand for ExpandMacro {
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
) -> ExpandMacroParams {
ExpandMacroParams {
text_document: lsp::TextDocumentIdentifier {
uri: lsp::Url::from_file_path(path).unwrap(),
},
) -> Result<ExpandMacroParams> {
Ok(ExpandMacroParams {
text_document: make_text_document_identifier(path)?,
position: point_to_lsp(self.position),
}
})
}
async fn response_from_lsp(
@ -179,13 +177,13 @@ impl LspCommand for OpenDocs {
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
) -> OpenDocsParams {
OpenDocsParams {
) -> Result<OpenDocsParams> {
Ok(OpenDocsParams {
text_document: lsp::TextDocumentIdentifier {
uri: lsp::Url::from_file_path(path).unwrap(),
},
position: point_to_lsp(self.position),
}
})
}
async fn response_from_lsp(
@ -292,10 +290,10 @@ impl LspCommand for SwitchSourceHeader {
_: &Buffer,
_: &Arc<LanguageServer>,
_: &AppContext,
) -> SwitchSourceHeaderParams {
SwitchSourceHeaderParams(lsp::TextDocumentIdentifier {
uri: lsp::Url::from_file_path(path).unwrap(),
})
) -> Result<SwitchSourceHeaderParams> {
Ok(SwitchSourceHeaderParams(make_text_document_identifier(
path,
)?))
}
async fn response_from_lsp(