HackStudio: Abstract away language-server details

This commit moves all the logic that deals with the language server
(from HackStudio) into a LanguageClient class, provides some functions
to make constructing them easier, and makes all language servers use a
singular IPC definition.
Also fixes the FIXME about making the autocompletion async.
This makes adding language servers in the future significantly less
duplicate-y, and significantly easier :^)
This commit is contained in:
AnotherTest 2020-10-02 03:01:33 +03:30 committed by Andreas Kling
parent 44f9637e20
commit ac5e08a541
Notes: sideshowbarker 2024-07-19 02:05:43 +09:00
17 changed files with 291 additions and 118 deletions

View file

@ -23,6 +23,7 @@ set(SOURCES
Git/GitRepo.cpp
Git/GitWidget.cpp
HackStudioWidget.cpp
LanguageClient.cpp
Locator.cpp
ProcessStateWidget.cpp
Project.cpp

View file

@ -473,7 +473,7 @@ void Editor::set_document(GUI::TextDocument& doc)
switch (code_document.language()) {
case Language::Cpp:
set_syntax_highlighter(make<GUI::CppSyntaxHighlighter>());
cpp_Language_server_connection().post_message(Messages::CppLanguageServer::FileOpened(code_document.file_path().string()));
m_language_client = get_language_client<LanguageClients::Cpp::ServerConnection>(project().root_directory());
break;
case Language::JavaScript:
set_syntax_highlighter(make<GUI::JSSyntaxHighlighter>());
@ -487,6 +487,9 @@ void Editor::set_document(GUI::TextDocument& doc)
default:
set_syntax_highlighter(nullptr);
}
if (m_language_client)
m_language_client->open_file(code_document.file_path().string());
}
Optional<Editor::AutoCompleteRequestData> Editor::get_autocomplete_request_data()
@ -517,22 +520,25 @@ Optional<Editor::AutoCompleteRequestData> Editor::get_autocomplete_request_data(
void Editor::update_autocomplete(const AutoCompleteRequestData& data)
{
if (code_document().language() != Language::Cpp)
if (!m_language_client)
return;
auto autocomplete_response = cpp_Language_server_connection().send_sync<Messages::CppLanguageServer::AutoCompleteSuggestions>(
m_language_client->on_autocomplete_suggestions = [=, this](auto suggestions) {
if (suggestions.is_empty()) {
close_autocomplete();
return;
}
show_autocomplete(data);
m_autocomplete_box->update_suggestions(data.partial_input, move(suggestions));
m_autocomplete_in_focus = true;
};
m_language_client->request_autocomplete(
code_document().file_path().string(),
data.position.line(),
data.position.column());
ASSERT(autocomplete_response);
auto suggestions = autocomplete_response->suggestions();
if (suggestions.is_empty()) {
close_autocomplete();
return;
}
m_autocomplete_box->update_suggestions(data.partial_input, move(suggestions));
m_autocomplete_in_focus = true;
}
void Editor::show_autocomplete(const AutoCompleteRequestData& data)
@ -549,29 +555,27 @@ void Editor::close_autocomplete()
void Editor::on_edit_action(const GUI::Command& command)
{
if (code_document().language() != Language::Cpp)
if (!m_language_client)
return;
if (command.is_insert_text()) {
const GUI::InsertTextCommand& insert_command = static_cast<const GUI::InsertTextCommand&>(command);
cpp_Language_server_connection().post_message(
Messages::CppLanguageServer::FileEditInsertText(
code_document().file_path().string(),
insert_command.text(),
insert_command.range().start().line(),
insert_command.range().start().column()));
m_language_client->insert_text(
code_document().file_path().string(),
insert_command.text(),
insert_command.range().start().line(),
insert_command.range().start().column());
return;
}
if (command.is_remove_text()) {
const GUI::RemoveTextCommand& remove_command = static_cast<const GUI::RemoveTextCommand&>(command);
cpp_Language_server_connection().post_message(
Messages::CppLanguageServer::FileEditRemoveText(
code_document().file_path().string(),
remove_command.range().start().line(),
remove_command.range().start().column(),
remove_command.range().end().line(),
remove_command.range().end().column()));
m_language_client->remove_text(
code_document().file_path().string(),
remove_command.range().start().line(),
remove_command.range().start().column(),
remove_command.range().end().line(),
remove_command.range().end().column());
return;
}
@ -592,13 +596,11 @@ void Editor::redo()
void Editor::flush_file_content_to_langauge_server()
{
if (code_document().language() != Language::Cpp)
if (!m_language_client)
return;
cpp_Language_server_connection().post_message(
Messages::CppLanguageServer::SetFileContent(
code_document().file_path().string(),
document().text()));
m_language_client->set_file_content(
code_document().file_path().string(),
document().text());
}
}

View file

@ -29,6 +29,7 @@
#include "AutoCompleteBox.h"
#include "CodeDocument.h"
#include "Debugger/BreakpointCallback.h"
#include "LanguageClient.h"
#include <AK/Optional.h>
#include <AK/OwnPtr.h>
#include <LibGUI/TextEditor.h>
@ -107,6 +108,8 @@ private:
bool m_hovering_link { false };
bool m_holding_ctrl { false };
bool m_autocomplete_in_focus { false };
OwnPtr<LanguageClient> m_language_client;
};
}

