Currently we only add parantheses to the functions if snippets are
enabled, which also inserts snippets for parameters into parantheses. Adding a
new option to put only parantheses. Also it moves the cursor within parantheses
or at the end of them by looking at whether completion item has any parameters
or not. Still requires snippets support on the client side.
Details
Diff Detail
- Repository
- rCTE Clang Tools Extra
- Build Status
Buildable 21617 Build 21617: arc lint + arc unit
Event Timeline
clangd/CodeComplete.h | ||
---|---|---|
86 | IIRC, the goal of this patch is to allow disabling snippet templates for function parameters while still allow appending () or ($0) to function candidates. If that's still the case, I think what we want is probably an option like DisableSnippetTemplateForFunctionArgs? |
- Change option name.
clangd/CodeComplete.h | ||
---|---|---|
86 | Yeah, that makes totally more sense. Thanks! |
clangd/CodeComplete.h | ||
---|---|---|
86 |
|
clangd/CodeComplete.cpp | ||
---|---|---|
1377 | There seems to be no guarantee on whether the snippet is function arg template when SnippetSuffix.size() > 2. A heuristic we could use is probably checking that the template starts with ( and ends with )? Alternatively, we could try to avoid generating the proper snippet according to the flag when we still have the function declaration around. Not sure if this is feasible for index results though. | |
clangd/CodeComplete.h | ||
86 | +1 to a better name. I didn't really give much thought about the name and just wanted to get the idea across :) |
clangd/CodeComplete.cpp | ||
---|---|---|
1377 | Actually I was first trying to directly look at function argument count as you mentioned, but unfortunately Symbols coming from index don't have any declarations. Therefore it turns back to looking at Signature in this case, which is same with this one. Apart from that, IIUC, SnippetSuffix contains anything only when completion item is a function otherwise it is empty. So IMO this check should be OK. |
clangd/CodeComplete.cpp | ||
---|---|---|
1377 |
This seems to be true for the current use cases, but I suspect the assumption can change when we add more snippet-based completion results in the future e.g. a snippet for if-statement if (${0}) {${1}}. |
clangd/CodeComplete.cpp | ||
---|---|---|
1379 | nit: add parentheses around (... == ...) | |
1380 | nit: no braces around one liner. | |
1381 | I think we are missing one case here: !EnableFunctionArgSnippets && (<not function or method>)? I think we could do something like: if (!EnableFunctionArgSnippets && (<function or metrhod>)) // Truncate parameter template else // append snippet like before |
clangd/CodeComplete.cpp | ||
---|---|---|
1381 | Thanks! |
IIRC, the goal of this patch is to allow disabling snippet templates for function parameters while still allow appending () or ($0) to function candidates. If that's still the case, I think what we want is probably an option like DisableSnippetTemplateForFunctionArgs?