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_ide_api/src/typing.rs | |
parent | ba76017d2eb1b7606106c15478ac658dc32b6dbd (diff) | |
parent | d690249bc81bc265cb3d1836c2922325f4fdb8af (diff) |
Merge branch 'master' into add-type-lenses
Diffstat (limited to 'crates/ra_ide_api/src/typing.rs')
-rw-r--r-- | crates/ra_ide_api/src/typing.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index 5a1cbcc49..6b3fd5904 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs | |||
@@ -1,11 +1,11 @@ | |||
1 | use ra_db::{FilePosition, SourceDatabase}; | 1 | use ra_db::{FilePosition, SourceDatabase}; |
2 | use ra_fmt::leading_indent; | 2 | use ra_fmt::leading_indent; |
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | algo::{find_node_at_offset, find_token_at_offset, TokenAtOffset}, | 4 | algo::find_node_at_offset, |
5 | ast::{self, AstToken}, | 5 | ast::{self, AstToken}, |
6 | AstNode, SmolStr, SourceFile, | 6 | AstNode, SmolStr, SourceFile, |
7 | SyntaxKind::*, | 7 | SyntaxKind::*, |
8 | SyntaxToken, TextRange, TextUnit, | 8 | SyntaxToken, TextRange, TextUnit, TokenAtOffset, |
9 | }; | 9 | }; |
10 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 10 | use ra_text_edit::{TextEdit, TextEditBuilder}; |
11 | 11 | ||
@@ -14,7 +14,9 @@ use crate::{db::RootDatabase, SourceChange, SourceFileEdit}; | |||
14 | pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<SourceChange> { | 14 | pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<SourceChange> { |
15 | let parse = db.parse(position.file_id); | 15 | let parse = db.parse(position.file_id); |
16 | let file = parse.tree(); | 16 | let file = parse.tree(); |
17 | let comment = find_token_at_offset(file.syntax(), position.offset) | 17 | let comment = file |
18 | .syntax() | ||
19 | .token_at_offset(position.offset) | ||
18 | .left_biased() | 20 | .left_biased() |
19 | .and_then(ast::Comment::cast)?; | 21 | .and_then(ast::Comment::cast)?; |
20 | 22 | ||
@@ -45,7 +47,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour | |||
45 | } | 47 | } |
46 | 48 | ||
47 | fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> { | 49 | fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> { |
48 | let ws = match find_token_at_offset(file.syntax(), token.text_range().start()) { | 50 | let ws = match file.syntax().token_at_offset(token.text_range().start()) { |
49 | TokenAtOffset::Between(l, r) => { | 51 | TokenAtOffset::Between(l, r) => { |
50 | assert!(r == *token); | 52 | assert!(r == *token); |
51 | l | 53 | l |
@@ -91,7 +93,10 @@ pub(crate) fn on_dot_typed(db: &RootDatabase, position: FilePosition) -> Option< | |||
91 | let parse = db.parse(position.file_id); | 93 | let parse = db.parse(position.file_id); |
92 | assert_eq!(parse.tree().syntax().text().char_at(position.offset), Some('.')); | 94 | assert_eq!(parse.tree().syntax().text().char_at(position.offset), Some('.')); |
93 | 95 | ||
94 | let whitespace = find_token_at_offset(parse.tree().syntax(), position.offset) | 96 | let whitespace = parse |
97 | .tree() | ||
98 | .syntax() | ||
99 | .token_at_offset(position.offset) | ||
95 | .left_biased() | 100 | .left_biased() |
96 | .and_then(ast::Whitespace::cast)?; | 101 | .and_then(ast::Whitespace::cast)?; |
97 | 102 | ||