kadircet updated this revision to Diff 322744.
kadircet added a comment.

- Rename Plugin to Module
- Have a ModuleSet that enables type-safe traversal of existing modules (with 
questions about implementation options)


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/CMakeLists.txt
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Module.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,60 @@
+#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. Currently this consists
+/// of only a public interface to access the functionality from C++ embedders,
+///    ClangdServer::getModule<FooModule>()->foo(...)
+///
+/// FIXME: Extend this with LSP bindings to support 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 creation, and
+///    we should make some server facilities like TUScheduler and index
+///    available to those modules after ClangdServer is initalized.
+///  - module hooks can be called afterwards.
+///  - modules can be destroyed before/after ClangdServer and ClangdLSPServer
+///    FIXME: Once we make server facilities available to modules, we'll need to
+///    ensure ClangdServer is destroyed after all the modules are done/gone.
+///
+/// Conventionally, standard modules live in the `clangd` namespace, and other
+/// exposed details live in a sub-namespace.
+class Module {
+public:
+  virtual ~Module() = default;
+
+  /// Identifier for the plugin, should be unique.
+  virtual llvm::StringLiteral id() = 0;
+
+  /// Some modules might own background tasks. They should override this method
+  /// to indicate status of these tasks.
+  virtual void blockUntilIdle() {}
+};
+
+/// Wrapper around a set of modules to provide type based grouping.
+// Ideas for implementing this:
+// - dyn_cast (with possibly some caching on top to only traverse once)
+// - have a plugin registry for each individual module type?
+// - make constructor of derived modules register themselves to a
+//   singleton-list, and provide an endpoint to iterate over.
+// I am leaning towards dyn_cast option and precomputing the grouping at
+// construction time in ModuleSet. WDYT?
+class ModuleSet {
+public:
+  explicit ModuleSet(std::vector<std::unique_ptr<Module>> Modules);
+  // Returns all the modules of type T.
+  template <typename T> std::vector<T *> getModules() { return {}; }
+};
+
+} // namespace clangd
+} // namespace clang
+#endif
Index: clang-tools-extra/clangd/Module.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/clangd/Module.cpp
@@ -0,0 +1,13 @@
+//===--- Module.cpp - Main clangd server code --------------------*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Module.h"
+
+namespace clang {
+namespace clangd {} // namespace clangd
+} // namespace clang
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/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -74,6 +74,7 @@
   Hover.cpp
   IncludeFixer.cpp
   JSONTransport.cpp
+  Module.cpp
   PathMapping.cpp
   Protocol.cpp
   Quality.cpp
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to