1 //===--- ConfigCompile.cpp - Translating Fragments into Config ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Fragments are applied to Configs in two steps:
10 //
11 // 1. (When the fragment is first loaded)
12 //    FragmentCompiler::compile() traverses the Fragment and creates
13 //    function objects that know how to apply the configuration.
14 // 2. (Every time a config is required)
15 //    CompiledFragment() executes these functions to populate the Config.
16 //
17 // Work could be split between these steps in different ways. We try to
18 // do as much work as possible in the first step. For example, regexes are
19 // compiled in stage 1 and captured by the apply function. This is because:
20 //
21 //  - it's more efficient, as the work done in stage 1 must only be done once
22 //  - problems can be reported in stage 1, in stage 2 we must silently recover
23 //
24 //===----------------------------------------------------------------------===//
25 
26 #include "CompileCommands.h"
27 #include "Config.h"
28 #include "ConfigFragment.h"
29 #include "ConfigProvider.h"
30 #include "Diagnostics.h"
31 #include "Feature.h"
32 #include "TidyProvider.h"
33 #include "support/Logger.h"
34 #include "support/Path.h"
35 #include "support/Trace.h"
36 #include "llvm/ADT/None.h"
37 #include "llvm/ADT/Optional.h"
38 #include "llvm/ADT/STLExtras.h"
39 #include "llvm/ADT/SmallString.h"
40 #include "llvm/ADT/StringRef.h"
41 #include "llvm/Support/FileSystem.h"
42 #include "llvm/Support/FormatVariadic.h"
43 #include "llvm/Support/Path.h"
44 #include "llvm/Support/Regex.h"
45 #include "llvm/Support/SMLoc.h"
46 #include "llvm/Support/SourceMgr.h"
47 #include <algorithm>
48 #include <memory>
49 #include <string>
50 #include <vector>
51 
52 namespace clang {
53 namespace clangd {
54 namespace config {
55 namespace {
56 
57 // Returns an empty stringref if Path is not under FragmentDir. Returns Path
58 // as-is when FragmentDir is empty.
59 llvm::StringRef configRelative(llvm::StringRef Path,
60                                llvm::StringRef FragmentDir) {
61   if (FragmentDir.empty())
62     return Path;
63   if (!Path.consume_front(FragmentDir))
64     return llvm::StringRef();
65   return Path.empty() ? "." : Path;
66 }
67 
68 struct CompiledFragmentImpl {
69   // The independent conditions to check before using settings from this config.
70   // The following fragment has *two* conditions:
71   //   If: { Platform: [mac, linux], PathMatch: foo/.* }
72   // All of them must be satisfied: the platform and path conditions are ANDed.
73   // The OR logic for the platform condition is implemented inside the function.
74   std::vector<llvm::unique_function<bool(const Params &) const>> Conditions;
75   // Mutations that this fragment will apply to the configuration.
76   // These are invoked only if the conditions are satisfied.
77   std::vector<llvm::unique_function<void(const Params &, Config &) const>>
78       Apply;
79 
80   bool operator()(const Params &P, Config &C) const {
81     for (const auto &C : Conditions) {
82       if (!C(P)) {
83         dlog("Config fragment {0}: condition not met", this);
84         return false;
85       }
86     }
87     dlog("Config fragment {0}: applying {1} rules", this, Apply.size());
88     for (const auto &A : Apply)
89       A(P, C);
90     return true;
91   }
92 };
93 
94 // Wrapper around condition compile() functions to reduce arg-passing.
95 struct FragmentCompiler {
96   FragmentCompiler(CompiledFragmentImpl &Out, DiagnosticCallback D,
97                    llvm::SourceMgr *SM)
98       : Out(Out), Diagnostic(D), SourceMgr(SM) {}
99   CompiledFragmentImpl &Out;
100   DiagnosticCallback Diagnostic;
101   llvm::SourceMgr *SourceMgr;
102   // Normalized Fragment::SourceInfo::Directory.
103   std::string FragmentDirectory;
104   bool Trusted = false;
105 
106   llvm::Optional<llvm::Regex>
107   compileRegex(const Located<std::string> &Text,
108                llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags) {
109     std::string Anchored = "^(" + *Text + ")$";
110     llvm::Regex Result(Anchored, Flags);
111     std::string RegexError;
112     if (!Result.isValid(RegexError)) {
113       diag(Error, "Invalid regex " + Anchored + ": " + RegexError, Text.Range);
114       return llvm::None;
115     }
116     return Result;
117   }
118 
119   llvm::Optional<std::string> makeAbsolute(Located<std::string> Path,
120                                            llvm::StringLiteral Description,
121                                            llvm::sys::path::Style Style) {
122     if (llvm::sys::path::is_absolute(*Path))
123       return *Path;
124     if (FragmentDirectory.empty()) {
125       diag(Error,
126            llvm::formatv(
127                "{0} must be an absolute path, because this fragment is not "
128                "associated with any directory.",
129                Description)
130                .str(),
131            Path.Range);
132       return llvm::None;
133     }
134     llvm::SmallString<256> AbsPath = llvm::StringRef(*Path);
135     llvm::sys::fs::make_absolute(FragmentDirectory, AbsPath);
136     llvm::sys::path::native(AbsPath, Style);
137     return AbsPath.str().str();
138   }
139 
140   // Helper with similar API to StringSwitch, for parsing enum values.
141   template <typename T> class EnumSwitch {
142     FragmentCompiler &Outer;
143     llvm::StringRef EnumName;
144     const Located<std::string> &Input;
145     llvm::Optional<T> Result;
146     llvm::SmallVector<llvm::StringLiteral> ValidValues;
147 
148   public:
149     EnumSwitch(llvm::StringRef EnumName, const Located<std::string> &In,
150                FragmentCompiler &Outer)
151         : Outer(Outer), EnumName(EnumName), Input(In) {}
152 
153     EnumSwitch &map(llvm::StringLiteral Name, T Value) {
154       assert(!llvm::is_contained(ValidValues, Name) && "Duplicate value!");
155       ValidValues.push_back(Name);
156       if (!Result && *Input == Name)
157         Result = Value;
158       return *this;
159     }
160 
161     llvm::Optional<T> value() {
162       if (!Result)
163         Outer.diag(
164             Warning,
165             llvm::formatv("Invalid {0} value '{1}'. Valid values are {2}.",
166                           EnumName, *Input, llvm::join(ValidValues, ", "))
167                 .str(),
168             Input.Range);
169       return Result;
170     };
171   };
172 
173   // Attempt to parse a specified string into an enum.
174   // Yields llvm::None and produces a diagnostic on failure.
175   //
176   // Optional<T> Value = compileEnum<En>("Foo", Frag.Foo)
177   //    .map("Foo", Enum::Foo)
178   //    .map("Bar", Enum::Bar)
179   //    .value();
180   template <typename T>
181   EnumSwitch<T> compileEnum(llvm::StringRef EnumName,
182                             const Located<std::string> &In) {
183     return EnumSwitch<T>(EnumName, In, *this);
184   }
185 
186   void compile(Fragment &&F) {
187     Trusted = F.Source.Trusted;
188     if (!F.Source.Directory.empty()) {
189       FragmentDirectory = llvm::sys::path::convert_to_slash(F.Source.Directory);
190       if (FragmentDirectory.back() != '/')
191         FragmentDirectory += '/';
192     }
193     compile(std::move(F.If));
194     compile(std::move(F.CompileFlags));
195     compile(std::move(F.Index));
196     compile(std::move(F.Diagnostics));
197     compile(std::move(F.Completion));
198     compile(std::move(F.Hover));
199     compile(std::move(F.InlayHints));
200   }
201 
202   void compile(Fragment::IfBlock &&F) {
203     if (F.HasUnrecognizedCondition)
204       Out.Conditions.push_back([&](const Params &) { return false; });
205 
206 #ifdef CLANGD_PATH_CASE_INSENSITIVE
207     llvm::Regex::RegexFlags Flags = llvm::Regex::IgnoreCase;
208 #else
209     llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
210 #endif
211 
212     auto PathMatch = std::make_unique<std::vector<llvm::Regex>>();
213     for (auto &Entry : F.PathMatch) {
214       if (auto RE = compileRegex(Entry, Flags))
215         PathMatch->push_back(std::move(*RE));
216     }
217     if (!PathMatch->empty()) {
218       Out.Conditions.push_back(
219           [PathMatch(std::move(PathMatch)),
220            FragmentDir(FragmentDirectory)](const Params &P) {
221             if (P.Path.empty())
222               return false;
223             llvm::StringRef Path = configRelative(P.Path, FragmentDir);
224             // Ignore the file if it is not nested under Fragment.
225             if (Path.empty())
226               return false;
227             return llvm::any_of(*PathMatch, [&](const llvm::Regex &RE) {
228               return RE.match(Path);
229             });
230           });
231     }
232 
233     auto PathExclude = std::make_unique<std::vector<llvm::Regex>>();
234     for (auto &Entry : F.PathExclude) {
235       if (auto RE = compileRegex(Entry, Flags))
236         PathExclude->push_back(std::move(*RE));
237     }
238     if (!PathExclude->empty()) {
239       Out.Conditions.push_back(
240           [PathExclude(std::move(PathExclude)),
241            FragmentDir(FragmentDirectory)](const Params &P) {
242             if (P.Path.empty())
243               return false;
244             llvm::StringRef Path = configRelative(P.Path, FragmentDir);
245             // Ignore the file if it is not nested under Fragment.
246             if (Path.empty())
247               return true;
248             return llvm::none_of(*PathExclude, [&](const llvm::Regex &RE) {
249               return RE.match(Path);
250             });
251           });
252     }
253   }
254 
255   void compile(Fragment::CompileFlagsBlock &&F) {
256     if (F.Compiler)
257       Out.Apply.push_back(
258           [Compiler(std::move(**F.Compiler))](const Params &, Config &C) {
259             C.CompileFlags.Edits.push_back(
260                 [Compiler](std::vector<std::string> &Args) {
261                   if (!Args.empty())
262                     Args.front() = Compiler;
263                 });
264           });
265 
266     if (!F.Remove.empty()) {
267       auto Remove = std::make_shared<ArgStripper>();
268       for (auto &A : F.Remove)
269         Remove->strip(*A);
270       Out.Apply.push_back([Remove(std::shared_ptr<const ArgStripper>(
271                               std::move(Remove)))](const Params &, Config &C) {
272         C.CompileFlags.Edits.push_back(
273             [Remove](std::vector<std::string> &Args) {
274               Remove->process(Args);
275             });
276       });
277     }
278 
279     if (!F.Add.empty()) {
280       std::vector<std::string> Add;
281       for (auto &A : F.Add)
282         Add.push_back(std::move(*A));
283       Out.Apply.push_back([Add(std::move(Add))](const Params &, Config &C) {
284         C.CompileFlags.Edits.push_back([Add](std::vector<std::string> &Args) {
285           // The point to insert at. Just append when `--` isn't present.
286           auto It = llvm::find(Args, "--");
287           Args.insert(It, Add.begin(), Add.end());
288         });
289       });
290     }
291 
292     if (F.CompilationDatabase) {
293       llvm::Optional<Config::CDBSearchSpec> Spec;
294       if (**F.CompilationDatabase == "Ancestors") {
295         Spec.emplace();
296         Spec->Policy = Config::CDBSearchSpec::Ancestors;
297       } else if (**F.CompilationDatabase == "None") {
298         Spec.emplace();
299         Spec->Policy = Config::CDBSearchSpec::NoCDBSearch;
300       } else {
301         if (auto Path =
302                 makeAbsolute(*F.CompilationDatabase, "CompilationDatabase",
303                              llvm::sys::path::Style::native)) {
304           // Drop trailing slash to put the path in canonical form.
305           // Should makeAbsolute do this?
306           llvm::StringRef Rel = llvm::sys::path::relative_path(*Path);
307           if (!Rel.empty() && llvm::sys::path::is_separator(Rel.back()))
308             Path->pop_back();
309 
310           Spec.emplace();
311           Spec->Policy = Config::CDBSearchSpec::FixedDir;
312           Spec->FixedCDBPath = std::move(Path);
313         }
314       }
315       if (Spec)
316         Out.Apply.push_back(
317             [Spec(std::move(*Spec))](const Params &, Config &C) {
318               C.CompileFlags.CDBSearch = Spec;
319             });
320     }
321   }
322 
323   void compile(Fragment::IndexBlock &&F) {
324     if (F.Background) {
325       if (auto Val = compileEnum<Config::BackgroundPolicy>("Background",
326                                                            **F.Background)
327                          .map("Build", Config::BackgroundPolicy::Build)
328                          .map("Skip", Config::BackgroundPolicy::Skip)
329                          .value())
330         Out.Apply.push_back(
331             [Val](const Params &, Config &C) { C.Index.Background = *Val; });
332     }
333     if (F.External)
334       compile(std::move(**F.External), F.External->Range);
335   }
336 
337   void compile(Fragment::IndexBlock::ExternalBlock &&External,
338                llvm::SMRange BlockRange) {
339     if (External.Server && !Trusted) {
340       diag(Error,
341            "Remote index may not be specified by untrusted configuration. "
342            "Copy this into user config to use it.",
343            External.Server->Range);
344       return;
345     }
346 #ifndef CLANGD_ENABLE_REMOTE
347     if (External.Server) {
348       elog("Clangd isn't compiled with remote index support, ignoring Server: "
349            "{0}",
350            *External.Server);
351       External.Server.reset();
352     }
353 #endif
354     // Make sure exactly one of the Sources is set.
355     unsigned SourceCount = External.File.hasValue() +
356                            External.Server.hasValue() + *External.IsNone;
357     if (SourceCount != 1) {
358       diag(Error, "Exactly one of File, Server or None must be set.",
359            BlockRange);
360       return;
361     }
362     Config::ExternalIndexSpec Spec;
363     if (External.Server) {
364       Spec.Kind = Config::ExternalIndexSpec::Server;
365       Spec.Location = std::move(**External.Server);
366     } else if (External.File) {
367       Spec.Kind = Config::ExternalIndexSpec::File;
368       auto AbsPath = makeAbsolute(std::move(*External.File), "File",
369                                   llvm::sys::path::Style::native);
370       if (!AbsPath)
371         return;
372       Spec.Location = std::move(*AbsPath);
373     } else {
374       assert(*External.IsNone);
375       Spec.Kind = Config::ExternalIndexSpec::None;
376     }
377     if (Spec.Kind != Config::ExternalIndexSpec::None) {
378       // Make sure MountPoint is an absolute path with forward slashes.
379       if (!External.MountPoint)
380         External.MountPoint.emplace(FragmentDirectory);
381       if ((**External.MountPoint).empty()) {
382         diag(Error, "A mountpoint is required.", BlockRange);
383         return;
384       }
385       auto AbsPath = makeAbsolute(std::move(*External.MountPoint), "MountPoint",
386                                   llvm::sys::path::Style::posix);
387       if (!AbsPath)
388         return;
389       Spec.MountPoint = std::move(*AbsPath);
390     }
391     Out.Apply.push_back([Spec(std::move(Spec))](const Params &P, Config &C) {
392       if (Spec.Kind == Config::ExternalIndexSpec::None) {
393         C.Index.External = Spec;
394         return;
395       }
396       if (P.Path.empty() || !pathStartsWith(Spec.MountPoint, P.Path,
397                                             llvm::sys::path::Style::posix))
398         return;
399       C.Index.External = Spec;
400       // Disable background indexing for the files under the mountpoint.
401       // Note that this will overwrite statements in any previous fragments
402       // (including the current one).
403       C.Index.Background = Config::BackgroundPolicy::Skip;
404     });
405   }
406 
407   void compile(Fragment::DiagnosticsBlock &&F) {
408     std::vector<std::string> Normalized;
409     for (const auto &Suppressed : F.Suppress) {
410       if (*Suppressed == "*") {
411         Out.Apply.push_back([&](const Params &, Config &C) {
412           C.Diagnostics.SuppressAll = true;
413           C.Diagnostics.Suppress.clear();
414         });
415         return;
416       }
417       Normalized.push_back(normalizeSuppressedCode(*Suppressed).str());
418     }
419     if (!Normalized.empty())
420       Out.Apply.push_back(
421           [Normalized(std::move(Normalized))](const Params &, Config &C) {
422             if (C.Diagnostics.SuppressAll)
423               return;
424             for (llvm::StringRef N : Normalized)
425               C.Diagnostics.Suppress.insert(N);
426           });
427 
428     if (F.UnusedIncludes)
429       if (auto Val = compileEnum<Config::UnusedIncludesPolicy>(
430                          "UnusedIncludes", **F.UnusedIncludes)
431                          .map("Strict", Config::UnusedIncludesPolicy::Strict)
432                          .map("None", Config::UnusedIncludesPolicy::None)
433                          .value())
434         Out.Apply.push_back([Val](const Params &, Config &C) {
435           C.Diagnostics.UnusedIncludes = *Val;
436         });
437     compile(std::move(F.Includes));
438 
439     compile(std::move(F.ClangTidy));
440   }
441 
442   void compile(Fragment::StyleBlock &&F) {
443     if (!F.FullyQualifiedNamespaces.empty()) {
444       std::vector<std::string> FullyQualifiedNamespaces;
445       for (auto &N : F.FullyQualifiedNamespaces) {
446         // Normalize the data by dropping both leading and trailing ::
447         StringRef Namespace(*N);
448         Namespace.consume_front("::");
449         Namespace.consume_back("::");
450         FullyQualifiedNamespaces.push_back(Namespace.str());
451       }
452       Out.Apply.push_back([FullyQualifiedNamespaces(
453                               std::move(FullyQualifiedNamespaces))](
454                               const Params &, Config &C) {
455         C.Style.FullyQualifiedNamespaces.insert(
456             C.Style.FullyQualifiedNamespaces.begin(),
457             FullyQualifiedNamespaces.begin(), FullyQualifiedNamespaces.end());
458       });
459     }
460   }
461 
462   void appendTidyCheckSpec(std::string &CurSpec,
463                            const Located<std::string> &Arg, bool IsPositive) {
464     StringRef Str = StringRef(*Arg).trim();
465     // Don't support negating here, its handled if the item is in the Add or
466     // Remove list.
467     if (Str.startswith("-") || Str.contains(',')) {
468       diag(Error, "Invalid clang-tidy check name", Arg.Range);
469       return;
470     }
471     if (!Str.contains('*') && !isRegisteredTidyCheck(Str)) {
472       diag(Warning,
473            llvm::formatv("clang-tidy check '{0}' was not found", Str).str(),
474            Arg.Range);
475       return;
476     }
477     CurSpec += ',';
478     if (!IsPositive)
479       CurSpec += '-';
480     CurSpec += Str;
481   }
482 
483   void compile(Fragment::DiagnosticsBlock::ClangTidyBlock &&F) {
484     std::string Checks;
485     for (auto &CheckGlob : F.Add)
486       appendTidyCheckSpec(Checks, CheckGlob, true);
487 
488     for (auto &CheckGlob : F.Remove)
489       appendTidyCheckSpec(Checks, CheckGlob, false);
490 
491     if (!Checks.empty())
492       Out.Apply.push_back(
493           [Checks = std::move(Checks)](const Params &, Config &C) {
494             C.Diagnostics.ClangTidy.Checks.append(
495                 Checks,
496                 C.Diagnostics.ClangTidy.Checks.empty() ? /*skip comma*/ 1 : 0,
497                 std::string::npos);
498           });
499     if (!F.CheckOptions.empty()) {
500       std::vector<std::pair<std::string, std::string>> CheckOptions;
501       for (auto &Opt : F.CheckOptions)
502         CheckOptions.emplace_back(std::move(*Opt.first),
503                                   std::move(*Opt.second));
504       Out.Apply.push_back(
505           [CheckOptions = std::move(CheckOptions)](const Params &, Config &C) {
506             for (auto &StringPair : CheckOptions)
507               C.Diagnostics.ClangTidy.CheckOptions.insert_or_assign(
508                   StringPair.first, StringPair.second);
509           });
510     }
511   }
512 
513   void compile(Fragment::DiagnosticsBlock::IncludesBlock &&F) {
514 #ifdef CLANGD_PATH_CASE_INSENSITIVE
515     static llvm::Regex::RegexFlags Flags = llvm::Regex::IgnoreCase;
516 #else
517     static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
518 #endif
519     auto Filters = std::make_shared<std::vector<llvm::Regex>>();
520     for (auto &HeaderPattern : F.IgnoreHeader) {
521       // Anchor on the right.
522       std::string AnchoredPattern = "(" + *HeaderPattern + ")$";
523       llvm::Regex CompiledRegex(AnchoredPattern, Flags);
524       std::string RegexError;
525       if (!CompiledRegex.isValid(RegexError)) {
526         diag(Warning,
527              llvm::formatv("Invalid regular expression '{0}': {1}",
528                            *HeaderPattern, RegexError)
529                  .str(),
530              HeaderPattern.Range);
531         continue;
532       }
533       Filters->push_back(std::move(CompiledRegex));
534     }
535     if (Filters->empty())
536       return;
537     auto Filter = [Filters](llvm::StringRef Path) {
538       for (auto &Regex : *Filters)
539         if (Regex.match(Path))
540           return true;
541       return false;
542     };
543     Out.Apply.push_back([Filter](const Params &, Config &C) {
544       C.Diagnostics.Includes.IgnoreHeader.emplace_back(Filter);
545     });
546   }
547 
548   void compile(Fragment::CompletionBlock &&F) {
549     if (F.AllScopes) {
550       Out.Apply.push_back(
551           [AllScopes(**F.AllScopes)](const Params &, Config &C) {
552             C.Completion.AllScopes = AllScopes;
553           });
554     }
555   }
556 
557   void compile(Fragment::HoverBlock &&F) {
558     if (F.ShowAKA) {
559       Out.Apply.push_back([ShowAKA(**F.ShowAKA)](const Params &, Config &C) {
560         C.Hover.ShowAKA = ShowAKA;
561       });
562     }
563   }
564 
565   void compile(Fragment::InlayHintsBlock &&F) {
566     if (F.Enabled)
567       Out.Apply.push_back([Value(**F.Enabled)](const Params &, Config &C) {
568         C.InlayHints.Enabled = Value;
569       });
570     if (F.ParameterNames)
571       Out.Apply.push_back(
572           [Value(**F.ParameterNames)](const Params &, Config &C) {
573             C.InlayHints.Parameters = Value;
574           });
575     if (F.DeducedTypes)
576       Out.Apply.push_back([Value(**F.DeducedTypes)](const Params &, Config &C) {
577         C.InlayHints.DeducedTypes = Value;
578       });
579     if (F.Designators)
580       Out.Apply.push_back([Value(**F.Designators)](const Params &, Config &C) {
581         C.InlayHints.Designators = Value;
582       });
583   }
584 
585   constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;
586   constexpr static llvm::SourceMgr::DiagKind Warning =
587       llvm::SourceMgr::DK_Warning;
588   void diag(llvm::SourceMgr::DiagKind Kind, llvm::StringRef Message,
589             llvm::SMRange Range) {
590     if (Range.isValid() && SourceMgr != nullptr)
591       Diagnostic(SourceMgr->GetMessage(Range.Start, Kind, Message, Range));
592     else
593       Diagnostic(llvm::SMDiagnostic("", Kind, Message));
594   }
595 };
596 
597 } // namespace
598 
599 CompiledFragment Fragment::compile(DiagnosticCallback D) && {
600   llvm::StringRef ConfigFile = "<unknown>";
601   std::pair<unsigned, unsigned> LineCol = {0, 0};
602   if (auto *SM = Source.Manager.get()) {
603     unsigned BufID = SM->getMainFileID();
604     LineCol = SM->getLineAndColumn(Source.Location, BufID);
605     ConfigFile = SM->getBufferInfo(BufID).Buffer->getBufferIdentifier();
606   }
607   trace::Span Tracer("ConfigCompile");
608   SPAN_ATTACH(Tracer, "ConfigFile", ConfigFile);
609   auto Result = std::make_shared<CompiledFragmentImpl>();
610   vlog("Config fragment: compiling {0}:{1} -> {2} (trusted={3})", ConfigFile,
611        LineCol.first, Result.get(), Source.Trusted);
612 
613   FragmentCompiler{*Result, D, Source.Manager.get()}.compile(std::move(*this));
614   // Return as cheaply-copyable wrapper.
615   return [Result(std::move(Result))](const Params &P, Config &C) {
616     return (*Result)(P, C);
617   };
618 }
619 
620 } // namespace config
621 } // namespace clangd
622 } // namespace clang
623