Skip to content
Closed
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
15 changes: 11 additions & 4 deletions pyrefly/lib/lsp/non_wasm/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4852,6 +4852,7 @@ impl Server {
handle: Handle,
uri: &Url,
position: Position,
find_preference: FindPreference,
include_declaration: bool,
activity_key: Option<ActivityKey>,
map_result: impl FnOnce(Vec<(Url, Vec<Range>)>) -> V + Send + Sync + 'static,
Expand All @@ -4867,10 +4868,7 @@ impl Server {
handle,
uri,
position,
FindPreference {
import_behavior: ImportBehavior::StopAtRenamedImports,
..Default::default()
},
find_preference,
activity_key,
move |transaction, handle, definition, telemetry, telemetry_event| {
let qualified_name =
Expand Down Expand Up @@ -4970,6 +4968,10 @@ impl Server {
handle,
uri,
params.text_document_position.position,
FindPreference {
import_behavior: ImportBehavior::StopAtRenamedImports,
..Default::default()
},
params.context.include_declaration,
activity_key,
move |results| {
Expand Down Expand Up @@ -5002,6 +5004,11 @@ impl Server {
handle,
uri,
params.text_document_position.position,
FindPreference {
import_behavior: ImportBehavior::StopAtRenamedImports,
resolve_call_dunders: false,
..Default::default()
},
true,
activity_key,
move |results| {
Expand Down
9 changes: 8 additions & 1 deletion pyrefly/lib/state/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3628,7 +3628,14 @@ impl<'a> Transaction<'a> {
let identifier_context = self.identifier_at(handle, position);

let definitions = self
.find_definition(handle, position, FindPreference::default())
.find_definition(
handle,
position,
FindPreference {
resolve_call_dunders: false,
..Default::default()
},
)
.map(Vec1::into_vec)
.unwrap_or_default();

Expand Down
70 changes: 70 additions & 0 deletions pyrefly/lib/test/lsp/lsp_interaction/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,81 @@ use lsp_types::Url;
use lsp_types::request::PrepareRenameRequest;
use lsp_types::request::Rename;
use serde_json::json;
use tempfile::TempDir;

use crate::object_model::InitializeSettings;
use crate::object_model::LspInteraction;
use crate::util::get_test_files_root;

#[test]
fn test_rename_constructor_call_renames_class() {
let root = TempDir::new().unwrap();
let path = root.path().join("main.py");
std::fs::write(
&path,
r#"from typing import Protocol

class WorkbookAction(Protocol):
def __call__(self, value: int) -> None: ...

class FooAction(WorkbookAction):
def __init__(self, sheet_name: str) -> None:
self.sheet_name = sheet_name

def __call__(self, value: int) -> None:
print(f"FooAction: {value} on sheet {self.sheet_name}")

FooAction("test")
"#,
)
.unwrap();

let mut interaction = LspInteraction::new();
interaction.set_root(root.path().to_path_buf());
interaction
.initialize(InitializeSettings {
workspace_folders: Some(vec![(
"test".to_owned(),
Url::from_file_path(root.path()).unwrap(),
)]),
configuration: Some(Some(json!([{ "indexing_mode": "lazy_blocking" }]))),
..Default::default()
})
.unwrap();
interaction.client.did_open("main.py");

interaction
.client
.send_request::<Rename>(json!({
"textDocument": {"uri": Url::from_file_path(&path).unwrap().to_string()},
"position": {"line": 12, "character": 1},
"newName": "BarAction"
}))
.expect_response(json!({
"changes": {
Url::from_file_path(&path).unwrap().to_string(): [
{
"newText": "BarAction",
"range": {
"start": {"line": 5, "character": 6},
"end": {"line": 5, "character": 15}
}
},
{
"newText": "BarAction",
"range": {
"start": {"line": 12, "character": 0},
"end": {"line": 12, "character": 9}
}
}
]
}
}))
.unwrap();

interaction.shutdown().unwrap();
}

#[test]
fn test_prepare_rename() {
let root = get_test_files_root();
Expand Down
Loading