mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Remove LocalEdit usage
This commit is contained in:
parent
58e77660de
commit
9bd8336c51
2 changed files with 17 additions and 16 deletions
|
@ -1,4 +1,5 @@
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use ra_db::FileRange;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
SourceFile, TextRange, TextUnit, AstNode, SyntaxNode,
|
SourceFile, TextRange, TextUnit, AstNode, SyntaxNode,
|
||||||
SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK},
|
SyntaxKind::{self, WHITESPACE, COMMA, R_CURLY, R_PAREN, R_BRACK},
|
||||||
|
@ -9,26 +10,19 @@ use ra_syntax::{
|
||||||
use ra_fmt::{
|
use ra_fmt::{
|
||||||
compute_ws, extract_trivial_expression
|
compute_ws, extract_trivial_expression
|
||||||
};
|
};
|
||||||
use ra_text_edit::TextEditBuilder;
|
use ra_text_edit::{TextEdit, TextEditBuilder};
|
||||||
use ra_ide_api_light::LocalEdit;
|
|
||||||
|
|
||||||
pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit {
|
pub fn join_lines(file: &SourceFile, frange: FileRange) -> TextEdit {
|
||||||
let range = if range.is_empty() {
|
let range = if frange.range.is_empty() {
|
||||||
let syntax = file.syntax();
|
let syntax = file.syntax();
|
||||||
let text = syntax.text().slice(range.start()..);
|
let text = syntax.text().slice(frange.range.start()..);
|
||||||
let pos = match text.find('\n') {
|
let pos = match text.find('\n') {
|
||||||
None => {
|
None => return TextEditBuilder::default().finish(),
|
||||||
return LocalEdit {
|
|
||||||
label: "join lines".to_string(),
|
|
||||||
edit: TextEditBuilder::default().finish(),
|
|
||||||
cursor_position: None,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Some(pos) => pos,
|
Some(pos) => pos,
|
||||||
};
|
};
|
||||||
TextRange::offset_len(range.start() + pos, TextUnit::of_char('\n'))
|
TextRange::offset_len(frange.range.start() + pos, TextUnit::of_char('\n'))
|
||||||
} else {
|
} else {
|
||||||
range
|
frange.range
|
||||||
};
|
};
|
||||||
|
|
||||||
let node = find_covering_node(file.syntax(), range);
|
let node = find_covering_node(file.syntax(), range);
|
||||||
|
@ -51,7 +45,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalEdit { label: "join lines".to_string(), edit: edit.finish(), cursor_position: None }
|
edit.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_newline(
|
fn remove_newline(
|
||||||
|
|
|
@ -279,7 +279,14 @@ impl Analysis {
|
||||||
/// stuff like trailing commas.
|
/// stuff like trailing commas.
|
||||||
pub fn join_lines(&self, frange: FileRange) -> SourceChange {
|
pub fn join_lines(&self, frange: FileRange) -> SourceChange {
|
||||||
let file = self.db.parse(frange.file_id);
|
let file = self.db.parse(frange.file_id);
|
||||||
SourceChange::from_local_edit(frange.file_id, join_lines::join_lines(&file, frange.range))
|
let file_edit =
|
||||||
|
SourceFileEdit { file_id: frange.file_id, edit: join_lines::join_lines(&file, frange) };
|
||||||
|
SourceChange {
|
||||||
|
label: "join lines".to_string(),
|
||||||
|
source_file_edits: vec![file_edit],
|
||||||
|
file_system_edits: vec![],
|
||||||
|
cursor_position: None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an edit which should be applied when opening a new line, fixing
|
/// Returns an edit which should be applied when opening a new line, fixing
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue