================
@@ -84,9 +84,34 @@ class Provider {
   /// Order is preserved; later providers take precedence over earlier ones.
   static std::unique_ptr<Provider> combine(std::vector<const Provider *>);
 
+  /// Returns providers for the configuration files that clangd tools read by
+  /// default: project config (ancestor `.clangd` files) and the user's
+  /// global config file.
+  static std::vector<std::unique_ptr<Provider>>
+  createDefaultProviders(const ThreadsafeFS &);
+
+  /// The result of combining several providers, bundled together with the
+  /// providers themselves. combine() only stores raw pointers to the
+  /// providers it combines, so those providers must outlive it; keeping
+  /// them together in one movable object (rather than as separate
+  /// same-scope variables at the call site) makes it hard to accidentally
+  /// let them go out of scope before Combined does.
+  struct OwningProvider {
+    std::unique_ptr<Provider> Combined;
+    std::vector<std::unique_ptr<Provider>> Sources;
+  };
+
+  /// Like combine(), but takes ownership of the providers being combined.
+  static OwningProvider
+  combineOwned(std::vector<std::unique_ptr<Provider>> Sources);
----------------
HighCommander4 wrote:

Instead of adding this additional interface, can we change `combine()` itself 
to behave this way? This would also remove the need for the `OwningProvider` 
struct (since the `CombinedProvider` class used in the implementation of 
`combine()` can store unique_ptrs).

The other call sites of `combine()` should be straightforward to port to this 
interface; the only one that's not fully obvious is the one in Check.cpp, which 
likely requires making `ClangdLSPServer::Options::ConfigProvider` a 
`unique_ptr` (which I think should be fine).

https://github.com/llvm/llvm-project/pull/214951
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to