Browse Source

Added Go to Method to markdown and json files

merge-requests/399/head
eidheim 6 years ago
parent
commit
7b34521a21
  1. 28
      src/ctags.cc
  2. 2
      src/source_clang.cc
  3. 33
      src/source_generic.cc

28
src/ctags.cc

@ -9,25 +9,29 @@
#include <vector>
std::pair<boost::filesystem::path, std::unique_ptr<std::stringstream>> 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<std::stringstream>();
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)};
}

2
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;

33
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 <algorithm>
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();
@ -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<std::pair<Offset, std::string>> 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<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() {

Loading…
Cancel
Save