1
- // ===--- Module .h - Plugging features into clangd ------- ----------*-C++-*-===//
1
+ // ===--- FeatureModule .h - Plugging features into clangd ----------*-C++-*-===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
- #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
10
- #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
9
+ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATUREMODULE_H
10
+ #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATUREMODULE_H
11
11
12
12
#include " support/Function.h"
13
13
#include " support/Threading.h"
@@ -26,11 +26,11 @@ class SymbolIndex;
26
26
class ThreadsafeFS ;
27
27
class TUScheduler ;
28
28
29
- // / A Module contributes a vertical feature to clangd.
29
+ // / A FeatureModule contributes a vertical feature to clangd.
30
30
// /
31
31
// / The lifetime of a module is roughly:
32
- // / - modules are created before the LSP server, in ClangdMain.cpp
33
- // / - these modules are then passed to ClangdLSPServer in a ModuleSet
32
+ // / - feature modules are created before the LSP server, in ClangdMain.cpp
33
+ // / - these modules are then passed to ClangdLSPServer in a FeatureModuleSet
34
34
// / - initializeLSP() is called when the editor calls initialize.
35
35
// - initialize() is then called by ClangdServer as it is constructed.
36
36
// / - module hooks can be called by the server at this point.
@@ -39,31 +39,31 @@ class TUScheduler;
39
39
// / FIXME: Block server shutdown until all the modules are idle.
40
40
// / - When shutting down, ClangdServer will wait for all requests to
41
41
// / finish, call stop(), and then blockUntilIdle().
42
- // / - modules will be destroyed after ClangdLSPServer is destroyed.
42
+ // / - feature modules will be destroyed after ClangdLSPServer is destroyed.
43
43
// /
44
- // / Modules are not threadsafe in general. A module's entrypoints are:
44
+ // / FeatureModules are not threadsafe in general. A module's entrypoints are:
45
45
// / - method handlers registered in initializeLSP()
46
- // / - public methods called directly via ClangdServer.getModule <T>()->...
47
- // / - specific overridable "hook" methods inherited from Module
46
+ // / - public methods called directly via ClangdServer.featureModule <T>()->...
47
+ // / - specific overridable "hook" methods inherited from FeatureModule
48
48
// / Unless otherwise specified, these are only called on the main thread.
49
49
// /
50
- // / Conventionally, standard modules live in the `clangd` namespace, and other
51
- // / exposed details live in a sub-namespace.
52
- class Module {
50
+ // / Conventionally, standard feature modules live in the `clangd` namespace,
51
+ // / and other exposed details live in a sub-namespace.
52
+ class FeatureModule {
53
53
public:
54
- virtual ~Module () {
54
+ virtual ~FeatureModule () {
55
55
// / Perform shutdown sequence on destruction in case the ClangdServer was
56
56
// / never initialized. Usually redundant, but shutdown is idempotent.
57
57
stop ();
58
58
blockUntilIdle (Deadline::infinity ());
59
59
}
60
60
61
- // / Called by the server to connect this module to LSP.
61
+ // / Called by the server to connect this feature module to LSP.
62
62
// / The module should register the methods/notifications/commands it handles,
63
63
// / and update the server capabilities to advertise them.
64
64
// /
65
65
// / This is only called if the module is running in ClangdLSPServer!
66
- // / Modules with a public interface should satisfy it without LSP bindings.
66
+ // / FeatureModules with a public interface should work without LSP bindings.
67
67
virtual void initializeLSP (LSPBinder &Bind,
68
68
const llvm::json::Object &ClientCaps,
69
69
llvm::json::Object &ServerCaps) {}
@@ -87,7 +87,7 @@ class Module {
87
87
// / Waits until the module is idle (no background work) or a deadline expires.
88
88
// / In general all modules should eventually go idle, though it may take a
89
89
// / long time (e.g. background indexing).
90
- // / Modules should go idle quickly if stop() has been called.
90
+ // / FeatureModules should go idle quickly if stop() has been called.
91
91
// / Called by the server when shutting down, and also by tests.
92
92
virtual bool blockUntilIdle (Deadline) { return true ; }
93
93
@@ -101,7 +101,7 @@ class Module {
101
101
// / The filesystem is used to read source files on disk.
102
102
const ThreadsafeFS &fs () { return facilities ().FS ; }
103
103
104
- // / Types of function objects that modules use for outgoing calls.
104
+ // / Types of function objects that feature modules use for outgoing calls.
105
105
// / (Bound throuh LSPBinder, made available here for convenience).
106
106
template <typename P>
107
107
using OutgoingNotification = llvm::unique_function<void (const P &)>;
@@ -112,28 +112,28 @@ class Module {
112
112
llvm::Optional<Facilities> Fac;
113
113
};
114
114
115
- // / A ModuleSet is a collection of modules installed in clangd.
115
+ // / A FeatureModuleSet is a collection of feature modules installed in clangd.
116
116
// /
117
- // / Modules can be looked up by type, or used through the Module interface.
117
+ // / Modules can be looked up by type, or used via the FeatureModule interface.
118
118
// / This allows individual modules to expose a public API.
119
- // / For this reason, there can be only one module of each type.
119
+ // / For this reason, there can be only one feature module of each type.
120
120
// /
121
- // / ModuleSet owns the modules. It is itself owned by main, not ClangdServer.
122
- class ModuleSet {
123
- std::vector<std::unique_ptr<Module >> Modules;
124
- llvm::DenseMap<void *, Module *> Map;
121
+ // / The set owns the modules. It is itself owned by main, not ClangdServer.
122
+ class FeatureModuleSet {
123
+ std::vector<std::unique_ptr<FeatureModule >> Modules;
124
+ llvm::DenseMap<void *, FeatureModule *> Map;
125
125
126
126
template <typename Mod> struct ID {
127
- static_assert (std::is_base_of<Module , Mod>::value &&
127
+ static_assert (std::is_base_of<FeatureModule , Mod>::value &&
128
128
std::is_final<Mod>::value,
129
129
" Modules must be final classes derived from clangd::Module" );
130
130
static int Key;
131
131
};
132
132
133
- bool addImpl (void *Key, std::unique_ptr<Module >, const char *Source);
133
+ bool addImpl (void *Key, std::unique_ptr<FeatureModule >, const char *Source);
134
134
135
135
public:
136
- ModuleSet () = default ;
136
+ FeatureModuleSet () = default ;
137
137
138
138
using iterator = llvm::pointee_iterator<decltype(Modules)::iterator>;
139
139
using const_iterator =
@@ -150,11 +150,11 @@ class ModuleSet {
150
150
return static_cast <Mod *>(Map.lookup (&ID<Mod>::Key));
151
151
}
152
152
template <typename Mod> const Mod *get () const {
153
- return const_cast <ModuleSet *>(this )->get <Mod>();
153
+ return const_cast <FeatureModuleSet *>(this )->get <Mod>();
154
154
}
155
155
};
156
156
157
- template <typename Mod> int ModuleSet ::ID<Mod>::Key;
157
+ template <typename Mod> int FeatureModuleSet ::ID<Mod>::Key;
158
158
159
159
} // namespace clangd
160
160
} // namespace clang
0 commit comments