mirror of https://github.com/astral-sh/ruff
[ty] Rename `ReferenceRequestHandler` file (#21680)
This commit is contained in:
parent
8bcfc198b8
commit
566c959add
|
|
@ -7,7 +7,7 @@ use ty_python_semantic::SemanticModel;
|
||||||
|
|
||||||
/// Find all references to a symbol at the given position.
|
/// Find all references to a symbol at the given position.
|
||||||
/// Search for references across all files in the project.
|
/// Search for references across all files in the project.
|
||||||
pub fn goto_references(
|
pub fn find_references(
|
||||||
db: &dyn Db,
|
db: &dyn Db,
|
||||||
file: File,
|
file: File,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
|
|
@ -41,7 +41,7 @@ mod tests {
|
||||||
impl CursorTest {
|
impl CursorTest {
|
||||||
fn references(&self) -> String {
|
fn references(&self) -> String {
|
||||||
let Some(mut reference_results) =
|
let Some(mut reference_results) =
|
||||||
goto_references(&self.db, self.cursor.file, self.cursor.offset, true)
|
find_references(&self.db, self.cursor.file, self.cursor.offset, true)
|
||||||
else {
|
else {
|
||||||
return "No references found".to_string();
|
return "No references found".to_string();
|
||||||
};
|
};
|
||||||
|
|
@ -84,7 +84,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parameter_references_in_function() {
|
fn parameter_references_in_function() {
|
||||||
let test = cursor_test(
|
let test = cursor_test(
|
||||||
"
|
"
|
||||||
def calculate_sum(<CURSOR>value: int) -> int:
|
def calculate_sum(<CURSOR>value: int) -> int:
|
||||||
|
|
@ -149,7 +149,7 @@ result = calculate_sum(value=42)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nonlocal_variable_references() {
|
fn nonlocal_variable_references() {
|
||||||
let test = cursor_test(
|
let test = cursor_test(
|
||||||
"
|
"
|
||||||
def outer_function():
|
def outer_function():
|
||||||
|
|
@ -272,7 +272,7 @@ def outer_function():
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_global_variable_references() {
|
fn global_variable_references() {
|
||||||
let test = cursor_test(
|
let test = cursor_test(
|
||||||
"
|
"
|
||||||
glo<CURSOR>bal_counter = 0
|
glo<CURSOR>bal_counter = 0
|
||||||
|
|
@ -389,7 +389,7 @@ final_value = global_counter
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_except_handler_variable_references() {
|
fn except_handler_variable_references() {
|
||||||
let test = cursor_test(
|
let test = cursor_test(
|
||||||
"
|
"
|
||||||
try:
|
try:
|
||||||
|
|
@ -450,7 +450,7 @@ except ValueError as err:
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pattern_match_as_references() {
|
fn pattern_match_as_references() {
|
||||||
let test = cursor_test(
|
let test = cursor_test(
|
||||||
"
|
"
|
||||||
match x:
|
match x:
|
||||||
|
|
@ -498,7 +498,7 @@ match x:
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pattern_match_mapping_rest_references() {
|
fn pattern_match_mapping_rest_references() {
|
||||||
let test = cursor_test(
|
let test = cursor_test(
|
||||||
"
|
"
|
||||||
match data:
|
match data:
|
||||||
|
|
@ -553,7 +553,7 @@ match data:
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_function_definition_references() {
|
fn function_definition_references() {
|
||||||
let test = cursor_test(
|
let test = cursor_test(
|
||||||
"
|
"
|
||||||
def my_func<CURSOR>tion():
|
def my_func<CURSOR>tion():
|
||||||
|
|
@ -632,7 +632,7 @@ value = my_function
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_class_definition_references() {
|
fn class_definition_references() {
|
||||||
let test = cursor_test(
|
let test = cursor_test(
|
||||||
"
|
"
|
||||||
class My<CURSOR>Class:
|
class My<CURSOR>Class:
|
||||||
|
|
@ -1445,7 +1445,7 @@ cls = MyClass
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_multi_file_function_references() {
|
fn multi_file_function_references() {
|
||||||
let test = CursorTest::builder()
|
let test = CursorTest::builder()
|
||||||
.source(
|
.source(
|
||||||
"utils.py",
|
"utils.py",
|
||||||
|
|
@ -1535,7 +1535,7 @@ class DataProcessor:
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_multi_file_class_attribute_references() {
|
fn multi_file_class_attribute_references() {
|
||||||
let test = CursorTest::builder()
|
let test = CursorTest::builder()
|
||||||
.source(
|
.source(
|
||||||
"models.py",
|
"models.py",
|
||||||
|
|
@ -1613,7 +1613,7 @@ def process_model():
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_import_alias_references_should_not_resolve_to_original() {
|
fn import_alias_references_should_not_resolve_to_original() {
|
||||||
let test = CursorTest::builder()
|
let test = CursorTest::builder()
|
||||||
.source(
|
.source(
|
||||||
"original.py",
|
"original.py",
|
||||||
|
|
@ -9,10 +9,10 @@ mod doc_highlights;
|
||||||
mod docstring;
|
mod docstring;
|
||||||
mod document_symbols;
|
mod document_symbols;
|
||||||
mod find_node;
|
mod find_node;
|
||||||
|
mod find_references;
|
||||||
mod goto;
|
mod goto;
|
||||||
mod goto_declaration;
|
mod goto_declaration;
|
||||||
mod goto_definition;
|
mod goto_definition;
|
||||||
mod goto_references;
|
|
||||||
mod goto_type_definition;
|
mod goto_type_definition;
|
||||||
mod hover;
|
mod hover;
|
||||||
mod importer;
|
mod importer;
|
||||||
|
|
@ -32,8 +32,8 @@ pub use code_action::{QuickFix, code_actions};
|
||||||
pub use completion::{Completion, CompletionKind, CompletionSettings, completion};
|
pub use completion::{Completion, CompletionKind, CompletionSettings, completion};
|
||||||
pub use doc_highlights::document_highlights;
|
pub use doc_highlights::document_highlights;
|
||||||
pub use document_symbols::document_symbols;
|
pub use document_symbols::document_symbols;
|
||||||
|
pub use find_references::find_references;
|
||||||
pub use goto::{goto_declaration, goto_definition, goto_type_definition};
|
pub use goto::{goto_declaration, goto_definition, goto_type_definition};
|
||||||
pub use goto_references::goto_references;
|
|
||||||
pub use hover::hover;
|
pub use hover::hover;
|
||||||
pub use inlay_hints::{
|
pub use inlay_hints::{
|
||||||
InlayHintKind, InlayHintLabel, InlayHintSettings, InlayHintTextEdit, inlay_hints,
|
InlayHintKind, InlayHintLabel, InlayHintSettings, InlayHintTextEdit, inlay_hints,
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ mod document_symbols;
|
||||||
mod execute_command;
|
mod execute_command;
|
||||||
mod goto_declaration;
|
mod goto_declaration;
|
||||||
mod goto_definition;
|
mod goto_definition;
|
||||||
mod goto_references;
|
|
||||||
mod goto_type_definition;
|
mod goto_type_definition;
|
||||||
mod hover;
|
mod hover;
|
||||||
mod inlay_hints;
|
mod inlay_hints;
|
||||||
mod prepare_rename;
|
mod prepare_rename;
|
||||||
|
mod references;
|
||||||
mod rename;
|
mod rename;
|
||||||
mod selection_range;
|
mod selection_range;
|
||||||
mod semantic_tokens;
|
mod semantic_tokens;
|
||||||
|
|
@ -28,11 +28,11 @@ pub(super) use document_symbols::DocumentSymbolRequestHandler;
|
||||||
pub(super) use execute_command::ExecuteCommand;
|
pub(super) use execute_command::ExecuteCommand;
|
||||||
pub(super) use goto_declaration::GotoDeclarationRequestHandler;
|
pub(super) use goto_declaration::GotoDeclarationRequestHandler;
|
||||||
pub(super) use goto_definition::GotoDefinitionRequestHandler;
|
pub(super) use goto_definition::GotoDefinitionRequestHandler;
|
||||||
pub(super) use goto_references::ReferencesRequestHandler;
|
|
||||||
pub(super) use goto_type_definition::GotoTypeDefinitionRequestHandler;
|
pub(super) use goto_type_definition::GotoTypeDefinitionRequestHandler;
|
||||||
pub(super) use hover::HoverRequestHandler;
|
pub(super) use hover::HoverRequestHandler;
|
||||||
pub(super) use inlay_hints::InlayHintRequestHandler;
|
pub(super) use inlay_hints::InlayHintRequestHandler;
|
||||||
pub(super) use prepare_rename::PrepareRenameRequestHandler;
|
pub(super) use prepare_rename::PrepareRenameRequestHandler;
|
||||||
|
pub(super) use references::ReferencesRequestHandler;
|
||||||
pub(super) use rename::RenameRequestHandler;
|
pub(super) use rename::RenameRequestHandler;
|
||||||
pub(super) use selection_range::SelectionRangeRequestHandler;
|
pub(super) use selection_range::SelectionRangeRequestHandler;
|
||||||
pub(super) use semantic_tokens::SemanticTokensRequestHandler;
|
pub(super) use semantic_tokens::SemanticTokensRequestHandler;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use std::borrow::Cow;
|
||||||
|
|
||||||
use lsp_types::request::References;
|
use lsp_types::request::References;
|
||||||
use lsp_types::{Location, ReferenceParams, Url};
|
use lsp_types::{Location, ReferenceParams, Url};
|
||||||
use ty_ide::goto_references;
|
use ty_ide::find_references;
|
||||||
use ty_project::ProjectDatabase;
|
use ty_project::ProjectDatabase;
|
||||||
|
|
||||||
use crate::document::{PositionExt, ToLink};
|
use crate::document::{PositionExt, ToLink};
|
||||||
|
|
@ -51,7 +51,7 @@ impl BackgroundDocumentRequestHandler for ReferencesRequestHandler {
|
||||||
|
|
||||||
let include_declaration = params.context.include_declaration;
|
let include_declaration = params.context.include_declaration;
|
||||||
|
|
||||||
let Some(references_result) = goto_references(db, file, offset, include_declaration) else {
|
let Some(references_result) = find_references(db, file, offset, include_declaration) else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -17,8 +17,8 @@ use ruff_python_formatter::formatted_file;
|
||||||
use ruff_source_file::{LineIndex, OneIndexed, SourceLocation};
|
use ruff_source_file::{LineIndex, OneIndexed, SourceLocation};
|
||||||
use ruff_text_size::{Ranged, TextSize};
|
use ruff_text_size::{Ranged, TextSize};
|
||||||
use ty_ide::{
|
use ty_ide::{
|
||||||
InlayHintSettings, MarkupKind, RangedValue, document_highlights, goto_declaration,
|
InlayHintSettings, MarkupKind, RangedValue, document_highlights, find_references,
|
||||||
goto_definition, goto_references, goto_type_definition, hover, inlay_hints,
|
goto_declaration, goto_definition, goto_type_definition, hover, inlay_hints,
|
||||||
};
|
};
|
||||||
use ty_ide::{NavigationTarget, NavigationTargets, signature_help};
|
use ty_ide::{NavigationTarget, NavigationTargets, signature_help};
|
||||||
use ty_project::metadata::options::Options;
|
use ty_project::metadata::options::Options;
|
||||||
|
|
@ -351,7 +351,7 @@ impl Workspace {
|
||||||
|
|
||||||
let offset = position.to_text_size(&source, &index, self.position_encoding)?;
|
let offset = position.to_text_size(&source, &index, self.position_encoding)?;
|
||||||
|
|
||||||
let Some(targets) = goto_references(&self.db, file_id.file, offset, true) else {
|
let Some(targets) = find_references(&self.db, file_id.file, offset, true) else {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue