|
|
|
|
@ -1,11 +1,24 @@
|
|
|
|
|
#include "source_generic.h" |
|
|
|
|
#include "ctags.h" |
|
|
|
|
#include "filesystem.h" |
|
|
|
|
#include "info.h" |
|
|
|
|
#include "selection_dialog.h" |
|
|
|
|
#include "snippets.h" |
|
|
|
|
#include "terminal.h" |
|
|
|
|
#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) { |
|
|
|
|
configure(); |
|
|
|
|
spellcheck_all = true; |
|
|
|
|
@ -43,14 +56,32 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const
|
|
|
|
|
|
|
|
|
|
setup_autocomplete(); |
|
|
|
|
|
|
|
|
|
if(language && (language->get_id() == "markdown" || language->get_id() == "json")) { |
|
|
|
|
get_methods = [this]() { |
|
|
|
|
auto pair = Ctags::get_result(this->file_path); |
|
|
|
|
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()) + this->file_path.filename().string()); |
|
|
|
|
filesystem::write(file_path, this->get_buffer()->get_text().raw()); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
file_path = this->file_path; |
|
|
|
|
|
|
|
|
|
auto pair = Ctags::get_result(file_path); |
|
|
|
|
if(use_tmp_file) |
|
|
|
|
boost::filesystem::remove(file_path, ec); |
|
|
|
|
auto path = std::move(pair.first); |
|
|
|
|
auto stream = std::move(pair.second); |
|
|
|
|
stream->seekg(0, std::ios::end); |
|
|
|
|
|
|
|
|
|
std::vector<std::pair<Offset, std::string>> methods; |
|
|
|
|
if(stream->tellg() == 0) { |
|
|
|
|
Info::get().print("No methods found in current buffer"); |
|
|
|
|
return methods; |
|
|
|
|
@ -58,9 +89,10 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const
|
|
|
|
|
stream->seekg(0, std::ios::beg); |
|
|
|
|
|
|
|
|
|
std::string line; |
|
|
|
|
auto filename = this->file_path.filename(); |
|
|
|
|
bool all_kinds = this->language && (this->language->get_id() == "markdown" || this->language->get_id() == "json"); |
|
|
|
|
while(std::getline(*stream, line)) { |
|
|
|
|
auto location = Ctags::get_location(line, true); |
|
|
|
|
if(all_kinds || location.kind == 'f' || location.kind == 's' || location.kind == 'm') |
|
|
|
|
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) { |
|
|
|
|
@ -71,7 +103,6 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const
|
|
|
|
|
Info::get().print("No methods found in current buffer"); |
|
|
|
|
return methods; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Source::GenericView::~GenericView() { |
|
|
|
|
|