This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Enable hover on character literal.
ClosedPublic

Authored by hokein on Jan 21 2022, 1:12 AM.

Details

Summary

In the initial hover expression patch (https://reviews.llvm.org/D72500), we
disabled all literals.

There is some value on running hover on character literals (e.g. see the
int value of the char).

Diff Detail

Event Timeline

hokein created this revision.Jan 21 2022, 1:12 AM
hokein requested review of this revision.Jan 21 2022, 1:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 21 2022, 1:12 AM
hokein added inline comments.Jan 21 2022, 1:32 AM
clang-tools-extra/clangd/Hover.cpp
744

there may be some value to enable StringLiteral as well (e.g. see the length of the string), but it seems to work partially:

  • auto char_ptr = "ab^c"; // fails
  • char abc[] = "a^bc"; // works
  • const char* ptr = "a^bc"; // fails"
  • "a^bc"; // fails
  • func("a^bc"); // fails

Looks like the reason is that EvaluateAsRValue fails on a lvalue StringLiteral. It'd require a bit of work to make it useful for common cases.

friendly ping, I think it would be nice to get it in before 14 release.

kadircet accepted this revision.Jan 26 2022, 6:50 AM

thanks, lgtm!

clang-tools-extra/clangd/unittests/HoverTests.cpp
1254

s/,/;

This revision is now accepted and ready to land.Jan 26 2022, 6:50 AM
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.