View file

@ -27,7 +27,7 @@
#pragma once
#include "EditorWrapper.h"
#include "LanguageClients/Cpp/ServerConnection.h"
#include "LanguageClients/ServerConnections.h"
#include "Project.h"
#include <AK/String.h>
#include <LibGUI/TextEditor.h>
@ -41,6 +41,5 @@ void open_file(const String&);
Project& project();
String currently_open_file();
void set_current_editor_wrapper(RefPtr<EditorWrapper>);
LanguageClients::Cpp::ServerConnection& cpp_Language_server_connection();
}

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "LanguageClient.h"
#include <AK/String.h>
#include <AK/Vector.h>
namespace HackStudio {
void ServerConnection::handle(const Messages::LanguageClient::AutoCompleteSuggestions& message)
{
if (m_language_client)
m_language_client->provide_autocomplete_suggestions(message.suggestions());
}
void LanguageClient::open_file(const String& path)
{
m_connection.post_message(Messages::LanguageServer::FileOpened(path));
}
void LanguageClient::set_file_content(const String& path, const String& content)
{
m_connection.post_message(Messages::LanguageServer::SetFileContent(path, content));
}
void LanguageClient::insert_text(const String& path, const String& text, size_t line, size_t column)
{
m_connection.post_message(Messages::LanguageServer::FileEditInsertText(path, text, line, column));
}
void LanguageClient::remove_text(const String& path, size_t from_line, size_t from_column, size_t to_line, size_t to_column)
{
m_connection.post_message(Messages::LanguageServer::FileEditRemoveText(path, from_line, from_column, to_line, to_column));
}
void LanguageClient::request_autocomplete(const String& path, size_t cursor_line, size_t cursor_column)
{
m_connection.post_message(Messages::LanguageServer::AutoCompleteSuggestions(path, cursor_line, cursor_column));
}
void LanguageClient::provide_autocomplete_suggestions(const Vector<String>& suggestions)
{
if (on_autocomplete_suggestions)
on_autocomplete_suggestions(suggestions);
// Otherwise, drop it on the floor :shrug:
}
}

View file

