This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Retrieve minimally formatted comment text in completion.
ClosedPublic

Authored by ilya-biryukov on Apr 24 2018, 4:50 AM.

Details

Summary

Previous implementation used to extract brief text from doxygen comments.
Brief text parsing slows down completion and is not suited for
non-doxygen comments.

This commit switches to providing comments that mimic the ones
originally written in the source code, doing minimal reindenting and
removing the comments markers to make the output more user-friendly.

It means we lose support for doxygen-specific features, e.g. extracting
brief text, but provide useful results for non-doxygen comments.
Switching the doxygen support back is an option, but I suggest to see
whether the current approach gives more useful results.

Diff Detail

Event Timeline

ilya-biryukov created this revision.Apr 24 2018, 4:50 AM

My main question/concern is: if these APIs extract/format based on CodeCompletionString and friends, what should our plan be using this this in AST-based features, such as hover?

clangd/CodeComplete.cpp
233

This should probably be SemaDocComment, as this code is all about merging; we want to emphasize sources.

clangd/CodeComplete.h
49

IIUC this fixme no longer applies, because the expensive part was the (eager?) parsing and we no longer do that?

clangd/CodeCompletionStrings.h
24

What does raw mean - range of the file? indentation stripped?

29

"active" is a bit confusing - at this level we just care which arg you're interested in, right?

29

Is this typically a substring of getDocComment for the function? If so, noting that would make this clearer.

33

getParameterDocComment?

51

The name here is confusingly similar to getDocComment, and the comment doesn't really explain how they're different.

Consider calling this formatDocumentation, with a comment like "Assembles formatted documentation for a completion result. This includes documentation comments and other relevant information like annotations."

ilya-biryukov marked 4 inline comments as done.
  • Renames and other comments
  • Don't include brief comments in signature help either, comments there are also handled by the code completion code now.
ilya-biryukov added inline comments.May 9 2018, 2:26 AM
clangd/CodeCompletionStrings.h
24

Added more details and a reference to RawComment::getFormattedString, which is used to get the comment text and has a more descriptive doc.

29

This refers to the parameter that should be reported as active in signatureHelp.
Agree that it requires too much context to understand, changed to a more detailed description involving CurrentArg parameter.

29

Is this typically a substring of getDocComment for the function? If so, noting that would make this clearer.

I mechanically translated the original source code without looking too much on what it does :-)

Extracting a substring from the function doc would be the behavior I expect.
However, we simply try to get doc comment for parameter in the same way we do for functions (e.g. look for comment doc for parameter decl, without looking at function decl in the first place)
It means we'll always get the empty doc currently. At least, I couldn't make the current code produce any docs for the parameter.

I would still keep this function, as it seems to be called in the right places. But we definitely need to parse a function comment instead.

51

Thanks! That was definitely confusing.

sammccall accepted this revision.May 14 2018, 1:25 AM

Looks good, nits as always and I think you want a new test case.

clangd/CodeComplete.cpp
809–813

"include brief comments" --> "parse doxygen syntax"? Or if you prefer, "parse \brief comments"

Calling these "brief comments" is confusing as a natural reading is "a one-line comment above the function" or similar.

clangd/CodeCompletionStrings.h
29

I think this function is easy to understand in isolation, and by naming the parameter CurrentArg one can only really understand it in terms of its callsite in signatureHelp. I'd name it ArgIndex or similar instead, but up to you.

29

Ah, thanks.
I'd suggest noting that in the comment (this currently looks for comments attached to the parameter itself, and doesn't extract them from function documentation). I think most people looking at this would be interested in that detail!

Looking at the doxygen docs, it seems like they want syntax like this to work:int foo(int x /** Doc */), and I'd hope we could also get this to work at some point:

int foo(
  // Doc
  int x
);

Not that I see much code in that style, but maybe we should write more!

unittests/clangd/CodeCompleteTests.cpp
264

You've updated the existing doxygen test cases, but I don't think you're testing the new non-doxygen functionality anywhere?

This revision is now accepted and ready to land.May 14 2018, 1:25 AM
ilya-biryukov marked 6 inline comments as done.
  • Fix code after a change in deps (getFormattedText now needs a SourceManager instead of an ASTContext)
  • Address review comments
ilya-biryukov added inline comments.May 15 2018, 7:36 AM
clangd/CodeCompletionStrings.h
29

Noting that is definitely useful. And yes, ideally we should support both styles.

unittests/clangd/CodeCompleteTests.cpp
264

Yep, I moved all the tests to clang when reviewing the patch. I'll add more tests to the last change that actually sets ParseAllComments to true.

Rebase onto head, fix merge conflicts