This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Store explicit template specializations in index for code navigation purposes
ClosedPublic

Authored by kadircet on Mar 7 2019, 2:52 AM.

Details

Summary

This introduces ~4k new symbols, and ~10k refs for LLVM. We need that
information for providing better code navigation support:

  • When references for a class template is requested, we should return these specializations as well.
  • When children of a specialization is requested, we should be able to query for those symbols(instead of just class template)

Number of symbols: 378574 -> 382784
Number of refs: 5098857 -> 5110689

Event Timeline

kadircet created this revision.Mar 7 2019, 2:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2019, 2:52 AM
gribozavr accepted this revision.Mar 7 2019, 3:14 AM
gribozavr added inline comments.
clangd/CodeComplete.cpp
1513

isExplicitTemplateSpecialization?

unittests/clangd/SymbolCollectorTests.cpp
395–401

"Template" -> "Primary template"

"is indexed" -> "are indexed"

This revision is now accepted and ready to land.Mar 7 2019, 3:14 AM
ioeric added a comment.Mar 7 2019, 3:33 AM

We need that information for providing better code navigation support, like find references, children/base classes etc.

It's not trivial how they make code navigation better. Can you explain and provide examples in the summary? Thanks!

clangd/CodeComplete.cpp
1613

nit: the context here is code completion. Maybe explain why they are not interesting for completion rather than why we index them?

kadircet edited the summary of this revision. (Show Details)Mar 7 2019, 11:08 AM
kadircet updated this revision to Diff 189817.Mar 8 2019, 12:13 AM
kadircet marked 3 inline comments as done.
  • Address comments
gribozavr accepted this revision.Mar 8 2019, 12:51 AM
gribozavr added inline comments.
clangd/CodeComplete.cpp
1613

which is the same as the name of the *primary* template in case of template specializations.

nridge added a subscriber: nridge.Mar 11 2019, 7:11 AM

Is any representation of the template arguments stored in the index?

Is any representation of the template arguments stored in the index?

No we only have, class name if you want to do a "name based" search/lookup. But symbol IDs for template specializations are different, so you can query them by ID.
Do you have any use case that needs names?

nridge added a comment.EditedMar 11 2019, 7:36 AM

One of the use cases I imagined for this (unrelated to D58880) is that if the user searches for vector (using workspace/symbols), they get a separate search result for the vector primary template, and a separate one for vector<bool>. For this to be useful, the server needs to print the <bool> as part of the search result.

(For D58880, I would find it useful for be able to look up an explicit spec. by template-id in the tests, but that can probably be worked around.)

To split this into multiple independent changes, we could start with storing the symbols for template specializations, but only showing the primary template in the results of workspaceSymbols.
This would enable other features (xrefs, etc), and we could re-add specializations to workspaceSymbols after we improve the presentation.

kadircet updated this revision to Diff 190382.Mar 13 2019, 2:05 AM
kadircet marked an inline comment as done.
  • Agree on ilya-biryukov@'s suggestion, changing fuzzyfind to skip template (partial) specializations for now.

To split this into multiple independent changes, we could start with storing the symbols for template specializations, but only showing the primary template in the results of workspaceSymbols.
This would enable other features (xrefs, etc), and we could re-add specializations to workspaceSymbols after we improve the presentation.

SGTM, moving forward with that approach.

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