This is an archive of the discontinued LLVM Phabricator instance.

Wiring of standard library indexing into clangd.
AcceptedPublic

Authored by kuhnel on Aug 16 2021, 4:18 AM.

Details

Reviewers
sammccall
Summary

Plumbing code to enable standard library indexing to enable end-to-end testing.
This does not change the stdlib indexing behavior.

I added an experimental flag to enable this feature. This flag would probably be removed (or negated) for the final product.

This is part of https://github.com/clangd/clangd/issues/618 and depends on D105177

Diff Detail

Event Timeline

kuhnel created this revision.Aug 16 2021, 4:18 AM
kuhnel requested review of this revision.Aug 16 2021, 4:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2021, 4:18 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
kuhnel retitled this revision from wired up standard library indexing to Wiring of standard library indexing into clangd..Aug 16 2021, 4:20 AM
kuhnel edited the summary of this revision. (Show Details)
kuhnel edited the summary of this revision. (Show Details)Aug 16 2021, 4:21 AM

(First just the bug that I suspect is blocking you from testing this, design feedback to come)

clang-tools-extra/clangd/ClangdServer.cpp
184

this pointer will dangle after the if block finishes (the local auto owns the index)

kuhnel updated this revision to Diff 366856.Aug 17 2021, 4:00 AM
kuhnel marked an inline comment as done.

fixed lifecycle of StdLibIndex variable

kuhnel added inline comments.Aug 17 2021, 4:03 AM
clang-tools-extra/clangd/ClangdServer.cpp
180

I'm not sure if returning a Expected<T> makes sense here. I suppose logging could be done from StandardLibraryIndex just as well.

184

Ah yes, you're right. The other indexes are kept in member variables...

sammccall added inline comments.Aug 17 2021, 5:39 AM
clang-tools-extra/clangd/ClangdServer.cpp
180

A couple of issues with indexing here and placing it in the stack:

  1. it's synchronous and blocks all other operations, we shouldn't do that. This is a latency sensitive path: the user just opened the first file in their editor. Our usual trick here is using a SwapIndex as a placeholder and loading asynchronously, but...
  1. there's no way to disable it or use a different configuration for e.g. C files, or according to config.

I think ultimately the triggering logic will want to live in TUScheduler so it can be sensitive to CompilerInvocation (and thus LangOpts) as well as config. Essentially it will wrap ParseInputs.Index after calling buildCompilerInvocation.

That's more complicated to get right, and if you want to delay it and still be able to use this locally it makes sense. Some FIXME comments should describe how this needs to be moved before the feature is usable by end-users though.

kuhnel updated this revision to Diff 367738.Aug 20 2021, 2:04 AM

addressed some review comments

question of integration with main functionality still open.

sammccall accepted this revision.Aug 20 2021, 2:12 AM

LG with the understanding that we'll have to move this to be more sophisticated later later, but it's useful to have the simple version now.
Similarly I think it's OK to add the tests later too as this version is experimental & safe.

clang-tools-extra/clangd/ClangdServer.cpp
180

add a FIXME that this happens synchronously, and can't respond to langopts or config and I think we're good to go as an experimental feature

clang-tools-extra/clangd/ClangdServer.h
412

You can push this into MergedIdx for storage. The reason for DynamicIdx and BackgroundIdx having dedicated variables is that they have special APIs we need to access.

This revision is now accepted and ready to land.Aug 20 2021, 2:12 AM
nridge added a subscriber: nridge.Aug 22 2021, 5:20 PM