-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code folding didn't work as expected in directives and block comment #407
Comments
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? |
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. |
According to microsoft/vscode#3422 (comment), please re-open this issue. |
+1 I hit this issue sometimes with our cross platform code. |
C++ folding without supporting this feature basically is useless for cross platform project. |
@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)):
|
This is a big enough daily nuisance that I started looking at doing it myself, but it looks like most of the language server functionality is bundled up into binaries that get downloaded: Any guidance on whether it's possible to get any sort of scope or AST information out of the language server in spite of this? |
@akbyrd The code for the Microsoft.VSCode.CPP processes is closed source and there's no way to get any AST info (i.e. so you'd need to be a Microsoft employee or contractor). I think we just need to respond to the textDocuent/foldingRange request and run our lexer to compute the ranges. If you can't wait for us, you might be able to write a separate extension that uses an open source lexer to do this. |
I figured as much. I'll roll with a custom extension for the time being. Do you have any information regarding an ETA for folding support? |
@akbyrd We don't have any ETA yet, but as soon as we do we'll add this issue to a Milestone with a target month. I would prefer to get this implemented by March, but other issues, such as improving our configuration experience, could get higher priority, and we haven't finished Find All References yet (our top requested feature). |
Over 3 years later.... This feature alone is the only reason I use Eclipse for a component in my project that makes extensive usage of conditional compilation macros. |
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. |
Issue 1 Issue 2 And here is the inconsistency that results Issue 3 There's room for debate here, as the case contents are not a scope, but personally I'd like to be able to fold them as they are still a logical block of code, if not a lexical scope. Issue 4 Issue 5 I have some quick and dirty tests here in the form of .cpp files with various code examples that should or should not fold. |
@akbyrd Issue 1 has the same root cause as #4143, i.e. none of our language server features will work until the file is saved. Issue 2 is because "case:" has no '{' associated with it in the C++ language like the other if/switch blocks, so it's treated like all other
The {... looks odd, but we can't do what VS does until VS Code makes changes (which has existing issues tracking it). Issue 3: I filed a feature request on VS at https://developercommunity.visualstudio.com/idea/1020490/c-intellisense-add-code-folding-for-case-regions.html . Our implementation is shared with VS. Issue 4: What is the result you expect in this case? It appears to fold correctly to me. Issue 5: I've filed a feature request on VS at https://developercommunity.visualstudio.com/idea/1020893/c-intellisense-multiline-macros-dont-generate-a-co.html . I don't see it in your screenshot, but the "if" block is supposed to generate a code folding region (so let us know if you're not getting that). |
I copy code into a temp file quite frequently. This was the very first issue I encountered.
Indeed,
Apologies. You are correct. However, it is incorrect when the the active preprocessor block is reversed. In this case I expect it to fold to the closing brace on line 39, which is in the active preprocessor region. If it were doing so, lines 38 and 39 would not be visible. Perhaps it's assuming the first preprocessor block is the active one?
The |
@akbyrd Oh, issue 4 is unexpected because it doesn't repro with VS's implementation, so it implies that we somehow regressed that case or did something differently with our changes. I've filed bug #5429 . I wasn't reproing issue 5 because my repro was slightly different with Did you want us to add a setting to disable Code Folding with our extension so it can be provided by the vsc-cpp-folding extension? We thought about that but were going to wait for complaints before adding another enable/disable setting. |
As a backup, yes, that would be helpful. That said, I'd much rather use the official plugin. It's already 90% there, so I expect I'll be able to use it. The new file behavior and macro folding are the only blockers I've encountered so far. Also, to clarify Issue 5, I would expect that the macro contents themselves fold, independent of whether the In the example, I'd expect that lines 20-21 and 23-27 are foldable. |
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. |
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: 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"? |
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. |
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. |
This issue is fixed in 0.28.0. |
@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? |
The file was saved, for heaven's sake.
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. |
@KaeLL It's caused by your setting |
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. |
@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 . |
@akbyrd Your issue 4 is fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/1.2.0-insiders2 (i.e. #5429 ). |
In my code there are many places look like this
or
or
EDIT (@bobbrow): (inserting request for folding on multiple consecutive single-line comments from #1443)
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.
System spec:
Please correct this.
The text was updated successfully, but these errors were encountered: