This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Implement GetEligiblePoints
ClosedPublic

Authored by kadircet on Sep 25 2019, 7:21 AM.

Details

Summary

This is an helper for incoming move definition out-of-line action to
figure out possible insertion locations for definition of a qualified name.

Diff Detail

Event Timeline

kadircet created this revision.Sep 25 2019, 7:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 25 2019, 7:21 AM
kadircet retitled this revision from [clangd] Implement GetEligibleRegions to [clangd] Implement GetEligiblePoints.Sep 26 2019, 1:18 AM
kadircet updated this revision to Diff 221896.Sep 26 2019, 1:19 AM
  • Rename regions to points
  • Return EOF if there are no shared namespaces with the target

A few go-by comments from me, Haojian should have better context here!

clang-tools-extra/clangd/SourceCode.cpp
724

Yay! Thanks! Less templates, more type-checking!

Could you rename 'A' to something more specific, though?
Not that there is no nice type name to guide the readers, A feels a bit confusing.

724

why const Position and not const Position&?
top-level const in function parameters is weird, it's basically ignored (except at the definition site)

742

Should this be const Position& or Position?

1064

If we were to do this, I'd rather try matching brace structure and only report closing brace that is probably end of the top-level decl(function, struct, etc) events.

Everything else seems super hard to get right.

clang-tools-extra/clangd/SourceCode.h
270

Do we ever name anonymous namespace here? How do we represent them?

kadircet marked 5 inline comments as done.Sep 26 2019, 4:43 AM
kadircet added inline comments.
clang-tools-extra/clangd/SourceCode.cpp
724

dropping the const

1064

agreed, my suggestion was also just for figuring out when a { might start a definition, and trigger an event at the corresponding }

kadircet updated this revision to Diff 221920.Sep 26 2019, 4:43 AM
kadircet marked an inline comment as done.
  • Address comments
ilya-biryukov marked an inline comment as done.Sep 26 2019, 6:52 AM
ilya-biryukov added inline comments.
clang-tools-extra/clangd/SourceCode.cpp
1064

Actually, now I remembered that this should also work just fine.
) { is a good marker for start of the function body, I believe clang also uses this to detect and skip function bodies for members.

So LG

The implementation looks good, just have some questions on the API.

clang-tools-extra/clangd/SourceCode.cpp
1066

If I understand the FIXME well, so we will extend the API to parse functions, so that we could get a more eligible point e.g. near the near the neighboring declaration.

clang-tools-extra/clangd/SourceCode.h
270

Current seems not clear enough, how about "MatchNamespace"?

273

I'm curious how the caller use this, it seems that the caller has no/little information to distinguish all the positions, even for a simple case where we add a definition at the last eligible point (I assume just just using EligiblePoints.back()).

kadircet marked 3 inline comments as done.Sep 27 2019, 6:10 AM
kadircet added inline comments.
clang-tools-extra/clangd/SourceCode.cpp
1066

yes that's the idea. we'll try to provide as many valid insertion points as possible in the closest namespace.

clang-tools-extra/clangd/SourceCode.h
273

for example a caller with access to AST and Index, could first look at the decls surrounding the target(fully qualified name), then check for their definition locations using index and find an eligible point between these two.

kadircet marked an inline comment as done.Sep 27 2019, 9:34 AM
kadircet added inline comments.
clang-tools-extra/clangd/SourceCode.h
270

what about enclosing?

hokein added inline comments.Sep 30 2019, 7:35 AM
clang-tools-extra/clangd/SourceCode.h
270

sounds good.

273

Fair enough, thanks for the explanation.

kadircet updated this revision to Diff 222434.Sep 30 2019, 7:54 AM
kadircet marked 7 inline comments as done.
  • Address comments
clang-tools-extra/clangd/SourceCode.h
270

Do we ever name anonymous namespace here? How do we represent them?

No we don't, represents anonymous namespaces. I also updated docs to mention that FullyQualifiedName should not contain anon namespaces.

hokein accepted this revision.Oct 1 2019, 3:39 AM

looks good.

clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
625

nit: I'd use a struct, it is hard to infer the member by reading get<0>, get<1> (I have to go back to the top)

This revision is now accepted and ready to land.Oct 1 2019, 3:39 AM
kadircet updated this revision to Diff 222590.Oct 1 2019, 4:27 AM
kadircet marked an inline comment as done.
  • Address comments
This revision was automatically updated to reflect the committed changes.