diff options
author | Itamar <itamar8910@gmail.com> | 2020-09-28 16:37:37 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-30 21:46:59 +0200 |
commit | 863f14788fa74591b58a276b194c4ceb5ae3d9e6 (patch) | |
tree | a6cd1bf3be5395647d6e1b957e484d9f83e3c174 /Libraries | |
parent | bf53d7ff64128a84dbd39171a2df2cf970a8d7df (diff) | |
download | serenity-863f14788fa74591b58a276b194c4ceb5ae3d9e6.zip |
HackStudio: Add C++ Language Server
The language server keeps track of the content of currently edited
files by receiving updates about edit actions.
Also, C++ autocompletion is no longer tied to HackStudio itself and
moved to be part of the language server.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/Command.h | 3 | ||||
-rw-r--r-- | Libraries/LibGUI/TextDocument.cpp | 12 | ||||
-rw-r--r-- | Libraries/LibGUI/TextDocument.h | 6 | ||||
-rw-r--r-- | Libraries/LibGUI/TextEditor.cpp | 9 |
4 files changed, 22 insertions, 8 deletions
diff --git a/Libraries/LibGUI/Command.h b/Libraries/LibGUI/Command.h index 9ff6a0aad9..3b2f081a6a 100644 --- a/Libraries/LibGUI/Command.h +++ b/Libraries/LibGUI/Command.h @@ -39,6 +39,9 @@ public: String action_text() const { return m_action_text; } + virtual bool is_insert_text() const { return false; } + virtual bool is_remove_text() const { return false; } + protected: Command() { } void set_action_text(const String& text) { m_action_text = text; } diff --git a/Libraries/LibGUI/TextDocument.cpp b/Libraries/LibGUI/TextDocument.cpp index 10a5ffe497..35abe1e3ac 100644 --- a/Libraries/LibGUI/TextDocument.cpp +++ b/Libraries/LibGUI/TextDocument.cpp @@ -282,6 +282,18 @@ void TextDocument::set_all_cursors(const TextPosition& position) } } +String TextDocument::text() const +{ + StringBuilder builder; + for (size_t i = 0; i < line_count(); ++i) { + auto& line = this->line(i); + builder.append(line.view()); + if (i != line_count() - 1) + builder.append('\n'); + } + return builder.to_string(); +} + String TextDocument::text_in_range(const TextRange& a_range) const { auto range = a_range.normalized(); diff --git a/Libraries/LibGUI/TextDocument.h b/Libraries/LibGUI/TextDocument.h index 85fad0e97a..e6ee731ceb 100644 --- a/Libraries/LibGUI/TextDocument.h +++ b/Libraries/LibGUI/TextDocument.h @@ -103,6 +103,7 @@ public: void update_views(Badge<TextDocumentLine>); + String text() const; String text_in_range(const TextRange&) const; Vector<TextRange> find_all(const StringView& needle) const; @@ -210,6 +211,9 @@ public: InsertTextCommand(TextDocument&, const String&, const TextPosition&); virtual void undo() override; virtual void redo() override; + virtual bool is_insert_text() const override { return true; } + const String& text() const { return m_text; } + const TextRange& range() const { return m_range; } private: String m_text; @@ -221,6 +225,8 @@ public: RemoveTextCommand(TextDocument&, const String&, const TextRange&); virtual void undo() override; virtual void redo() override; + virtual bool is_remove_text() const override { return true; } + const TextRange& range() const { return m_range; } private: String m_text; diff --git a/Libraries/LibGUI/TextEditor.cpp b/Libraries/LibGUI/TextEditor.cpp index f67d04cf72..07593715cb 100644 --- a/Libraries/LibGUI/TextEditor.cpp +++ b/Libraries/LibGUI/TextEditor.cpp @@ -1254,14 +1254,7 @@ bool TextEditor::write_to_file(const StringView& path) String TextEditor::text() const { - StringBuilder builder; - for (size_t i = 0; i < line_count(); ++i) { - auto& line = this->line(i); - builder.append(line.view()); - if (i != line_count() - 1) - builder.append('\n'); - } - return builder.to_string(); + return document().text(); } void TextEditor::clear() |