diff options
author | Adolfo OchagavĂa <[email protected]> | 2018-10-12 07:59:12 +0100 |
---|---|---|
committer | Adolfo OchagavĂa <[email protected]> | 2018-10-12 07:59:12 +0100 |
commit | ee0a6bf0535a5a6c7e536d2cffa11959c3ee2ae3 (patch) | |
tree | 51ae5f73f3069769cf8d87f5d3d3e500408930fd | |
parent | 2ba6f18586d02a6dbc32e0bea88f7b4236277ea1 (diff) |
Fold multiline comments
-rw-r--r-- | crates/ra_editor/src/folding_ranges.rs | 38 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 4 |
2 files changed, 21 insertions, 21 deletions
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index 3aabd54ae..1d89ac853 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs | |||
@@ -1,6 +1,8 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | 2 | ||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | ast, | ||
5 | AstNode, | ||
4 | File, TextRange, SyntaxNodeRef, | 6 | File, TextRange, SyntaxNodeRef, |
5 | SyntaxKind, | 7 | SyntaxKind, |
6 | Direction, | 8 | Direction, |
@@ -27,27 +29,25 @@ pub fn folding_ranges(file: &File) -> Vec<Fold> { | |||
27 | continue; | 29 | continue; |
28 | } | 30 | } |
29 | 31 | ||
30 | let range_and_kind = match node.kind() { | 32 | if let Some(comment) = ast::Comment::cast(node) { |
31 | SyntaxKind::COMMENT => ( | 33 | // Multiline comments (`/* ... */`) can only be folded if they span multiple lines |
32 | contiguous_range_for(SyntaxKind::COMMENT, node, &mut visited), | 34 | let range = if let ast::CommentFlavor::Multiline = comment.flavor() { |
33 | Some(FoldKind::Comment), | 35 | if comment.text().contains('\n') { |
34 | ), | 36 | Some(comment.syntax().range()) |
35 | SyntaxKind::USE_ITEM => ( | 37 | } else { |
36 | contiguous_range_for(SyntaxKind::USE_ITEM, node, &mut visited), | 38 | None |
37 | Some(FoldKind::Imports), | 39 | } |
38 | ), | 40 | } else { |
39 | _ => (None, None), | 41 | contiguous_range_for(SyntaxKind::COMMENT, node, &mut visited) |
40 | }; | 42 | }; |
41 | 43 | ||
42 | match range_and_kind { | 44 | range.map(|range| res.push(Fold { range, kind: FoldKind::Comment })); |
43 | (Some(range), Some(kind)) => { | ||
44 | res.push(Fold { | ||
45 | range: range, | ||
46 | kind: kind | ||
47 | }); | ||
48 | } | ||
49 | _ => {} | ||
50 | } | 45 | } |
46 | |||
47 | if let SyntaxKind::USE_ITEM = node.kind() { | ||
48 | contiguous_range_for(SyntaxKind::USE_ITEM, node, &mut visited) | ||
49 | .map(|range| res.push(Fold { range, kind: FoldKind::Imports})); | ||
50 | }; | ||
51 | } | 51 | } |
52 | 52 | ||
53 | res | 53 | res |
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index ff8f23c7a..d1c525f68 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -20,8 +20,8 @@ export function activate(context: vscode.ExtensionContext) { | |||
20 | f: (...args: any[]) => Promise<boolean> | 20 | f: (...args: any[]) => Promise<boolean> |
21 | ) { | 21 | ) { |
22 | const defaultCmd = `default:${name}`; | 22 | const defaultCmd = `default:${name}`; |
23 | const original = async (...args: any[]) => | 23 | const original = (...args: any[]) => |
24 | await vscode.commands.executeCommand(defaultCmd, ...args); | 24 | vscode.commands.executeCommand(defaultCmd, ...args); |
25 | 25 | ||
26 | registerCommand(name, async (...args: any[]) => { | 26 | registerCommand(name, async (...args: any[]) => { |
27 | const editor = vscode.window.activeTextEditor; | 27 | const editor = vscode.window.activeTextEditor; |