This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Drop template argument lists from completions followed by <
ClosedPublic

Authored by kbobyrev on Oct 21 2020, 4:22 AM.

Details

Summary

Now, given template <typename T> foo() {} when user types fo^<int>() the
completion snippet will not contain <int>().

Also, when the next token is opening parenthesis (() and completion snippet
contains template argument list, it is still emitted.

This patch complements D81380.

Related issue: https://github.com/clangd/clangd/issues/387

Diff Detail

Event Timeline

kbobyrev created this revision.Oct 21 2020, 4:22 AM
kbobyrev requested review of this revision.Oct 21 2020, 4:22 AM
kbobyrev edited the summary of this revision. (Show Details)Oct 21 2020, 4:30 AM

@sammccall Ping, this is a real patch :)

kbobyrev edited reviewers, added: kadircet; removed: sammccall.Feb 4 2021, 11:27 PM
kbobyrev added a subscriber: sammccall.
nridge added a subscriber: nridge.Feb 15 2021, 4:25 PM

(sorry for forgetting about this)

clang-tools-extra/clangd/CodeComplete.cpp
456

nit: move this case above and get rid of if(Snippet part of the check?

469

what if we have ( in the template parameter list ? i think we need to literally find the matching > and include all the text in between instead.

475

nit: again might be worth putting the easy-to-reason case above to reduce mental load when reading.

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
3090

umm, where did this fixme come from exactly? don't we emit these as replacements for the fo part of the text anyway ?

kbobyrev updated this revision to Diff 324386.Feb 17 2021, 12:09 PM
kbobyrev marked 4 inline comments as done.

Address review comments.

kadircet accepted this revision.Feb 18 2021, 12:53 AM

thanks, lgtm!

clang-tools-extra/clangd/CodeComplete.cpp
474

RHS should be function<int>(42) right?

480

nit:

int Balance = 0;
size_t I = 0;
do {
  if(Snippet[I] == '>') --Balance;
  else if(Snippet[I] == '<') ++Balance;
  ++I;
} while(Balance > 0);
return Snippet->substr(0, I);

This should handle both the case snippet starts with < and not. reducing the nesting a little and making the flow more uniform (i.e. getting rid of the second return statement).

Up to you though, if you keep the existing version please move definition of Balance into for-init statement, use size_t instead of unsigned and array subscripts instead of at(Index).

496

i think it is better to omit (42) in this example.

497

You've marked the previous nit as done, but this case still seems to be coming after the complicated case, just in case it slipped :D

This revision is now accepted and ready to land.Feb 18 2021, 12:53 AM
kbobyrev updated this revision to Diff 324593.Feb 18 2021, 4:04 AM
kbobyrev marked 4 inline comments as done.

Address review comments

This revision was landed with ongoing or failed builds.Feb 18 2021, 4:10 AM
This revision was automatically updated to reflect the committed changes.