diff --git a/juci/notebook.cc b/juci/notebook.cc index 0e11dbb..e2b04c9 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -1,6 +1,6 @@ #include "notebook.h" #include - +#include "clangmm.h" Notebook::Model::Model() { cc_extension_ = ".cc"; @@ -21,9 +21,9 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings, OnNewPage("juCi++"); refClipboard_ = Gtk::Clipboard::get(); ispopup = false; - view().pack1(directories_.widget(),true,true); + view().pack1(directories_.widget(), true, true); CreateKeybindings(keybindings); -}// Constructor +} // Constructor void Notebook::Controller::CreateKeybindings(Keybindings::Controller @@ -141,16 +141,10 @@ bool Notebook::Controller:: OnMouseRelease(GdkEventButton* button){ bool Notebook::Controller::GeneratePopup(Gtk::Window* window){ // Get function to fill popup with suggests item vector under is for testing std::vector items; - items.push_back("toString(std::string& string) -> void"); - items.push_back("toLower(std::string& string) -> void"); - items.push_back("toUpper(std::string& string) -> void"); - items.push_back("fuckOFF(const std::string string) -> bool"); - items.push_back("fuckOFF(const std::string string) -> bool"); - items.push_back("toString(std::string& string) -> void"); - items.push_back("toLower(std::string& string) -> void"); - items.push_back("toUpper(std::string& string) -> void"); - items.push_back("fuckOFF(const std::string string) -> bool"); - items.push_back("fuckOFF(const std::string string) -> bool"); + Gtk::TextIter start = CurrentTextView().get_buffer()->get_insert()->get_iter(); + text_vec_.at(CurrentPage())->GetAutoCompleteSuggestions(start.get_line()+1, + start.get_line_offset()+2, + &items); // Replace over with get suggestions from zalox! OVER IS JUST FOR TESTING diff --git a/juci/source.cc b/juci/source.cc index 2117b79..baec800 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -132,6 +132,39 @@ ReParse(const std::string &buffer) { // fired when a line in the buffer is edited void Source::Controller::OnLineEdit() { } +void Source::Controller:: +GetAutoCompleteSuggestions(int line_number, + int column, + std::vector *suggestions) { + parsing.lock(); + model().GetAutoCompleteSuggestions(view().get_buffer() + ->get_text().raw(), + line_number, + column, + suggestions); + parsing.unlock(); +} + +void Source::Model:: +GetAutoCompleteSuggestions(const std::string& buffer, + int line_number, + int column, + std::vector *suggestions) { + clang::CodeCompleteResults results(&tu_, + file_path(), + buffer, + line_number, + column); + for (int i = 0; i < results.size(); i++) { + std::stringstream ss; + const vector c = results.get(i).get_chunks(); + for (auto &stringchunk : c) { + ss << stringchunk.chunk(); + } + suggestions->emplace_back(ss.str()); + } +} + // sets the filepath for this mvc void Source::Model:: set_file_path(const std::string &file_path) { diff --git a/juci/source.h b/juci/source.h index 67b3d9a..8450807 100644 --- a/juci/source.h +++ b/juci/source.h @@ -95,7 +95,11 @@ namespace Source { const string& project_path() const; // gets the config member const Config& config() const; - ~Model() { } + void GetAutoCompleteSuggestions(const std::string& buffer, + int line_number, + int column, + std::vector *suggestions); + ~Model() { } int ReParse(const std::string &buffer); std::vector ExtractTokens(int, int); @@ -121,6 +125,9 @@ namespace Source { Model& model(); void OnNewEmptyFile(); void OnOpenFile(const string &filename); + void GetAutoCompleteSuggestions(int line_number, + int column, + std::vector *suggestions); Glib::RefPtr buffer(); private: