mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
LanguageServers: Add function to collect TODO entries in a document
This commit is contained in:
parent
c397e030f4
commit
26a7356e90
12 changed files with 103 additions and 0 deletions
|
@ -43,6 +43,7 @@ set(SOURCES
|
|||
ProjectFile.cpp
|
||||
ProjectTemplate.cpp
|
||||
TerminalWrapper.cpp
|
||||
ToDoEntries.cpp
|
||||
main.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())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) =|
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
34
Userland/DevTools/HackStudio/ToDoEntries.cpp
Normal file
34
Userland/DevTools/HackStudio/ToDoEntries.cpp
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
38
Userland/DevTools/HackStudio/ToDoEntries.h
Normal file
38
Userland/DevTools/HackStudio/ToDoEntries.h
Normal file
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue