diff options
author | Sergey Bugaev <bugaevc@serenityos.org> | 2020-11-21 22:12:37 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-23 18:37:40 +0100 |
commit | e7e179212c5b1938fd00da62a1d5aca8441cf487 (patch) | |
tree | 26b9c07ba7e806ce90e1098ca76248bb1ea5168a /DevTools/HackStudio/LanguageServers/Shell | |
parent | 098070b767db2d74595829040d8ef55bb3b81bd5 (diff) | |
download | serenity-e7e179212c5b1938fd00da62a1d5aca8441cf487.zip |
HackStudio: Send an open file to language servers
Language servers will now receive an open file instead of just its path. This
means the language servers no longer need to access the filesystem to open the
file themselves.
The C++ language server now has no filesystem access whatsoever (although we
might need to relax this in the future if it learns to complete #include paths),
while the Shell language server can read /etc/passwd (it wants that in order to
get the user's home directory) and browse (but not read!) the whole file system
tree for completing paths.
Diffstat (limited to 'DevTools/HackStudio/LanguageServers/Shell')
3 files changed, 18 insertions, 16 deletions
diff --git a/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.cpp b/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.cpp index 823a36290f..3e32c0d7e9 100644 --- a/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.cpp +++ b/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.cpp @@ -53,12 +53,8 @@ void ClientConnection::die() exit(0); } -OwnPtr<Messages::LanguageServer::GreetResponse> ClientConnection::handle(const Messages::LanguageServer::Greet& message) +OwnPtr<Messages::LanguageServer::GreetResponse> ClientConnection::handle(const Messages::LanguageServer::Greet&) { - m_project_root = LexicalPath(message.project_root()); -#ifdef DEBUG_SH_LANGUAGE_SERVER - dbgln("project_root: {}", m_project_root); -#endif return make<Messages::LanguageServer::GreetResponse>(client_id()); } @@ -81,16 +77,11 @@ static DefaultDocumentClient s_default_document_client; void ClientConnection::handle(const Messages::LanguageServer::FileOpened& message) { - LexicalPath file_path(String::formatted("{}/{}", m_project_root, message.file_name())); -#ifdef DEBUG_SH_LANGUAGE_SERVER - dbgln("FileOpened: {}", file_path); -#endif - - auto file = Core::File::construct(file_path.string()); - if (!file->open(Core::IODevice::ReadOnly)) { + auto file = Core::File::construct(this); + if (!file->open(message.file().fd(), Core::IODevice::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes)) { errno = file->error(); perror("open"); - dbgln("Failed to open project file: {}", file_path); + dbgln("Failed to open project file"); return; } auto content = file->read_all(); diff --git a/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h b/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h index 27f53857b3..bb7fc14bd9 100644 --- a/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h +++ b/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h @@ -59,7 +59,6 @@ private: RefPtr<GUI::TextDocument> document_for(const String& file_name); - LexicalPath m_project_root; HashMap<String, NonnullRefPtr<GUI::TextDocument>> m_open_files; AutoComplete m_autocomplete; diff --git a/DevTools/HackStudio/LanguageServers/Shell/main.cpp b/DevTools/HackStudio/LanguageServers/Shell/main.cpp index a5e1417e67..90e3f62271 100644 --- a/DevTools/HackStudio/LanguageServers/Shell/main.cpp +++ b/DevTools/HackStudio/LanguageServers/Shell/main.cpp @@ -36,16 +36,28 @@ int main(int, char**) { Core::EventLoop event_loop; - if (pledge("stdio unix rpath", nullptr) < 0) { + if (pledge("stdio unix rpath recvfd", nullptr) < 0) { perror("pledge"); return 1; } auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server(); IPC::new_client_connection<LanguageServers::Shell::ClientConnection>(socket.release_nonnull(), 1); - if (pledge("stdio rpath", nullptr) < 0) { + if (pledge("stdio rpath recvfd", nullptr) < 0) { perror("pledge"); return 1; } + if (unveil("/etc/passwd", "r") < 0) { + perror("unveil"); + return 1; + } + if (unveil("/", "b") < 0) { + perror("unveil"); + return 1; + } + if (unveil(nullptr, nullptr) < 0) { + perror("unveil"); + return 1; + } return event_loop.exec(); } |