Noticed this when I tried to port the Protocol.h parsers.
And tests for the inspect API, which caught a small bug.
Details
Diff Detail
- Repository
- rCTE Clang Tools Extra
Event Timeline
clangd/JSONExpr.h | ||
---|---|---|
368 | Why is this needed? v[x].null() seems to be more intuitive than v.null(x). | |
unittests/clangd/JSONExprTests.cpp | ||
203 | It's not very obvious that this accesses a KV and converts the value, by only reading this line. Would it make sense to make the APIs more explicit e.g. get_as_xxx(...)? |
clangd/JSONExpr.h | ||
---|---|---|
368 | In the overwhelmingly common case when parsing, v is a pointer, because it resulted from a call to array(). So it's (*v)[x].null() vs v->null(x) - I think the latter is slightly more readable. But more compelling to me is having consistency between object/array. We *can* live without these if you like, though - most of the time we iterate over arrays rather than indexed access. | |
unittests/clangd/JSONExprTests.cpp | ||
203 | I think this is made worse because it's an artificial example. I think the best variant names would be asString() or getString(). I'm a bit reluctant to add a fixed prefix to these common accessors as they seem noisy. I also think we'd need to change all the names on Expr(), which seems like a shame. So I'm not sure about changing this, but curious what you think of the Protocol conversion code. |
Thanks for the review! I think you're right about new names.
clangd/JSONExpr.h | ||
---|---|---|
368 | I've kept these for now, for readability and symmetry. | |
unittests/clangd/JSONExprTests.cpp | ||
203 | After offline discussion, renamed to Expr::asString() and obj::getString(). |
Why is this needed? v[x].null() seems to be more intuitive than v.null(x).