diff options
author | Kirill Bulatov <[email protected]> | 2019-07-21 22:10:29 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2019-07-21 22:10:29 +0100 |
commit | 31aef808d96b779dbc8ce41e27857965e79bd96f (patch) | |
tree | 254d69a1ec3abe6d70b2dd9737ef699f33f88f62 /crates/ra_assists | |
parent | ba76017d2eb1b7606106c15478ac658dc32b6dbd (diff) | |
parent | d690249bc81bc265cb3d1836c2922325f4fdb8af (diff) |
Merge branch 'master' into add-type-lenses
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_assists/src/add_impl.rs | 5 | ||||
-rw-r--r-- | crates/ra_assists/src/assist_ctx.rs | 5 | ||||
-rw-r--r-- | crates/ra_assists/src/ast_editor.rs | 9 | ||||
-rw-r--r-- | crates/ra_assists/src/introduce_variable.rs | 5 | ||||
-rw-r--r-- | crates/ra_assists/src/move_guard.rs | 8 |
6 files changed, 18 insertions, 15 deletions
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml index 5ddac1e48..2113286a3 100644 --- a/crates/ra_assists/Cargo.toml +++ b/crates/ra_assists/Cargo.toml | |||
@@ -5,6 +5,7 @@ version = "0.1.0" | |||
5 | authors = ["rust-analyzer developers"] | 5 | authors = ["rust-analyzer developers"] |
6 | 6 | ||
7 | [dependencies] | 7 | [dependencies] |
8 | format-buf = "1.0.0" | ||
8 | once_cell = "0.2.0" | 9 | once_cell = "0.2.0" |
9 | join_to_string = "0.1.3" | 10 | join_to_string = "0.1.3" |
10 | itertools = "0.8.0" | 11 | itertools = "0.8.0" |
diff --git a/crates/ra_assists/src/add_impl.rs b/crates/ra_assists/src/add_impl.rs index 59ca88468..4b61f4031 100644 --- a/crates/ra_assists/src/add_impl.rs +++ b/crates/ra_assists/src/add_impl.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | use std::fmt::Write; | 1 | use format_buf::format; |
2 | |||
3 | use hir::db::HirDatabase; | 2 | use hir::db::HirDatabase; |
4 | use join_to_string::join; | 3 | use join_to_string::join; |
5 | use ra_syntax::{ | 4 | use ra_syntax::{ |
@@ -19,7 +18,7 @@ pub(crate) fn add_impl(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
19 | let mut buf = String::new(); | 18 | let mut buf = String::new(); |
20 | buf.push_str("\n\nimpl"); | 19 | buf.push_str("\n\nimpl"); |
21 | if let Some(type_params) = &type_params { | 20 | if let Some(type_params) = &type_params { |
22 | write!(buf, "{}", type_params.syntax()).unwrap(); | 21 | format!(buf, "{}", type_params.syntax()); |
23 | } | 22 | } |
24 | buf.push_str(" "); | 23 | buf.push_str(" "); |
25 | buf.push_str(name.text().as_str()); | 24 | buf.push_str(name.text().as_str()); |
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 4d5a76de6..a12c3ed54 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs | |||
@@ -2,8 +2,9 @@ use hir::db::HirDatabase; | |||
2 | use ra_db::FileRange; | 2 | use ra_db::FileRange; |
3 | use ra_fmt::{leading_indent, reindent}; | 3 | use ra_fmt::{leading_indent, reindent}; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | algo::{find_covering_element, find_node_at_offset, find_token_at_offset, TokenAtOffset}, | 5 | algo::{find_covering_element, find_node_at_offset}, |
6 | AstNode, SourceFile, SyntaxElement, SyntaxNode, SyntaxToken, TextRange, TextUnit, | 6 | AstNode, SourceFile, SyntaxElement, SyntaxNode, SyntaxToken, TextRange, TextUnit, |
7 | TokenAtOffset, | ||
7 | }; | 8 | }; |
8 | use ra_text_edit::TextEditBuilder; | 9 | use ra_text_edit::TextEditBuilder; |
9 | 10 | ||
@@ -105,7 +106,7 @@ impl<'a, DB: HirDatabase> AssistCtx<'a, DB> { | |||
105 | } | 106 | } |
106 | 107 | ||
107 | pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> { | 108 | pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> { |
108 | find_token_at_offset(self.source_file.syntax(), self.frange.range.start()) | 109 | self.source_file.syntax().token_at_offset(self.frange.range.start()) |
109 | } | 110 | } |
110 | 111 | ||
111 | pub(crate) fn node_at_offset<N: AstNode>(&self) -> Option<N> { | 112 | pub(crate) fn node_at_offset<N: AstNode>(&self) -> Option<N> { |
diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index ab6c347ad..95b871b30 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs | |||
@@ -4,7 +4,10 @@ use arrayvec::ArrayVec; | |||
4 | use hir::Name; | 4 | use hir::Name; |
5 | use ra_fmt::leading_indent; | 5 | use ra_fmt::leading_indent; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | ast, AstNode, Direction, InsertPosition, SourceFile, SyntaxElement, SyntaxKind::*, T, | 7 | algo::{insert_children, replace_children}, |
8 | ast, AstNode, Direction, InsertPosition, SourceFile, SyntaxElement, | ||
9 | SyntaxKind::*, | ||
10 | T, | ||
8 | }; | 11 | }; |
9 | use ra_text_edit::TextEditBuilder; | 12 | use ra_text_edit::TextEditBuilder; |
10 | 13 | ||
@@ -38,7 +41,7 @@ impl<N: AstNode> AstEditor<N> { | |||
38 | position: InsertPosition<SyntaxElement>, | 41 | position: InsertPosition<SyntaxElement>, |
39 | to_insert: impl Iterator<Item = SyntaxElement>, | 42 | to_insert: impl Iterator<Item = SyntaxElement>, |
40 | ) -> N { | 43 | ) -> N { |
41 | let new_syntax = self.ast().syntax().insert_children(position, to_insert); | 44 | let new_syntax = insert_children(self.ast().syntax(), position, to_insert); |
42 | N::cast(new_syntax).unwrap() | 45 | N::cast(new_syntax).unwrap() |
43 | } | 46 | } |
44 | 47 | ||
@@ -48,7 +51,7 @@ impl<N: AstNode> AstEditor<N> { | |||
48 | to_delete: RangeInclusive<SyntaxElement>, | 51 | to_delete: RangeInclusive<SyntaxElement>, |
49 | to_insert: impl Iterator<Item = SyntaxElement>, | 52 | to_insert: impl Iterator<Item = SyntaxElement>, |
50 | ) -> N { | 53 | ) -> N { |
51 | let new_syntax = self.ast().syntax().replace_children(to_delete, to_insert); | 54 | let new_syntax = replace_children(self.ast().syntax(), to_delete, to_insert); |
52 | N::cast(new_syntax).unwrap() | 55 | N::cast(new_syntax).unwrap() |
53 | } | 56 | } |
54 | 57 | ||
diff --git a/crates/ra_assists/src/introduce_variable.rs b/crates/ra_assists/src/introduce_variable.rs index 911de2d48..5eb708310 100644 --- a/crates/ra_assists/src/introduce_variable.rs +++ b/crates/ra_assists/src/introduce_variable.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | use std::fmt::Write; | 1 | use format_buf::format; |
2 | |||
3 | use hir::db::HirDatabase; | 2 | use hir::db::HirDatabase; |
4 | use ra_syntax::{ | 3 | use ra_syntax::{ |
5 | ast::{self, AstNode}, | 4 | ast::{self, AstNode}, |
@@ -37,7 +36,7 @@ pub(crate) fn introduce_variable(mut ctx: AssistCtx<impl HirDatabase>) -> Option | |||
37 | buf.push_str("let var_name = "); | 36 | buf.push_str("let var_name = "); |
38 | TextUnit::of_str("let ") | 37 | TextUnit::of_str("let ") |
39 | }; | 38 | }; |
40 | write!(buf, "{}", expr.syntax()).unwrap(); | 39 | format!(buf, "{}", expr.syntax()); |
41 | let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone()); | 40 | let full_stmt = ast::ExprStmt::cast(anchor_stmt.clone()); |
42 | let is_full_stmt = if let Some(expr_stmt) = &full_stmt { | 41 | let is_full_stmt = if let Some(expr_stmt) = &full_stmt { |
43 | Some(expr.syntax().clone()) == expr_stmt.expr().map(|e| e.syntax().clone()) | 42 | Some(expr.syntax().clone()) == expr_stmt.expr().map(|e| e.syntax().clone()) |
diff --git a/crates/ra_assists/src/move_guard.rs b/crates/ra_assists/src/move_guard.rs index 0f3cdbe53..127c9e068 100644 --- a/crates/ra_assists/src/move_guard.rs +++ b/crates/ra_assists/src/move_guard.rs | |||
@@ -2,7 +2,7 @@ use hir::db::HirDatabase; | |||
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast, | 3 | ast, |
4 | ast::{AstNode, AstToken, IfExpr, MatchArm}, | 4 | ast::{AstNode, AstToken, IfExpr, MatchArm}, |
5 | SyntaxElement, TextUnit, | 5 | TextUnit, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::{Assist, AssistCtx, AssistId}; | 8 | use crate::{Assist, AssistCtx, AssistId}; |
@@ -18,10 +18,10 @@ pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx<impl HirDatabase>) -> Op | |||
18 | 18 | ||
19 | ctx.add_action(AssistId("move_guard_to_arm_body"), "move guard to arm body", |edit| { | 19 | ctx.add_action(AssistId("move_guard_to_arm_body"), "move guard to arm body", |edit| { |
20 | edit.target(guard.syntax().text_range()); | 20 | edit.target(guard.syntax().text_range()); |
21 | let offseting_amount = match &space_before_guard { | 21 | let offseting_amount = match space_before_guard.and_then(|it| it.into_token()) { |
22 | Some(SyntaxElement::Token(tok)) => { | 22 | Some(tok) => { |
23 | if let Some(_) = ast::Whitespace::cast(tok.clone()) { | 23 | if let Some(_) = ast::Whitespace::cast(tok.clone()) { |
24 | let ele = space_before_guard.unwrap().text_range(); | 24 | let ele = tok.text_range(); |
25 | edit.delete(ele); | 25 | edit.delete(ele); |
26 | ele.len() | 26 | ele.len() |
27 | } else { | 27 | } else { |