mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Implement Find All References for local variables
This commit is contained in:
parent
2a704035f4
commit
3746689e9d
8 changed files with 96 additions and 3 deletions
|
@ -27,7 +27,7 @@ pub fn server_capabilities() -> ServerCapabilities {
|
|||
definition_provider: Some(true),
|
||||
type_definition_provider: None,
|
||||
implementation_provider: None,
|
||||
references_provider: None,
|
||||
references_provider: Some(true),
|
||||
document_highlight_provider: None,
|
||||
document_symbol_provider: Some(true),
|
||||
workspace_symbol_provider: Some(true),
|
||||
|
|
|
@ -460,6 +460,22 @@ pub fn handle_signature_help(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn handle_references(
|
||||
world: ServerWorld,
|
||||
params: req::ReferenceParams,
|
||||
token: JobToken,
|
||||
) -> Result<Option<Vec<Location>>> {
|
||||
let file_id = params.text_document.try_conv_with(&world)?;
|
||||
let line_index = world.analysis().file_line_index(file_id);
|
||||
let offset = params.position.conv_with(&line_index);
|
||||
|
||||
let refs = world.analysis().find_all_refs(file_id, offset, &token);
|
||||
|
||||
Ok(Some(refs.into_iter()
|
||||
.filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok())
|
||||
.collect()))
|
||||
}
|
||||
|
||||
pub fn handle_code_action(
|
||||
world: ServerWorld,
|
||||
params: req::CodeActionParams,
|
||||
|
|
|
@ -248,6 +248,7 @@ fn on_request(
|
|||
.on::<req::CodeActionRequest>(handlers::handle_code_action)?
|
||||
.on::<req::FoldingRangeRequest>(handlers::handle_folding_range)?
|
||||
.on::<req::SignatureHelpRequest>(handlers::handle_signature_help)?
|
||||
.on::<req::References>(handlers::handle_references)?
|
||||
.finish();
|
||||
match req {
|
||||
Ok((id, handle)) => {
|
||||
|
|
|
@ -7,7 +7,7 @@ pub use languageserver_types::{
|
|||
CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams,
|
||||
DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult,
|
||||
PublishDiagnosticsParams, SignatureHelp, TextDocumentEdit, TextDocumentPositionParams,
|
||||
TextEdit, WorkspaceSymbolParams,
|
||||
TextEdit, WorkspaceSymbolParams, ReferenceParams,
|
||||
};
|
||||
|
||||
pub enum SyntaxTree {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue