[PATCH] D110823: [clangd] Add code completion of param name on /* inside function calls.

Adam Czachorowski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 7 09:45:00 PDT 2021


adamcz added inline comments.


================
Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1148
+  std::set<llvm::StringRef> ParamNamesSeen;
+}; // SignatureHelpCollector
+
----------------
kadircet wrote:
> change the ending comment (well, I'd actually drop it completely)
Oops, too much copy/paste.

We should have a clang-tidy check for that ;-)


================
Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1956
+  auto Content = llvm::StringRef(ParseInput.Contents).take_front(*Offset);
+  if (Content.endswith("/*")) {
+    // We are doing code completion of a comment, where we currently only
----------------
kadircet wrote:
> what if the user triggers at `foo(/*  b^`? I think we'd still want to provide `bar`.
> 
> I think we should detect whether we're in a comment first, we can run the Lexer for that but it'd probably be an overkill. For now I think we can just check for the string after last `*/`, if it has a `/*` we're in a comment, otherwise we check for the current line only. if it has a `//` we're again in a comment.
> 
> Then we can switch to the `codeCompleteComment` mode, inside there one branch can collect completion results for possible parameter names (while filtering using the currently typed text) and we can expand with more logic later on (e.g. suggest identifiers from index?).
> 
> WDYT?
Good point about /* b^, thanks! I did not consider manually triggered code completion at all.

Detecting last */ the way you suggest seems fragile. There's macros that can expand to /* or */, there's strings, lines that are already comments (i.e. "// blah /* blah), "#if 0" sections, etc.
Running Lexer is an option, but I don't think it's necessary. Currently there's very few options when we can offer code completion:
/*^
/*   ^
/*foo^
/*   foo^
This can be quickly detected by scanning back through whitespace, then valid identifier characters, then whitespace again.

Since it's unclear if and when we'll be adding more code completion in comments I want to keep this simple rather than build for the future when we may indeed need a lexer.

WDYT?

(also added some tests to cover this).


================
Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1963
+    auto OffsetBeforeComment = *Offset - 2;
+    return codeCompleteComment(FileName, OffsetBeforeComment, Preamble,
+                               ParseInput);
----------------
kadircet wrote:
> i think we should propagate `Opts` here and then override the pieces accordingly.
Hmm...why?

It seems that everything that could be relevant would be overridden here. SignatureHelp, which is very similar to this, doesn't use code complete options either. I think it may be confusing to accept an object but then override literally every single thing that matters anyway.

It's not unlikely that in the future we'll need options, but for now it seems useless. Do you have a specific option you want propagated?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110823



More information about the cfe-commits mailing list