aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/call_hierarchy.rs20
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs2
-rw-r--r--crates/ra_ide/src/extend_selection.rs24
-rw-r--r--crates/ra_ide/src/join_lines.rs25
-rw-r--r--crates/ra_ide/src/lib.rs2
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs52
6 files changed, 72 insertions, 53 deletions
diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs
index f984f40ad..51ac59a71 100644
--- a/crates/ra_ide/src/call_hierarchy.rs
+++ b/crates/ra_ide/src/call_hierarchy.rs
@@ -4,16 +4,11 @@ use indexmap::IndexMap;
4 4
5use hir::db::AstDatabase; 5use hir::db::AstDatabase;
6use ra_ide_db::RootDatabase; 6use ra_ide_db::RootDatabase;
7use ra_syntax::{ 7use ra_syntax::{ast, match_ast, AstNode, TextRange};
8 ast::{self, DocCommentsOwner},
9 match_ast, AstNode, TextRange,
10};
11 8
12use crate::{ 9use crate::{
13 call_info::FnCallNode, 10 call_info::FnCallNode, display::ToNav, expand::descend_into_macros, goto_definition,
14 display::{ShortLabel, ToNav}, 11 references, FilePosition, NavigationTarget, RangeInfo,
15 expand::descend_into_macros,
16 goto_definition, references, FilePosition, NavigationTarget, RangeInfo,
17}; 12};
18 13
19#[derive(Debug, Clone)] 14#[derive(Debug, Clone)]
@@ -49,6 +44,7 @@ pub(crate) fn incoming_calls(db: &RootDatabase, position: FilePosition) -> Optio
49 let refs = references::find_all_refs(db, position, None)?; 44 let refs = references::find_all_refs(db, position, None)?;
50 45
51 let mut calls = CallLocations::default(); 46 let mut calls = CallLocations::default();
47 let mut sb = hir::SourceBinder::new(db);
52 48
53 for reference in refs.info.references() { 49 for reference in refs.info.references() {
54 let file_id = reference.file_range.file_id; 50 let file_id = reference.file_range.file_id;
@@ -62,12 +58,8 @@ pub(crate) fn incoming_calls(db: &RootDatabase, position: FilePosition) -> Optio
62 match_ast! { 58 match_ast! {
63 match node { 59 match node {
64 ast::FnDef(it) => { 60 ast::FnDef(it) => {
65 Some(NavigationTarget::from_named( 61 let def = sb.to_def(token.with_value(it))?;
66 db, 62 Some(def.to_nav(sb.db))
67 token.with_value(&it),
68 it.doc_comment_text(),
69 it.short_label(),
70 ))
71 }, 63 },
72 _ => { None }, 64 _ => { None },
73 } 65 }
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index b42cb477e..c9d0058a6 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -125,7 +125,7 @@ impl NavigationTarget {
125 } 125 }
126 126
127 /// Allows `NavigationTarget` to be created from a `NameOwner` 127 /// Allows `NavigationTarget` to be created from a `NameOwner`
128 pub(crate) fn from_named( 128 fn from_named(
129 db: &RootDatabase, 129 db: &RootDatabase,
130 node: InFile<&dyn ast::NameOwner>, 130 node: InFile<&dyn ast::NameOwner>,
131 docs: Option<String>, 131 docs: Option<String>,
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index 4757d8e22..1e7d0621a 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -145,25 +145,25 @@ fn extend_tokens_from_range(
145 let src = db.parse_or_expand(expanded.file_id)?; 145 let src = db.parse_or_expand(expanded.file_id)?;
146 let parent = shallowest_node(&find_covering_element(&src, expanded.value))?.parent()?; 146 let parent = shallowest_node(&find_covering_element(&src, expanded.value))?.parent()?;
147 147
148 let validate = |token: SyntaxToken| { 148 let validate = |token: &SyntaxToken| {
149 let node = descend_into_macros(db, file_id, token.clone()); 149 let node = descend_into_macros(db, file_id, token.clone());
150 if node.file_id == expanded.file_id 150 node.file_id == expanded.file_id
151 && node.value.text_range().is_subrange(&parent.text_range()) 151 && node.value.text_range().is_subrange(&parent.text_range())
152 {
153 Some(token)
154 } else {
155 None
156 }
157 }; 152 };
158 153
159 // Find the first and last text range under expanded parent 154 // Find the first and last text range under expanded parent
160 let first = successors(Some(first_token), |token| { 155 let first = successors(Some(first_token), |token| {
161 validate(skip_whitespace(token.prev_token()?, Direction::Prev)?) 156 let token = token.prev_token()?;
157 skip_whitespace(token, Direction::Prev)
162 }) 158 })
159 .take_while(validate)
163 .last()?; 160 .last()?;
161
164 let last = successors(Some(last_token), |token| { 162 let last = successors(Some(last_token), |token| {
165 validate(skip_whitespace(token.next_token()?, Direction::Next)?) 163 let token = token.next_token()?;
164 skip_whitespace(token, Direction::Next)
166 }) 165 })
166 .take_while(validate)
167 .last()?; 167 .last()?;
168 168
169 let range = union_range(first.text_range(), last.text_range()); 169 let range = union_range(first.text_range(), last.text_range());
@@ -334,10 +334,12 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment {
334 334
335#[cfg(test)] 335#[cfg(test)]
336mod tests { 336mod tests {
337 use super::*;
338 use crate::mock_analysis::single_file;
339 use test_utils::extract_offset; 337 use test_utils::extract_offset;
340 338
339 use crate::mock_analysis::single_file;
340
341 use super::*;
342
341 fn do_check(before: &str, afters: &[&str]) { 343 fn do_check(before: &str, afters: &[&str]) {
342 let (cursor, before) = extract_offset(before); 344 let (cursor, before) = extract_offset(before);
343 let (analysis, file_id) = single_file(&before); 345 let (analysis, file_id) = single_file(&before);
diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs
index 01fb32b3d..7d70dab9c 100644
--- a/crates/ra_ide/src/join_lines.rs
+++ b/crates/ra_ide/src/join_lines.rs
@@ -228,6 +228,31 @@ fn foo() {
228 } 228 }
229 229
230 #[test] 230 #[test]
231 fn test_join_lines_diverging_block() {
232 let before = r"
233 fn foo() {
234 loop {
235 match x {
236 92 => <|>{
237 continue;
238 }
239 }
240 }
241 }
242 ";
243 let after = r"
244 fn foo() {
245 loop {
246 match x {
247 92 => <|>continue,
248 }
249 }
250 }
251 ";
252 check_join_lines(before, after);
253 }
254
255 #[test]
231 fn join_lines_adds_comma_for_block_in_match_arm() { 256 fn join_lines_adds_comma_for_block_in_match_arm() {
232 check_join_lines( 257 check_join_lines(
233 r" 258 r"
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index f86f98be7..82e10bc7e 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -75,7 +75,7 @@ pub use crate::{
75 runnables::{Runnable, RunnableKind, TestId}, 75 runnables::{Runnable, RunnableKind, TestId},
76 source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, 76 source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
77 ssr::SsrError, 77 ssr::SsrError,
78 syntax_highlighting::HighlightedRange, 78 syntax_highlighting::{tags, HighlightedRange},
79}; 79};
80 80
81pub use hir::Documentation; 81pub use hir::Documentation;
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index d873f153e..812229b4e 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -17,32 +17,32 @@ use crate::{
17}; 17};
18 18
19pub mod tags { 19pub mod tags {
20 pub(crate) const FIELD: &str = "field"; 20 pub const FIELD: &str = "field";
21 pub(crate) const FUNCTION: &str = "function"; 21 pub const FUNCTION: &str = "function";
22 pub(crate) const MODULE: &str = "module"; 22 pub const MODULE: &str = "module";
23 pub(crate) const CONSTANT: &str = "constant"; 23 pub const CONSTANT: &str = "constant";
24 pub(crate) const MACRO: &str = "macro"; 24 pub const MACRO: &str = "macro";
25 25
26 pub(crate) const VARIABLE: &str = "variable"; 26 pub const VARIABLE: &str = "variable";
27 pub(crate) const VARIABLE_MUT: &str = "variable.mut"; 27 pub const VARIABLE_MUT: &str = "variable.mut";
28 28
29 pub(crate) const TYPE: &str = "type"; 29 pub const TYPE: &str = "type";
30 pub(crate) const TYPE_BUILTIN: &str = "type.builtin"; 30 pub const TYPE_BUILTIN: &str = "type.builtin";
31 pub(crate) const TYPE_SELF: &str = "type.self"; 31 pub const TYPE_SELF: &str = "type.self";
32 pub(crate) const TYPE_PARAM: &str = "type.param"; 32 pub const TYPE_PARAM: &str = "type.param";
33 pub(crate) const TYPE_LIFETIME: &str = "type.lifetime"; 33 pub const TYPE_LIFETIME: &str = "type.lifetime";
34 34
35 pub(crate) const LITERAL_BYTE: &str = "literal.byte"; 35 pub const LITERAL_BYTE: &str = "literal.byte";
36 pub(crate) const LITERAL_NUMERIC: &str = "literal.numeric"; 36 pub const LITERAL_NUMERIC: &str = "literal.numeric";
37 pub(crate) const LITERAL_CHAR: &str = "literal.char"; 37 pub const LITERAL_CHAR: &str = "literal.char";
38 38
39 pub(crate) const LITERAL_COMMENT: &str = "comment"; 39 pub const LITERAL_COMMENT: &str = "comment";
40 pub(crate) const LITERAL_STRING: &str = "string"; 40 pub const LITERAL_STRING: &str = "string";
41 pub(crate) const LITERAL_ATTRIBUTE: &str = "attribute"; 41 pub const LITERAL_ATTRIBUTE: &str = "attribute";
42 42
43 pub(crate) const KEYWORD: &str = "keyword"; 43 pub const KEYWORD: &str = "keyword";
44 pub(crate) const KEYWORD_UNSAFE: &str = "keyword.unsafe"; 44 pub const KEYWORD_UNSAFE: &str = "keyword.unsafe";
45 pub(crate) const KEYWORD_CONTROL: &str = "keyword.control"; 45 pub const KEYWORD_CONTROL: &str = "keyword.control";
46} 46}
47 47
48#[derive(Debug)] 48#[derive(Debug)]