Skip to content
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

ifdef/else/`endif folding #142

Open
eng-tp opened this issue Feb 23, 2022 · 3 comments
Open

ifdef/else/`endif folding #142

eng-tp opened this issue Feb 23, 2022 · 3 comments

Comments

@eng-tp
Copy link

eng-tp commented Feb 23, 2022

Hi,

I'm seeing issues with folding whenever ifdef/endif pairs have else or elsif directives in between them.
These issues persist even when defining the foldingStrategy as indentation.
E.g.:

`ifndef COMP_GUARD
`define COMP_GUARD
  class x
    function z
      `ifdef A
        behavior 1
      `else //A
        behavior 2
      `endif //A
    endfunction
  endclass
`endif //COMP_GUARD
  • folding on ifdef A folds code all the way to endif //COMP_GUARD, ignoring the middle else //A and endif //A
  • folding on else //A folds to endif //A as expected

Looking at the languageSettings.json file for systemverilog, I see that:

  1. else and elsif are present in both start and end markers
  2. markers for all ifdef - related directives do not assume \b at the beginning (so, no indentation is detected and/or preserved)

I can't say whether any of these is responsible for the indentation failure - but I assume it's the latter -, and I also don't know how I can experiment with this locally: I am a new user to VSCode and its extensions, and it seems I can't edit the languageSettings.json file for the systemverilog extension locally - or I don't know how to do it...

This seems related with #65 , but that issue was closed and this behavior persists.

Can you please help me in figuring this out?

Thanks, and BR

P.S.: all tick chars were removed due to formatting issues, but you get the point :)

@joecrop
Copy link
Collaborator

joecrop commented Mar 9, 2022

Hi @eng-tp, I dug into this, and it appears to be a limitation of the vscode language configuration. You are right, language-configuration.json is the file that controls folding of ifdefs. Unfortunately, because else is both a begin and end pattern, vscode seems to be greedy and ignore it as an end and skips to endif.

It seems like we would need to implement a registerFoldingRangeProvider like this extension does, as it supports middle expressions. But that is a pretty involved effort.

If you want to play around with this yourself, you can follow the contributing guide to download the git repo and run the extension in the debugger.

@joecrop
Copy link
Collaborator

joecrop commented Mar 9, 2022

Another potential solution is to install this extension and configure it to support else folding.

@eng-tp
Copy link
Author

eng-tp commented Mar 9, 2022

Hi @joecrop,

Thanks for your comments. I will see if I can find the time to experiment with the git repo.

In any case, to me a quick & dirty fix would be to remove the else/elsif from both the begin and end patterns, leaving just the ifdef/ifndef as begin, and endif as end - it would fold everything inside the same ifdef/endif, but it would be much better than the current behavior.

If I can try this out and get it to work, I'll let you know.

Cheers,
Tiago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants