adamcz added inline comments.

================
Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1145
+  CodeCompletionTUInfo CCTUInfo;
+  std::vector<std::string> &ParamNames;
+  // For de-duplication only. StringRefs based on strings in ParamNames.
----------------
kadircet wrote:
> nit: Why not directly have an `llvm::DenseSet` here? I am not sure if the 
> order we're preserving currently is a good one anyway (depends a lot on the 
> order of includes, i think?). If we really want to preserve some ordering, it 
> would probably make sense to have the lexicographical one instead.
I decided to preserve the order to match what SignatureHelp is doing, but I now 
realize it re-orders them anyway, so good point, fixed.

Note that I used std::set, since that works with std::string and I don't think 
we can safely return llvm::StringRef here.


================
Comment at: clang-tools-extra/clangd/CodeComplete.cpp:1966
+bool shouldCodeCompleteComment(llvm::StringRef Content, unsigned &Offset,
+                               llvm::StringRef &Prefix) {
+  if (Content.empty())
----------------
kadircet wrote:
> this might read easier as:
> 
> ```
> while (!Contents.empty() && isAciiIdentifierContinue(Contents.back())
>   Contents = Contents.drop_back();
> Contents.rtrim(); // by default this drops the chars you have in `Whitespace` 
> already.
> Offset = Contents.size();
> return Contents.endswith("/*");
> ```
> 
> this has the different behaviour for `/* qwer ^` but I don't think we want to 
> complete after a word anyway (that's not what we do in the rest of the 
> completion, space terminates the previous identifier).
> 
> As for propagating prefix, I think it's enough to check that the file content 
> endswith whatever name we're going to suggest in the signature help collector.
> 
> nit: As for `Offset`, I might actually prefer returning an 
> `Optional<unsigned>` while renaming the function to 
> `getFunctionArgumentCommentStart`, but i am fine with this too, up to you.
First, returning Optional instead of bool + unsigned is better. Done.

Second, you're right that there's no need to return Prefix, it can be just as 
easily computed later. However, we still need it. I'm not sure what you're 
suggesting with checking if content ends with name. If it's literally 
Content.endswith(Name) that means you must have already typed the entire 
argument name.
I moved the CommentPrefix computation out of this function to make the 
signature nicer. It's just one line anyway. We can't easily move this to the 
collector, since it gets the original content, meaning we'd have to pass two 
offsets (original completion point and the new one) so we can extract something 
like "fun(/*foo^);" - we need to remove everything before /* and everything 
after ^. Does that explanation make sense?

Third, your version is better now. Note there is no difference in behavior on 
"/* qwer ^". There's even a test for that. I think I ended up with that 
complicated version because of the Prefix extraction, and, ironically, the "/* 
qwer ^" case - I just confused myself too much ;-)

Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110823

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to