Переглянути джерело

LanguageServers: Remove ClientConnection dependency

We now no longer need to provide a ClientConnection object to construct
AutoCompleteEngine.
Itamar 4 роки тому
батько
коміт
c49cf23a86

+ 3 - 4
Userland/DevTools/HackStudio/LanguageServers/AutoCompleteEngine.cpp

@@ -8,9 +8,8 @@
 
 namespace LanguageServers {
 
-AutoCompleteEngine::AutoCompleteEngine(ClientConnection& connection, const FileDB& filedb, bool should_store_all_declarations)
-    : m_connection(connection)
-    , m_filedb(filedb)
+AutoCompleteEngine::AutoCompleteEngine(const FileDB& filedb, bool should_store_all_declarations)
+    : m_filedb(filedb)
     , m_store_all_declarations(should_store_all_declarations)
 {
 }
@@ -29,6 +28,6 @@ void AutoCompleteEngine::set_declarations_of_document(const String& filename, Ve
     }
     if (m_store_all_declarations)
         m_all_declarations.set(filename, declarations);
-    set_declarations_of_document_callback(m_connection, filename, move(declarations));
+    set_declarations_of_document_callback(filename, move(declarations));
 }
 }

+ 2 - 3
Userland/DevTools/HackStudio/LanguageServers/AutoCompleteEngine.h

@@ -17,7 +17,7 @@ class ClientConnection;
 
 class AutoCompleteEngine {
 public:
-    AutoCompleteEngine(ClientConnection&, const FileDB& filedb, bool store_all_declarations = false);
+    AutoCompleteEngine(const FileDB& filedb, bool store_all_declarations = false);
     virtual ~AutoCompleteEngine();
 
     virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position) = 0;
@@ -29,7 +29,7 @@ public:
     virtual Optional<GUI::AutocompleteProvider::ProjectLocation> find_declaration_of(const String&, const GUI::TextPosition&) { return {}; };
 
 public:
-    Function<void(ClientConnection&, String, Vector<GUI::AutocompleteProvider::Declaration>)> set_declarations_of_document_callback;
+    Function<void(const String&, Vector<GUI::AutocompleteProvider::Declaration>&&)> set_declarations_of_document_callback;
 
 protected:
     const FileDB& filedb() const { return m_filedb; }
@@ -37,7 +37,6 @@ protected:
     const HashMap<String, Vector<GUI::AutocompleteProvider::Declaration>>& all_declarations() const { return m_all_declarations; }
 
 private:
-    ClientConnection& m_connection;
     HashMap<String, Vector<GUI::AutocompleteProvider::Declaration>> m_all_declarations;
     const FileDB& m_filedb;
     bool m_store_all_declarations { false };

+ 0 - 5
Userland/DevTools/HackStudio/LanguageServers/ClientConnection.cpp

@@ -118,9 +118,4 @@ void ClientConnection::find_declaration(GUI::AutocompleteProvider::ProjectLocati
     async_declaration_location(GUI::AutocompleteProvider::ProjectLocation { decl_location.value().file, decl_location.value().line, decl_location.value().column });
 }
 
-void ClientConnection::set_declarations_of_document_callback(ClientConnection& instance, const String& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations)
-{
-    instance.async_declarations_in_document(filename, move(declarations));
-}
-
 }

+ 0 - 2
Userland/DevTools/HackStudio/LanguageServers/ClientConnection.h

@@ -36,8 +36,6 @@ protected:
     virtual void find_declaration(GUI::AutocompleteProvider::ProjectLocation const&) override;
     virtual void set_auto_complete_mode(String const&) override = 0;
 
-    static void set_declarations_of_document_callback(ClientConnection&, const String&, Vector<GUI::AutocompleteProvider::Declaration>&&);
-
     FileDB m_filedb;
     OwnPtr<AutoCompleteEngine> m_autocomplete_engine;
 };

+ 6 - 4
Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h

@@ -19,8 +19,10 @@ public:
     ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
         : LanguageServers::ClientConnection(move(socket), client_id)
     {
-        m_autocomplete_engine = make<ParserAutoComplete>(*this, m_filedb);
-        m_autocomplete_engine->set_declarations_of_document_callback = &ClientConnection::set_declarations_of_document_callback;
+        m_autocomplete_engine = make<ParserAutoComplete>(m_filedb);
+        m_autocomplete_engine->set_declarations_of_document_callback = [this](const String& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations) {
+            async_declarations_in_document(filename, move(declarations));
+        };
     }
 
     virtual ~ClientConnection() override = default;
