nvim-treesitter
nvim-treesitter copied to clipboard
`#pragma region` code folding for C
Hi , is it possible to fold code based on the #pragma region #pragma endregion for C?
If not I hope you add it to your todo list.
Thanks
No, that's not possible at the moment and probably won't be possible in near future since we can't express that in our query system and we don't have multi-node folding at them moment.
You might want to try to modify the c++ parser to recognize #pragma region #pragma endregion as a separate construct. Then, folding is easy.
@okuma10 still around? Can I get a code snippet to demonstrate where you want folding? I'll see about implementing it then
@amaanq I'm referring to this https://learn.microsoft.com/en-us/cpp/preprocessor/region-endregion?view=msvc-170
a simple example:
#pragma region Some Descripton Text
// Some Code stuff
#pragma endregion
Is this MSVC specific? I'm sorry, but if so then, although it'd be nice, this likely won't get added until we have multi-node folding. It's too specific and upstream won't accept it.
Yes I used it in MSVC, VSCode, and I think in CLion when I was testing the free trial.
In python there is #region #endregion that does the same and I used that in Pycharm and VSCode.
I'm sorry, I don't mean editor-specific stuff - that'll never get added here as it's not really a part of the language. I meant more Microsoft C/C++ specifics (MSVC)
But yeah, I'll leave this open - I hope we get multi-node captures soon to the point where we can fold two nodes at the same level. Then it'd be easy to just check if the first pragma directive has "region", and the second "endregion"
Lol I'm a noob. Yeah, now that I look at it I think that's MSVC thing then.