Collapse only methods

Answered

Hi,

I think it would be nice to have a menu option and/or keyboard shortcut to collapse only the methods (or any other hierarchy level) in an open file, so as to see clearly and easily navigate a neat list of the uppermost elements that form a class.

As of today, you can collapse everything at certain predefined levels, which would of course include methods, but doing so also recursively collapses everything inside the methods themselves, which forces you to manually unfold any conditionals, etc. inside the method once you unfold it.

4
10 comments

Hi, 

If I've understood you correctly, 'Expand Recursively' action may help. Put cursor on the method and press 'Ctrl+Alt+NumPad Plus'(Visual Studio keymap) to expand the method and everything inside of it. More info on folding actions in Rider: https://www.jetbrains.com/help/rider/2017.1/Code_Folding.html

Hope it helps,

Julia

0
Avatar
Permanently deleted user

That does help! I hadn't tried putting the cursor on the method, I just pressed the keyboard shortcut and everything in the file collpased. Thanks Julia.

0

You are welcome!

0

Please add an easier version of this. I want to be able to expand all methods recursively 

1

vs code has fold level 1, intellij does not have

0

Serkanozel380,

Please take a look at the new Rider docs on folding code elements: https://www.jetbrains.com/help/rider/Code_Folding.html#folding_menu. We have added new actions there. Does any of them suits you? If not, could you please provide a code example with expected and actual results after you expand it?

 

0

Julia Vaseva let me elaborate more:

Think about this code (typescript, language does not matter at all)

let bar: boolean;

function add(a: number, b: number) {

if (a > b) {

console.log('a is bigger')

} else if (a == b) {

console.log('a is equal to b')

} else {

console.log('b is bigger')

}

return a + b;

}

function add2(a: number, b: number) {

if (a > b) {

console.log('a is bigger')

} else if (a == b) {

console.log('a is equal to b')

} else {

console.log('b is bigger')

}

return a + b;

}

 

after vscode's fold level 1

 

let bar: boolean;

function add(a: number, b: number) {

(folded)

}

function add2(a: number, b: number) {

(folded)

}
and if I expand one of the functions, if blocks are not folded which is great:
let bar: boolean;

function add(a: number, b: number) {

if (a > b) {

console.log('a is bigger')

} else if (a == b) {

console.log('a is equal to b')

} else {

console.log('b is bigger')

}

return a + b;

}

function add2(a: number, b: number) {

(folded)

}
 
If I used jetbrains's "collapse all", then "expand all to level 1"; the if blocks would be folded. And this is not so great user experience.
 
 
Please notice what's desired:
 
Fold every top level block and nothing inside them.
Fold all of them at once.
 

 

1

Serkanozel380,

For C# Rider has a nice action named `Collapse to definitions` (Code -> Folding -> Collapse to Definitions), which collapses methods, but not their contents. To expand all of them back, use `Expand all` action. Unfortunately, other languages doesn't support it. Here is the feature request for other languages: https://youtrack.jetbrains.com/issue/IDEA-231351. Please feel free to add a comment and upvote.

2

Julia Vaseva

Here is an example of code from VueJs

export default {
data() {
return {....}
),
computed: {
...mapState(...)
}
methods: { // collapse only method1/2/3/4 but not the content of the methods
method1() {},
method2() {},
method3() {},
method4() {},
}
}

I would like to be able to collapse to level 1 so that only the methods in "methods" are collapsed, without the loops and conditions being collapsed when I open a method.

A bit like PHP's collapse which only collapses the method but not the contents of the method when the method is opened.

1

Jeremy

Thank you for the code example. I have added it as an internal comment to IDEA-231351 feature request so that the developers team can see it. Please upvote the issue in order to demonstrate additional interest and bring increased awareness to the issue.

0

Please sign in to leave a comment.