@@ -30,9 +32,9 @@ private:
     {
         dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "SetAutoCompleteMode: {}", mode);
         if (mode == "Parser")
-            m_autocomplete_engine = make<ParserAutoComplete>(*this, m_filedb);
+            m_autocomplete_engine = make<ParserAutoComplete>(m_filedb);
         else
-            m_autocomplete_engine = make<LexerAutoComplete>(*this, m_filedb);
+            m_autocomplete_engine = make<LexerAutoComplete>(m_filedb);
     }
 };
 }

+ 2 - 2
Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.cpp

@@ -11,8 +11,8 @@
 
 namespace LanguageServers::Cpp {
 
-LexerAutoComplete::LexerAutoComplete(ClientConnection& connection, const FileDB& filedb)
-    : AutoCompleteEngine(connection, filedb)
+LexerAutoComplete::LexerAutoComplete(const FileDB& filedb)
+    : AutoCompleteEngine(filedb)
 {
 }
 

+ 1 - 1
Userland/DevTools/HackStudio/LanguageServers/Cpp/LexerAutoComplete.h

@@ -19,7 +19,7 @@ using namespace ::Cpp;
 
 class LexerAutoComplete : public AutoCompleteEngine {
 public:
-    LexerAutoComplete(ClientConnection&, const FileDB& filedb);
+    LexerAutoComplete(const FileDB& filedb);
 
     virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position) override;
 

+ 2 - 2
Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp

@@ -17,8 +17,8 @@
 
 namespace LanguageServers::Cpp {
 
-ParserAutoComplete::ParserAutoComplete(ClientConnection& connection, const FileDB& filedb)
-    : AutoCompleteEngine(connection, filedb, true)
+ParserAutoComplete::ParserAutoComplete(const FileDB& filedb)
+    : AutoCompleteEngine(filedb, true)
 {
 }
 

+ 1 - 1
Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.h

@@ -23,7 +23,7 @@ using namespace ::Cpp;
 
 class ParserAutoComplete : public AutoCompleteEngine {
 public:
-    ParserAutoComplete(ClientConnection&, const FileDB& filedb);
+    ParserAutoComplete(const FileDB& filedb);
 
     virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position) override;
     virtual void on_edit(const String& file) override;

+ 2 - 2
Userland/DevTools/HackStudio/LanguageServers/Shell/AutoComplete.cpp

@@ -14,8 +14,8 @@ namespace LanguageServers::Shell {
 
 RefPtr<::Shell::Shell> AutoComplete::s_shell {};
 
-AutoComplete::AutoComplete(ClientConnection& connection, const FileDB& filedb)
-    : AutoCompleteEngine(connection, filedb, true)
+AutoComplete::AutoComplete(const FileDB& filedb)
+    : AutoCompleteEngine(filedb, true)
 {
 }
 

+ 1 - 1
Userland/DevTools/HackStudio/LanguageServers/Shell/AutoComplete.h

@@ -13,7 +13,7 @@ namespace LanguageServers::Shell {
 
 class AutoComplete : public AutoCompleteEngine {
 public:
-    AutoComplete(ClientConnection&, const FileDB& filedb);
+    AutoComplete(const FileDB& filedb);
     virtual Vector<GUI::AutocompleteProvider::Entry> get_suggestions(const String& file, const GUI::TextPosition& position) override;
     virtual void on_edit(const String& file) override;
     virtual void file_opened([[maybe_unused]] const String& file) override;

+ 4 - 2
Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h

@@ -17,8 +17,10 @@ class ClientConnection final : public LanguageServers::ClientConnection {
     ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
         : LanguageServers::ClientConnection(move(socket), client_id)
     {
-        m_autocomplete_engine = make<AutoComplete>(*this, m_filedb);
-        m_autocomplete_engine->set_declarations_of_document_callback = &ClientConnection::set_declarations_of_document_callback;
+        m_autocomplete_engine = make<AutoComplete>(m_filedb);
+        m_autocomplete_engine->set_declarations_of_document_callback = [this](const String& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations) {
+            async_declarations_in_document(filename, move(declarations));
+        };
     }
     virtual ~ClientConnection() override = default;