Skip to content

Code folding didn't work as expected in directives and block comment #407

Closed

Description

@LeThiHyVong

In my code there are many places look like this

#if SOME_CONST_EXP
;//       some code
#else
      // some code
#endif

or

if SOME_CONST_EXP
;//      some code
#endif


or

/*************************************
//
//
//
//
*************************************/

EDIT (Bob Brown (@bobbrow)): (inserting request for folding on multiple consecutive single-line comments from #1443)

// Comment
// Comment
// Comment
// Comment

The code folding only work correctly between #else and #endif.
From #if to next directive (#else in 1st case or #endif in 2nd case), if all line is started with ';//', the code folding didn't work.
From #endif to next directive, it automatically group the code outside the directive for all time.
The coding folder didn't work for 3rd, too.

codefolding

System spec:

  • Windows 7 SP1 x86
  • VSCode 1.7.2
  • Plugin 0.9.3

Please correct this.

Activity

  1. changed the title [-]No code folding after #if directive and incorrect folding after #endif[/-] [+]Code folding didn't work as expected in directives and block comment[/+] on Dec 13, 2016
  2. sean-mcmanus commented on Dec 14, 2016

    @sean-mcmanus
    Contributor

    Yes, the code folding is buggy, but it's not a bug with the C/C++ extension. We don't implement any code folding. Can you move this to the vscode team?

  3. sean-mcmanus commented on Dec 15, 2016

    @sean-mcmanus
    Contributor

    Actually, it sounds like the folding behavior you are seeing is "by design". The fixing of this is being tracked at microsoft/vscode#3422 . VS Code implements the folding behavior and there isn't an API yet to allow language-aware folding.

  4. LeThiHyVong commented on Apr 19, 2018

    @LeThiHyVong
    Author

    According to microsoft/vscode#3422 (comment), please re-open this issue.
    Thanks.

  5. hoffmael commented on Jun 1, 2018

    @hoffmael

    This would be a great feature and bug fix to have and essential for the code base I work on which relies on many preprocessor switches to support multiple builds. Diming the inactive code with "C_Cpp.dimInactiveRegions": true is a good first step, but having the ability to collapse and hide the inactive code region altogether is even better.
    Eclipse even has the option to collapse inactive regions by default when opening a file by default.

    Here's a screenshot from 0.17.4 showing the various issues with folding currently.
    image

  6. sean-mcmanus commented on Jun 11, 2018

    @sean-mcmanus
    Contributor

    +1 I hit this issue sometimes with our cross platform code.

  7. intijk commented on Aug 30, 2018

    @intijk

    C++ folding without supporting this feature basically is useless for cross platform project.

  8. Flamefire commented on Sep 3, 2018

    @Flamefire

    hoffmael Great example why this is required. I ran into pretty much the same thing. What is even worse: It breaks folding of whole namespaces making that completely useless.

    Note why this breaks (microsoft/vscode#57696 (comment)):

    The folding strategy that you are seeing is based purely on the indentation of lines. A folding region starts when a line has a smaller indent than one or more following lines and ends when there is a line with the same or smaller indent.

  9. added this to the On Deck milestone on Sep 4, 2018
  10. 47 remaining items

  11. sean-mcmanus commented on May 8, 2020

    @sean-mcmanus
    Contributor

    A C_Cpp.codeFolding ("Enabled"/"Disabled") setting has been added for 0.28.0 (not released yet): #5435 .

    There is no ETA on when the blocking issues are going to be fixed.

  12. KaeLL commented on May 13, 2020

    @KaeLL

    Accurate C++ code folding is available in https://github.com/microsoft/vscode-cpptools/releases/tag/0.28.0-insiders2 . Let us know if anyone find any issues with it.

    Ok. I understand that this issue is actually an umbrella for a lot of small issues related to how C/C++ code should be folded. I also believe the following problem, which are different issues about the same problem, indentation folding, is the most prominent of the bunch:
    #1584
    #2116
    #3589
    microsoft/vscode#57696

    I just checked, it's still not fixed, and indentation-based folding is still at play here, so I'm not sure what you mean by "Accurate"?

    code

  13. akbyrd commented on May 13, 2020

    @akbyrd

    It's only in the insiders build of the plugin. If you follow the link it has instructions for enabling the insiders branch of the cpp plugin.

  14. KaeLL commented on May 13, 2020

    @KaeLL

    It's only in the insiders build of the plugin. If you follow the link it has instructions for enabling the insiders branch of the cpp plugin.

    settings

    Here's the link to my settings.json file backup I update every time I change something in case you think I just added this setting. It's been enabled for quite a while.
    https://pastebin.com/txMGa5Et

  15. elahehrashedi commented on May 13, 2020

    @elahehrashedi
    Contributor
  16. sean-mcmanus commented on May 15, 2020

    @sean-mcmanus
    Contributor

    Pedro (@KaeLL) Are you still reproing those issues with 0.28.0? I'm not able to repro those issues. Could you file a new issue with more repro details?

    image

  17. sean-mcmanus commented on May 15, 2020

    @sean-mcmanus
    Contributor

    mc (@ret394) Pedro (@KaeLL) Yeah, our extension doesn't process unsaved files, so it'll fall back to use the previous code folding behavior provided by VS. You can upvote the unsaved file issue at #3343 .

  18. KaeLL commented on May 15, 2020

    @KaeLL

    The file was saved, for heaven's sake.
    Open VS, open a new file, write that code, save it as trash.c, and there'll be no collapse arrow for the curly brackets (the main function block of code), only the individual preprocessor directives.
    Indent the directives by 1 tab, and the collapse arrow shows up for the curly brackets and disappear for the directives, proving it's still indentation based folding. I'm using the 0.28.0 version of the extension, with the 1.45.1 version of VSCode on Clear Linux.
    Here's my settings.json

    {
    	"editor.fontFamily": "'Cascadia Code', 'Source Code Pro Medium', 'Ubuntu Mono', 'Cascadia Mono'",
    	"editor.fontSize": 16,
    	"editor.accessibilitySupport": "off",
    	"editor.wordWrap": "on",
    	"editor.renderControlCharacters": true,
    	"editor.renderWhitespace": "all",
    	"editor.smoothScrolling": true,
    	"editor.fontLigatures": true,
    	"editor.cursorSmoothCaretAnimation": true,
    	"editor.minimap.enabled": false,
    	"editor.quickSuggestionsDelay": 0,
    	"editor.renderLineHighlight": "all",
    
    	"[c]": {
    		"editor.wordWrapColumn": 8000,
    		"editor.acceptSuggestionOnEnter": "off",
    		"editor.detectIndentation": false,
    		"editor.dragAndDrop": false,
    		"editor.emptySelectionClipboard": false,
    		"editor.insertSpaces": false,
    		"editor.showFoldingControls": "always",
    		"editor.wordBasedSuggestions": false,
    		"editor.acceptSuggestionOnCommitCharacter": false,
    		"editor.autoClosingBrackets": "beforeWhitespace",
    		"editor.autoClosingQuotes": "beforeWhitespace",
    		"editor.autoSurround": "brackets",
    		"editor.copyWithSyntaxHighlighting": false,
    		// "editor.defaultFormatter": "ms-vscode.cpptools",
    		"editor.foldingStrategy": "indentation",
    		// "editor.formatOnType": true,
    		"editor.largeFileOptimizations": false,
    	},
    
    	"files.enableTrash": false,
    	// "files.insertFinalNewline": true,
    	"files.trimFinalNewlines": true,
    	"files.trimTrailingWhitespace": true,
    	"files.hotExit": "off",
    	// "files.watcherExclude": {
    	// //	"**/.**":true
    	// 	"**/*.old/**":true,
    	// },
    	// "search.exclude": {
    	// 	"**/*.old/**":true,
    	// 	"**/[.]":true,
    	// 	"**/esp-idf/**":true
    	// },
    
    	"workbench.editor.enablePreview": false,
    	"workbench.editor.enablePreviewFromQuickOpen": false,
    	"workbench.editor.highlightModifiedTabs": true,
    	"workbench.settings.editor": "json",
    	"workbench.settings.useSplitJSON": true,
    	"workbench.settings.openDefaultSettings": true,
    	"workbench.colorTheme": "Default High Contrast",
    	"workbench.colorCustomizations": {
    		// "editorWhitespace.foreground": "#000000a0",
    		"editorWhitespace.foreground": "#ffffff50",
    		// "editor.selectionBackground": "#ffffffc2",
    		// "editor.selectionHighlightBackground": "#00000000"
    	},
    
    	"window.menuBarVisibility": "toggle",
    	"terminal.integrated.fontFamily": "'Cascadia Mono', 'Source Code Pro Medium', 'Ubuntu Mono'",
    	"terminal.integrated.cursorBlinking": true,
    	"terminal.integrated.cursorStyle": "line",
    	"terminal.integrated.fontSize": 16,
    	"terminal.integrated.scrollback": 18446744073709551615,
    
    	"C_Cpp.clang_format_path": "/usr/bin/clang-format",
    
    	"C_Cpp.experimentalFeatures": "Enabled",
    	"C_Cpp.updateChannel": "Insiders",
    	"C_Cpp.loggingLevel": "Information",
    
    	"diffEditor.ignoreTrimWhitespace": false,
    	"breadcrumbs.enabled": true,
    	"breadcrumbs.symbolSortOrder": "type",
    	"files.associations": {
    		"*.h": "c"
    	},
    	"window.zoomLevel": 0,
    	"C_Cpp.autoAddFileAssociations": false,
    	"C_Cpp.clang_format_sortIncludes": false,
    	"C_Cpp.default.browse.limitSymbolsToIncludedHeaders": false,
    	"C_Cpp.default.cppStandard": "c++20",
    	"C_Cpp.default.cStandard": "c11",
    	"C_Cpp.default.intelliSenseMode": "gcc-x64",
    	"C_Cpp.suggestSnippets": false,
    	"C_Cpp.vcpkg.enabled": false,
    }
    

    I have nothing more to add. The issue exists, but if it's happening only to me, then it's not happening and it's fixed for all intents and purposes, and I no longer care enough to pursue to the end. Might as well close the thread. Good day.

  19. sean-mcmanus commented on May 16, 2020

    @sean-mcmanus
    Contributor

    Pedro (@KaeLL) It's caused by your setting "editor.foldingStrategy": "indentation". The issue should be fixed if you remove that.

  20. yuchongbo commented on May 16, 2020

    @yuchongbo

    I tried using the .28 version cpp extension, vscode version 1.45.1 and found an interesting thing.
    the case block cannot be folded in [switch] statement in an exist .cpp file, but when I copied the same content to a new created cpp file, case block folding works!
    switch_case_folding

  21. akbyrd commented on May 16, 2020

    @akbyrd

    VS Code seems to cache the folding regions of files. When you open a folder or workspace it saves your open files and some other state. I think folding is part of that state. I haven't played around with it enough to know how to reliably reset that state. Maybe editing the file? Closing all files and clearing editor history? Just a thought.

  22. sean-mcmanus commented on May 18, 2020

    @sean-mcmanus
    Contributor

    yuchongbo The case folding is being tracked by #5523 . The fact that it starts working when it's copied to unsaved/new file is due to the fact that our extension only works on "file"-based URIs (and not the "untitled" URI scheme), which is tracked by #3343 .

  23. locked and limited conversation to collaborators on Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Feature RequestLanguage ServicefixedCheck the Milestone for the release in which the fix is or will be available.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions