Append optional chunks with their default values. For example: before - "int i", after - "int i = 10"
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Sure :)
Currently default value string does not contain default value itself. This change fixes it and adds the default value to the string.
Ok, now I get it - can you please add tests? This is usually tested by adding a c-index-test based test.
lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
2411–2417 ↗ | (On Diff #100705) | Can you use Lexer::getSourceText instead? |
2453 ↗ | (On Diff #100705) | Why the check for = in the PlaceholderStr? |
lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
2411–2417 ↗ | (On Diff #100705) | If that does the same i will use it in the next diff update |
2453 ↗ | (On Diff #100705) | Not to add default value twice. If there's already "=" in placeholder string that means we've already added it in FormatFunctionParameter call |
lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
2453 ↗ | (On Diff #100705) | In which cases would the default value not be added in FormatFunctionParameter if there is one, and need to be added here? |
lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
2453 ↗ | (On Diff #100705) | If Param->evaluateValue() can evaluate it it will set the default value in FormatFunctionParameter (that means it's a primitive type like "void func(int i = 0)"). |
lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
2453 ↗ | (On Diff #100705) | Why don't we always add it in the unevaluated form? I'd expect constants from macros are useful to see unevaluated? |
lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
2453 ↗ | (On Diff #100705) | Hm, after using Lexer::getSourceText that makes sense! I had some issues getting source parts on my own without evaluation in some complicated cases with macros usage, etc. |
Do not evaluate numbers.
Check for != "=" is needed not to mess with invalid default arguments or their types (without it I get "const Bar& bar = =" when Bar is not defined)
I don't know the proper way to do that :) I also don't know the full amount of errors that might cause such behavior.
You can suggest the solution if you have some idea. Current one is safe because we just ignore any case that causes empty default string.
Taking your example "const Bar& bar = =" when Bar is not defined:
What happens now? Will it be "const Bar& bar ="? I argue that is not better than "const Bar& bar = =".
Btw, can you add tests? I think that will make it easier to see what's actually happening.
It will be just "const Bar& bar" in that case with this patch applied. So it is better than both "const Bar& bar =" and "const Bar& bar = =" :)
About tests - I agree that it's nice to have them. Can I find something similar in the current test set (as an example) and where is it better to put my tests?
All of test/Index/complete-* basically test this, I think. Try to find a good spot or write a new test.
Add tests, append tests with default values. Move all default value handling to GetDefaultValueString
lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
2411–2412 ↗ | (On Diff #105045) | Can you expand in the comment on when each of these happens? Intuitively I'd have expected that only one of these cases can happen (I assume this is because of the forward-declared type?) |
+Richard, as apparently we get the source ranges for default values of built-in types without the preceding "=", but for user-defined types including the preceding "=" - is that intentional?
lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
2424 ↗ | (On Diff #106170) | "The Lexer returns default-values of built-in types without '=', and default-value of user-defined types with it." But apart from that: that seems like a bug in the range of the default value? I'm now really confused :) |
So do we wait until the '=' case is more clear? This change should not break anything if it's fixed in either direction (if '=' will be provided always or never)
lg
lib/Sema/SemaCodeComplete.cpp | ||
---|---|---|
2422 ↗ | (On Diff #107077) | Final nit: TODO is spelled FIXME in llvm/clang. |