This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Show documentation in hover, and fetch docs from index if needed.
ClosedPublic

Authored by sammccall on Jul 7 2019, 5:49 AM.

Details

Summary

I assume showing docs is going to be part of structured hover rendering, but
it's unclear whether that's going to make clangd 9 so this is low-hanging fruit.

(Also fixes a bug uncovered in FormattedString's plain text output: need blank
lines when text follows codeblocks)

Diff Detail

Repository
rL LLVM

Event Timeline

sammccall created this revision.Jul 7 2019, 5:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2019, 5:49 AM

mostly nits, only important comment is around ordering of include in the rendered hover response

clang-tools-extra/clangd/FormattedString.cpp
148 ↗(On Diff #208291)

could you add braces to outermost if, and clang-format this chunk.

148 ↗(On Diff #208291)

nit: if the following change(regarding cleaning whitespaces at the end of each chunk) was unintentional,
why not make this one a lambda(like ensurewhitespaces) and just call it before and after we insert a codeblocks contents?

170 ↗(On Diff #208291)

why perform this for every chunk? This was previously used to get rid of trailing whitespaces, now this also trims trailing whitespaces in chunks. this doesn't sound valid to me?

clang-tools-extra/clangd/XRefs.cpp
616 ↗(On Diff #208291)

/*IsMainFileOnly=*/false

616 ↗(On Diff #208291)

also could you add a comment explaining why it is checked for IsMainFileOnly=false.

IIRC we decided that it was because, main file symbols' comments should already exist in the ast.

736 ↗(On Diff #208291)

clang-format

1257 ↗(On Diff #208291)

I believe documentation should come first. Since it has a non-fixed length, I believe it would be nice if people could simply not notice it(assuming bottom is closer to cursor location) WDYT?

1258 ↗(On Diff #208291)

clang-format

sammccall marked 8 inline comments as done.Jul 8 2019, 11:42 AM
sammccall added inline comments.
clang-tools-extra/clangd/FormattedString.cpp
148 ↗(On Diff #208291)

The problem then is if you insert two code blocks in a row, you get 4 newlines between them.

170 ↗(On Diff #208291)

This normalizes the whitespace between inline chunks to one space. Note that the text/inline blocks ensure there's a space before following another inline chunk. Is there a case where we'd be adding inline text and *want* multiple spaces between chunks?

This was an incomplete thought though: it allows the \n\n block to be simplified.

(I'm not totally happy with this rendering logic either, but I'm fairly convinced we're going to have to replace FormattedString with something hierarchical before too long, so I'm trying to avoid doing too much surgery here)

clang-tools-extra/clangd/XRefs.cpp
1257 ↗(On Diff #208291)

The problem is that the hover text is often limited length and will almost certainly be truncated at the bottom. Hover also sometimes appears below the cursor.

Prioritizing from bottom->top is an interesting idea, but I don't think editors or users are expecting it.

sammccall updated this revision to Diff 208470.Jul 8 2019, 11:42 AM

address comments

kadircet accepted this revision.Jul 9 2019, 4:22 AM

LGTM, thanks!

clang-tools-extra/clangd/FormattedString.cpp
170 ↗(On Diff #208291)

This normalizes the whitespace between inline chunks to one space. Note that the text/inline blocks ensure there's a space before following another inline chunk. Is there a case where we'd be adding inline text and *want* multiple spaces between chunks?

I am not sure if we would ever want to put some spaces between chunks, but it is still doable by prepending it to the second chunk instead of appending to the first.

So, I suppose it is OK until we figure out some other use case.

clang-tools-extra/clangd/XRefs.cpp
1257 ↗(On Diff #208291)

you are right, truncation is definitely a bigger concern

This revision is now accepted and ready to land.Jul 9 2019, 4:22 AM
sammccall marked an inline comment as done.Jul 9 2019, 10:40 AM
sammccall added inline comments.
clang-tools-extra/clangd/FormattedString.cpp
170 ↗(On Diff #208291)

Yeah, I think that's unlikely to do by accident. Mostly I don't want to worry about whether a doc comment or prettyprinted decl or whatever ends in \n.

This revision was automatically updated to reflect the committed changes.