Index: clangd/ClangdLSPServer.h =================================================================== --- clangd/ClangdLSPServer.h +++ clangd/ClangdLSPServer.h @@ -23,9 +23,12 @@ /// This class provides implementation of an LSP server, glueing the JSON /// dispatch and ClangdServer together. -class ClangdLSPServer { +class ClangdLSPServer : public DiagnosticsConsumer { public: - ClangdLSPServer(JSONOutput &Out, bool RunSynchronously); + ClangdLSPServer(JSONOutput &Out, + GlobalCompilationDatabase &CDB, + FileSystemProvider &FSProvider, + bool RunSynchronously); /// Run LSP server loop, receiving input for it from \p In. \p In must be /// opened in binary mode. Output will be written using Out variable passed to @@ -33,19 +36,12 @@ /// each instance of ClangdLSPServer. void run(std::istream &In); + void + onDiagnosticsReady(PathRef File, + Tagged> Diagnostics) override; + private: class LSPProtocolCallbacks; - class LSPDiagnosticsConsumer : public DiagnosticsConsumer { - public: - LSPDiagnosticsConsumer(ClangdLSPServer &Server); - - virtual void - onDiagnosticsReady(PathRef File, - Tagged> Diagnostics); - - private: - ClangdLSPServer &Server; - }; std::vector getFixIts(StringRef File, const clangd::Diagnostic &D); @@ -70,9 +66,8 @@ // Various ClangdServer parameters go here. It's important they're created // before ClangdServer. - DirectoryBasedGlobalCompilationDatabase CDB; - LSPDiagnosticsConsumer DiagConsumer; - RealFileSystemProvider FSProvider; + GlobalCompilationDatabase &CDB; + FileSystemProvider &FSProvider; // Server must be the last member of the class to allow its destructor to exit // the worker thread that may otherwise run an async callback on partially Index: clangd/ClangdLSPServer.cpp =================================================================== --- clangd/ClangdLSPServer.cpp +++ clangd/ClangdLSPServer.cpp @@ -38,13 +38,9 @@ } // namespace -ClangdLSPServer::LSPDiagnosticsConsumer::LSPDiagnosticsConsumer( - ClangdLSPServer &Server) - : Server(Server) {} - -void ClangdLSPServer::LSPDiagnosticsConsumer::onDiagnosticsReady( +void ClangdLSPServer::onDiagnosticsReady( PathRef File, Tagged> Diagnostics) { - Server.consumeDiagnostics(File, Diagnostics.Value); + consumeDiagnostics(File, Diagnostics.Value); } class ClangdLSPServer::LSPProtocolCallbacks : public ProtocolCallbacks { @@ -191,9 +187,13 @@ R"(,"result":[)" + Completions + R"(]})"); } -ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, bool RunSynchronously) - : Out(Out), DiagConsumer(*this), - Server(CDB, DiagConsumer, FSProvider, RunSynchronously) {} +ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, + GlobalCompilationDatabase &CDB, + FileSystemProvider &FSProvider, + bool RunSynchronously) + : Out(Out), CDB(CDB), FSProvider(FSProvider), + Server(CDB, /*DiagnosticsConsumer=*/*this, FSProvider, RunSynchronously) { +} void ClangdLSPServer::run(std::istream &In) { assert(!IsDone && "Run was called before"); Index: clangd/tool/ClangdMain.cpp =================================================================== --- clangd/tool/ClangdMain.cpp +++ clangd/tool/ClangdMain.cpp @@ -35,6 +35,9 @@ // Change stdin to binary to not lose \r\n on windows. llvm::sys::ChangeStdinToBinary(); - ClangdLSPServer LSPServer(Out, RunSynchronously); + DirectoryBasedGlobalCompilationDatabase CDB; + RealFileSystemProvider FSProvider; + + ClangdLSPServer LSPServer(Out, CDB, FSProvider, RunSynchronously); LSPServer.run(std::cin); }