@ -0,0 +1,122 @@
/*
* Copyright (c) 2020, the SerenityOS developers.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/Forward.h>
#include <AK/LexicalPath.h>
#include <AK/Types.h>
#include <DevTools/HackStudio/LanguageServers/LanguageClientEndpoint.h>
#include <DevTools/HackStudio/LanguageServers/LanguageServerEndpoint.h>
#include <LibIPC/ServerConnection.h>
namespace HackStudio {
class LanguageClient;
class ServerConnection
: public IPC::ServerConnection<LanguageClientEndpoint, LanguageServerEndpoint>
, public LanguageClientEndpoint {
public:
ServerConnection(const StringView& socket, const StringView& project_path)
: IPC::ServerConnection<LanguageClientEndpoint, LanguageServerEndpoint>(*this, socket)
, m_project_path(project_path)
{
}
void attach(LanguageClient& client)
{
m_language_client = &client;
}
void detach()
{
m_language_client = nullptr;
}
virtual void handshake() override
{
auto response = send_sync<Messages::LanguageServer::Greet>(m_project_path.string());
set_my_client_id(response->client_id());
}
template<typename ConcreteType>
static NonnullRefPtr<ServerConnection> get_or_create(const String& project_path)
{
static HashMap<String, NonnullRefPtr<ConcreteType>> s_instances_for_projects;
auto key = LexicalPath { project_path }.string();
if (auto instance = s_instances_for_projects.get(key); instance.has_value())
return *instance.value();
auto connection = ConcreteType::construct(project_path);
connection->handshake();
s_instances_for_projects.set(key, *connection);
return *connection;
}
protected:
virtual void handle(const Messages::LanguageClient::AutoCompleteSuggestions&) override;
LanguageClient* m_language_client { nullptr };
LexicalPath m_project_path;
};
class LanguageClient {
public:
explicit LanguageClient(NonnullRefPtr<ServerConnection>&& connection)
: m_connection(*connection)
, m_server_connection(move(connection))
{
m_connection.attach(*this);
}
virtual ~LanguageClient()
{
m_connection.detach();
}
virtual void open_file(const String& path);
virtual void set_file_content(const String& path, const String& content);
virtual void insert_text(const String& path, const String& text, size_t line, size_t column);
virtual void remove_text(const String& path, size_t from_line, size_t from_column, size_t to_line, size_t to_column);
virtual void request_autocomplete(const String& path, size_t cursor_line, size_t cursor_column);
void provide_autocomplete_suggestions(const Vector<String>&);
Function<void(Vector<String>)> on_autocomplete_suggestions;
private:
ServerConnection& m_connection;
NonnullRefPtr<ServerConnection> m_server_connection;
};
template<typename ServerConnectionT>
static inline NonnullOwnPtr<LanguageClient> get_language_client(const String& project_path)
{
return make<LanguageClient>(ServerConnection::get_or_create<ServerConnectionT>(project_path));
}
}

View file

@ -1 +1,4 @@
add_subdirectory(Cpp)
set(GENERATED_SOURCES
../../LanguageServers/LanguageServerEndpoint.h
../../LanguageServers/LanguageClientEndpoint.h
)

View file

@ -1,4 +0,0 @@
set(GENERATED_SOURCES
../../LanguageServers/Cpp/CppLanguageServerEndpoint.h
../../LanguageServers/Cpp/CppLanguageClientEndpoint.h
)

View file

@ -26,35 +26,28 @@
#pragma once
#include "../LanguageClient.h"
#include <AK/LexicalPath.h>
#include <DevTools/HackStudio/LanguageServers/Cpp/CppLanguageClientEndpoint.h>
#include <DevTools/HackStudio/LanguageServers/Cpp/CppLanguageServerEndpoint.h>
#include <DevTools/HackStudio/LanguageServers/LanguageClientEndpoint.h>
#include <DevTools/HackStudio/LanguageServers/LanguageServerEndpoint.h>
#include <LibIPC/ServerConnection.h>
#define LANGUAGE_CLIENT(namespace_, socket_name) \
namespace namespace_ { \
class ServerConnection : public HackStudio::ServerConnection { \
C_OBJECT(ServerConnection) \
private: \
ServerConnection(const String& project_path) \
: HackStudio::ServerConnection("/tmp/portal/language/" #socket_name, project_path) \
{ \
} \
}; \
}
namespace LanguageClients {
namespace Cpp {
class ServerConnection : public IPC::ServerConnection<CppLanguageClientEndpoint, CppLanguageServerEndpoint>
, public CppLanguageClientEndpoint {
C_OBJECT(ServerConnection)
public:
virtual void handshake() override
{
auto response = send_sync<Messages::CppLanguageServer::Greet>(m_project_path.string());
set_my_client_id(response->client_id());
}
private:
ServerConnection(const String& project_path)
: IPC::ServerConnection<CppLanguageClientEndpoint, CppLanguageServerEndpoint>(*this, "/tmp/portal/language/cpp")
, m_project_path(project_path)
{
}
virtual void handle(const Messages::CppLanguageClient::Dummy&) override { }
LexicalPath m_project_path;
};
LANGUAGE_CLIENT(Cpp, cpp)
}
}
#undef LANGUAGE_CLIENT

View file

@ -1 +1,4 @@
compile_ipc(LanguageServer.ipc LanguageServerEndpoint.h)
compile_ipc(LanguageClient.ipc LanguageClientEndpoint.h)
add_subdirectory(Cpp)

View file

@ -1,16 +1,15 @@
compile_ipc(CppLanguageServer.ipc CppLanguageServerEndpoint.h)
compile_ipc(CppLanguageClient.ipc CppLanguageClientEndpoint.h)
set(SOURCES
ClientConnection.cpp
main.cpp
CppLanguageServerEndpoint.h
CppLanguageClientEndpoint.h
AutoComplete.cpp
)
set(GENERATED_SOURCES
../LanguageServerEndpoint.h
../LanguageClientEndpoint.h)
serenity_bin(CppLanguageServer)
# We link with LibGUI because we use GUI::TextDocument to update
# We link with LibGUI because we use GUI::TextDocument to update
# the content of files according to the edit actions we receive over IPC.
target_link_libraries(CppLanguageServer LibIPC LibCpp LibGUI)

View file

@ -38,7 +38,7 @@ namespace LanguageServers::Cpp {
static HashMap<int, RefPtr<ClientConnection>> s_connections;
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
: IPC::ClientConnection<CppLanguageClientEndpoint, CppLanguageServerEndpoint>(*this, move(socket), client_id)
: IPC::ClientConnection<LanguageClientEndpoint, LanguageServerEndpoint>(*this, move(socket), client_id)
{
s_connections.set(client_id, *this);
}
@ -53,13 +53,13 @@ void ClientConnection::die()
exit(0);
}
OwnPtr<Messages::CppLanguageServer::GreetResponse> ClientConnection::handle(const Messages::CppLanguageServer::Greet& message)
OwnPtr<Messages::LanguageServer::GreetResponse> ClientConnection::handle(const Messages::LanguageServer::Greet& message)
{
m_project_root = LexicalPath(message.project_root());
#ifdef DEBUG_CPP_LANGUAGE_SERVER
dbg() << "project_root: " << m_project_root.string();
#endif
return make<Messages::CppLanguageServer::GreetResponse>(client_id());
return make<Messages::LanguageServer::GreetResponse>(client_id());
}
class DefaultDocumentClient final : public GUI::TextDocument::Client {
@ -74,12 +74,12 @@ public:
virtual void document_did_set_cursor(const GUI::TextPosition&) override {};
virtual bool is_automatic_indentation_enabled() const override { return true; }
virtual int soft_tab_width() const { return 4; }
virtual int soft_tab_width() const override { return 4; }
};
static DefaultDocumentClient s_default_document_client;
void ClientConnection::handle(const Messages::CppLanguageServer::FileOpened& message)
void ClientConnection::handle(const Messages::LanguageServer::FileOpened& message)
{
LexicalPath file_path(String::format("%s/%s", m_project_root.string().characters(), message.file_name().characters()));
#ifdef DEBUG_CPP_LANGUAGE_SERVER
@ -103,7 +103,7 @@ void ClientConnection::handle(const Messages::CppLanguageServer::FileOpened& mes
#endif
}
void ClientConnection::handle(const Messages::CppLanguageServer::FileEditInsertText& message)
void ClientConnection::handle(const Messages::LanguageServer::FileEditInsertText& message)
{
#ifdef DEBUG_CPP_LANGUAGE_SERVER
dbg() << "InsertText for file: " << message.file_name();
@ -122,7 +122,7 @@ void ClientConnection::handle(const Messages::CppLanguageServer::FileEditInsertT
#endif
}
void ClientConnection::handle(const Messages::CppLanguageServer::FileEditRemoveText& message)
void ClientConnection::handle(const Messages::LanguageServer::FileEditRemoveText& message)
{
#ifdef DEBUG_CPP_LANGUAGE_SERVER
dbg() << "RemoveText for file: " << message.file_name();
@ -147,9 +147,7 @@ void ClientConnection::handle(const Messages::CppLanguageServer::FileEditRemoveT
#endif
}
// FIXME: The work we do here could be taxing and block the client for a significant time.
// Would should turn this to an async IPC endpoint and report the reuslts back in a separate Server->Client message.
OwnPtr<Messages::CppLanguageServer::AutoCompleteSuggestionsResponse> ClientConnection::handle(const Messages::CppLanguageServer::AutoCompleteSuggestions& message)
void ClientConnection::handle(const Messages::LanguageServer::AutoCompleteSuggestions& message)
{
#ifdef DEBUG_CPP_LANGUAGE_SERVER
dbg() << "AutoCompleteSuggestions for: " << message.file_name() << " " << message.cursor_line() << ":" << message.cursor_column();
@ -158,11 +156,11 @@ OwnPtr<Messages::CppLanguageServer::AutoCompleteSuggestionsResponse> ClientConne
auto document = document_for(message.file_name());
if (!document) {
dbg() << "file " << message.file_name() << " has not been opened";
return nullptr;
return;
}
Vector<String> suggestions = AutoComplete::get_suggestions(document->text(), { (size_t)message.cursor_line(), (size_t)message.cursor_column() });
return make<Messages::CppLanguageServer::AutoCompleteSuggestionsResponse>(suggestions);
post_message(Messages::LanguageClient::AutoCompleteSuggestions(move(suggestions)));
}
RefPtr<GUI::TextDocument> ClientConnection::document_for(const String& file_name)
@ -174,7 +172,7 @@ RefPtr<GUI::TextDocument> ClientConnection::document_for(const String& file_name
return document_optional.value();
}
void ClientConnection::handle(const Messages::CppLanguageServer::SetFileContent& message)
void ClientConnection::handle(const Messages::LanguageServer::SetFileContent& message)
{
auto document = document_for(message.file_name());
if (!document) {

View file

@ -28,16 +28,16 @@
#include <AK/HashMap.h>
#include <AK/LexicalPath.h>
#include <DevTools/HackStudio/LanguageServers/Cpp/CppLanguageClientEndpoint.h>
#include <DevTools/HackStudio/LanguageServers/Cpp/CppLanguageServerEndpoint.h>
#include <DevTools/HackStudio/LanguageServers/LanguageClientEndpoint.h>
#include <DevTools/HackStudio/LanguageServers/LanguageServerEndpoint.h>
#include <LibGUI/TextDocument.h>
#include <LibIPC/ClientConnection.h>
namespace LanguageServers::Cpp {
class ClientConnection final
: public IPC::ClientConnection<CppLanguageClientEndpoint, CppLanguageServerEndpoint>
, public CppLanguageServerEndpoint {
: public IPC::ClientConnection<LanguageClientEndpoint, LanguageServerEndpoint>
, public LanguageServerEndpoint {
C_OBJECT(ClientConnection);
public:
@ -47,12 +47,12 @@ public:
virtual void die() override;
private:
virtual OwnPtr<Messages::CppLanguageServer::GreetResponse> handle(const Messages::CppLanguageServer::Greet&) override;
virtual void handle(const Messages::CppLanguageServer::FileOpened&) override;
virtual void handle(const Messages::CppLanguageServer::FileEditInsertText&) override;
virtual void handle(const Messages::CppLanguageServer::FileEditRemoveText&) override;
virtual void handle(const Messages::CppLanguageServer::SetFileContent&) override;
virtual OwnPtr<Messages::CppLanguageServer::AutoCompleteSuggestionsResponse> handle(const Messages::CppLanguageServer::AutoCompleteSuggestions&) override;
virtual OwnPtr<Messages::LanguageServer::GreetResponse> handle(const Messages::LanguageServer::Greet&) override;
virtual void handle(const Messages::LanguageServer::FileOpened&) override;
virtual void handle(const Messages::LanguageServer::FileEditInsertText&) override;
virtual void handle(const Messages::LanguageServer::FileEditRemoveText&) override;
virtual void handle(const Messages::LanguageServer::SetFileContent&) override;
virtual void handle(const Messages::LanguageServer::AutoCompleteSuggestions&) override;
RefPtr<GUI::TextDocument> document_for(const String& file_name);

View file

@ -1,4 +0,0 @@
endpoint CppLanguageClient = 8002
{
Dummy() =|
}

View file

@ -0,0 +1,4 @@
endpoint LanguageClient = 8002
{
AutoCompleteSuggestions(Vector<String> suggestions) =|
}

View file

@ -1,4 +1,4 @@
endpoint CppLanguageServer = 8001
endpoint LanguageServer = 8001
{
Greet(String project_root) => (i32 client_id)
@ -7,5 +7,5 @@ endpoint CppLanguageServer = 8001
FileEditRemoveText(String file_name, i32 start_line, i32 start_column, i32 end_line, i32 end_column) =|
SetFileContent(String file_name, String content) =|
AutoCompleteSuggestions(String file_name, i32 cursor_line, i32 cursor_column) => (Vector<String> suggestions)
AutoCompleteSuggestions(String file_name, i32 cursor_line, i32 cursor_column) =|
}

View file

@ -26,7 +26,6 @@
#include "HackStudio.h"
#include "HackStudioWidget.h"
#include "LanguageClients/Cpp/ServerConnection.h"
#include "Project.h"
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
@ -52,13 +51,11 @@ using namespace HackStudio;
static RefPtr<GUI::Window> s_window;
static RefPtr<HackStudioWidget> s_hack_studio_widget;
static RefPtr<LanguageClients::Cpp::ServerConnection> s_cpp_Language_server_connection;
static bool make_is_available();
static void update_path_environment_variable();
static String path_to_project(const String& path_argument_absolute_path);
static void open_default_project_file(const String& project_path);
static void initialize_connections_to_language_servers(const String& project_path);
int main(int argc, char** argv)
{
@ -95,8 +92,6 @@ int main(int argc, char** argv)
auto project_path = path_to_project(argument_absolute_path);
s_hack_studio_widget = s_window->set_main_widget<HackStudioWidget>(project_path);
initialize_connections_to_language_servers(project_path);
s_hack_studio_widget->initialize_menubar(menubar);
app->set_menubar(menubar);
@ -152,13 +147,6 @@ static void open_default_project_file(const String& project_path)
open_file(s_hack_studio_widget->project().default_file());
}
static void initialize_connections_to_language_servers(const String& project_path)
{
LexicalPath project_root_dir(LexicalPath(project_path).dirname());
s_cpp_Language_server_connection = LanguageClients::Cpp::ServerConnection::construct(project_root_dir.string());
s_cpp_Language_server_connection->handshake();
}
namespace HackStudio {
GUI::TextEditor& current_editor()
@ -195,10 +183,4 @@ void set_current_editor_wrapper(RefPtr<EditorWrapper> wrapper)
s_hack_studio_widget->set_current_editor_wrapper(wrapper);
}
LanguageClients::Cpp::ServerConnection& cpp_Language_server_connection()
{
ASSERT(s_cpp_Language_server_connection);
return *s_cpp_Language_server_connection;
}
}