forked from OSchip/llvm-project
[clangd] Make config::Provider::combine non-owning. NFC
This is a prerequisite for having ClangdLSPServer inject its own.
This commit is contained in:
parent
77ee4b4c9b
commit
f88ce078f7
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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")));
|
||||
|
|
|
|||
Loading…
Reference in New Issue