Browse Source

add autocompletion demo

master
Jørgen Lien Sellæg 11 years ago
parent
commit
a27517293c
  1. 12
      juci/notebook.cc
  2. 33
      juci/source.cc
  3. 7
      juci/source.h

12
juci/notebook.cc

@ -1,4 +1,5 @@
#include "notebook.h"
#include "clangmm.h"
Notebook::Model::Model() {
cc_extension_ = ".cc";
@ -388,14 +389,13 @@ void Notebook::Controller::OnBufferChange() {
end = Buffer(text_vec_.at(page))->get_insert()->get_iter();
start.backward_char();
word = Buffer(text_vec_.at(page))->get_text(start, end);
std::cout << start.get_line() << std::endl;
std::cout << start.get_line_offset() << std::endl;
if (word == ".") {
// TODO(Forgie) Zalox,Forgie) Remove TEST
std::vector<std::string> TEST;
TEST.push_back("toString()");
TEST.push_back("toLower()");
TEST.push_back("toUpper()");
TEST.push_back("fuckOFF()");
TEST.push_back("fuckOFF()");
std::vector<std::string> TEST
= text_vec_[page]->GetAutoCompleteSuggestions(start.get_line()+1,
start.get_line_offset()+2);
GeneratePopup(TEST);
}
}

33
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() { }
std::vector<std::string> Source::Controller::
GetAutoCompleteSuggestions(int line_number,
int column) {
return model().GetAutoCompleteSuggestions(view().get_buffer()
->get_text().raw(),
line_number,
column);
}
std::vector<std::string> Source::Model::
GetAutoCompleteSuggestions(const std::string& buffer,
int line_number,
int column) {
std::vector<std::string> res;
parsing.lock();
clang::CodeCompleteResults results(&tu_,
file_path(),
buffer,
line_number,
column);
for (int i = 0; i < results.size(); i++) {
std::stringstream ss;
const vector<clang::CompletionChunk> c = results.get(i).get_chunks();
for (auto &stringchunk : c) {
ss << stringchunk.chunk();
}
res.emplace_back(ss.str());
}
parsing.unlock();
return res;
}
// sets the filepath for this mvc
void Source::Model::
set_file_path(const std::string &file_path) {

7
juci/source.h

@ -95,6 +95,10 @@ namespace Source {
const string& project_path() const;
// gets the config member
const Config& config() const;
std::vector<std::string>
GetAutoCompleteSuggestions(const std::string& buffer,
int line_number,
int column);
~Model() { }
int ReParse(const std::string &buffer);
std::vector<Range> ExtractTokens(int, int);
@ -121,6 +125,9 @@ namespace Source {
Model& model();
void OnNewEmptyFile();
void OnOpenFile(const string &filename);
std::vector<std::string>
GetAutoCompleteSuggestions(int line_number,
int column);
Glib::RefPtr<Gtk::TextBuffer> buffer();
private:

Loading…
Cancel
Save