|
|
|
@ -4,7 +4,7 @@ |
|
|
|
#include <boost/property_tree/json_parser.hpp> |
|
|
|
#include <boost/property_tree/json_parser.hpp> |
|
|
|
#include <fstream> |
|
|
|
#include <fstream> |
|
|
|
#include <boost/timer/timer.hpp> |
|
|
|
#include <boost/timer/timer.hpp> |
|
|
|
|
|
|
|
#include "notebook.h" |
|
|
|
|
|
|
|
|
|
|
|
#define log( var ) \ |
|
|
|
#define log( var ) \ |
|
|
|
std::cout << "source.cc (" << __LINE__ << ") " << #var << std::endl |
|
|
|
std::cout << "source.cc (" << __LINE__ << ") " << #var << std::endl |
|
|
|
@ -102,16 +102,18 @@ Source::Model::Model(const Source::Config &config) : |
|
|
|
void Source::Model:: |
|
|
|
void Source::Model:: |
|
|
|
InitSyntaxHighlighting(const std::string &filepath, |
|
|
|
InitSyntaxHighlighting(const std::string &filepath, |
|
|
|
const std::string &project_path, |
|
|
|
const std::string &project_path, |
|
|
|
const std::string &text, |
|
|
|
const std::map<std::string, std::string> |
|
|
|
|
|
|
|
&buffers, |
|
|
|
int start_offset, |
|
|
|
int start_offset, |
|
|
|
int end_offset) { |
|
|
|
int end_offset, |
|
|
|
|
|
|
|
clang::Index *index) { |
|
|
|
set_file_path(filepath); |
|
|
|
set_file_path(filepath); |
|
|
|
set_project_path(project_path); |
|
|
|
set_project_path(project_path); |
|
|
|
std::vector<const char*> arguments = get_compilation_commands(); |
|
|
|
std::vector<const char*> arguments = get_compilation_commands(); |
|
|
|
tu_ = clang::TranslationUnit(true, |
|
|
|
tu_ = clang::TranslationUnit(index, |
|
|
|
filepath, |
|
|
|
filepath, |
|
|
|
arguments, |
|
|
|
arguments, |
|
|
|
text); |
|
|
|
buffers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Source::View::UpdateLine
|
|
|
|
// Source::View::UpdateLine
|
|
|
|
@ -123,7 +125,7 @@ OnLineEdit(const std::vector<Source::Range> &locations, |
|
|
|
|
|
|
|
|
|
|
|
// Source::Model::UpdateLine
|
|
|
|
// Source::Model::UpdateLine
|
|
|
|
int Source::Model:: |
|
|
|
int Source::Model:: |
|
|
|
ReParse(const std::string &buffer) { |
|
|
|
ReParse(const std::map<std::string, std::string> &buffer) { |
|
|
|
return tu_.ReparseTranslationUnit(file_path(), buffer); |
|
|
|
return tu_.ReparseTranslationUnit(file_path(), buffer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -138,8 +140,9 @@ GetAutoCompleteSuggestions(int line_number, |
|
|
|
std::vector<Source::AutoCompleteData> |
|
|
|
std::vector<Source::AutoCompleteData> |
|
|
|
*suggestions) { |
|
|
|
*suggestions) { |
|
|
|
parsing.lock(); |
|
|
|
parsing.lock(); |
|
|
|
model().GetAutoCompleteSuggestions(view().get_buffer() |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
->get_text().raw(), |
|
|
|
notebook_->MapBuffers(&buffers); |
|
|
|
|
|
|
|
model().GetAutoCompleteSuggestions(buffers, |
|
|
|
line_number, |
|
|
|
line_number, |
|
|
|
column, |
|
|
|
column, |
|
|
|
suggestions); |
|
|
|
suggestions); |
|
|
|
@ -147,14 +150,14 @@ GetAutoCompleteSuggestions(int line_number, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Source::Model:: |
|
|
|
void Source::Model:: |
|
|
|
GetAutoCompleteSuggestions(const std::string& buffer, |
|
|
|
GetAutoCompleteSuggestions(const std::map<std::string, std::string> &buffers, |
|
|
|
int line_number, |
|
|
|
int line_number, |
|
|
|
int column, |
|
|
|
int column, |
|
|
|
std::vector<Source::AutoCompleteData> |
|
|
|
std::vector<Source::AutoCompleteData> |
|
|
|
*suggestions) { |
|
|
|
*suggestions) { |
|
|
|
clang::CodeCompleteResults results(&tu_, |
|
|
|
clang::CodeCompleteResults results(&tu_, |
|
|
|
file_path(), |
|
|
|
file_path(), |
|
|
|
buffer, |
|
|
|
buffers, |
|
|
|
line_number, |
|
|
|
line_number, |
|
|
|
column); |
|
|
|
column); |
|
|
|
for (int i = 0; i < results.size(); i++) { |
|
|
|
for (int i = 0; i < results.size(); i++) { |
|
|
|
@ -263,9 +266,9 @@ HighlightToken(clang::Token *token, |
|
|
|
|
|
|
|
|
|
|
|
// Source::Controller::Controller()
|
|
|
|
// Source::Controller::Controller()
|
|
|
|
// Constructor for Controller
|
|
|
|
// Constructor for Controller
|
|
|
|
Source::Controller::Controller(const Source::Config &config) : |
|
|
|
Source::Controller::Controller(const Source::Config &config, |
|
|
|
model_(config) { |
|
|
|
Notebook::Controller *notebook) : |
|
|
|
} |
|
|
|
model_(config), notebook_(notebook) { } |
|
|
|
|
|
|
|
|
|
|
|
// Source::Controller::view()
|
|
|
|
// Source::Controller::view()
|
|
|
|
// return shared_ptr to the view
|
|
|
|
// return shared_ptr to the view
|
|
|
|
@ -313,7 +316,7 @@ void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges, |
|
|
|
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer(); |
|
|
|
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer(); |
|
|
|
buffer->remove_all_tags(buffer->begin(), buffer->end()); |
|
|
|
buffer->remove_all_tags(buffer->begin(), buffer->end()); |
|
|
|
for (auto &range : ranges) { |
|
|
|
for (auto &range : ranges) { |
|
|
|
string type = std::to_string(range.kind()); |
|
|
|
std::string type = std::to_string(range.kind()); |
|
|
|
try { |
|
|
|
try { |
|
|
|
config.typetable().at(type); |
|
|
|
config.typetable().at(type); |
|
|
|
} catch (std::exception) { |
|
|
|
} catch (std::exception) { |
|
|
|
@ -337,17 +340,20 @@ void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges, |
|
|
|
|
|
|
|
|
|
|
|
void Source::Controller::OnOpenFile(const string &filepath) { |
|
|
|
void Source::Controller::OnOpenFile(const string &filepath) { |
|
|
|
sourcefile s(filepath); |
|
|
|
sourcefile s(filepath); |
|
|
|
|
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
|
|
|
|
notebook_->MapBuffers(&buffers); |
|
|
|
|
|
|
|
buffers[filepath] = s.get_content(); |
|
|
|
buffer()->set_text(s.get_content()); |
|
|
|
buffer()->set_text(s.get_content()); |
|
|
|
int start_offset = buffer()->begin().get_offset(); |
|
|
|
int start_offset = buffer()->begin().get_offset(); |
|
|
|
int end_offset = buffer()->end().get_offset(); |
|
|
|
int end_offset = buffer()->end().get_offset(); |
|
|
|
|
|
|
|
|
|
|
|
if (check_extention(filepath)) { |
|
|
|
if (check_extention(filepath)) { |
|
|
|
view().ApplyConfig(model().config()); |
|
|
|
view().ApplyConfig(model().config()); |
|
|
|
model().InitSyntaxHighlighting(filepath, |
|
|
|
model().InitSyntaxHighlighting(filepath, |
|
|
|
extract_file_path(filepath), |
|
|
|
extract_file_path(filepath), |
|
|
|
buffer()->get_text().raw(), |
|
|
|
buffers, |
|
|
|
start_offset, |
|
|
|
start_offset, |
|
|
|
end_offset); |
|
|
|
end_offset, |
|
|
|
|
|
|
|
notebook_->index()); |
|
|
|
view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset), |
|
|
|
view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset), |
|
|
|
model().config()); |
|
|
|
model().config()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -358,7 +364,10 @@ void Source::Controller::OnOpenFile(const string &filepath) { |
|
|
|
if (parsing.try_lock()) { |
|
|
|
if (parsing.try_lock()) { |
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
const std::string raw = buffer()->get_text().raw(); |
|
|
|
const std::string raw = buffer()->get_text().raw(); |
|
|
|
if (model().ReParse(raw) == 0 && |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
|
|
|
|
notebook_->MapBuffers(&buffers); |
|
|
|
|
|
|
|
buffers[model().file_path()] = raw; |
|
|
|
|
|
|
|
if (model().ReParse(buffers) == 0 && |
|
|
|
raw == buffer()->get_text().raw()) { |
|
|
|
raw == buffer()->get_text().raw()) { |
|
|
|
syntax.lock(); |
|
|
|
syntax.lock(); |
|
|
|
go = true; |
|
|
|
go = true; |
|
|
|
@ -373,7 +382,6 @@ void Source::Controller::OnOpenFile(const string &filepath) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buffer()->signal_begin_user_action().connect([this]() { |
|
|
|
buffer()->signal_begin_user_action().connect([this]() { |
|
|
|
if (go) { |
|
|
|
if (go) { |
|
|
|
syntax.lock(); |
|
|
|
syntax.lock(); |
|
|
|
|