This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Respect shouldIndexFile when collecting symbols.
Needs ReviewPublic

Authored by hokein on Nov 9 2018, 3:10 AM.

Details

Reviewers
ioeric

Event Timeline

hokein created this revision.Nov 9 2018, 3:10 AM
ioeric added inline comments.Nov 9 2018, 4:46 AM
clangd/index/SymbolCollector.cpp
576

Should we use getTokenLocation like what we do below?

634

IIUC, if D is declared in d.h that is filtered out and defined in d.cc that is not filtered, this would only create a basic symbol with definition?

I think what we want is a full symbol with declaration, definition, includes etc. This is one assumption we make in order for the merging in auto-index to work.

hokein updated this revision to Diff 173324.Nov 9 2018, 7:06 AM
hokein marked 2 inline comments as done.

Address comments and simplify the code.

hokein updated this revision to Diff 173326.Nov 9 2018, 7:10 AM

clang-format and fix typos

hokein added inline comments.Nov 9 2018, 7:11 AM
clangd/index/SymbolCollector.cpp
576

getTokenLocation doesn't return a SourceLocation, it returns a SymbolLocation.

ioeric added inline comments.Nov 9 2018, 7:22 AM
clangd/index/SymbolCollector.cpp
217

nit: this is very easily confused with the callback with the same name on the call sites.

220

This is following the implementation detail of how location is generated in addDeclaration/addDefinition. I think we could put the filtering into addDeclaration/addDeclaration to avoid the duplicate here (i.e. return nullptr if decl is filtered like what you did in the previous revision?).

391

OriginalDecl.getCanonicalDecl() might not be the one we prefer. I think we should check all redecls and pick the preferred one?

unittests/clangd/SymbolCollectorTests.cpp
533

It's not trivial to tell what are the cases we are testing here. Maybe add some comments?

There are a few cases that are interesting. For examples:

  • Symbol is declared in a filtered header and defined in a index file.
  • Symbol is declared in a indexed file and defined in a filter file.
  • Symbol has forward declaration and canonical declaration in filtered header and definition in indexed file.
  • ...

It might be clearer to split them into multiple cases.

hokein updated this revision to Diff 173662.Nov 12 2018, 5:50 AM
hokein marked 3 inline comments as done.

Update the patch based on offline discussion.

hokein added inline comments.Nov 12 2018, 5:51 AM
clangd/index/SymbolCollector.cpp
217

removed it.

220

as discussed, we decide to move the filter logic out of addDeclaration/addDefinition, and also move out the findNameLoc logic.

391

As discussed, canonicalDecl is always the decl we preferred here. If the definition decl is preferred, it will be handled in above isPreferredDeclaration code.

unittests/clangd/SymbolCollectorTests.cpp
533

Added comments.

ioeric added inline comments.Nov 26 2018, 5:53 AM
clangd/index/SymbolCollector.cpp
386

shouldIndexLoc seems more accurate?

392

DeclSLoc is a bit confusing (SLoc is used somewhere else). Maybe DeclSymLoc or simply DeclLoc?

397

We would be doing redundant work if OriginalDecl == ND?

409

Could you document here why we are also checking !BasicSymbol here?

571

nit: s/DeclSLoc/DeclLoc? and maybe add documentation about why we need this?

unittests/clangd/SymbolCollectorTests.cpp
598

I think making RefsInFile take a single file and using it in combination with anyOf/allOf would be more straightforward.