[clangd] Make config::Provider::combine non-owning. NFC

This is a prerequisite for having ClangdLSPServer inject its own.
This commit is contained in:
Sam McCall 2020-07-14 20:44:59 +02:00
parent 77ee4b4c9b
commit f88ce078f7
4 changed files with 11 additions and 10 deletions

View File

@ -193,9 +193,9 @@ Provider::fromAncestorRelativeYAMLFiles(llvm::StringRef RelPath,
}
std::unique_ptr<Provider>
Provider::combine(std::vector<std::unique_ptr<Provider>> Providers) {
Provider::combine(std::vector<const Provider *> Providers) {
struct CombinedProvider : Provider {
std::vector<std::unique_ptr<Provider>> Providers;
std::vector<const Provider *> Providers;
std::vector<CompiledFragment>
getFragments(const Params &P, DiagnosticCallback DC) const override {

View File

@ -76,8 +76,7 @@ public:
/// A provider that includes fragments from all the supplied providers.
/// Order is preserved; later providers take precedence over earlier ones.
static std::unique_ptr<Provider>
combine(std::vector<std::unique_ptr<Provider>>);
static std::unique_ptr<Provider> combine(std::vector<const Provider *>);
/// Build a config based on this provider.
Config getConfig(const Params &, DiagnosticCallback) const;

View File

@ -703,9 +703,9 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
CCOpts.RunParser = CodeCompletionParse;
RealThreadsafeFS TFS;
std::vector<std::unique_ptr<config::Provider>> ProviderStack;
std::unique_ptr<config::Provider> Config;
if (EnableConfig) {
std::vector<std::unique_ptr<config::Provider>> ProviderStack;
ProviderStack.push_back(
config::Provider::fromAncestorRelativeYAMLFiles(".clangd", TFS));
llvm::SmallString<256> UserConfig;
@ -716,7 +716,10 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
} else {
elog("Couldn't determine user config file, not loading");
}
Config = config::Provider::combine(std::move(ProviderStack));
std::vector<const config::Provider *> ProviderPointers;
for (const auto& P : ProviderStack)
ProviderPointers.push_back(P.get());
Config = config::Provider::combine(std::move(ProviderPointers));
Opts.ConfigProvider = Config.get();
}

View File

@ -57,10 +57,9 @@ std::vector<std::string> getAddedArgs(Config &C) {
// cache their results.
TEST(ProviderTest, Combine) {
CapturedDiags Diags;
std::vector<std::unique_ptr<Provider>> Providers;
Providers.push_back(std::make_unique<FakeProvider>("foo"));
Providers.push_back(std::make_unique<FakeProvider>("bar"));
auto Combined = Provider::combine(std::move(Providers));
FakeProvider Foo("foo");
FakeProvider Bar("bar");
auto Combined = Provider::combine({&Foo, &Bar});
Config Cfg = Combined->getConfig(Params(), Diags.callback());
EXPECT_THAT(Diags.Diagnostics,
ElementsAre(DiagMessage("foo"), DiagMessage("bar")));