diff --git a/src/ctags.cc b/src/ctags.cc index 1fa7fdc..b2c8c10 100644 --- a/src/ctags.cc +++ b/src/ctags.cc @@ -9,25 +9,29 @@ #include std::pair> Ctags::get_result(const boost::filesystem::path &path) { - auto build = Project::Build::create(path); - auto run_path = build->project_path; - std::string exclude = " --exclude=node_modules"; - if(!run_path.empty()) { - exclude += " --exclude=" + filesystem::get_relative_path(build->get_default_path(), run_path).string(); - exclude += " --exclude=" + filesystem::get_relative_path(build->get_debug_path(), run_path).string(); + boost::filesystem::path run_path; + std::string command; + boost::system::error_code ec; + if(boost::filesystem::is_directory(path, ec)) { + auto build = Project::Build::create(path); + std::string exclude = " --exclude=node_modules"; + if(!build->project_path.empty()) { + run_path = build->project_path; + exclude += " --exclude=" + filesystem::get_relative_path(build->get_default_path(), run_path).string(); + exclude += " --exclude=" + filesystem::get_relative_path(build->get_debug_path(), run_path).string(); + } + else + run_path = path; + command = Config::get().project.ctags_command + exclude + " --fields=ns --sort=foldcase -I \"override noexcept\" -f - -R *"; } else { - boost::system::error_code ec; - if(boost::filesystem::is_directory(path, ec) || ec) - run_path = path; - else - run_path = path.parent_path(); + run_path = path.parent_path(); + command = Config::get().project.ctags_command + " --fields=ns --sort=foldcase -I \"override noexcept\" -f - " + path.string(); } std::stringstream stdin_stream; //TODO: when debian stable gets newer g++ version that supports move on streams, remove unique_ptr below auto stdout_stream = std::make_unique(); - auto command = Config::get().project.ctags_command + exclude + " --fields=ns --sort=foldcase -I \"override noexcept\" -f - -R *"; Terminal::get().process(stdin_stream, *stdout_stream, command, run_path); return {run_path, std::move(stdout_stream)}; } diff --git a/src/source_clang.cc b/src/source_clang.cc index dcf1c35..c604b8b 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -1279,7 +1279,7 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file name.insert(0, spelling); parent = parent.get_semantic_parent(); } - auto ctags_locations = Ctags::get_locations(this->file_path, name, identifier.cursor.get_type_description()); + auto ctags_locations = Ctags::get_locations(this->file_path.parent_path(), name, identifier.cursor.get_type_description()); if(!ctags_locations.empty()) { for(auto &ctags_location : ctags_locations) { Offset offset; diff --git a/src/source_generic.cc b/src/source_generic.cc index 44209c8..50cbcab 100644 --- a/src/source_generic.cc +++ b/src/source_generic.cc @@ -1,7 +1,10 @@ #include "source_generic.h" +#include "ctags.h" +#include "info.h" #include "selection_dialog.h" #include "snippets.h" #include "terminal.h" +#include 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(); @@ -39,6 +42,36 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const setup_buffer_words(); 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"); + return methods; + } + stream->seekg(0, std::ios::beg); + + 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; + }); + + if(methods.empty()) + Info::get().print("No methods found in current buffer"); + return methods; + }; + } } Source::GenericView::~GenericView() {