From f551e50c16d189a724885ce5f208595a31af49cc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 24 Feb 2020 17:17:05 +0100 Subject: When joining lines, unwrap trivial diverging blocks --- crates/ra_ide/src/join_lines.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'crates/ra_ide/src') 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 @@ -227,6 +227,31 @@ fn foo() { ); } + #[test] + fn test_join_lines_diverging_block() { + let before = r" + fn foo() { + loop { + match x { + 92 => <|>{ + continue; + } + } + } + } + "; + let after = r" + fn foo() { + loop { + match x { + 92 => <|>continue, + } + } + } + "; + check_join_lines(before, after); + } + #[test] fn join_lines_adds_comma_for_block_in_match_arm() { check_join_lines( -- cgit v1.2.3 From 9f0cfb7ad2120514ca8ffd21e08e3ddd0bfb34e9 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Fri, 14 Feb 2020 17:56:28 -0500 Subject: Teach the server about Semantic Tokens proposed LSP --- crates/ra_ide/src/lib.rs | 2 +- crates/ra_ide/src/syntax_highlighting.rs | 52 ++++++++++++++++---------------- 2 files changed, 27 insertions(+), 27 deletions(-) (limited to 'crates/ra_ide/src') 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::{ runnables::{Runnable, RunnableKind, TestId}, source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, ssr::SsrError, - syntax_highlighting::HighlightedRange, + syntax_highlighting::{tags, HighlightedRange}, }; pub 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::{ }; pub mod tags { - pub(crate) const FIELD: &str = "field"; - pub(crate) const FUNCTION: &str = "function"; - pub(crate) const MODULE: &str = "module"; - pub(crate) const CONSTANT: &str = "constant"; - pub(crate) const MACRO: &str = "macro"; - - pub(crate) const VARIABLE: &str = "variable"; - pub(crate) const VARIABLE_MUT: &str = "variable.mut"; - - pub(crate) const TYPE: &str = "type"; - pub(crate) const TYPE_BUILTIN: &str = "type.builtin"; - pub(crate) const TYPE_SELF: &str = "type.self"; - pub(crate) const TYPE_PARAM: &str = "type.param"; - pub(crate) const TYPE_LIFETIME: &str = "type.lifetime"; - - pub(crate) const LITERAL_BYTE: &str = "literal.byte"; - pub(crate) const LITERAL_NUMERIC: &str = "literal.numeric"; - pub(crate) const LITERAL_CHAR: &str = "literal.char"; - - pub(crate) const LITERAL_COMMENT: &str = "comment"; - pub(crate) const LITERAL_STRING: &str = "string"; - pub(crate) const LITERAL_ATTRIBUTE: &str = "attribute"; - - pub(crate) const KEYWORD: &str = "keyword"; - pub(crate) const KEYWORD_UNSAFE: &str = "keyword.unsafe"; - pub(crate) const KEYWORD_CONTROL: &str = "keyword.control"; + pub const FIELD: &str = "field"; + pub const FUNCTION: &str = "function"; + pub const MODULE: &str = "module"; + pub const CONSTANT: &str = "constant"; + pub const MACRO: &str = "macro"; + + pub const VARIABLE: &str = "variable"; + pub const VARIABLE_MUT: &str = "variable.mut"; + + pub const TYPE: &str = "type"; + pub const TYPE_BUILTIN: &str = "type.builtin"; + pub const TYPE_SELF: &str = "type.self"; + pub const TYPE_PARAM: &str = "type.param"; + pub const TYPE_LIFETIME: &str = "type.lifetime"; + + pub const LITERAL_BYTE: &str = "literal.byte"; + pub const LITERAL_NUMERIC: &str = "literal.numeric"; + pub const LITERAL_CHAR: &str = "literal.char"; + + pub const LITERAL_COMMENT: &str = "comment"; + pub const LITERAL_STRING: &str = "string"; + pub const LITERAL_ATTRIBUTE: &str = "attribute"; + + pub const KEYWORD: &str = "keyword"; + pub const KEYWORD_UNSAFE: &str = "keyword.unsafe"; + pub const KEYWORD_CONTROL: &str = "keyword.control"; } #[derive(Debug)] -- cgit v1.2.3 From 6542ab89ceb32d6ec108a28ad9d938d24762c029 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 25 Feb 2020 13:49:34 +0100 Subject: Simplify --- crates/ra_ide/src/call_hierarchy.rs | 20 ++++++-------------- crates/ra_ide/src/display/navigation_target.rs | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) (limited to 'crates/ra_ide/src') 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; use hir::db::AstDatabase; use ra_ide_db::RootDatabase; -use ra_syntax::{ - ast::{self, DocCommentsOwner}, - match_ast, AstNode, TextRange, -}; +use ra_syntax::{ast, match_ast, AstNode, TextRange}; use crate::{ - call_info::FnCallNode, - display::{ShortLabel, ToNav}, - expand::descend_into_macros, - goto_definition, references, FilePosition, NavigationTarget, RangeInfo, + call_info::FnCallNode, display::ToNav, expand::descend_into_macros, goto_definition, + references, FilePosition, NavigationTarget, RangeInfo, }; #[derive(Debug, Clone)] @@ -49,6 +44,7 @@ pub(crate) fn incoming_calls(db: &RootDatabase, position: FilePosition) -> Optio let refs = references::find_all_refs(db, position, None)?; let mut calls = CallLocations::default(); + let mut sb = hir::SourceBinder::new(db); for reference in refs.info.references() { let file_id = reference.file_range.file_id; @@ -62,12 +58,8 @@ pub(crate) fn incoming_calls(db: &RootDatabase, position: FilePosition) -> Optio match_ast! { match node { ast::FnDef(it) => { - Some(NavigationTarget::from_named( - db, - token.with_value(&it), - it.doc_comment_text(), - it.short_label(), - )) + let def = sb.to_def(token.with_value(it))?; + Some(def.to_nav(sb.db)) }, _ => { None }, } 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 { } /// Allows `NavigationTarget` to be created from a `NameOwner` - pub(crate) fn from_named( + fn from_named( db: &RootDatabase, node: InFile<&dyn ast::NameOwner>, docs: Option, -- cgit v1.2.3 From d7da42bd402aedb167bfb33aec7ce61279716ff7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 25 Feb 2020 14:59:13 +0100 Subject: Simplify --- crates/ra_ide/src/extend_selection.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'crates/ra_ide/src') 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( let src = db.parse_or_expand(expanded.file_id)?; let parent = shallowest_node(&find_covering_element(&src, expanded.value))?.parent()?; - let validate = |token: SyntaxToken| { + let validate = |token: &SyntaxToken| { let node = descend_into_macros(db, file_id, token.clone()); - if node.file_id == expanded.file_id + node.file_id == expanded.file_id && node.value.text_range().is_subrange(&parent.text_range()) - { - Some(token) - } else { - None - } }; // Find the first and last text range under expanded parent let first = successors(Some(first_token), |token| { - validate(skip_whitespace(token.prev_token()?, Direction::Prev)?) + let token = token.prev_token()?; + skip_whitespace(token, Direction::Prev) }) + .take_while(validate) .last()?; + let last = successors(Some(last_token), |token| { - validate(skip_whitespace(token.next_token()?, Direction::Next)?) + let token = token.next_token()?; + skip_whitespace(token, Direction::Next) }) + .take_while(validate) .last()?; let range = union_range(first.text_range(), last.text_range()); @@ -334,10 +334,12 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment { #[cfg(test)] mod tests { - use super::*; - use crate::mock_analysis::single_file; use test_utils::extract_offset; + use crate::mock_analysis::single_file; + + use super::*; + fn do_check(before: &str, afters: &[&str]) { let (cursor, before) = extract_offset(before); let (analysis, file_id) = single_file(&before); -- cgit v1.2.3