[PATCH] D81380: [clangd] Don't produce snippets when completion location is followed by parenthesis

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 9 02:42:50 PDT 2020


sammccall added inline comments.


================
Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1712
+            SemaCCS, QueryScopes, *Inserter, FileName, CCContextKind, Opts,
+            /*GenerateSnippets=*/!IsUsingDeclaration && !HasParenthesisAfter);
       else
----------------
sammccall wrote:
> kbobyrev wrote:
> > sammccall wrote:
> > > how sure are we that paren-after is the right condition in all cases? Does "snippet" cover template snippets (std::vector<{$0}>)?
> > > 
> > > Don't need to handle this but it'd be nice to cover in tests.
> > Yeah templates are hard :( The problem here is that this is a heuristic and I was considering suppressing pieces of the CC snippets (e.g. the templated parts) upon having `<` token ahead but this can also be "less than" sign and the heuristics are probably going to be harder for this. Maybe some semantic analysis would do, but I'm not sure about all the details right now.
> > 
> > I've added a test which shows how the template snippet will be omitted, is that OK with you?
> Yes, adding a test showing we don't handle this edge case is fine.
BTW it might be possible to handle this robustly by having Preprocessor::Lex look ahead once it reaches the CC token and call setCodeCompletionTokenRange appropriately. You'd then have to look for the token at the endpoint of this range, rather than the one after the code completion point.

Clangd is the only (in-tree) user of the code completion token range, we use it to decide what to replace.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81380/new/

https://reviews.llvm.org/D81380





More information about the cfe-commits mailing list