This is an archive of the discontinued LLVM Phabricator instance.

Add foldings for multi-line comment.
ClosedPublic

Authored by usaxena95 on Jul 19 2022, 5:48 AM.

Diff Detail

Event Timeline

usaxena95 created this revision.Jul 19 2022, 5:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2022, 5:48 AM
usaxena95 requested review of this revision.Jul 19 2022, 5:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2022, 5:48 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
hokein added inline comments.Jul 19 2022, 6:39 AM
clang-tools-extra/clangd/SemanticSelection.cpp
176

nit: update the fixme, comment is supported now.

231

we can save some cost if we first get the final End comment, and calculate the offset from it.

235

since LSP defines 3 kinds (region, comment, import), I'd suggest defining these string literals in the Protocol.h, rather than using the magic string here.

clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
351

For this case, my personal preference would be to have 3 different foldings, rather than a union one.

If you think about cases like below, it makes more sense to have individual folding per comment.

/* comment 1
*/

/* comment 2
*/
/* comment 1
*/

// comment 2
usaxena95 marked 4 inline comments as done.

Addressed comments.

clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
351

In the cases mentioned, I think these comments would be about the same context. If I want to fold (possibly long) comments with interleaved new lines, I would be interested in folding all the related comments to look at the code clearly.

Do not fill Kind in JSON when it is unspecified.

hokein added inline comments.Jul 21 2022, 2:21 AM
clang-tools-extra/clangd/Protocol.h
1782 ↗(On Diff #445893)

sorry for not being clear on my previous comment, I think the current string kind; is good, and it aligns with the LSP one.

what I suggest was adding string literals to FoldingRange, something like

struct FoldingRange {
  const static llvm::StringLiteral REGION_KIND;
  const static llvm::StringLiteral COMMENT_KIND;
  const static llvm::StringLiteral IMPORT_KIND;
  
  // other fields keep as-is.
  ...
}

we're diverging from the LSP structure.

clang-tools-extra/clangd/SemanticSelection.cpp
231

this seems incorrect -- the LastComment->Line == T->Line + 1 condition is not true initially (because LastComment == T), so we will never run into this loop, then I'm confused, why the unittest are passed (premerge test is green).

clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
351

In the cases mentioned, I think these comments would be about the same context.

I'm not sure this is true. I could image a case like below, these comments are not about the same context. I think for cases where these comments are about the same context, they are generally separated by // <blankline> rather than <blankline>.

btw, Kirill has a patch (https://reviews.llvm.org/D83914) for proposed folding behaviors, see the comments part (which seems reasonable to me).

//===-- This is a file comment ------------------------------------------===//
//
// ...
//
//===----------------------------------------------------------------------===//


// This is a doc comment of `foo` class
class Foo {};
nridge added a subscriber: nridge.Jul 23 2022, 11:48 PM
kadircet added inline comments.Jul 26 2022, 3:54 AM
clang-tools-extra/clangd/Protocol.h
1782 ↗(On Diff #445893)

+1, we already have the same pattern for code action kinds, i was also referring to this in our offline discussion.

usaxena95 updated this revision to Diff 447926.Jul 26 2022, 9:15 PM
usaxena95 marked 4 inline comments as done.

Addressed comments.

clang-tools-extra/clangd/SemanticSelection.cpp
231

I think I missed to update the patch last time I fixed this.

usaxena95 updated this revision to Diff 447928.Jul 26 2022, 9:19 PM

Remove unintended changes.

hokein accepted this revision.Jul 28 2022, 1:25 AM
hokein added inline comments.
clang-tools-extra/clangd/SemanticSelection.cpp
178

nit: there is an extra space (I'd rather just use FIXME:)

216–218

nit: add a comment explaining the +1 offset (skipping the bracket).

231

nit: the <= seems to do much --I think we care about = LastCommentEnd.line and = LastCommentEnd.line + 1 cases, < LastCommentEnd.line should be impossible, right?

This revision is now accepted and ready to land.Jul 28 2022, 1:25 AM
This revision was automatically updated to reflect the committed changes.