-
Notifications
You must be signed in to change notification settings - Fork 565
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
uncrustify doesn't seem to have a way to force gap between pointer parameters and type #3770
Comments
This commit adds a new option, align_var_dev_star_dangle_gap, that when paired with align_var_dev_star_style = dangle, provides a way to specify a minimum gap that stars won't dangle into. Closes: uncrustify#3770
This commit adds a new option, align_var_dev_star_dangle_gap, that when paired with align_var_dev_star_style = dangle, provides a way to specify a minimum gap that stars won't dangle into. Closes: uncrustify#3770
I did some tests here. The double space on the second function seems unrelated to the first function alignment. If you use
You can see you still have the double space in the second function anyway. Further checking seems to indicate that the additional space comes from Btw, you can use the option |
I'm not sure I understand the bug you're saying. My (very limited) understanding of things is:
So I would expect Furthermore, if It does seem weird to me that there is only one space between Let me know if my understanding of Assuming they aren't off base, I don't think there is a way to express what I want with the current options. If you know of a set of options that is supposed to give me what I want but isn't, let me know, and I'll try to figure out why they aren't working. |
This is correct. The bug I am referring to is that it seems that
This should be the minimum amount of space between the type and the alignment column. Currently, IMO there is bug in the fact that this does not consider
where the 2-space gap is between the type and the left-most part of the alignment block, which is Last, the code in PR #3889 seems to incorrectly affect the functionality of (the already broken) Hope this helps to making things a bit clearer. IMO, the correct solution would be working on fixing point 1 and 2. |
There may actually be another bug as well: I would expect |
I believed I'll have to do some experimenting and get a better handle on what these configuration options actually mean |
So looking at the code, I'm pretty sure the span is only supposed to be per parameter list. │ 22 Chunk *align_func_param(Chunk *start)•
│ 23 {•
…
│ 67 while ((pc = pc->GetNext())->IsNotNullChunk())•
│ 68 {•
…
│104 else if (pc->GetLevel() <= start->GetLevel())•
│105 {•
│106 break;•
│107 }•
│108 else if (pc->TestFlags(PCF_VAR_DEF))•
│109 {•
…
│122 many_as[pc->GetLevel()].Add(pc);•
…
│124 }•
…
│152 }•
…
│156 for (size_t idx = 1; idx <= max_level_is; idx++)•
│157 {•
│158 many_as[idx].End();•
│159 }•
…
│162 } // align_func_param• My understanding is that line 106 breaks out of the current aligning operation when the code gets to a chunk that is no longer in the parameter list (I'm assuming "level" is the nesting level of parenthesis here, but may be wrong) |
So my understanding is that So i fully expect a span of 1, to apply a gap to the first line of the parameter list of each function, but a span of 0 to not apply a gap to any of the parameters in any of the parameter lists.
So now I'm confused again, I thought the whole point of |
The docs say this:
So it shows the star encroaching into the gap with |
I have not looked at the code for this specific case (function parameter alignment) but I believe
You could be right and I could be wrong, I haven't really gone deeper in the code. Line 106 breaks out when we reach an outer level than the start (i.e. likely the ')' or the function.). Nevertheless alignment assumes we align across multiple lines, IMO, hence the
Correct.
Span of X would mean looking at the next X lines and search for opportunity for alignment. Works like that for var definition, so I assume it should work like that for function parameters too.
Good finding, but it seems the comment is wrong and I was also wrong in my post yesterday. I did a quick test with
and based on the value of |
It definitely looks like we need 1) to do further investigation on what the behavior should be and 2) that there are a few things that may need some work on :-) |
So, tbh, I just did some tests, and it seems to be behaving like the comment for me. Maybe you have an outstanding patch or something? Or maybe our configs are subtly different... Regardless, it would be good to have better test coverage in the test suite for testing a gap with the different star styles, so i'll do a pull request for that. |
This commit adds a new option, align_var_dev_star_dangle_gap, that when paired with align_var_dev_star_style = dangle, provides a way to specify a minimum gap that stars won't dangle into. Closes: uncrustify#3770
⬆️ okay that adds the tests to show the way it currently works. Once that gets merged I'll rebase #3889 on top of it and make it augment that test instead of adding a separate test. Can you see if the test suite passes with these new tests on your machine? |
@halfline |
Regarding the gap and star/ampersand, what do you think we should do? IMO it would be good if the gap was considering |
ah, yea I think there are separate options for aligning the parameter lists of function prototypes with each other. That's I can do a pull request adding a more fleshed out comment, sure. I personally don't see a way to make the current options do I what I want. For my use case, I need two separate gaps: I need a gap where stars are allowed to go, but variable names aren't allowed to go, and I need a gap where neither stars nor variable names are allowed to go. I don't think there's a way we can implicitly guess when to allow a star into a gap and when to make it avoid the gap. In my case, the gap where neither star nor variable name can go is only 1 column. We could hardcode that 1 column and I would be happy, but that sort of change is likely to break existing configs in the wild, and it might make other people unhappy. It's purely subjective whether the extra column is aesthetically pleasing or not. So my next step will be to rebase #3889 on top of master. I'll make it modify the new test case source that just landed instead of adding its own and I'll throw in more docs in the same pull request, just for convenience sake, since it's all roughly related anyway. EDIT: I actually ended up using a new test case source file anyway. It was just clearer to see the results that way. |
This commit adds a new option, align_func_params_star_gap, that when paired with align_var_dev_star_style = dangle, provides a way to specify a minimum gap that stars won't dangle into. Closes: uncrustify#3770
This commit adds a new option, align_func_params_star_gap, that when paired with align_var_dev_star_style = dangle, provides a way to specify a minimum gap that stars won't dangle into. Closes: uncrustify#3770
This commit adds a new option, align_func_params_star_gap, that when paired with align_var_dev_star_style = dangle, provides a way to specify a minimum gap that stars won't dangle into. Closes: uncrustify#3770
Good use case! Will fit me too :-) |
For my projects, I really like function parameters aligned, with stars filling the gap. It seems uncrustify can mostly handle this, except for one complication: I want at least one column of gap space that the stars can't invade. For instance,
You can see there is a two column gap, one to keep the star away from the type, and one column for the star to occupy.
I don't think there's a way to make uncrustify do that right now, without also forcing an extra space for functions that don't have stars like
You can see this run:
debug.txt
before:
foo.c
after:
bar.c
I think maybe there could be a new option that will force a column of space between the star and the type, but still allow
the star to dangle in the remainder of the gap?
The text was updated successfully, but these errors were encountered: