kadircet updated this revision to Diff 323361.
kadircet marked 7 inline comments as done.
kadircet added a comment.
- Address comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96244/new/
https://reviews.llvm.org/D96244
Files:
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/Module.h
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -376,7 +376,7 @@
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange, const FileEntry *,
- StringRef, StringRef, const Module *,
+ StringRef, StringRef, const clang::Module *,
SrcMgr::CharacteristicKind) override {
Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled,
FilenameRange);
Index: clang-tools-extra/clangd/Module.h
===================================================================
--- /dev/null
+++ clang-tools-extra/clangd/Module.h
@@ -0,0 +1,52 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+
+#include "llvm/ADT/StringRef.h"
+#include <memory>
+#include <vector>
+
+namespace clang {
+namespace clangd {
+
+/// A Module contributes a vertical feature to clangd.
+///
+/// FIXME: Extend this with LSP bindings to support reading/updating
+/// capabilities and implementing LSP endpoints.
+///
+/// The lifetime of a module is roughly:
+/// - modules are created before the LSP server, in ClangdMain.cpp
+/// - these modules are then passed to ClangdLSPServer and ClangdServer
+/// FIXME: LSP bindings should be registered at ClangdLSPServer
+/// initialization.
+/// - module hooks can be called at this point.
+/// FIXME: We should make some server facilities like TUScheduler and index
+/// available to those modules after ClangdServer is initalized.
+/// - ClangdServer will not be destroyed until all the requests are done.
+/// FIXME: Block server shutdown until all the modules are idle.
+/// - modules will be destroyed after ClangdLSPServer is destroyed.
+///
+/// Conventionally, standard modules live in the `clangd` namespace, and other
+/// exposed details live in a sub-namespace.
+class Module {
+public:
+ virtual ~Module() = default;
+};
+
+class ModuleSet {
+ std::vector<std::unique_ptr<Module>> Modules;
+
+public:
+ explicit ModuleSet(std::vector<std::unique_ptr<Module>> Modules)
+ : Modules(std::move(Modules)) {}
+
+ using iterator = llvm::pointee_iterator<decltype(Modules)::iterator>;
+ using const_iterator =
+ llvm::pointee_iterator<decltype(Modules)::const_iterator>;
+ iterator begin() { return iterator(Modules.begin()); }
+ iterator end() { return iterator(Modules.end()); }
+ const_iterator begin() const { return const_iterator(Modules.begin()); }
+ const_iterator end() const { return const_iterator(Modules.end()); }
+};
+} // namespace clangd
+} // namespace clang
+#endif
Index: clang-tools-extra/clangd/Headers.cpp
===================================================================
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -36,7 +36,7 @@
CharSourceRange /*FilenameRange*/,
const FileEntry *File, llvm::StringRef /*SearchPath*/,
llvm::StringRef /*RelativePath*/,
- const Module * /*Imported*/,
+ const clang::Module * /*Imported*/,
SrcMgr::CharacteristicKind FileKind) override {
auto MainFID = SM.getMainFileID();
// If an include is part of the preamble patch, translate #line directives.
Index: clang-tools-extra/clangd/ClangdServer.h
===================================================================
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -14,6 +14,7 @@
#include "ConfigProvider.h"
#include "GlobalCompilationDatabase.h"
#include "Hover.h"
+#include "Module.h"
#include "Protocol.h"
#include "SemanticHighlighting.h"
#include "TUScheduler.h"
@@ -151,6 +152,8 @@
/// Enable preview of FoldingRanges feature.
bool FoldingRanges = false;
+ ModuleSet *Modules = nullptr;
+
explicit operator TUScheduler::Options() const;
};
// Sensible default options for use in tests.
@@ -345,6 +348,7 @@
const GlobalCompilationDatabase &CDB;
const ThreadsafeFS &TFS;
+ ModuleSet *Modules = nullptr;
Path ResourceDir;
// The index used to look up symbols. This could be:
Index: clang-tools-extra/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -138,7 +138,7 @@
ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
const ThreadsafeFS &TFS, const Options &Opts,
Callbacks *Callbacks)
- : CDB(CDB), TFS(TFS),
+ : CDB(CDB), TFS(TFS), Modules(Opts.Modules),
DynamicIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
ClangTidyProvider(Opts.ClangTidyProvider),
WorkspaceRoot(Opts.WorkspaceRoot),
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits