diff options
Diffstat (limited to 'cli/lsp/tsc.rs')
-rw-r--r-- | cli/lsp/tsc.rs | 107 |
1 files changed, 78 insertions, 29 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 67d6afcc5..b545a796b 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -413,6 +413,66 @@ impl QuickInfo { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] +pub struct DocumentSpan { + text_span: TextSpan, + pub file_name: String, + original_text_span: Option<TextSpan>, + original_file_name: Option<String>, + context_span: Option<TextSpan>, + original_context_span: Option<TextSpan>, +} + +impl DocumentSpan { + pub async fn to_link<F, Fut>( + &self, + line_index: &[u32], + index_provider: F, + ) -> Option<lsp_types::LocationLink> + where + F: Fn(ModuleSpecifier) -> Fut, + Fut: Future<Output = Result<Vec<u32>, AnyError>>, + { + let target_specifier = + ModuleSpecifier::resolve_url(&self.file_name).unwrap(); + if let Ok(target_line_index) = index_provider(target_specifier).await { + let target_uri = utils::normalize_file_name(&self.file_name).unwrap(); + let (target_range, target_selection_range) = + if let Some(context_span) = &self.context_span { + ( + context_span.to_range(&target_line_index), + self.text_span.to_range(&target_line_index), + ) + } else { + ( + self.text_span.to_range(&target_line_index), + self.text_span.to_range(&target_line_index), + ) + }; + let link = lsp_types::LocationLink { + origin_selection_range: Some(self.text_span.to_range(line_index)), + target_uri, + target_range, + target_selection_range, + }; + Some(link) + } else { + None + } + } +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ImplementationLocation { + #[serde(flatten)] + pub document_span: DocumentSpan, + // ImplementationLocation props + kind: ScriptElementKind, + display_parts: Vec<SymbolDisplayPart>, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct RenameLocation { // inherit from DocumentSpan text_span: TextSpan, @@ -520,12 +580,9 @@ pub struct DefinitionInfo { name: String, container_kind: Option<ScriptElementKind>, container_name: Option<String>, - text_span: TextSpan, - pub file_name: String, - original_text_span: Option<TextSpan>, - original_file_name: Option<String>, - context_span: Option<TextSpan>, - original_context_span: Option<TextSpan>, + + #[serde(flatten)] + pub document_span: DocumentSpan, } #[derive(Debug, Deserialize)] @@ -542,34 +599,18 @@ impl DefinitionInfoAndBoundSpan { index_provider: F, ) -> Option<lsp_types::GotoDefinitionResponse> where - F: Fn(ModuleSpecifier) -> Fut, + F: Fn(ModuleSpecifier) -> Fut + Clone, Fut: Future<Output = Result<Vec<u32>, AnyError>>, { if let Some(definitions) = &self.definitions { let mut location_links = Vec::<lsp_types::LocationLink>::new(); for di in definitions { - let target_specifier = - ModuleSpecifier::resolve_url(&di.file_name).unwrap(); - if let Ok(target_line_index) = index_provider(target_specifier).await { - let target_uri = utils::normalize_file_name(&di.file_name).unwrap(); - let (target_range, target_selection_range) = - if let Some(context_span) = &di.context_span { - ( - context_span.to_range(&target_line_index), - di.text_span.to_range(&target_line_index), - ) - } else { - ( - di.text_span.to_range(&target_line_index), - di.text_span.to_range(&target_line_index), - ) - }; - location_links.push(lsp_types::LocationLink { - origin_selection_range: Some(self.text_span.to_range(line_index)), - target_uri, - target_range, - target_selection_range, - }); + if let Some(link) = di + .document_span + .to_link(line_index, index_provider.clone()) + .await + { + location_links.push(link); } } Some(lsp_types::GotoDefinitionResponse::Link(location_links)) @@ -1135,6 +1176,8 @@ pub enum RequestMethod { GetDefinition((ModuleSpecifier, u32)), /// Get completion information at a given position (IntelliSense). GetCompletions((ModuleSpecifier, u32, UserPreferences)), + /// Get implementation information for a specific position. + GetImplementation((ModuleSpecifier, u32)), /// Get rename locations at a given position. FindRenameLocations((ModuleSpecifier, u32, bool, bool, bool)), } @@ -1195,6 +1238,12 @@ impl RequestMethod { "preferences": preferences, }) } + RequestMethod::GetImplementation((specifier, position)) => json!({ + "id": id, + "method": "getImplementation", + "specifier": specifier, + "position": position, + }), RequestMethod::FindRenameLocations(( specifier, position, |