diff options
author | Federico Guerinoni <guerinoni.federico@gmail.com> | 2021-05-17 22:19:50 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-23 19:00:11 +0100 |
commit | 26a7356e90a1717b7259510e13af906c7bb09c43 (patch) | |
tree | 2a0d331a6a6ddd302fe9672a87f1a6f3423cda7d /Userland/DevTools/HackStudio | |
parent | c397e030f40e9126b98eb3c203daeb40d00fef40 (diff) | |
download | serenity-26a7356e90a1717b7259510e13af906c7bb09c43.zip |
LanguageServers: Add function to collect TODO entries in a document
Diffstat (limited to 'Userland/DevTools/HackStudio')
12 files changed, 103 insertions, 0 deletions
diff --git a/Userland/DevTools/HackStudio/CMakeLists.txt b/Userland/DevTools/HackStudio/CMakeLists.txt index 06bd5b3c57..5d27af90ef 100644 --- a/Userland/DevTools/HackStudio/CMakeLists.txt +++ b/Userland/DevTools/HackStudio/CMakeLists.txt @@ -43,6 +43,7 @@ set(SOURCES ProjectFile.cpp ProjectTemplate.cpp TerminalWrapper.cpp + ToDoEntries.cpp main.cpp ) diff --git a/Userland/DevTools/HackStudio/LanguageClient.cpp b/Userland/DevTools/HackStudio/LanguageClient.cpp index e0bae003e5..72335a9c36 100644 --- a/Userland/DevTools/HackStudio/LanguageClient.cpp +++ b/Userland/DevTools/HackStudio/LanguageClient.cpp @@ -7,6 +7,7 @@ #include "LanguageClient.h" #include "HackStudio.h" #include "ProjectDeclarations.h" +#include "ToDoEntries.h" #include <AK/String.h> #include <AK/Vector.h> #include <DevTools/HackStudio/LanguageServers/LanguageServerEndpoint.h> @@ -98,6 +99,11 @@ void ServerConnection::declarations_in_document(const String& filename, const Ve ProjectDeclarations::the().set_declared_symbols(filename, declarations); } +void ServerConnection::todo_entries_in_document(const String& filename, const Vector<String>& todo_entries) +{ + ToDoEntries::the().set_entries(filename, move(todo_entries)); +} + void LanguageClient::search_declaration(const String& path, size_t line, size_t column) { if (!m_connection_wrapper.connection()) diff --git a/Userland/DevTools/HackStudio/LanguageClient.h b/Userland/DevTools/HackStudio/LanguageClient.h index 02deed9385..1555ccccad 100644 --- a/Userland/DevTools/HackStudio/LanguageClient.h +++ b/Userland/DevTools/HackStudio/LanguageClient.h @@ -46,6 +46,7 @@ protected: virtual void auto_complete_suggestions(Vector<GUI::AutocompleteProvider::Entry> const&) override; virtual void declaration_location(GUI::AutocompleteProvider::ProjectLocation const&) override; virtual void declarations_in_document(String const&, Vector<GUI::AutocompleteProvider::Declaration> const&) override; + virtual void todo_entries_in_document(String const&, Vector<String> const&) override; void set_wrapper(ServerConnectionWrapper& wrapper) { m_wrapper = &wrapper; } String m_project_path; diff --git a/Userland/DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.cpp b/Userland/DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.cpp index 20f2a7a1d6..02dd66bb44 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.cpp @@ -31,4 +31,11 @@ void CodeComprehensionEngine::set_declarations_of_document(const String& filenam m_all_declarations.set(filename, declarations); set_declarations_of_document_callback(filename, move(declarations)); } + +void CodeComprehensionEngine::set_todo_entries_of_document(const String& filename, Vector<String>&& todo_entries) +{ + VERIFY(set_todo_entries_of_document_callback); + set_todo_entries_of_document_callback(filename, move(todo_entries)); +} + } diff --git a/Userland/DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.h b/Userland/DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.h index 3db803d7c2..75c2020201 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.h +++ b/Userland/DevTools/HackStudio/LanguageServers/CodeComprehensionEngine.h @@ -30,10 +30,12 @@ public: public: Function<void(const String&, Vector<GUI::AutocompleteProvider::Declaration>&&)> set_declarations_of_document_callback; + Function<void(const String&, Vector<String>&&)> set_todo_entries_of_document_callback; protected: const FileDB& filedb() const { return m_filedb; } void set_declarations_of_document(const String&, Vector<GUI::AutocompleteProvider::Declaration>&&); + void set_todo_entries_of_document(const String&, Vector<String>&&); const HashMap<String, Vector<GUI::AutocompleteProvider::Declaration>>& all_declarations() const { return m_all_declarations; } private: diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h index e3eb4c33a0..96234a2164 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ClientConnection.h @@ -22,6 +22,9 @@ public: m_autocomplete_engine->set_declarations_of_document_callback = [this](const String& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations) { async_declarations_in_document(filename, move(declarations)); }; + m_autocomplete_engine->set_todo_entries_of_document_callback = [this](const String& filename, Vector<String>&& todo_entries) { + async_todo_entries_in_document(filename, move(todo_entries)); + }; } virtual ~ClientConnection() override = default; diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp index c403669c73..4f1a05296d 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp @@ -520,6 +520,11 @@ void CppComprehensionEngine::update_declared_symbols(DocumentData& document) set_declarations_of_document(document.filename(), move(declarations)); } +void CppComprehensionEngine::update_todo_entries(DocumentData& document) +{ + set_todo_entries_of_document(document.filename(), document.parser().get_todo_entries()); +} + GUI::AutocompleteProvider::DeclarationType CppComprehensionEngine::type_of_declaration(const Declaration& decl) { if (decl.is_struct()) @@ -574,6 +579,7 @@ OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_docu root->dump(); update_declared_symbols(*document_data); + update_todo_entries(*document_data); return document_data; } diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h index 60fc58c483..f25b704d0c 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.h @@ -121,6 +121,7 @@ private: OwnPtr<DocumentData> create_document_data_for(const String& file); String document_path_from_include_path(const StringView& include_path) const; void update_declared_symbols(DocumentData&); + void update_todo_entries(DocumentData&); GUI::AutocompleteProvider::DeclarationType type_of_declaration(const Declaration&); Vector<StringView> scope_of_node(const ASTNode&) const; Vector<StringView> scope_of_reference_to_symbol(const ASTNode&) const; diff --git a/Userland/DevTools/HackStudio/LanguageServers/LanguageClient.ipc b/Userland/DevTools/HackStudio/LanguageServers/LanguageClient.ipc index 2a1c0f238c..ed6397f41c 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/LanguageClient.ipc +++ b/Userland/DevTools/HackStudio/LanguageServers/LanguageClient.ipc @@ -3,4 +3,5 @@ endpoint LanguageClient auto_complete_suggestions(Vector<GUI::AutocompleteProvider::Entry> suggestions) =| declaration_location(GUI::AutocompleteProvider::ProjectLocation location) =| declarations_in_document(String filename, Vector<GUI::AutocompleteProvider::Declaration> declarations) =| + todo_entries_in_document(String filename, Vector<String> todo_entries) =| } diff --git a/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h b/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h index 542faccc31..67a5da80f6 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h +++ b/Userland/DevTools/HackStudio/LanguageServers/Shell/ClientConnection.h @@ -21,6 +21,9 @@ class ClientConnection final : public LanguageServers::ClientConnection { m_autocomplete_engine->set_declarations_of_document_callback = [this](const String& filename, Vector<GUI::AutocompleteProvider::Declaration>&& declarations) { async_declarations_in_document(filename, move(declarations)); }; + m_autocomplete_engine->set_todo_entries_of_document_callback = [this](const String& filename, Vector<String>&& todo_entries) { + async_todo_entries_in_document(filename, move(todo_entries)); + }; } virtual ~ClientConnection() override = default; }; diff --git a/Userland/DevTools/HackStudio/ToDoEntries.cpp b/Userland/DevTools/HackStudio/ToDoEntries.cpp new file mode 100644 index 0000000000..00c27cd8d2 --- /dev/null +++ b/Userland/DevTools/HackStudio/ToDoEntries.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021, Federico Guerinoni <guerinoni.federico@gmail.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "ToDoEntries.h" + +namespace HackStudio { + +ToDoEntries& HackStudio::ToDoEntries::the() +{ + static ToDoEntries s_instance; + return s_instance; +} + +void ToDoEntries::set_entries(const String& filename, const Vector<String>&& entries) +{ + m_document_to_entries.set(filename, move(entries)); + if (on_update) + on_update(); +} + +Vector<ToDoEntryPair> ToDoEntries::get_entries() +{ + Vector<ToDoEntryPair> ret; + for (auto& it : m_document_to_entries) + for (auto& entry : it.value) + ret.append({ it.key, entry }); + + return ret; +} + +} diff --git a/Userland/DevTools/HackStudio/ToDoEntries.h b/Userland/DevTools/HackStudio/ToDoEntries.h new file mode 100644 index 0000000000..849145b374 --- /dev/null +++ b/Userland/DevTools/HackStudio/ToDoEntries.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021, Federico Guerinoni <guerinoni.federico@gmail.com> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Function.h> +#include <AK/HashMap.h> +#include <AK/Noncopyable.h> +#include <AK/String.h> + +namespace HackStudio { + +struct ToDoEntryPair { + String filename; + String comment; +}; + +class ToDoEntries { + AK_MAKE_NONCOPYABLE(ToDoEntries); + +public: + static ToDoEntries& the(); + + void set_entries(const String& filename, const Vector<String>&& entries); + + Vector<ToDoEntryPair> get_entries(); + + Function<void()> on_update = nullptr; + +private: + ToDoEntries() = default; + HashMap<String, Vector<String>> m_document_to_entries; +}; + +} |