|
|
|
@ -1,5 +1,4 @@ |
|
|
|
#include "source_generic.h" |
|
|
|
#include "source_generic.h" |
|
|
|
#include "ctags.h" |
|
|
|
|
|
|
|
#include "filesystem.h" |
|
|
|
#include "filesystem.h" |
|
|
|
#include "info.h" |
|
|
|
#include "info.h" |
|
|
|
#include "selection_dialog.h" |
|
|
|
#include "selection_dialog.h" |
|
|
|
@ -7,18 +6,6 @@ |
|
|
|
#include "terminal.h" |
|
|
|
#include "terminal.h" |
|
|
|
#include <algorithm> |
|
|
|
#include <algorithm> |
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
|
|
|
#include <windows.h> |
|
|
|
|
|
|
|
inline DWORD get_current_process_id() { |
|
|
|
|
|
|
|
return GetCurrentProcessId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
#include <unistd.h> |
|
|
|
|
|
|
|
inline pid_t get_current_process_id() { |
|
|
|
|
|
|
|
return getpid(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Source::GenericView::GenericView(const boost::filesystem::path &file_path, const Glib::RefPtr<Gsv::Language> &language) : BaseView(file_path, language), View(file_path, language, true), autocomplete(this, interactive_completion, last_keyval, false) { |
|
|
|
Source::GenericView::GenericView(const boost::filesystem::path &file_path, const Glib::RefPtr<Gsv::Language> &language) : BaseView(file_path, language), View(file_path, language, true), autocomplete(this, interactive_completion, last_keyval, false) { |
|
|
|
spellcheck_all = true; |
|
|
|
spellcheck_all = true; |
|
|
|
|
|
|
|
|
|
|
|
@ -55,60 +42,6 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const |
|
|
|
setup_buffer_words(); |
|
|
|
setup_buffer_words(); |
|
|
|
|
|
|
|
|
|
|
|
setup_autocomplete(); |
|
|
|
setup_autocomplete(); |
|
|
|
|
|
|
|
|
|
|
|
get_methods = [this]() { |
|
|
|
|
|
|
|
std::vector<std::pair<Offset, std::string>> methods; |
|
|
|
|
|
|
|
boost::filesystem::path file_path; |
|
|
|
|
|
|
|
boost::system::error_code ec; |
|
|
|
|
|
|
|
bool use_tmp_file = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this->get_buffer()->get_modified()) { |
|
|
|
|
|
|
|
use_tmp_file = true; |
|
|
|
|
|
|
|
file_path = boost::filesystem::temp_directory_path(ec); |
|
|
|
|
|
|
|
if(ec) { |
|
|
|
|
|
|
|
Terminal::get().print("Error: could not get temporary directory folder\n", true); |
|
|
|
|
|
|
|
return methods; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
file_path /= "jucipp_get_methods" + std::to_string(get_current_process_id()); |
|
|
|
|
|
|
|
boost::filesystem::create_directory(file_path, ec); |
|
|
|
|
|
|
|
if(ec) { |
|
|
|
|
|
|
|
Terminal::get().print("Error: could not create temporary folder\n", true); |
|
|
|
|
|
|
|
return methods; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
file_path /= this->file_path.filename(); |
|
|
|
|
|
|
|
filesystem::write(file_path, this->get_buffer()->get_text().raw()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
file_path = this->file_path; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ctags ctags(file_path, false, true); |
|
|
|
|
|
|
|
if(use_tmp_file) |
|
|
|
|
|
|
|
boost::filesystem::remove_all(file_path.parent_path(), ec); |
|
|
|
|
|
|
|
if(!ctags) { |
|
|
|
|
|
|
|
Info::get().print("No methods found in current buffer"); |
|
|
|
|
|
|
|
return methods; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string line; |
|
|
|
|
|
|
|
while(std::getline(ctags.output, line)) { |
|
|
|
|
|
|
|
auto location = ctags.get_location(line, true); |
|
|
|
|
|
|
|
std::transform(location.kind.begin(), location.kind.end(), location.kind.begin(), |
|
|
|
|
|
|
|
[](char c) { return std::tolower(c); }); |
|
|
|
|
|
|
|
std::vector<std::string> ignore_kinds = {"variable", "local", "constant", "global", "property", "member", "enum", |
|
|
|
|
|
|
|
"macro", "param", "header", |
|
|
|
|
|
|
|
"typedef", "using", "alias", |
|
|
|
|
|
|
|
"project", "option"}; |
|
|
|
|
|
|
|
if(std::none_of(ignore_kinds.begin(), ignore_kinds.end(), [&location](const std::string &e) { return location.kind.find(e) != std::string::npos; })) |
|
|
|
|
|
|
|
methods.emplace_back(Offset(location.line, location.index), location.source); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
std::sort(methods.begin(), methods.end(), [](const std::pair<Offset, std::string> &e1, const std::pair<Offset, std::string> &e2) { |
|
|
|
|
|
|
|
return e1.first < e2.first; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(methods.empty()) |
|
|
|
|
|
|
|
Info::get().print("No methods found in current buffer"); |
|
|
|
|
|
|
|
return methods; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Source::GenericView::~GenericView() { |
|
|
|
Source::GenericView::~GenericView() { |
|
|
|
|