diff options
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_context.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/extend_selection.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_type_definition.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/matching_brace.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide_api/src/typing.rs | 15 |
5 files changed, 21 insertions, 14 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index 2f78d5409..968f5694b 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use hir::source_binder; | 1 | use hir::source_binder; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | algo::{find_covering_element, find_node_at_offset, find_token_at_offset}, | 3 | algo::{find_covering_element, find_node_at_offset}, |
4 | ast, AstNode, Parse, SourceFile, | 4 | ast, AstNode, Parse, SourceFile, |
5 | SyntaxKind::*, | 5 | SyntaxKind::*, |
6 | SyntaxNode, SyntaxToken, TextRange, TextUnit, | 6 | SyntaxNode, SyntaxToken, TextRange, TextUnit, |
@@ -48,7 +48,7 @@ impl<'a> CompletionContext<'a> { | |||
48 | ) -> Option<CompletionContext<'a>> { | 48 | ) -> Option<CompletionContext<'a>> { |
49 | let module = source_binder::module_from_position(db, position); | 49 | let module = source_binder::module_from_position(db, position); |
50 | let token = | 50 | let token = |
51 | find_token_at_offset(original_parse.tree().syntax(), position.offset).left_biased()?; | 51 | original_parse.tree().syntax().token_at_offset(position.offset).left_biased()?; |
52 | let analyzer = | 52 | let analyzer = |
53 | hir::SourceAnalyzer::new(db, position.file_id, &token.parent(), Some(position.offset)); | 53 | hir::SourceAnalyzer::new(db, position.file_id, &token.parent(), Some(position.offset)); |
54 | let mut ctx = CompletionContext { | 54 | let mut ctx = CompletionContext { |
diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index f78c562af..edbf622c1 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs | |||
@@ -1,10 +1,10 @@ | |||
1 | use ra_db::SourceDatabase; | 1 | use ra_db::SourceDatabase; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | algo::{find_covering_element, find_token_at_offset, TokenAtOffset}, | 3 | algo::find_covering_element, |
4 | ast::{self, AstNode, AstToken}, | 4 | ast::{self, AstNode, AstToken}, |
5 | Direction, NodeOrToken, | 5 | Direction, NodeOrToken, |
6 | SyntaxKind::*, | 6 | SyntaxKind::*, |
7 | SyntaxNode, SyntaxToken, TextRange, TextUnit, T, | 7 | SyntaxNode, SyntaxToken, TextRange, TextUnit, TokenAtOffset, T, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | use crate::{db::RootDatabase, FileRange}; | 10 | use crate::{db::RootDatabase, FileRange}; |
@@ -34,7 +34,7 @@ fn try_extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange | |||
34 | 34 | ||
35 | if range.is_empty() { | 35 | if range.is_empty() { |
36 | let offset = range.start(); | 36 | let offset = range.start(); |
37 | let mut leaves = find_token_at_offset(root, offset); | 37 | let mut leaves = root.token_at_offset(offset); |
38 | if leaves.clone().all(|it| it.kind() == WHITESPACE) { | 38 | if leaves.clone().all(|it| it.kind() == WHITESPACE) { |
39 | return Some(extend_ws(root, leaves.next()?, offset)); | 39 | return Some(extend_ws(root, leaves.next()?, offset)); |
40 | } | 40 | } |
diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index 007259d9e..72884e5ca 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use ra_db::SourceDatabase; | 1 | use ra_db::SourceDatabase; |
2 | use ra_syntax::{algo::find_token_at_offset, ast, AstNode}; | 2 | use ra_syntax::{ast, AstNode}; |
3 | 3 | ||
4 | use crate::{db::RootDatabase, FilePosition, NavigationTarget, RangeInfo}; | 4 | use crate::{db::RootDatabase, FilePosition, NavigationTarget, RangeInfo}; |
5 | 5 | ||
@@ -9,7 +9,7 @@ pub(crate) fn goto_type_definition( | |||
9 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { | 9 | ) -> Option<RangeInfo<Vec<NavigationTarget>>> { |
10 | let parse = db.parse(position.file_id); | 10 | let parse = db.parse(position.file_id); |
11 | 11 | ||
12 | let node = find_token_at_offset(parse.tree().syntax(), position.offset).find_map(|token| { | 12 | let node = parse.tree().syntax().token_at_offset(position.offset).find_map(|token| { |
13 | token | 13 | token |
14 | .parent() | 14 | .parent() |
15 | .ancestors() | 15 | .ancestors() |
diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs index 1e2fac848..e802d01e4 100644 --- a/crates/ra_ide_api/src/matching_brace.rs +++ b/crates/ra_ide_api/src/matching_brace.rs | |||
@@ -1,9 +1,11 @@ | |||
1 | use ra_syntax::{algo::find_token_at_offset, ast::AstNode, SourceFile, SyntaxKind, TextUnit, T}; | 1 | use ra_syntax::{ast::AstNode, SourceFile, SyntaxKind, TextUnit, T}; |
2 | 2 | ||
3 | pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { | 3 | pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { |
4 | const BRACES: &[SyntaxKind] = | 4 | const BRACES: &[SyntaxKind] = |
5 | &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>]]; | 5 | &[T!['{'], T!['}'], T!['['], T![']'], T!['('], T![')'], T![<], T![>]]; |
6 | let (brace_node, brace_idx) = find_token_at_offset(file.syntax(), offset) | 6 | let (brace_node, brace_idx) = file |
7 | .syntax() | ||
8 | .token_at_offset(offset) | ||
7 | .filter_map(|node| { | 9 | .filter_map(|node| { |
8 | let idx = BRACES.iter().position(|&brace| brace == node.kind())?; | 10 | let idx = BRACES.iter().position(|&brace| brace == node.kind())?; |
9 | Some((node, idx)) | 11 | Some((node, idx)) |
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 | ||