nvim-treesitter icon indicating copy to clipboard operation
nvim-treesitter copied to clipboard

`#pragma region` code folding for C

Open okuma10 opened this issue 3 years ago • 7 comments

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

okuma10 avatar Aug 25 '22 12:08 okuma10

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.

theHamsta avatar Aug 27 '22 08:08 theHamsta

@okuma10 still around? Can I get a code snippet to demonstrate where you want folding? I'll see about implementing it then

amaanq avatar Feb 25 '23 07:02 amaanq

@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

okuma10 avatar Feb 25 '23 07:02 okuma10

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.

amaanq avatar Feb 25 '23 07:02 amaanq

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.

okuma10 avatar Feb 25 '23 08:02 okuma10

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"

amaanq avatar Feb 25 '23 08:02 amaanq

Lol I'm a noob. Yeah, now that I look at it I think that's MSVC thing then.

okuma10 avatar Feb 25 '23 10:02 okuma10