Skip to content

Commit 74780a1

Browse files
committed
Jump to sourceChanges in other files
1 parent ba8faf3 commit 74780a1

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

crates/ra_assists/src/handlers/add_function.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -907,23 +907,14 @@ mod foo;
907907
fn main() {
908908
foo::bar<|>()
909909
}
910-
911910
//- /foo.rs
912-
913911
",
914912
r"
915-
//- /main.rs
916-
mod foo;
917913
918-
fn main() {
919-
foo::bar()
920-
}
921914
922-
//- /foo.rs
923-
fn bar() {
915+
pub(crate) fn bar() {
924916
<|>todo!()
925-
}
926-
",
917+
}",
927918
)
928919
}
929920

crates/ra_assists/src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ mod helpers {
197197
use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
198198
use test_utils::{add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset};
199199

200-
use crate::{AssistCtx, AssistHandler};
200+
use crate::{AssistCtx, AssistFile, AssistHandler};
201201
use hir::Semantics;
202202

203203
pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
@@ -259,7 +259,13 @@ mod helpers {
259259
(Some(assist), ExpectedResult::After(after)) => {
260260
let action = assist.0[0].action.clone().unwrap();
261261

262-
let mut actual = action.edit.apply(&text_without_caret);
262+
let assisted_file_text = if let AssistFile::TargetFile(file_id) = action.file {
263+
db.file_text(file_id).as_ref().to_owned()
264+
} else {
265+
text_without_caret
266+
};
267+
268+
let mut actual = action.edit.apply(&assisted_file_text);
263269
match action.cursor_position {
264270
None => {
265271
if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset {

editors/code/src/source_change.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ export async function applySourceChange(ctx: Ctx, change: ra.SourceChange) {
3737
toReveal.position,
3838
);
3939
const editor = vscode.window.activeTextEditor;
40-
if (!editor || editor.document.uri.toString() !== uri.toString()) {
40+
if (!editor || !editor.selection.isEmpty) {
4141
return;
4242
}
43-
if (!editor.selection.isEmpty) {
44-
return;
43+
44+
if (editor.document.uri !== uri) {
45+
const doc = await vscode.workspace.openTextDocument(uri);
46+
await vscode.window.showTextDocument(doc);
4547
}
4648
editor.selection = new vscode.Selection(position, position);
4749
editor.revealRange(

0 commit comments

Comments
 (0)