This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add Value field to HoverInfo
ClosedPublic

Authored by kadircet on Jun 14 2019, 5:05 AM.

Details

Summary

Put a symbols value information which is deduced from initializer
expression into HoverInfo struct.

Diff Detail

Repository
rL LLVM

Event Timeline

kadircet created this revision.Jun 14 2019, 5:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2019, 5:05 AM
sammccall added inline comments.Jun 18 2019, 6:43 AM
clang-tools-extra/clangd/XRefs.cpp
722 ↗(On Diff #204750)

do we want the initializer both here and in Definition?

I suspect we'd like to turn off one or the other when both are present.

Looking at the examples, I think it's clearer to keep a non-evaluated initializer as part of the Definition (which is mostly as-written), and only include Value if it's evaluated.

733 ↗(On Diff #204750)

why not print the non-evaluated init if it's dependent?

clang-tools-extra/clangd/unittests/XRefsTests.cpp
920 ↗(On Diff #204750)

constexpr may not be required here, I think?
At least the docs suggest evaluation ignores language semantics like this.

956 ↗(On Diff #204750)

Hmm, actually I'm not sure whether this is TypeLoc vs Decl here. Rather this should be a DeclRefExpr to the VarDecl (result) in the *expanded* CXXRecordDecl.

This suggests that maybe the isValueDependent check isn't quite right - the initializer expression is value dependent as spelled, but in the instantiation it's resolved. Not sure if this is fixable. What happens if you comment out the check?

981 ↗(On Diff #204750)

whoa, that's... weird. But fine, I think.

(It would be nice to elide the &[] if the index is zero, or maybe print as "1234" + 2 etc)

kadircet updated this revision to Diff 205530.Jun 19 2019, 2:45 AM
kadircet marked 6 inline comments as done.
  • Address comments
clang-tools-extra/clangd/XRefs.cpp
733 ↗(On Diff #204750)

not-necessary anymore, since we only generate value if it can be evaluated.

clang-tools-extra/clangd/unittests/XRefsTests.cpp
956 ↗(On Diff #204750)

yes, and the problem lies in the IndexingAPI, inside handleDeclOccurence implicit instantiations are resolved into templated decls. therefore we lose the template params :/

we can't call expression evaluator on value dependent expressions, there is an assertion in the beginning of EvaluateAsRvalue.

981 ↗(On Diff #204750)

do you think it is worth changing that in printpretty (either the defaults or via some PrintingPolicy option)?

sammccall accepted this revision.Jun 24 2019, 3:16 AM

Implementation LG though please do check that the new test results look useful and not too duplicative

clang-tools-extra/clangd/XRefs.cpp
723 ↗(On Diff #205530)

Maybe add a FIXME about doing this for arbitrary expressions (like sizeof and function calls), not just VarDecl?

clang-tools-extra/clangd/XRefs.h
106 ↗(On Diff #205530)

if exists -> if available?

clang-tools-extra/clangd/unittests/XRefsTests.cpp
673 ↗(On Diff #205530)

are these actually still emitted, or tests not updated?

Some of them (e.g. the lambda below!) don't seem useful

956 ↗(On Diff #204750)

OK, let's leave this to later. Can you change the FIXME comment? I think it's misleading as it stands

981 ↗(On Diff #204750)

Let's leave it for now and see if it actually proves annoying.

This revision is now accepted and ready to land.Jun 24 2019, 3:16 AM
kadircet updated this revision to Diff 206210.Jun 24 2019, 7:05 AM
kadircet marked 9 inline comments as done and an inline comment as not done.
  • Address comments
clang-tools-extra/clangd/unittests/XRefsTests.cpp
673 ↗(On Diff #205530)

oops, somehow I've deleted the expect line that checks the values :/

920 ↗(On Diff #204750)

apparently this constexpr is necessary, otherwise evaluation fails.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2019, 1:02 AM