mirror of
https://github.com/denoland/deno.git
synced 2025-03-10 06:07:03 -04:00
fix(lsp): document spans use original range (#9525)
Fixes: #9444 Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
This commit is contained in:
parent
1917c8e582
commit
0217587fcd
2 changed files with 32 additions and 16 deletions
|
@ -1575,29 +1575,26 @@ impl Inner {
|
||||||
LspError::invalid_request()
|
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| {
|
.map_err(|err| {
|
||||||
error!("Failed to deserialized tsserver response to Vec<ImplementationLocation> {}", err);
|
error!("Failed to deserialized tsserver response to Vec<ImplementationLocation> {}", err);
|
||||||
LspError::internal_error()
|
LspError::internal_error()
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Some(implementations) = maybe_implementations {
|
let result = if let Some(implementations) = maybe_implementations {
|
||||||
let mut results = Vec::new();
|
let mut links = Vec::new();
|
||||||
for impl_ in implementations {
|
for implementation in implementations {
|
||||||
let document_span = impl_.document_span;
|
if let Some(link) = implementation.to_link(&line_index, self).await {
|
||||||
let impl_specifier = resolve_url(&document_span.file_name).unwrap();
|
links.push(link)
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.performance.measure(mark);
|
Some(GotoDefinitionResponse::Link(links))
|
||||||
Ok(Some(GotoDefinitionResponse::Link(results)))
|
|
||||||
} else {
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
self.performance.measure(mark);
|
self.performance.measure(mark);
|
||||||
Ok(None)
|
Ok(result)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn rename(
|
async fn rename(
|
||||||
|
|
|
@ -500,8 +500,16 @@ impl DocumentSpan {
|
||||||
self.text_span.to_range(&target_line_index),
|
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 {
|
let link = lsp::LocationLink {
|
||||||
origin_selection_range: Some(self.text_span.to_range(line_index)),
|
origin_selection_range,
|
||||||
target_uri,
|
target_uri,
|
||||||
target_range,
|
target_range,
|
||||||
target_selection_range,
|
target_selection_range,
|
||||||
|
@ -593,6 +601,17 @@ impl ImplementationLocation {
|
||||||
range: self.document_span.text_span.to_range(line_index),
|
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)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue