From a1c8bdecfd408b7573357604f9c6543556f3f19a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 4 Dec 2020 15:51:23 +0100 Subject: Use items can also have doc comments --- crates/ide/src/folding_ranges.rs | 13 ++++++------- crates/syntax/src/ast/node_ext.rs | 1 + crates/syntax/src/parsing/text_tree_sink.rs | 2 +- .../test_data/parser/inline/ok/0002_use_tree_list.rast | 18 +++++++++--------- .../test_data/parser/inline/ok/0110_use_path.rast | 12 ++++++------ 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 7523aec55..45170dd29 100644 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -83,7 +83,6 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { fn fold_kind(kind: SyntaxKind) -> Option { match kind { COMMENT => Some(FoldKind::Comment), - USE => Some(FoldKind::Imports), ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), ASSOC_ITEM_LIST | RECORD_FIELD_LIST @@ -258,11 +257,11 @@ fn main() { fn test_fold_imports() { check( r#" -use std::{ +use std::{ str, vec, io as iop -}; +}; fn main() { }"#, @@ -306,9 +305,9 @@ use std::io as iop; use std::mem; use std::f64; -use std::collections::HashMap; +use std::collections::HashMap; // Some random comment -use std::collections::VecDeque; +use std::collections::VecDeque; fn main() { }"#, @@ -326,10 +325,10 @@ use std::io as iop; use std::mem; use std::f64; -use std::collections::{ +use std::collections::{ HashMap, VecDeque, -}; +}; // Some random comment fn main() { diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index b70b840b8..aa3a4b606 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -477,3 +477,4 @@ impl ast::DocCommentsOwner for ast::Const {} impl ast::DocCommentsOwner for ast::TypeAlias {} impl ast::DocCommentsOwner for ast::Impl {} impl ast::DocCommentsOwner for ast::MacroCall {} +impl ast::DocCommentsOwner for ast::Use {} diff --git a/crates/syntax/src/parsing/text_tree_sink.rs b/crates/syntax/src/parsing/text_tree_sink.rs index 997bc5d28..49842177a 100644 --- a/crates/syntax/src/parsing/text_tree_sink.rs +++ b/crates/syntax/src/parsing/text_tree_sink.rs @@ -148,7 +148,7 @@ fn n_attached_trivias<'a>( ) -> usize { match kind { MACRO_CALL | CONST | TYPE_ALIAS | STRUCT | ENUM | VARIANT | FN | TRAIT | MODULE - | RECORD_FIELD | STATIC => { + | RECORD_FIELD | STATIC | USE => { let mut res = 0; let mut trivias = trivias.enumerate().peekable(); diff --git a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast index 1e80dd7e2..b1fb75ed1 100644 --- a/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast +++ b/crates/syntax/test_data/parser/inline/ok/0002_use_tree_list.rast @@ -49,9 +49,9 @@ SOURCE_FILE@0..249 R_CURLY@56..57 "}" SEMICOLON@57..58 ";" WHITESPACE@58..59 " " - COMMENT@59..97 "// Rust 2018 (with a ..." - WHITESPACE@97..98 "\n" - USE@98..121 + USE@59..121 + COMMENT@59..97 "// Rust 2018 (with a ..." + WHITESPACE@97..98 "\n" USE_KW@98..101 "use" WHITESPACE@101..102 " " USE_TREE@102..120 @@ -75,9 +75,9 @@ SOURCE_FILE@0..249 R_CURLY@119..120 "}" SEMICOLON@120..121 ";" WHITESPACE@121..122 " " - COMMENT@122..134 "// Rust 2015" - WHITESPACE@134..135 "\n" - USE@135..166 + USE@122..166 + COMMENT@122..134 "// Rust 2015" + WHITESPACE@134..135 "\n" USE_KW@135..138 "use" WHITESPACE@138..139 " " USE_TREE@139..165 @@ -102,9 +102,9 @@ SOURCE_FILE@0..249 R_CURLY@164..165 "}" SEMICOLON@165..166 ";" WHITESPACE@166..167 " " - COMMENT@167..179 "// Rust 2015" - WHITESPACE@179..180 "\n" - USE@180..205 + USE@167..205 + COMMENT@167..179 "// Rust 2015" + WHITESPACE@179..180 "\n" USE_KW@180..183 "use" WHITESPACE@183..184 " " USE_TREE@184..204 diff --git a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast b/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast index 82028096f..c9fad5f8c 100644 --- a/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast +++ b/crates/syntax/test_data/parser/inline/ok/0110_use_path.rast @@ -10,9 +10,9 @@ SOURCE_FILE@0..154 IDENT@6..16 "crate_name" SEMICOLON@16..17 ";" WHITESPACE@17..18 " " - COMMENT@18..45 "// Rust 2018 - All fl ..." - WHITESPACE@45..46 "\n" - USE@46..61 + USE@18..61 + COMMENT@18..45 "// Rust 2018 - All fl ..." + WHITESPACE@45..46 "\n" USE_KW@46..49 "use" WHITESPACE@49..50 " " USE_TREE@50..60 @@ -22,9 +22,9 @@ SOURCE_FILE@0..154 IDENT@50..60 "crate_name" SEMICOLON@60..61 ";" WHITESPACE@61..62 " " - COMMENT@62..91 "// Rust 2018 - Anchor ..." - WHITESPACE@91..92 "\n" - USE@92..124 + USE@62..124 + COMMENT@62..91 "// Rust 2018 - Anchor ..." + WHITESPACE@91..92 "\n" USE_KW@92..95 "use" WHITESPACE@95..96 " " USE_TREE@96..123 -- cgit v1.2.3