In case of a top level context the first template argument of a concept
should be dropped. Currently the indexer doesn't support different
signatures for different contexts (for an index entry always the default
Symbol context is used). Thus we add a hack which checks if we are in
a top level context and have a concept and in that case removes the
first argument of the signature and snippet suffix. If there is only a
single argument, the signature and snippet suffix are completely
removed. The check for the first argument is done by simply looking for
the first comma which should be sufficient in most cases.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Cool! This makes sense, and is much cheaper than actually working out how to render the abbreviated arg list and store it in the index.
Nice that TopLevel gives us some of these contexts, but I suspect it's not all. (If not, it's fine to handle just this case for now and leave the others as tests showing the bad behavior with a FIXME)
clang-tools-extra/clangd/CodeComplete.cpp | ||
---|---|---|
321 | RemoveFirst => removeFirst | |
321 | (if this function takes StringRef instead you get nicer APIs like split, and less copying) | |
327 | I don't love the arithmetic, the repetition of 2 as the length of the string, and the reliance on the space after the comma. Maybe: (assuming Signature is a StringRef) [First, Rest] = Signature.split(","); if (Rest.empty()) // no comma => one argument => no list needed return ""; return ("<" + Rest.ltrim()).str(); | |
479 | more important to say why rather than what: which cases? /// When a concept is used as a type-constraint (e.g. `Iterator auto x`), /// and in some other contexts, its first type argument is not written. /// Drop the parameter from the signature. | |
482 | maybe leave a comment: dropping the first placeholder from the suffix will leave a $2 with no $1. (assuming you've tested this in vscode) | |
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp | ||
3964 | this doesn't look valid - what is U here? (generally if we're mixing completion cases in one file it's important that they're valid so subsequent ones parse correctly - also to not confuse the reader) | |
3968–3972 | I think it might be worth renaming "other" to "expr", it seems to more clearly describe all the situations here | |
3974–3975 | can you also add tests for void abbreviated(A auto x) {} template<A auto X> int constrainedNTTP(); | |
clang-tools-extra/clangd/unittests/TestIndex.h | ||
38 ↗ | (On Diff #537108) | this diverges from how the other helpers work: they're mostly creating minimal skeletons and encapsulate the mess of synthesizing USRs. Instead of extending the function here, we can assign the appropriate fields on the returned symbol at the callsite (or add a local helper to do so) (objcSym is also out-of-line with the pattern here, but we shouldn't follow it off the rails) |
clang-tools-extra/clangd/CodeComplete.cpp | ||
---|---|---|
327 | Thanks! I agree that the code with StringRefs looks much better. | |
482 | Yes I've tested it with vscode and it looks fine. Why is the numbering of the parameters required? | |
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp | ||
3974–3975 | The case doesn't work yet. I will fix it in a follow-up patch. |
clang-tools-extra/clangd/CodeComplete.cpp | ||
---|---|---|
482 | The numbering defines the logical sequence, in practice which placeholder will be selected first, and the order that pressing <tab> will visit the others in. I guess this could make sense when they're not parameters but some other snippet placeholders, but honestly this seems more confusing than useful, I'd prefer they were un-numbered and always LTR. |
RemoveFirst => removeFirst