summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/lsp/language_server.rs27
-rw-r--r--cli/lsp/tsc.rs21
2 files changed, 32 insertions, 16 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 8de90607f..7c196d67e 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -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(
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 9a8dc7b21..8fc429d9d 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -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)]