Skip to content

Commit 3cba0dc

Browse files
bors[bot]matklad
andauthored
Merge #4552
4552: Transition OnEnter to WorkspaceSnippetEdit r=matklad a=matklad This also changes our handiling of snippet edits on the client side. `editor.insertSnippet` unfortunately forces indentation, which we really don't want to have to deal with. So, let's just implement our manual hacky way of dealing with a simple subset of snippets we actually use in rust-analyzer bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 0c2b548 + ff28c79 commit 3cba0dc

File tree

16 files changed

+109
-478
lines changed

16 files changed

+109
-478
lines changed

crates/ra_assists/src/tests.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt};
77
use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
88
use ra_syntax::TextRange;
99
use test_utils::{
10-
add_cursor, assert_eq_text, extract_offset, extract_range, extract_range_or_offset,
11-
RangeOrOffset,
10+
assert_eq_text, extract_offset, extract_range, extract_range_or_offset, RangeOrOffset,
1211
};
1312

1413
use crate::{handlers::Handler, Assist, AssistConfig, AssistContext, Assists};
@@ -103,12 +102,6 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) {
103102

104103
let mut actual = db.file_text(change.file_id).as_ref().to_owned();
105104
change.edit.apply(&mut actual);
106-
107-
if !source_change.is_snippet {
108-
if let Some(off) = source_change.cursor_position {
109-
actual = add_cursor(&actual, off.offset)
110-
}
111-
}
112105
assert_eq_text!(after, &actual);
113106
}
114107
(Some(assist), ExpectedResult::Target(target)) => {

crates/ra_ide/src/diagnostics.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ mod tests {
628628
path: "foo.rs",
629629
},
630630
],
631-
cursor_position: None,
632631
is_snippet: false,
633632
},
634633
),
@@ -685,7 +684,6 @@ mod tests {
685684
},
686685
],
687686
file_system_edits: [],
688-
cursor_position: None,
689687
is_snippet: false,
690688
},
691689
),

crates/ra_ide/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ pub use ra_db::{
8787
pub use ra_ide_db::{
8888
change::{AnalysisChange, LibraryData},
8989
line_index::{LineCol, LineIndex},
90-
line_index_utils::translate_offset_with_edit,
9190
search::SearchScope,
9291
source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
9392
symbol_index::Query,

crates/ra_ide/src/references/rename.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ mod tests {
669669
dst_path: "bar/foo2.rs",
670670
},
671671
],
672-
cursor_position: None,
673672
is_snippet: false,
674673
},
675674
},
@@ -722,7 +721,6 @@ mod tests {
722721
dst_path: "foo2/mod.rs",
723722
},
724723
],
725-
cursor_position: None,
726724
is_snippet: false,
727725
},
728726
},
@@ -819,7 +817,6 @@ mod tests {
819817
dst_path: "bar/foo2.rs",
820818
},
821819
],
822-
cursor_position: None,
823820
is_snippet: false,
824821
},
825822
},

crates/ra_ide/src/typing/on_enter.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,15 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
3838
}
3939

4040
let indent = node_indent(&file, comment.syntax())?;
41-
let inserted = format!("\n{}{} ", indent, prefix);
42-
let cursor_position = position.offset + TextSize::of(&inserted);
41+
let inserted = format!("\n{}{} $0", indent, prefix);
4342
let edit = TextEdit::insert(position.offset, inserted);
4443

45-
Some(
46-
SourceChange::source_file_edit(
47-
"On enter",
48-
SourceFileEdit { edit, file_id: position.file_id },
49-
)
50-
.with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }),
51-
)
44+
let mut res = SourceChange::source_file_edit(
45+
"On enter",
46+
SourceFileEdit { edit, file_id: position.file_id },
47+
);
48+
res.is_snippet = true;
49+
Some(res)
5250
}
5351

5452
fn followed_by_comment(comment: &ast::Comment) -> bool {
@@ -84,7 +82,7 @@ fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> {
8482

8583
#[cfg(test)]
8684
mod tests {
87-
use test_utils::{add_cursor, assert_eq_text, extract_offset};
85+
use test_utils::{assert_eq_text, extract_offset};
8886

8987
use crate::mock_analysis::single_file;
9088

@@ -98,7 +96,6 @@ mod tests {
9896
assert_eq!(result.source_file_edits.len(), 1);
9997
let mut actual = before.to_string();
10098
result.source_file_edits[0].edit.apply(&mut actual);
101-
let actual = add_cursor(&actual, result.cursor_position.unwrap().offset);
10299
Some(actual)
103100
}
104101

@@ -121,7 +118,7 @@ fn foo() {
121118
",
122119
r"
123120
/// Some docs
124-
/// <|>
121+
/// $0
125122
fn foo() {
126123
}
127124
",
@@ -137,7 +134,7 @@ impl S {
137134
r"
138135
impl S {
139136
/// Some
140-
/// <|> docs.
137+
/// $0 docs.
141138
fn foo() {}
142139
}
143140
",
@@ -151,7 +148,7 @@ fn foo() {
151148
",
152149
r"
153150
///
154-
/// <|> Some docs
151+
/// $0 Some docs
155152
fn foo() {
156153
}
157154
",
@@ -175,7 +172,7 @@ fn main() {
175172
r"
176173
fn main() {
177174
// Fix
178-
// <|> me
175+
// $0 me
179176
let x = 1 + 1;
180177
}
181178
",
@@ -195,7 +192,7 @@ fn main() {
195192
r"
196193
fn main() {
197194
// Fix
198-
// <|>
195+
// $0
199196
// me
200197
let x = 1 + 1;
201198
}

crates/ra_ide_db/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search.
44
55
pub mod line_index;
6-
pub mod line_index_utils;
76
pub mod symbol_index;
87
pub mod change;
98
pub mod defs;

0 commit comments

Comments
 (0)