This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Add visited contexts to CodeCompleteContext
ClosedPublic

Authored by hokein on Jan 15 2018, 8:02 AM.

Details

Summary

This would allow code completion clients to know which context is visited during Sema code completion.

Also some changes:

  • add EnteredContext callback in VisibleDeclConsumer.
  • add a simple unittest for sema code completion (only for visited contexts at the moment).

Diff Detail

Repository
rC Clang

Event Timeline

hokein created this revision.Jan 15 2018, 8:02 AM
ilya-biryukov added inline comments.Jan 15 2018, 8:36 AM
include/clang/Sema/Lookup.h
791

Maybe rename it to VisitedContext ? Seems more in-line with FoundDecl.
BeginVisitContext also suggest there should be EndVisitContext

We should have a unit test for this, otherwise it's dead code.

include/clang/Sema/Lookup.h
791

Semicolon is not needed here.

hokein updated this revision to Diff 130117.Jan 17 2018, 3:21 AM
hokein marked 2 inline comments as done.

Refine the patch:

  • expose visited contexts to client by adding getVisitedContexts in CodeCompleteContext.
  • add unittest for sema code completion.
hokein retitled this revision from [Sema] Add a callback in VisibleDeclConsumer allowing client to know which DeclContext is going to visit. to [Sema] Add visited contexts to CodeCompleteContext.Jan 17 2018, 3:22 AM
hokein edited the summary of this revision. (Show Details)
ilya-biryukov accepted this revision.Jan 17 2018, 5:38 AM

LGTM.
Look at the comments for a few NITs.

include/clang/Sema/CodeCompleteConsumer.h
271

Given that lookup does not visit the same DeclContext twice, we're probably fine with vector here, rather than the set.
On the other hand, using set gives a better understanding that the order of items is not specified.
I don't think we should necessarily changes the code here, just something to think about.

290

s/breif/brief

290

I'd mention lookup explicitly in the comment, e.g.

/// \brief A set of decl contexts visited when doing lookup for code completion.
unittests/Sema/CodeCompleteTest.cpp
54

Why onyl namespaces and not all DeclContexts?

71

NIT: local var starts with a lower-case letter.

This revision is now accepted and ready to land.Jan 17 2018, 5:38 AM
hokein updated this revision to Diff 130155.Jan 17 2018, 6:02 AM
hokein marked 5 inline comments as done.
hokein retitled this revision from [Sema] Add visited contexts to CodeCompleteContext to [Sema] Add visited contexts to CodeCompleteContext.
hokein edited the summary of this revision. (Show Details)

Address review comments.

hokein added inline comments.Jan 17 2018, 6:03 AM
include/clang/Sema/CodeCompleteConsumer.h
271

Good point. Yeah, technically, there should be no duplicated DeclContext.

include/clang/Sema/Lookup.h
791

Renamed it to EnteredContext based on offline discussion.

unittests/Sema/CodeCompleteTest.cpp
54

Yeah, this is intended (the method name has indicated it), we only verify the results for namespaces in the test (for simplicity).

This revision was automatically updated to reflect the committed changes.