This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Introduce a CommandLineConfigProvider
ClosedPublic

Authored by kadircet on Mar 5 2021, 3:16 AM.

Details

Summary

This enables unifying command line flags with config options in clangd
internals. This patch changes behaviour in 2 places:

  • BackgroundIndex was previously disabled when -remote-index was

provided. After this patch, it will be enabled but all files will have
bkgindex policy set to Skip.

  • -index-file was loaded at startup (at least load was initiated), now

the load will happen through ProjectAwareIndex with first index query.

Unfortunately this doesn't simplify any options initially, as

  • CompileCommandsDir is also used by clangd --check workflow, which

doesn't use configs.

  • EnableBackgroundIndex option controls whether the component will be

created at all, which implies creation of extra threads registering a
listener for compilation database discoveries.

Diff Detail

Event Timeline

kadircet created this revision.Mar 5 2021, 3:16 AM
kadircet requested review of this revision.Mar 5 2021, 3:16 AM
sammccall accepted this revision.Mar 5 2021, 4:14 AM

Both side-effects seem fine to me.

EnableBackgroundIndex option controls whether the component will be created at all

Do you think we should eventually switch to always setting ClangdServer::Options::BackgroundIndex to true in ClangdServerMain (or removing the option?)
If not, I'm not sure if there's much benefit in also setting the config flag...

CompileCommandsDir is also used by clangd --check workflow, which doesn't use configs

We can/should fix this though, right?

clang-tools-extra/clangd/tool/ClangdMain.cpp
555

(This seems a little weird, get passed in a task runner and maybe ignore it. Seems like the asyncprojectindex should know whether it's supposed to be sync or not, and either pass in a null runner or it should handle the asynchrony itself... not something for this patch)

568

or just FlagsConfigProvider?

572

Hmm, it seems natural to move assembling some of these objects into the constructor, I'm not sure it matters much, at least for now, but putting the actual flag-inspection on the hot-ish path seems constraining.

(Lowest-ceremony I can come up with is just making them e.g. Optional<ExternalIndexSpec> members of the provider, and then having a single fragment which capture the provider this and keep the conditionals inside it)

775

If we fix this, we can move the rest of the logic into the flags config provider constructor.

This revision is now accepted and ready to land.Mar 5 2021, 4:14 AM
kadircet updated this revision to Diff 328485.Mar 5 2021, 5:34 AM
kadircet marked 4 inline comments as done.
  • Address comments
kadircet added inline comments.Mar 8 2021, 1:01 AM
clang-tools-extra/clangd/tool/ClangdMain.cpp
555

adding a fixme, will follow-up.

775

yes, i was unsure about whether we would like to propagate config into --check mode, (but you didn't oppose the fixme, so doing that now :D)

This revision was landed with ongoing or failed builds.Mar 11 2021, 4:37 AM
This revision was automatically updated to reflect the committed changes.