diff options
-rw-r--r-- | Userland/DevTools/HackStudio/LanguageClient.cpp | 23 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/LanguageClient.h | 20 | ||||
-rw-r--r-- | Userland/DevTools/HackStudio/LanguageClients/ServerConnections.h | 7 |
3 files changed, 21 insertions, 29 deletions
diff --git a/Userland/DevTools/HackStudio/LanguageClient.cpp b/Userland/DevTools/HackStudio/LanguageClient.cpp index 5d0328534d..45e7c0eece 100644 --- a/Userland/DevTools/HackStudio/LanguageClient.cpp +++ b/Userland/DevTools/HackStudio/LanguageClient.cpp @@ -122,7 +122,7 @@ void LanguageClient::on_server_crash() { VERIFY(m_server_connection); auto project_path = m_server_connection->project_path(); - ServerConnection::remove_instance_for_project(project_path); + ServerConnection::remove_instance_for_language(project_path); m_server_connection = nullptr; auto notification = GUI::Notification::construct(); @@ -133,27 +133,16 @@ void LanguageClient::on_server_crash() notification->show(); } -HashMap<String, NonnullRefPtr<ServerConnection>> ServerConnection::s_instances_for_projects; +HashMap<String, NonnullRefPtr<ServerConnection>> ServerConnection::s_instance_for_language; -RefPtr<ServerConnection> ServerConnection::instance_for_project(const String& project_path) +void ServerConnection::set_instance_for_project(const String& language_name, NonnullRefPtr<ServerConnection>&& instance) { - auto key = LexicalPath { project_path }.string(); - auto value = s_instances_for_projects.get(key); - if (!value.has_value()) - return nullptr; - return *value.value(); + s_instance_for_language.set(language_name, move(instance)); } -void ServerConnection::set_instance_for_project(const String& project_path, NonnullRefPtr<ServerConnection>&& instance) +void ServerConnection::remove_instance_for_language(const String& language_name) { - auto key = LexicalPath { project_path }.string(); - s_instances_for_projects.set(key, move(instance)); -} - -void ServerConnection::remove_instance_for_project(const String& project_path) -{ - auto key = LexicalPath { project_path }.string(); - s_instances_for_projects.remove(key); + s_instance_for_language.remove(language_name); } void ServerConnection::handle(const Messages::LanguageClient::DeclarationsInDocument& message) { diff --git a/Userland/DevTools/HackStudio/LanguageClient.h b/Userland/DevTools/HackStudio/LanguageClient.h index b9b233f028..c0569fbf4c 100644 --- a/Userland/DevTools/HackStudio/LanguageClient.h +++ b/Userland/DevTools/HackStudio/LanguageClient.h @@ -69,24 +69,24 @@ public: WeakPtr<LanguageClient> language_client() { return m_language_client; } const String& project_path() const { return m_project_path; } - template<typename ConcreteType> + template<typename LanguageServerType> static NonnullRefPtr<ServerConnection> get_or_create(const String& project_path) { - auto key = LexicalPath { project_path }.string(); - if (auto instance = s_instances_for_projects.get(key); instance.has_value()) + auto key = LanguageServerType::language_name(); + if (auto instance = s_instance_for_language.get(key); instance.has_value()) { return *instance.value(); + } - auto connection = ConcreteType::construct(project_path); + auto connection = LanguageServerType::construct(project_path); connection->handshake(); - set_instance_for_project(project_path, *connection); + set_instance_for_project(LanguageServerType::language_name(), *connection); return *connection; } - static RefPtr<ServerConnection> instance_for_project(const String& project_path); - static void set_instance_for_project(const String& project_path, NonnullRefPtr<ServerConnection>&&); - static void remove_instance_for_project(const String& project_path); + static void set_instance_for_project(const String& language_name, NonnullRefPtr<ServerConnection>&&); + static void remove_instance_for_language(const String& language_name); - virtual void die(); + virtual void die() override; protected: virtual void handle(const Messages::LanguageClient::AutoCompleteSuggestions&) override; @@ -97,7 +97,7 @@ protected: WeakPtr<LanguageClient> m_language_client; private: - static HashMap<String, NonnullRefPtr<ServerConnection>> s_instances_for_projects; + static HashMap<String, NonnullRefPtr<ServerConnection>> s_instance_for_language; }; class LanguageClient : public Weakable<LanguageClient> { diff --git a/Userland/DevTools/HackStudio/LanguageClients/ServerConnections.h b/Userland/DevTools/HackStudio/LanguageClients/ServerConnections.h index 89266e37ca..d26f32f272 100644 --- a/Userland/DevTools/HackStudio/LanguageClients/ServerConnections.h +++ b/Userland/DevTools/HackStudio/LanguageClients/ServerConnections.h @@ -32,10 +32,13 @@ #include <DevTools/HackStudio/LanguageServers/LanguageServerEndpoint.h> #include <LibIPC/ServerConnection.h> -#define LANGUAGE_CLIENT(namespace_, socket_name) \ - namespace namespace_ { \ +#define LANGUAGE_CLIENT(language_name_, socket_name) \ + namespace language_name_ { \ class ServerConnection : public HackStudio::ServerConnection { \ C_OBJECT(ServerConnection) \ + public: \ + static const char* language_name() { return #language_name_; } \ + \ private: \ ServerConnection(const String& project_path) \ : HackStudio::ServerConnection("/tmp/portal/language/" #socket_name, project_path) \ |