diff options
Diffstat (limited to 'cli/lsp/tsc.rs')
-rw-r--r-- | cli/lsp/tsc.rs | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 316436988..e846cc496 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -149,7 +149,28 @@ impl TsServer { if self.0.send((req, snapshot, tx, token)).is_err() { return Err(anyhow!("failed to send request to tsc thread")); } - rx.await?.map(|v| serde_json::from_value::<R>(v).unwrap()) + let value = rx.await??; + Ok(serde_json::from_value::<R>(value)?) + } + + // todo(dsherret): refactor the rest of the request methods to have + // methods to call on this struct, then make `RequestMethod` and + // friends internal + + pub async fn find_references( + &self, + snapshot: Arc<StateSnapshot>, + specifier: &ModuleSpecifier, + position: u32, + ) -> Result<Option<Vec<ReferencedSymbol>>, LspError> { + let req = RequestMethod::FindReferences { + specifier: specifier.clone(), + position, + }; + self.request(snapshot, req).await.map_err(|err| { + log::error!("Unable to get references from TypeScript: {}", err); + LspError::internal_error() + }) } } @@ -1688,10 +1709,31 @@ pub struct CombinedCodeActions { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct ReferenceEntry { - // is_write_access: bool, +pub struct ReferencedSymbol { + pub definition: ReferencedSymbolDefinitionInfo, + pub references: Vec<ReferencedSymbolEntry>, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ReferencedSymbolDefinitionInfo { + #[serde(flatten)] + pub definition_info: DefinitionInfo, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ReferencedSymbolEntry { #[serde(default)] pub is_definition: bool, + #[serde(flatten)] + pub entry: ReferenceEntry, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ReferenceEntry { + // is_write_access: bool, // is_in_string: Option<bool>, #[serde(flatten)] pub document_span: DocumentSpan, @@ -3178,8 +3220,11 @@ pub enum RequestMethod { GetOutliningSpans(ModuleSpecifier), /// Return quick info at position (hover information). GetQuickInfo((ModuleSpecifier, u32)), - /// Get document references for a specific position. - GetReferences((ModuleSpecifier, u32)), + /// Finds the document references for a specific position. + FindReferences { + specifier: ModuleSpecifier, + position: u32, + }, /// Get signature help items for a specific position. GetSignatureHelpItems((ModuleSpecifier, u32, SignatureHelpItemsOptions)), /// Get a selection range for a specific position. @@ -3349,9 +3394,12 @@ impl RequestMethod { "specifier": state.denormalize_specifier(specifier), "position": position, }), - RequestMethod::GetReferences((specifier, position)) => json!({ + RequestMethod::FindReferences { + specifier, + position, + } => json!({ "id": id, - "method": "getReferences", + "method": "findReferences", "specifier": state.denormalize_specifier(specifier), "position": position, }), |