Browse Source

More code cleanup: get_autocomplete_suggestions (previously GetAutoCompleteSuggestions) now only in Source::Parser class.

merge-requests/365/head
eidheim 11 years ago
parent
commit
9d3cda4199
  1. 8
      juci/notebook.cc
  2. 53
      juci/source.cc
  3. 15
      juci/source.h

8
juci/notebook.cc

@ -229,11 +229,9 @@ bool Notebook::Controller::GeneratePopup(int key_id) {
return false;
}
INFO("Notebook genereate popup, getting autocompletions");
std::vector<Source::AutoCompleteData> acdata;
text_vec_.at(CurrentPage())->
GetAutoCompleteSuggestions(beg.get_line()+1,
beg.get_line_offset()+2,
&acdata);
std::vector<Source::AutoCompleteData> acdata=text_vec_.at(CurrentPage())->parser.
get_autocomplete_suggestions(beg.get_line()+1,
beg.get_line_offset()+2);
std::map<std::string, std::string> items;
for (auto &data : acdata) {
std::stringstream ss;

53
juci/source.cc

@ -88,7 +88,7 @@ SetTagTable(const std::unordered_map<string, string> &tagtable) {
tagtable_ = tagtable;
}
bool Source::Config::legal_extension(std::string e) const {
bool Source::Config::legal_extension(std::string e) const {/Users/eidheim/test/jucipp/juci
std::transform(e.begin(), e.end(),e.begin(), ::tolower);
if (find(extensiontable_.begin(), extensiontable_.end(), e) != extensiontable_.end()) {
DEBUG("Legal extension");
@ -103,6 +103,11 @@ bool Source::Config::legal_extension(std::string e) const {
///////////////
clang::Index Source::Parser::clang_index(0, 1);
Source::Parser::~Parser() {
parsing_mutex.lock(); //Be sure not to destroy while still parsing with libclang
parsing_mutex.unlock();
}
void Source::Parser::
InitSyntaxHighlighting(const std::string &filepath,
const std::string &project_path,
@ -142,36 +147,16 @@ ReParse(const std::map<std::string, std::string> &buffer) {
return tu_->ReparseTranslationUnit(file_path, buffer);
}
// Source::Controller::OnLineEdit()
// fired when a line in the buffer is edited
void Source::Controller::OnLineEdit() { }
void Source::Controller::
GetAutoCompleteSuggestions(int line_number,
int column,
std::vector<Source::AutoCompleteData>
*suggestions) {
std::vector<Source::AutoCompleteData> Source::Parser::
get_autocomplete_suggestions(int line_number,
int column) {
INFO("Getting auto complete suggestions");
parsing.lock();
parser.GetAutoCompleteSuggestions(parser.get_buffer_map(),
line_number,
column,
suggestions);
DEBUG("Number of suggestions");
DEBUG_VAR(suggestions->size());
parsing.unlock();
}
void Source::Parser::
GetAutoCompleteSuggestions(const std::map<std::string, std::string> &buffers,
int line_number,
int column,
std::vector<Source::AutoCompleteData>
*suggestions) {
std::vector<Source::AutoCompleteData> suggestions;
auto buffer_map=get_buffer_map();
parsing_mutex.lock();
clang::CodeCompleteResults results(tu_.get(),
file_path,
buffers,
buffer_map,
line_number,
column);
for (int i = 0; i < results.size(); i++) {
@ -180,8 +165,12 @@ GetAutoCompleteSuggestions(const std::map<std::string, std::string> &buffers,
for (auto &chunk : chunks_) {
chunks.emplace_back(chunk);
}
suggestions->emplace_back(chunks);
suggestions.emplace_back(chunks);
}
parsing_mutex.unlock();
DEBUG("Number of suggestions");
DEBUG_VAR(suggestions.size());
return suggestions;
}
std::vector<std::string> Source::Parser::
@ -274,8 +263,6 @@ Source::Controller::Controller(const Source::Config &config,
Source::Controller::~Controller() {
parse_thread_stop=true;
parsing.lock(); //Be sure not to destroy while still parsing with libclang
parsing.unlock();
if(parse_thread.joinable())
parse_thread.join();
}
@ -370,10 +357,10 @@ void Source::Controller::OnOpenFile(const string &filepath) {
parse_thread_go=false;
parse_start();
}
else if (parse_thread_mapped && parsing.try_lock() && parse_thread_buffer_map_mutex.try_lock()) {
else if (parse_thread_mapped && parser.parsing_mutex.try_lock() && parse_thread_buffer_map_mutex.try_lock()) {
parser.ReParse(this->parse_thread_buffer_map);
parse_thread_go=false;
parsing.unlock();
parser.parsing_mutex.unlock();
parse_thread_buffer_map_mutex.unlock();
parse_done();
}

15
juci/source.h

@ -98,6 +98,7 @@ namespace Source {
public:
Parser(const std::vector<std::unique_ptr<Source::Controller> > &controllers):
controllers(controllers) {}
~Parser();
// inits the syntax highligthing on file open
void InitSyntaxHighlighting(const std::string &filepath,
const std::string &project_path,
@ -106,12 +107,7 @@ namespace Source {
int start_offset,
int end_offset,
clang::Index *index);
void GetAutoCompleteSuggestions(const std::map<std::string, std::string>
&buffers,
int line_number,
int column,
std::vector<AutoCompleteData>
*suggestions);
std::vector<Source::AutoCompleteData> get_autocomplete_suggestions(int line_number, int column);
int ReParse(const std::map<std::string, std::string> &buffers);
std::vector<Range> ExtractTokens(int, int);
@ -119,6 +115,7 @@ namespace Source {
std::string project_path;
static clang::Index clang_index;
std::map<std::string, std::string> get_buffer_map() const;
std::mutex parsing_mutex;
private:
std::unique_ptr<clang::TranslationUnit> tu_; //use unique_ptr since it is not initialized in constructor
void HighlightToken(clang::Token *token,
@ -138,13 +135,8 @@ namespace Source {
~Controller();
void OnNewEmptyFile();
void OnOpenFile(const std::string &filename);
void GetAutoCompleteSuggestions(int line_number,
int column,
std::vector<AutoCompleteData>
*suggestions);
Glib::RefPtr<Gsv::Buffer> buffer();
bool OnKeyPress(GdkEventKey* key);
bool LegalExtension(std::string e);
bool is_saved = false; //TODO: Is never set to false in Notebook::Controller
bool is_changed = false; //TODO: Is never set to true
@ -155,7 +147,6 @@ namespace Source {
private:
void OnLineEdit();
void OnSaveFile();
std::mutex parsing;
Glib::Dispatcher parse_done;
Glib::Dispatcher parse_start;
std::thread parse_thread;

Loading…
Cancel
Save