From 54bc9114b3ab741aed6cccb3e5eeb4ecd3ffc604 Mon Sep 17 00:00:00 2001 From: Itamar Date: Sat, 27 Feb 2021 09:50:02 +0200 Subject: [PATCH] HackStudio: Support searching symbol declarations in the Locator The Locator now keeps a cache of the declared symbol in a document. The language client updates that cache whenever it gets an update from the language server about declared symbols. This allows searching for symbol declarations in the Locator, in addition to file names. Closes #5478 --- Base/res/icons/hackstudio/Class.png | Bin 0 -> 892 bytes Base/res/icons/hackstudio/Function.png | Bin 0 -> 708 bytes Base/res/icons/hackstudio/Struct.png | Bin 0 -> 918 bytes Base/res/icons/hackstudio/Variable.png | Bin 0 -> 805 bytes Userland/DevTools/HackStudio/Editor.cpp | 13 +-- Userland/DevTools/HackStudio/Editor.h | 9 +- .../DevTools/HackStudio/EditorWrapper.cpp | 2 + Userland/DevTools/HackStudio/EditorWrapper.h | 2 + Userland/DevTools/HackStudio/HackStudio.h | 5 +- .../DevTools/HackStudio/HackStudioWidget.h | 6 ++ .../DevTools/HackStudio/LanguageClient.cpp | 12 +-- Userland/DevTools/HackStudio/Locator.cpp | 100 ++++++++++++++++-- Userland/DevTools/HackStudio/Locator.h | 4 + Userland/DevTools/HackStudio/main.cpp | 14 ++- Userland/Libraries/LibCpp/AST.h | 1 - Userland/Libraries/LibGUI/TextEditor.h | 2 +- 16 files changed, 140 insertions(+), 30 deletions(-) create mode 100644 Base/res/icons/hackstudio/Class.png create mode 100644 Base/res/icons/hackstudio/Function.png create mode 100644 Base/res/icons/hackstudio/Struct.png create mode 100644 Base/res/icons/hackstudio/Variable.png diff --git a/Base/res/icons/hackstudio/Class.png b/Base/res/icons/hackstudio/Class.png new file mode 100644 index 0000000000000000000000000000000000000000..082bdd16f52ffec0355c7b766d31c3ff7b6d2038 GIT binary patch literal 892 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7TQZ%U13aCb6$*;-(=u~X z85lGs)=sqbIP4&EG(LE#k|=w(S7ArMT%C?Ci!9NufQ47M)>_So`NirhHAzI={ovLI z4~{2YJ$N)SoITu8;15G#adA+|M4|uFMWT*W6x``A|1MYlo?&5J+Nzs|d@E+9E_q~V zI5}37dA)#un?0L>j$!b8Z#Cf$GV$L(eEh0+YV)4+e=Vz~%sI(0-^1o~$zi2?3iIx5 zDLME1h+^0jkw?Xk44d^l{+uYi`PBRzYdh;aNux_ED<27LjL1md*&BH=pmTYLa@VTB zeG>{JAMQCCsT&^odETGagLAfRI#W8!xg%N7+rz1)N6Sm&u+x;VUJ+rdlN%H7L?qz$7~9G5i1K`*&ykJjrRUDZy+NpYuDJh2srV@2uQ<`P*fWSw7e^hew@` zU&(Adf64Wzs3#mR?y~8vi=MTIJ?0%lv;VFXkG?0%HJ^Mw@LRGrSnS1a)?L@{+?(~= zqL$&(mC#3Q78WdS+*9_x`}l6%w|oC=FTZ)uUOKC2#hV8IGYkw2Y)RhkE(~Ds(|LD2 z0|NtRfk$L91B0G22s2hJwJ&2}U|=ut^mS!_$|NPGrO-V6y9NUTgJg+oM2T~LZf7|qR>N^KY9IJnxRqffDA?4fL zc;tAJ#>Sr!D|qitxtW$I{@+2o`Cw9t<0VHGQKhJ3WfRTLSs9nj zzI^gge}D3`%Kq;swU?N)nso4x4~)?6EGlyhwI{b%== zOzA(PyG3Wg&V#-d`_4yy`|s42*kumdzRRl sb~=cd2L7Aov|w99@`7azALbYTV`2#{jm&JC`4bdtp00i_>zopr0JL_84FCWD literal 0 HcmV?d00001 diff --git a/Base/res/icons/hackstudio/Function.png b/Base/res/icons/hackstudio/Function.png new file mode 100644 index 0000000000000000000000000000000000000000..c776832b370028b6ec92b76afe990d901a599a43 GIT binary patch literal 708 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7TQZ%U13aCb6$*;-(=u~X z85lGs)=sqbIP4&EG(LE#k|=w(S7ArMT%C?Ci!9NufQ47M)>_So`NirhHAzI={ovLI z4~{2YJ$N)SoITu8;15G#adA+|M4|uFMWT*W6x``A|1MYlo?&5J+Nzs|d@E+9E_q~V zI5}37dA)#un?0L>j$!b8Z#Cf$GV$L(eEh0+YV)4+e=Vz~%sI(0-^1o~$zi2?3iIx5 zDLME1h+^0jkw?Xk44d^l{+uYi`PBRzYdh;aNux_ED<27LjL1md*&BH=pmTYLa@VTB zeG>{JAMQCCsT&^odETGagLAfRI#W8!xg%N7+rz1)N6Sm&u+x;VUJ+rdlN%H7L?qz$7~9G5i1K`*&ykJjrRUDZy+NpYuDJh2srV@2uQ<`P*fWSw7e^hew@` zU&(Adf64Wzs3#mR?y~8vi=MTIJ?0%lv;VFXkG?0%HJ^Mw@LRGrSnS1a)?L@{+?(~= zqL$&(mC#3Q78WdS+*9_x`}l6%w|oC=FTZ)uUOKC2#hV8IGYkw2Y)RhkE(~Ds(|LD2 z0|NtRfk$L91B0G22s2hJwJ&2}U|=ut^mS!_$|NPGsprqs`G$dkL9)a(qQp5rH#aq} zgu%HeHL)Z$MWH;iBtya7(>EZzkx!g~fnkoPi(`nz>Eu8E|NpON<6_`uW@bKo{`-H4 zMgMA)Js)$G>9K{`sj;cCv9V1uH8wCX2&w;f?!bWq42BId1=HW!*D>=QYcX6S{J8b; zZSH4}_?Tl3{QgzTR+cEZM=vpHfxv^(gJHg|7Pnts@ML4;UF-Owwb8uc$}pT-G@y GGywpb5ht1e literal 0 HcmV?d00001 diff --git a/Base/res/icons/hackstudio/Struct.png b/Base/res/icons/hackstudio/Struct.png new file mode 100644 index 0000000000000000000000000000000000000000..763d984654aa1301dfb4bf59ebca6a53a1e3a270 GIT binary patch literal 918 zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s7TQZ%U13aCb6$*;-(=u~X z85lGs)=sqbIP4&EG(LE#k|=w(S7ArMT%C?Ci!9NufQ47M)>_So`NirhHAzI={ovLI z4~{2YJ$N)SoITu8;15G#adA+|M4|uFMWT*W6x``A|1MYlo?&5J+Nzs|d@E+9E_q~V zI5}37dA)#un?0L>j$!b8Z#Cf$GV$L(eEh0+YV)4+e=Vz~%sI(0-^1o~$zi2?3iIx5 zDLME1h+^0jkw?Xk44d^l{+uYi`PBRzYdh;aNux_ED<27LjL1md*&BH=pmTYLa@VTB zeG>{JAMQCCsT&^odETGagLAfRI#W8!xg%N7+rz1)N6Sm&u+x;VUJ+rdlN%H7L?qz$7~9G5i1K`*&ykJjrRUDZy+NpYuDJh2srV@2uQ<`P*fWSw7e^hew@` zU&(Adf64Wzs3#mR?y~8vi=MTIJ?0%lv;VFXkG?0%HJ^Mw@LRGrSnS1a)?L@{+?(~= zqL$&(mC#3Q78WdS+*9_x`}l6%w|oC=FTZ)uUOKC2#hV8IGYkw2Y)RhkE)4%caKYZ? zlNlHoI14-?iy0X7ltGxWVyS%@0|NtliKnkC`%@+T5jC7Bq0+`D=HjFDi(lf5TIW%XjpZ98RFpn;EsT}$kT6+vg7?(dWozS_ zO=eBo<-7m#NlVN7HT$0{`dl{AWHxK)|IPEuYu1#!wI?qoEMk3oL$s4+N96WJ`aGz!6>`SprdStkj)>kZ&7wXd~7U;ip-OOV{cF(U>$KpFv>K?uPJ8|X*mB)J( z4_%(k^IN@R&N~tLB)z!F=eK0V&AO}0u%gRtL-rT{CMMQZ-iKemOv$Wn%*dIpt?aka zS6oBD$>5st(ZAkJ+REpyeU#enf4${b`icqL{)?sr#=cy3_i^%)>Pg4Vn?JjpnZ^3| z;iTThp*`2F?TqKg+?l(vUT)!~mz&ZYLrt<`wYsH?U6OZ~n3Nk^oAj^BaOEiCbL8q= zui3C(GvVa|m4>zJzNi;veR6la+t8dHq*5x}$gn9}yT@0tplZRf_>XgSzt7#zAS6(J Vb07cBHU_So`NirhHAzI={ovLI z4~{2YJ$N)SoITu8;15G#adA+|M4|uFMWT*W6x``A|1MYlo?&5J+Nzs|d@E+9E_q~V zI5}37dA)#un?0L>j$!b8Z#Cf$GV$L(eEh0+YV)4+e=Vz~%sI(0-^1o~$zi2?3iIx5 zDLME1h+^0jkw?Xk44d^l{+uYi`PBRzYdh;aNux_ED<27LjL1md*&BH=pmTYLa@VTB zeG>{JAMQCCsT&^odETGagLAfRI#W8!xg%N7+rz1)N6Sm&u+x;VUJ+rdlN%H7L?qz$7~9G5i1K`*&ykJjrRUDZy+NpYuDJh2srV@2uQ<`P*fWSw7e^hew@` zU&(Adf64Wzs3#mR?y~8vi=MTIJ?0%lv;VFXkG?0%HJ^Mw@LRGrSnS1a)?L@{+?(~= zqL$&(mC#3Q78WdS+*9_x`}l6%w|oC=FTZ)uUOKC2#hV8IGYkw2Y)RhkE(~Ds(|LD2 z0|NtRfk$L91B0G22s2hJwJ&2}U|=ut^mS!_$|NPGtygREI*);YL9)a(qQp5rH#aq} zgu%HeHL)Z$MWH;iBtya7(>EZzkx!g~f#I*Gi(`nz>7|nmvzr4%-2COj=5#e%ybv+k z@lvg6b|ll>pj-0ORQD?daPhS&?YVfghtE-5U9pkRkM-qifhY~l-fQ`L_7p$(w9h)& zOH<8-xuX8}gP*15TrunAcI*`8NHF2~@TDk?MYvee-6RFwnzIdzg+4lz#`)M zF}ch}?xG3r=}qgnW3De6j#zgh6T|t> z6M_~^S(GWYNaK(}&qJomCL42SZ_B;;{`-%8_J73p3AHH(d97M?sBq55rk^!_^Pa1C zHVHg>uk~Ln_WI2nv&Y?E)~l@x?_YfI_ikh3*;VJ}E6w$9*${m1D=2t9UHx3vIVCg! E07{2eF#rGn literal 0 HcmV?d00001 diff --git a/Userland/DevTools/HackStudio/Editor.cpp b/Userland/DevTools/HackStudio/Editor.cpp index f865ffef2c..a7754a79b3 100644 --- a/Userland/DevTools/HackStudio/Editor.cpp +++ b/Userland/DevTools/HackStudio/Editor.cpp @@ -522,19 +522,16 @@ void Editor::on_navigatable_link_click(const GUI::TextDocumentSpan& span) navigate_to_include_if_available(header_path); } -void Editor::open_and_set_cursor(const String& file, size_t line, size_t column) -{ - if (code_document().file_path() != file) - on_open(file); - set_cursor(GUI::TextPosition { line, column }); -} - void Editor::on_identifier_click(const GUI::TextDocumentSpan& span) { m_language_client->on_declaration_found = [this](const String& file, size_t line, size_t column) { - open_and_set_cursor(file, line, column); + HackStudio::open_file(file, line, column); }; m_language_client->search_declaration(code_document().file_path(), span.range.start().line(), span.range.start().column()); } +void Editor::set_cursor(const GUI::TextPosition& a_position) +{ + TextEditor::set_cursor(a_position); +} } diff --git a/Userland/DevTools/HackStudio/Editor.h b/Userland/DevTools/HackStudio/Editor.h index 87ef310a44..588965bfc9 100644 --- a/Userland/DevTools/HackStudio/Editor.h +++ b/Userland/DevTools/HackStudio/Editor.h @@ -30,6 +30,7 @@ #include "CodeDocument.h" #include "Debugger/BreakpointCallback.h" #include "LanguageClient.h" +#include #include #include #include @@ -66,6 +67,13 @@ public: virtual void undo() override; virtual void redo() override; + LanguageClient& language_client() + { + VERIFY(m_language_client); + return *m_language_client; + } + virtual void set_cursor(const GUI::TextPosition& a_position) override; + private: virtual void focusin_event(GUI::FocusEvent&) override; virtual void focusout_event(GUI::FocusEvent&) override; @@ -79,7 +87,6 @@ private: void navigate_to_include_if_available(String); void on_navigatable_link_click(const GUI::TextDocumentSpan&); void on_identifier_click(const GUI::TextDocumentSpan&); - void open_and_set_cursor(const String& file, size_t line, size_t column); Gfx::IntRect breakpoint_icon_rect(size_t line_number) const; static const Gfx::Bitmap& breakpoint_icon_bitmap(); diff --git a/Userland/DevTools/HackStudio/EditorWrapper.cpp b/Userland/DevTools/HackStudio/EditorWrapper.cpp index 40771b4d61..b96c4d645f 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.cpp +++ b/Userland/DevTools/HackStudio/EditorWrapper.cpp @@ -80,4 +80,6 @@ void EditorWrapper::set_editor_has_focus(Badge, bool focus) m_filename_label->set_font(focus ? Gfx::FontDatabase::default_bold_font() : Gfx::FontDatabase::default_font()); } +LanguageClient& EditorWrapper::language_client() { return m_editor->language_client(); } + } diff --git a/Userland/DevTools/HackStudio/EditorWrapper.h b/Userland/DevTools/HackStudio/EditorWrapper.h index 0cf67032a2..6dd19012c0 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.h +++ b/Userland/DevTools/HackStudio/EditorWrapper.h @@ -27,6 +27,7 @@ #pragma once #include "Debugger/BreakpointCallback.h" +#include "LanguageClient.h" #include #include #include @@ -48,6 +49,7 @@ public: const GUI::Label& filename_label() const { return *m_filename_label; } void set_editor_has_focus(Badge, bool); + LanguageClient& language_client(); private: EditorWrapper(); diff --git a/Userland/DevTools/HackStudio/HackStudio.h b/Userland/DevTools/HackStudio/HackStudio.h index 85247453d8..cf57b78a80 100644 --- a/Userland/DevTools/HackStudio/HackStudio.h +++ b/Userland/DevTools/HackStudio/HackStudio.h @@ -37,9 +37,12 @@ namespace HackStudio { GUI::TextEditor& current_editor(); void open_file(const String&); RefPtr current_editor_wrapper(); -void open_file(const String&); +void open_file(const String&, size_t line, size_t column); Project& project(); String currently_open_file(); void set_current_editor_wrapper(RefPtr); +class Locator; +Locator& locator(); + } diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h index ef43639357..d7ce22f331 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.h +++ b/Userland/DevTools/HackStudio/HackStudioWidget.h @@ -65,6 +65,12 @@ public: String currently_open_file() const { return m_currently_open_file; } void initialize_menubar(GUI::MenuBar&); + Locator& locator() + { + VERIFY(m_locator); + return *m_locator; + } + private: static String get_full_path_of_serenity_source(const String& file); diff --git a/Userland/DevTools/HackStudio/LanguageClient.cpp b/Userland/DevTools/HackStudio/LanguageClient.cpp index 7d701f46d2..fecd848cb8 100644 --- a/Userland/DevTools/HackStudio/LanguageClient.cpp +++ b/Userland/DevTools/HackStudio/LanguageClient.cpp @@ -25,6 +25,8 @@ */ #include "LanguageClient.h" +#include "HackStudio.h" +#include "Locator.h" #include #include #include @@ -50,11 +52,6 @@ void ServerConnection::handle(const Messages::LanguageClient::DeclarationLocatio m_language_client->declaration_found(message.location().file, message.location().line, message.location().column); } -void ServerConnection::handle(const Messages::LanguageClient::DeclarationList& message) -{ - (void)message; -} - void ServerConnection::die() { dbgln("ServerConnection::die()"); @@ -158,6 +155,10 @@ void ServerConnection::remove_instance_for_project(const String& project_path) auto key = LexicalPath { project_path }.string(); s_instances_for_projects.remove(key); } +void ServerConnection::handle(const Messages::LanguageClient::DeclarationsInDocument& message) +{ + locator().set_declared_symbols(message.filename(), message.declarations()); +} void LanguageClient::search_declaration(const String& path, size_t line, size_t column) { @@ -173,7 +174,6 @@ void LanguageClient::declaration_found(const String& file, size_t line, size_t c dbgln("on_declaration_found callback is not set"); return; } - dbgln("calling on_declaration_found"); on_declaration_found(file, line, column); } diff --git a/Userland/DevTools/HackStudio/Locator.cpp b/Userland/DevTools/HackStudio/Locator.cpp index 50c16fde1e..994600eab2 100644 --- a/Userland/DevTools/HackStudio/Locator.cpp +++ b/Userland/DevTools/HackStudio/Locator.cpp @@ -27,6 +27,7 @@ #include "Locator.h" #include "HackStudio.h" #include "Project.h" +#include #include #include #include @@ -37,7 +38,18 @@ namespace HackStudio { class LocatorSuggestionModel final : public GUI::Model { public: - explicit LocatorSuggestionModel(Vector&& suggestions) + struct Suggestion { + static Suggestion create_filename(const String& filename); + static Suggestion create_symbol_declaration(const GUI::AutocompleteProvider::Declaration&); + + bool is_filename() const { return as_filename.has_value(); } + bool is_symbol_declaration() const { return as_symbol_declaration.has_value(); } + + Optional as_filename; + Optional as_symbol_declaration; + }; + + explicit LocatorSuggestionModel(Vector&& suggestions) : m_suggestions(move(suggestions)) { } @@ -45,6 +57,7 @@ public: enum Column { Icon, Name, + Filename, __Column_Count, }; virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_suggestions.size(); } @@ -52,20 +65,63 @@ public: virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override { auto& suggestion = m_suggestions.at(index.row()); - if (role == GUI::ModelRole::Display) { + if (role != GUI::ModelRole::Display) + return {}; + + if (suggestion.is_filename()) { if (index.column() == Column::Name) - return suggestion; + return suggestion.as_filename.value(); + if (index.column() == Column::Filename) + return ""; if (index.column() == Column::Icon) - return GUI::FileIconProvider::icon_for_path(suggestion); + return GUI::FileIconProvider::icon_for_path(suggestion.as_filename.value()); + } + if (suggestion.is_symbol_declaration()) { + if (index.column() == Column::Name) + return suggestion.as_symbol_declaration.value().name; + if (index.column() == Column::Filename) + return suggestion.as_symbol_declaration.value().position.file; + if (index.column() == Column::Icon) { + static GUI::Icon struct_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Struct.png")); + static GUI::Icon class_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Class.png")); + static GUI::Icon function_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Function.png")); + static GUI::Icon variable_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Variable.png")); + switch (suggestion.as_symbol_declaration.value().type) { + case GUI::AutocompleteProvider::DeclarationType::Struct: + return struct_icon; + case GUI::AutocompleteProvider::DeclarationType::Class: + return class_icon; + case GUI::AutocompleteProvider::DeclarationType::Function: + return function_icon; + case GUI::AutocompleteProvider::DeclarationType::Variable: + return variable_icon; + } + return {}; + } } return {}; } virtual void update() override {}; + const Vector& suggestions() const { return m_suggestions; } + private: - Vector m_suggestions; + Vector m_suggestions; }; +LocatorSuggestionModel::Suggestion LocatorSuggestionModel::Suggestion::create_filename(const String& filename) +{ + LocatorSuggestionModel::Suggestion s; + s.as_filename = filename; + return s; +} +LocatorSuggestionModel::Suggestion LocatorSuggestionModel::Suggestion::create_symbol_declaration(const GUI::AutocompleteProvider::Declaration& decl) +{ + LocatorSuggestionModel::Suggestion s; + s.as_symbol_declaration = decl; + return s; +} + Locator::Locator() { set_layout(); @@ -128,9 +184,16 @@ Locator::~Locator() void Locator::open_suggestion(const GUI::ModelIndex& index) { - auto filename_index = m_suggestion_view->model()->index(index.row(), LocatorSuggestionModel::Column::Name); - auto filename = filename_index.data().to_string(); - open_file(filename); + auto& model = reinterpret_cast(*m_suggestion_view->model()); + auto suggestion = model.suggestions()[index.row()]; + if (suggestion.is_filename()) { + auto filename = suggestion.as_filename.value(); + open_file(filename); + } + if (suggestion.is_symbol_declaration()) { + auto position = suggestion.as_symbol_declaration.value().position; + open_file(position.file, position.line, position.column); + } close(); } @@ -151,14 +214,25 @@ void Locator::close() void Locator::update_suggestions() { auto typed_text = m_textbox->text(); - Vector suggestions; + Vector suggestions; project().for_each_text_file([&](auto& file) { if (file.name().contains(typed_text, CaseSensitivity::CaseInsensitive)) - suggestions.append(file.name()); + suggestions.append(LocatorSuggestionModel::Suggestion::create_filename(file.name())); }); + + for (auto& item : m_document_to_declarations) { + for (auto& decl : item.value) { + if (decl.name.contains(typed_text, CaseSensitivity::CaseInsensitive)) + suggestions.append((LocatorSuggestionModel::Suggestion::create_symbol_declaration(decl))); + } + } + dbgln("I have {} suggestion(s):", suggestions.size()); for (auto& s : suggestions) { - dbgln(" {}", s); + if (s.is_filename()) + dbgln(" {}", s.as_filename.value()); + if (s.is_symbol_declaration()) + dbgln(" {} ({})", s.as_symbol_declaration.value().name, s.as_symbol_declaration.value().position.file); } bool has_suggestions = !suggestions.is_empty(); @@ -174,5 +248,9 @@ void Locator::update_suggestions() dbgln("Popup rect: {}", m_popup_window->rect()); m_popup_window->show(); } +void Locator::set_declared_symbols(const String& filename, const Vector& declarations) +{ + m_document_to_declarations.set(filename, declarations); +} } diff --git a/Userland/DevTools/HackStudio/Locator.h b/Userland/DevTools/HackStudio/Locator.h index e52eb02447..9dfe28aca0 100644 --- a/Userland/DevTools/HackStudio/Locator.h +++ b/Userland/DevTools/HackStudio/Locator.h @@ -26,6 +26,8 @@ #pragma once +#include +#include #include namespace HackStudio { @@ -37,6 +39,7 @@ public: void open(); void close(); + void set_declared_symbols(const String& filename, const Vector&); private: void update_suggestions(); @@ -47,6 +50,7 @@ private: RefPtr m_textbox; RefPtr m_popup_window; RefPtr m_suggestion_view; + HashMap> m_document_to_declarations; }; } diff --git a/Userland/DevTools/HackStudio/main.cpp b/Userland/DevTools/HackStudio/main.cpp index 2384dce1d0..bc2636e6e9 100644 --- a/Userland/DevTools/HackStudio/main.cpp +++ b/Userland/DevTools/HackStudio/main.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "Editor.h" #include "HackStudio.h" #include "HackStudioWidget.h" #include "Project.h" @@ -153,7 +154,13 @@ GUI::TextEditor& current_editor() void open_file(const String& file_name) { - return s_hack_studio_widget->open_file(file_name); + s_hack_studio_widget->open_file(file_name); +} + +void open_file(const String& file_name, size_t line, size_t column) +{ + s_hack_studio_widget->open_file(file_name); + s_hack_studio_widget->current_editor_wrapper().editor().set_cursor({ line, column }); } RefPtr current_editor_wrapper() @@ -180,4 +187,9 @@ void set_current_editor_wrapper(RefPtr wrapper) s_hack_studio_widget->set_current_editor_wrapper(wrapper); } +Locator& locator() +{ + return s_hack_studio_widget->locator(); +} + } diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h index 26bcba7bd8..ce797609ba 100644 --- a/Userland/Libraries/LibCpp/AST.h +++ b/Userland/Libraries/LibCpp/AST.h @@ -149,7 +149,6 @@ protected: : Statement(parent, start, end, filename) { } - }; class InvalidDeclaration : public Declaration { diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h index 052e6cb024..30083da163 100644 --- a/Userland/Libraries/LibGUI/TextEditor.h +++ b/Userland/Libraries/LibGUI/TextEditor.h @@ -174,7 +174,7 @@ public: void set_cursor_and_focus_line(size_t line, size_t column); void set_cursor(size_t line, size_t column); - void set_cursor(const TextPosition&); + virtual void set_cursor(const TextPosition&); const Syntax::Highlighter* syntax_highlighter() const; void set_syntax_highlighter(OwnPtr);