diff options
author | Aleksey Kladov <[email protected]> | 2019-07-21 11:28:58 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-07-21 11:28:58 +0100 |
commit | d52ee59a712932bc381d8c690dc2f681598760fe (patch) | |
tree | f1fd1615203dd5552172cc35e0b6c5c9b76104c2 /crates/ra_ide_api/src/typing.rs | |
parent | 62be91b82d6368a20a40893b199bc4f7a35a2223 (diff) |
streamline API
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 | ||