1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 18:14:58 +00:00

HackStudio: Integrate with C++ Language Server

Editors now communicate with the c++ language server when openning and
editing c++ source files, and go through the language server to get
autocomplete suggestions.
This commit is contained in:
Itamar 2020-09-27 00:11:15 +03:00 committed by Andreas Kling
parent 863f14788f
commit a39c4cc340
13 changed files with 197 additions and 34 deletions

View file

@ -26,6 +26,7 @@
#include "HackStudio.h"
#include "HackStudioWidget.h"
#include "LanguageClients/Cpp/ServerConnection.h"
#include "Project.h"
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
@ -51,22 +52,24 @@ 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)
{
if (pledge("stdio tty accept rpath cpath wpath shared_buffer proc exec unix fattr thread", nullptr) < 0) {
if (pledge("stdio tty accept rpath cpath wpath shared_buffer proc exec unix fattr thread unix", nullptr) < 0) {
perror("pledge");
return 1;
}
auto app = GUI::Application::construct(argc, argv);
if (pledge("stdio tty accept rpath cpath wpath shared_buffer proc exec fattr thread", nullptr) < 0) {
if (pledge("stdio tty accept rpath cpath wpath shared_buffer proc exec fattr thread unix", nullptr) < 0) {
perror("pledge");
return 1;
}
@ -89,7 +92,10 @@ int main(int argc, char** argv)
auto argument_absolute_path = Core::File::real_path_for(path_argument);
auto menubar = GUI::MenuBar::construct();
s_hack_studio_widget = s_window->set_main_widget<HackStudioWidget>(path_to_project(argument_absolute_path));
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);
@ -146,6 +152,13 @@ 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()
@ -182,4 +195,10 @@ 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;
}
}