clang-tools  14.0.0git
FeatureModule.cpp
Go to the documentation of this file.
1 //===--- FeatureModule.cpp - Plugging features into clangd ----------------===//
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 #include "FeatureModule.h"
10 #include "support/Logger.h"
11 
12 namespace clang {
13 namespace clangd {
14 
16  assert(!Fac.hasValue() && "Initialized twice");
17  Fac.emplace(F);
18 }
19 
21  assert(Fac.hasValue() && "Not initialized yet");
22  return *Fac;
23 }
24 
25 bool FeatureModuleSet::addImpl(void *Key, std::unique_ptr<FeatureModule> M,
26  const char *Source) {
27  if (!Map.try_emplace(Key, M.get()).second) {
28  // Source should (usually) include the name of the concrete module type.
29  elog("Tried to register duplicate feature modules via {0}", Source);
30  return false;
31  }
32  Modules.push_back(std::move(M));
33  return true;
34 }
35 
36 } // namespace clangd
37 } // namespace clang
clang::clangd::FeatureModule::Facilities
Shared server facilities needed by the module to get its work done.
Definition: FeatureModule.h:75
M
const google::protobuf::Message & M
Definition: Server.cpp:309
Logger.h
clang::clangd::Key
Values in a Context are indexed by typed keys.
Definition: Context.h:40
FeatureModule.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::FeatureModule::facilities
Facilities & facilities()
Accessors for modules to access shared server facilities they depend on.
Definition: FeatureModule.cpp:20
clang::clangd::elog
void elog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:62
clang::clangd::FeatureModule::initialize
void initialize(const Facilities &F)
Called by the server to prepare this module for use.
Definition: FeatureModule.cpp:15