1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:37:35 +00:00

LibSyntax+Userland: Make LibSyntax not depend on LibGUI

This moves some stuff around to make LibGUI depend on LibSyntax instead
of the other way around, as not every application that wishes to do
syntax highlighting is necessarily a LibGUI (or even a GUI) application.
This commit is contained in:
Ali Mohammad Pur 2023-08-29 12:43:41 +03:30 committed by Tim Flynn
parent 2495302991
commit ba4db899d4
26 changed files with 773 additions and 683 deletions

View file

@ -8,8 +8,8 @@
#include <AK/Noncopyable.h>
#include <AK/WeakPtr.h>
#include <LibGUI/TextDocument.h>
#include <LibGfx/Palette.h>
#include <LibSyntax/Document.h>
#include <LibSyntax/HighlighterClient.h>
#include <LibSyntax/Language.h>
@ -61,7 +61,7 @@ protected:
struct BuddySpan {
int index { -1 };
GUI::TextDocumentSpan span_backup;
TextDocumentSpan span_backup;
};
bool m_has_brace_buddies { false };
@ -71,7 +71,7 @@ protected:
class ProxyHighlighterClient final : public Syntax::HighlighterClient {
public:
ProxyHighlighterClient(Syntax::HighlighterClient& client, GUI::TextPosition start, u64 nested_kind_start_value, StringView source)
ProxyHighlighterClient(Syntax::HighlighterClient& client, TextPosition start, u64 nested_kind_start_value, StringView source)
: m_document(client.get_document())
, m_text(source)
, m_start(start)
@ -79,9 +79,9 @@ public:
{
}
Vector<GUI::TextDocumentSpan> corrected_spans() const
Vector<TextDocumentSpan> corrected_spans() const
{
Vector<GUI::TextDocumentSpan> spans { m_spans };
Vector<TextDocumentSpan> spans { m_spans };
for (auto& entry : spans) {
entry.range.start() = {
entry.range.start().line() + m_start.line(),
@ -98,9 +98,9 @@ public:
return spans;
}
Vector<GUI::TextDocumentFoldingRegion> corrected_folding_regions() const
Vector<TextDocumentFoldingRegion> corrected_folding_regions() const
{
Vector<GUI::TextDocumentFoldingRegion> folding_regions { m_folding_regions };
Vector<TextDocumentFoldingRegion> folding_regions { m_folding_regions };
for (auto& entry : folding_regions) {
entry.range.start() = {
entry.range.start().line() + m_start.line(),
@ -125,24 +125,24 @@ public:
}
private:
virtual Vector<GUI::TextDocumentSpan> const& spans() const override { return m_spans; }
virtual void set_span_at_index(size_t index, GUI::TextDocumentSpan span) override { m_spans.at(index) = move(span); }
virtual Vector<TextDocumentSpan> const& spans() const override { return m_spans; }
virtual void set_span_at_index(size_t index, TextDocumentSpan span) override { m_spans.at(index) = move(span); }
virtual Vector<GUI::TextDocumentFoldingRegion>& folding_regions() override { return m_folding_regions; }
virtual Vector<GUI::TextDocumentFoldingRegion> const& folding_regions() const override { return m_folding_regions; }
virtual Vector<TextDocumentFoldingRegion>& folding_regions() override { return m_folding_regions; }
virtual Vector<TextDocumentFoldingRegion> const& folding_regions() const override { return m_folding_regions; }
virtual DeprecatedString highlighter_did_request_text() const override { return m_text; }
virtual void highlighter_did_request_update() override { }
virtual GUI::TextDocument& highlighter_did_request_document() override { return m_document; }
virtual GUI::TextPosition highlighter_did_request_cursor() const override { return {}; }
virtual void highlighter_did_set_spans(Vector<GUI::TextDocumentSpan> spans) override { m_spans = move(spans); }
virtual void highlighter_did_set_folding_regions(Vector<GUI::TextDocumentFoldingRegion> folding_regions) override { m_folding_regions = folding_regions; }
virtual Document& highlighter_did_request_document() override { return m_document; }
virtual TextPosition highlighter_did_request_cursor() const override { return {}; }
virtual void highlighter_did_set_spans(Vector<TextDocumentSpan> spans) override { m_spans = move(spans); }
virtual void highlighter_did_set_folding_regions(Vector<TextDocumentFoldingRegion> folding_regions) override { m_folding_regions = folding_regions; }
Vector<GUI::TextDocumentSpan> m_spans;
Vector<GUI::TextDocumentFoldingRegion> m_folding_regions;
GUI::TextDocument& m_document;
Vector<TextDocumentSpan> m_spans;
Vector<TextDocumentFoldingRegion> m_folding_regions;
Document& m_document;
StringView m_text;
GUI::TextPosition m_start;
TextPosition m_start;
u64 m_nested_kind_start_value { 0 };
};