1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix(lsp): document spans use original range (#9525)

Fixes: #9444

Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
This commit is contained in:
Kitson Kelly 2021-02-18 14:15:13 +11:00 committed by GitHub
parent c7dabc99ee
commit 78e34d4912
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 16 deletions

View file

@ -1575,29 +1575,26 @@ impl Inner {
LspError::invalid_request()
})?;
let maybe_implementations = serde_json::from_value::<Option<Vec<tsc::ImplementationLocation>>>(res)
let maybe_implementations: Option<Vec<tsc::ImplementationLocation>> = serde_json::from_value(res)
.map_err(|err| {
error!("Failed to deserialized tsserver response to Vec<ImplementationLocation> {}", err);
LspError::internal_error()
})?;
if let Some(implementations) = maybe_implementations {
let mut results = Vec::new();
for impl_ in implementations {
let document_span = impl_.document_span;
let impl_specifier = resolve_url(&document_span.file_name).unwrap();
let impl_line_index =
&self.get_line_index(impl_specifier).await.unwrap();
if let Some(link) = document_span.to_link(impl_line_index, self).await {
results.push(link);
let result = if let Some(implementations) = maybe_implementations {
let mut links = Vec::new();
for implementation in implementations {
if let Some(link) = implementation.to_link(&line_index, self).await {
links.push(link)
}
}
self.performance.measure(mark);
Ok(Some(GotoDefinitionResponse::Link(results)))
Some(GotoDefinitionResponse::Link(links))
} else {
self.performance.measure(mark);
Ok(None)
}
None
};
self.performance.measure(mark);
Ok(result)
}
async fn rename(

View file

@ -496,8 +496,16 @@ impl DocumentSpan {
self.text_span.to_range(&target_line_index),
)
};
let origin_selection_range =
if let Some(original_context_span) = &self.original_context_span {
Some(original_context_span.to_range(line_index))
} else if let Some(original_text_span) = &self.original_text_span {
Some(original_text_span.to_range(line_index))
} else {
None
};
let link = lsp::LocationLink {
origin_selection_range: Some(self.text_span.to_range(line_index)),
origin_selection_range,
target_uri,
target_range,
target_selection_range,
@ -589,6 +597,17 @@ impl ImplementationLocation {
range: self.document_span.text_span.to_range(line_index),
}
}
pub(crate) async fn to_link(
&self,
line_index: &LineIndex,
language_server: &mut language_server::Inner,
) -> Option<lsp::LocationLink> {
self
.document_span
.to_link(line_index, language_server)
.await
}
}
#[derive(Debug, Deserialize)]