diff --git a/src/ctags.cc b/src/ctags.cc index b2c8c10..db69420 100644 --- a/src/ctags.cc +++ b/src/ctags.cc @@ -22,11 +22,11 @@ std::pair> Ctags::ge } else run_path = path; - command = Config::get().project.ctags_command + exclude + " --fields=ns --sort=foldcase -I \"override noexcept\" -f - -R *"; + command = Config::get().project.ctags_command + exclude + " --fields=nsk --sort=foldcase -I \"override noexcept\" -f - -R *"; } else { run_path = path.parent_path(); - command = Config::get().project.ctags_command + " --fields=ns --sort=foldcase -I \"override noexcept\" -f - " + path.string(); + command = Config::get().project.ctags_command + " --fields=nsk --sort=foldcase -I \"override noexcept\" -f - " + path.string(); } std::stringstream stdin_stream; @@ -87,7 +87,14 @@ Ctags::Location Ctags::get_location(const std::string &line_, bool markup) { } location.source = line.substr(source_start, source_end - source_start - (line[source_end - 1] == '$' ? 1 : 0)); - auto line_start = source_end + 9; + auto kind_start = source_end + 4; + if(kind_start >= line.size()) { + std::cerr << "Warning (ctags): could not parse line: " << line << std::endl; + return location; + } + location.kind = line[kind_start]; + + auto line_start = kind_start + 7; if(line_start >= line.size()) { std::cerr << "Warning (ctags): could not parse line: " << line << std::endl; return location; diff --git a/src/ctags.h b/src/ctags.h index fab226b..0bfe43d 100644 --- a/src/ctags.h +++ b/src/ctags.h @@ -14,6 +14,7 @@ public: std::string symbol; std::string scope; std::string source; + char kind; operator bool() const { return !file_path.empty(); } }; diff --git a/src/source_generic.cc b/src/source_generic.cc index 50cbcab..8cfa23d 100644 --- a/src/source_generic.cc +++ b/src/source_generic.cc @@ -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 +#ifdef _WIN32 +#include +inline DWORD get_current_process_id() { + return GetCurrentProcessId(); +} +#else +#include +inline pid_t get_current_process_id() { + return getpid(); +} +#endif + Source::GenericView::GenericView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : BaseView(file_path, language), View(file_path, language, true), autocomplete(this, interactive_completion, last_keyval, false) { configure(); spellcheck_all = true; @@ -43,35 +56,53 @@ 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); - auto path = std::move(pair.first); - auto stream = std::move(pair.second); - stream->seekg(0, std::ios::end); - - std::vector> methods; - if(stream->tellg() == 0) { - Info::get().print("No methods found in current buffer"); + get_methods = [this]() { + std::vector> 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; } - stream->seekg(0, std::ios::beg); + 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; - std::string line; - auto filename = this->file_path.filename(); - while(std::getline(*stream, line)) { - auto location = Ctags::get_location(line, true); - methods.emplace_back(Offset(location.line, location.index), location.source); - } - std::sort(methods.begin(), methods.end(), [](const std::pair &e1, const std::pair &e2) { - return e1.first < e2.first; - }); + 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); - if(methods.empty()) - Info::get().print("No methods found in current buffer"); + if(stream->tellg() == 0) { + Info::get().print("No methods found in current buffer"); return methods; - }; - } + } + stream->seekg(0, std::ios::beg); + + std::string line; + 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 &e1, const std::pair &e2) { + return e1.first < e2.first; + }); + + if(methods.empty()) + Info::get().print("No methods found in current buffer"); + return methods; + }; } Source::GenericView::~GenericView() { diff --git a/src/usages_clang.cc b/src/usages_clang.cc index 6cd86a0..6f4d9d8 100644 --- a/src/usages_clang.cc +++ b/src/usages_clang.cc @@ -11,12 +11,12 @@ #ifdef _WIN32 #include -DWORD get_current_process_id() { +inline DWORD get_current_process_id() { return GetCurrentProcessId(); } #else #include -pid_t get_current_process_id() { +inline pid_t get_current_process_id() { return getpid(); } #endif