Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ty_python_semantic::SemanticModel;

/// Find all references to a symbol at the given position.
/// Search for references across all files in the project.
pub fn goto_references(
pub fn find_references(
db: &dyn Db,
file: File,
offset: TextSize,
Expand Down Expand Up @@ -41,7 +41,7 @@ mod tests {
impl CursorTest {
fn references(&self) -> String {
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 {
return "No references found".to_string();
};
Expand Down Expand Up @@ -84,7 +84,7 @@ mod tests {
}

#[test]
fn test_parameter_references_in_function() {
fn parameter_references_in_function() {
let test = cursor_test(
"
def calculate_sum(<CURSOR>value: int) -> int:
Expand Down Expand Up @@ -149,28 +149,28 @@ result = calculate_sum(value=42)
}

#[test]
fn test_nonlocal_variable_references() {
fn nonlocal_variable_references() {
let test = cursor_test(
"
def outer_function():
coun<CURSOR>ter = 0

def increment():
nonlocal counter
counter += 1
return counter

def decrement():
nonlocal counter
counter -= 1
return counter

# Use counter in outer scope
initial = counter
increment()
decrement()
final = counter

return increment, decrement
",
);
Expand Down Expand Up @@ -272,7 +272,7 @@ def outer_function():
}

#[test]
fn test_global_variable_references() {
fn global_variable_references() {
let test = cursor_test(
"
glo<CURSOR>bal_counter = 0
Expand Down Expand Up @@ -389,7 +389,7 @@ final_value = global_counter
}

#[test]
fn test_except_handler_variable_references() {
fn except_handler_variable_references() {
let test = cursor_test(
"
try:
Expand Down Expand Up @@ -450,7 +450,7 @@ except ValueError as err:
}

#[test]
fn test_pattern_match_as_references() {
fn pattern_match_as_references() {
let test = cursor_test(
"
match x:
Expand Down Expand Up @@ -498,7 +498,7 @@ match x:
}

#[test]
fn test_pattern_match_mapping_rest_references() {
fn pattern_match_mapping_rest_references() {
let test = cursor_test(
"
match data:
Expand Down Expand Up @@ -553,7 +553,7 @@ match data:
}

#[test]
fn test_function_definition_references() {
fn function_definition_references() {
let test = cursor_test(
"
def my_func<CURSOR>tion():
Expand Down Expand Up @@ -632,7 +632,7 @@ value = my_function
}

#[test]
fn test_class_definition_references() {
fn class_definition_references() {
let test = cursor_test(
"
class My<CURSOR>Class:
Expand Down Expand Up @@ -1105,7 +1105,7 @@ cls = MyClass
def __init__(self, pos, btn):
self.position: int = pos
self.button: str = btn

def my_func(event: Click):
match event:
case Click(x, button=a<CURSOR>b):
Expand Down Expand Up @@ -1144,7 +1144,7 @@ cls = MyClass
def __init__(self, pos, btn):
self.position: int = pos
self.button: str = btn

def my_func(event: Click):
match event:
case Click(x, button=ab):
Expand Down Expand Up @@ -1183,7 +1183,7 @@ cls = MyClass
def __init__(self, pos, btn):
self.position: int = pos
self.button: str = btn

def my_func(event: Click):
match event:
case Cl<CURSOR>ick(x, button=ab):
Expand Down Expand Up @@ -1233,7 +1233,7 @@ cls = MyClass
def __init__(self, pos, btn):
self.position: int = pos
self.button: str = btn

def my_func(event: Click):
match event:
case Click(x, but<CURSOR>ton=ab):
Expand Down Expand Up @@ -1445,7 +1445,7 @@ cls = MyClass
}

#[test]
fn test_multi_file_function_references() {
fn multi_file_function_references() {
let test = CursorTest::builder()
.source(
"utils.py",
Expand All @@ -1471,7 +1471,7 @@ from utils import func
class DataProcessor:
def __init__(self):
self.multiplier = func

def process(self, value):
return func(value)
",
Expand Down Expand Up @@ -1535,14 +1535,14 @@ class DataProcessor:
}

#[test]
fn test_multi_file_class_attribute_references() {
fn multi_file_class_attribute_references() {
let test = CursorTest::builder()
.source(
"models.py",
"
class MyModel:
a<CURSOR>ttr = 42

def get_attribute(self):
return MyModel.attr
",
Expand Down Expand Up @@ -1613,7 +1613,7 @@ def process_model():
}

#[test]
fn test_import_alias_references_should_not_resolve_to_original() {
fn import_alias_references_should_not_resolve_to_original() {
let test = CursorTest::builder()
.source(
"original.py",
Expand Down
4 changes: 2 additions & 2 deletions crates/ty_ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ mod doc_highlights;
mod docstring;
mod document_symbols;
mod find_node;
mod find_references;
mod goto;
mod goto_declaration;
mod goto_definition;
mod goto_references;
mod goto_type_definition;
mod hover;
mod importer;
Expand All @@ -32,8 +32,8 @@ pub use code_action::{QuickFix, code_actions};
pub use completion::{Completion, CompletionKind, CompletionSettings, completion};
pub use doc_highlights::document_highlights;
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_references::goto_references;
pub use hover::hover;
pub use inlay_hints::{
InlayHintKind, InlayHintLabel, InlayHintSettings, InlayHintTextEdit, inlay_hints,
Expand Down
4 changes: 2 additions & 2 deletions crates/ty_server/src/server/api/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ mod document_symbols;
mod execute_command;
mod goto_declaration;
mod goto_definition;
mod goto_references;
mod goto_type_definition;
mod hover;
mod inlay_hints;
mod prepare_rename;
mod references;
mod rename;
mod selection_range;
mod semantic_tokens;
Expand All @@ -28,11 +28,11 @@ pub(super) use document_symbols::DocumentSymbolRequestHandler;
pub(super) use execute_command::ExecuteCommand;
pub(super) use goto_declaration::GotoDeclarationRequestHandler;
pub(super) use goto_definition::GotoDefinitionRequestHandler;
pub(super) use goto_references::ReferencesRequestHandler;
pub(super) use goto_type_definition::GotoTypeDefinitionRequestHandler;
pub(super) use hover::HoverRequestHandler;
pub(super) use inlay_hints::InlayHintRequestHandler;
pub(super) use prepare_rename::PrepareRenameRequestHandler;
pub(super) use references::ReferencesRequestHandler;
pub(super) use rename::RenameRequestHandler;
pub(super) use selection_range::SelectionRangeRequestHandler;
pub(super) use semantic_tokens::SemanticTokensRequestHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Cow;

use lsp_types::request::References;
use lsp_types::{Location, ReferenceParams, Url};
use ty_ide::goto_references;
use ty_ide::find_references;
use ty_project::ProjectDatabase;

use crate::document::{PositionExt, ToLink};
Expand Down Expand Up @@ -51,7 +51,7 @@ impl BackgroundDocumentRequestHandler for ReferencesRequestHandler {

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);
};

Expand Down
6 changes: 3 additions & 3 deletions crates/ty_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use ruff_python_formatter::formatted_file;
use ruff_source_file::{LineIndex, OneIndexed, SourceLocation};
use ruff_text_size::{Ranged, TextSize};
use ty_ide::{
InlayHintSettings, MarkupKind, RangedValue, document_highlights, goto_declaration,
goto_definition, goto_references, goto_type_definition, hover, inlay_hints,
InlayHintSettings, MarkupKind, RangedValue, document_highlights, find_references,
goto_declaration, goto_definition, goto_type_definition, hover, inlay_hints,
};
use ty_ide::{NavigationTarget, NavigationTargets, signature_help};
use ty_project::metadata::options::Options;
Expand Down Expand Up @@ -351,7 +351,7 @@ impl Workspace {

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());
};

Expand Down
Loading