Browse Source

Merge pull request #87 from eidheim/master

Go to Usage implementation
merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
ad5528c5b2
  1. 1
      CMakeLists.txt
  2. 8
      docs/install.md
  3. 4
      share/juci.desktop
  4. 2
      src/CMakeLists.txt
  5. 20
      src/cmake.cc
  6. 13
      src/config.cc
  7. 8
      src/config.h
  8. 19
      src/directories.cc
  9. 1
      src/directories.h
  10. 9
      src/files.h
  11. 5
      src/menu.cc
  12. 15
      src/source.h
  13. 71
      src/source_clang.cc
  14. 9
      src/source_clang.h
  15. 79
      src/window.cc

1
CMakeLists.txt

@ -11,5 +11,6 @@ add_subdirectory("src")
find_program(XDG_DESKTOP_MENU_EXECUTABLE xdg-desktop-menu) find_program(XDG_DESKTOP_MENU_EXECUTABLE xdg-desktop-menu)
if(XDG_DESKTOP_MENU_EXECUTABLE) if(XDG_DESKTOP_MENU_EXECUTABLE)
file(MAKE_DIRECTORY "/usr/share/desktop-directories") #Workaround for https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=730621
install(CODE "execute_process(COMMAND ${XDG_DESKTOP_MENU_EXECUTABLE} install --novendor share/juci.desktop)") install(CODE "execute_process(COMMAND ${XDG_DESKTOP_MENU_EXECUTABLE} install --novendor share/juci.desktop)")
endif() endif()

8
docs/install.md

@ -3,7 +3,7 @@
## Debian/Ubuntu 15 ## Debian/Ubuntu 15
Install dependencies: Install dependencies:
```sh ```sh
sudo apt-get install git cmake make g++ libclang-dev pkg-config libboost-system-dev libboost-thread-dev libboost-filesystem-dev libboost-log-dev libgtkmm-3.0-dev libgtksourceviewmm-3.0-dev aspell-en libaspell-dev sudo apt-get install git cmake make g++ libclang-dev pkg-config libboost-system-dev libboost-thread-dev libboost-filesystem-dev libboost-log-dev libboost-regex-dev libgtkmm-3.0-dev libgtksourceviewmm-3.0-dev aspell-en libaspell-dev
sudo apt-get install clang-format-3.6 || sudo apt-get install clang-format-3.5 sudo apt-get install clang-format-3.6 || sudo apt-get install clang-format-3.5
``` ```
@ -19,11 +19,7 @@ sudo make install
## Ubuntu 14/Linux Mint 17 ## Ubuntu 14/Linux Mint 17
Install dependencies: Install dependencies:
```sh ```sh
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get install git cmake make g++ libclang-3.6-dev clang-format-3.6 pkg-config libboost-system-dev libboost-thread-dev libboost-filesystem-dev libboost-log-dev libboost-regex-dev libgtkmm-3.0-dev libgtksourceviewmm-3.0-dev aspell-en libaspell-dev
sudo apt-get update
sudo apt-get install g++-4.9
sudo apt-get remove g++-4.8
sudo apt-get install git cmake make g++ libclang-3.6-dev clang-format-3.6 pkg-config libboost-system1.55-dev libboost-thread1.55-dev libboost-filesystem1.55-dev libboost-log1.55-dev libgtkmm-3.0-dev libgtksourceviewmm-3.0-dev aspell-en libaspell-dev
``` ```
Get juCi++ source, compile and install: Get juCi++ source, compile and install:

4
share/juci.desktop

@ -1,8 +1,10 @@
[Desktop Entry] [Desktop Entry]
Version=1.0
Name=juCi++ Name=juCi++
Comment=A lightweight IDE Comment=A lightweight IDE
Exec=juci %F Exec=juci %F
Terminal=false Terminal=false
Type=Application Type=Application
StartupNotify=true StartupNotify=true
MimeType=text/plain; MimeType=text/plain;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-cmake;
Categories=Utility;Development;TextEditor;

2
src/CMakeLists.txt

@ -32,7 +32,7 @@ find_package(LibClang REQUIRED)
#find_package(PythonLibs 2.7) #find_package(PythonLibs 2.7)
#find_package(Boost 1.55 COMPONENTS python thread log system filesystem REQUIRED) #find_package(Boost 1.55 COMPONENTS python thread log system filesystem REQUIRED)
find_package(Boost 1.55 COMPONENTS thread log system filesystem REQUIRED) find_package(Boost 1.54 COMPONENTS thread log system filesystem regex REQUIRED)
pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) # The name GTKMM is set here for the variables abouve pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) # The name GTKMM is set here for the variables abouve

20
src/cmake.cc

@ -1,7 +1,7 @@
#include "cmake.h" #include "cmake.h"
#include "singletons.h" #include "singletons.h"
#include "filesystem.h" #include "filesystem.h"
#include <regex> #include <boost/regex.hpp>
#include "dialogs.h" #include "dialogs.h"
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
@ -10,9 +10,9 @@ using namespace std; //TODO: remove
CMake::CMake(const boost::filesystem::path &path) { CMake::CMake(const boost::filesystem::path &path) {
const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) { const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) {
for(auto &line: filesystem::read_lines(cmake_path)) { for(auto &line: filesystem::read_lines(cmake_path)) {
const std::regex project_regex("^ *project *\\(.*$"); const boost::regex project_regex("^ *project *\\(.*$");
std::smatch sm; boost::smatch sm;
if(std::regex_match(line, sm, project_regex)) { if(boost::regex_match(line, sm, project_regex)) {
return true; return true;
} }
} }
@ -142,9 +142,9 @@ void CMake::find_variables() {
end_line=file.size(); end_line=file.size();
if(end_line>start_line) { if(end_line>start_line) {
auto line=file.substr(start_line, end_line-start_line); auto line=file.substr(start_line, end_line-start_line);
const std::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$"); const boost::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$");
std::smatch sm; boost::smatch sm;
if(std::regex_match(line, sm, set_regex)) { if(boost::regex_match(line, sm, set_regex)) {
auto data=sm[2].str(); auto data=sm[2].str();
while(data.size()>0 && data.back()==' ') while(data.size()>0 && data.back()==' ')
data.pop_back(); data.pop_back();
@ -264,9 +264,9 @@ std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > CMak
end_line=file.size(); end_line=file.size();
if(end_line>start_line) { if(end_line>start_line) {
auto line=file.substr(start_line, end_line-start_line); auto line=file.substr(start_line, end_line-start_line);
const std::regex function_regex("^ *"+name+" *\\( *(.*)\\) *$"); const boost::regex function_regex("^ *"+name+" *\\( *(.*)\\) *$");
std::smatch sm; boost::smatch sm;
if(std::regex_match(line, sm, function_regex)) { if(boost::regex_match(line, sm, function_regex)) {
auto data=sm[1].str(); auto data=sm[1].str();
while(data.size()>0 && data.back()==' ') while(data.size()>0 && data.back()==' ')
data.pop_back(); data.pop_back();

13
src/config.cc

@ -81,7 +81,6 @@ void Config::retrieve_config() {
menu.keys[i.first] = i.second.get_value<std::string>(); menu.keys[i.first] = i.second.get_value<std::string>();
} }
get_source(); get_source();
get_directory_filter();
window.theme_name=cfg.get<std::string>("gtk_theme.name"); window.theme_name=cfg.get<std::string>("gtk_theme.name");
window.theme_variant=cfg.get<std::string>("gtk_theme.variant"); window.theme_variant=cfg.get<std::string>("gtk_theme.variant");
@ -188,15 +187,3 @@ void Config::get_source() {
} }
} }
} }
void Config::get_directory_filter() {
boost::property_tree::ptree dir_json = cfg.get_child("directoryfilter");
boost::property_tree::ptree ignore_json = dir_json.get_child("ignore");
boost::property_tree::ptree except_json = dir_json.get_child("exceptions");
directories.exceptions.clear();
directories.ignored.clear();
for ( auto &i : except_json )
directories.exceptions.emplace_back(i.second.get_value<std::string>());
for ( auto &i : ignore_json )
directories.ignored.emplace_back(i.second.get_value<std::string>());
}

8
src/config.h

@ -31,12 +31,6 @@ public:
int history_size; int history_size;
}; };
class Directories {
public:
std::vector<std::string> ignored;
std::vector<std::string> exceptions;
};
class Source { class Source {
public: public:
class DocumentationSearch { class DocumentationSearch {
@ -72,7 +66,6 @@ public:
Menu menu; Menu menu;
Window window; Window window;
Terminal terminal; Terminal terminal;
Directories directories;
Source source; Source source;
const boost::filesystem::path& juci_home_path() const { return home; } const boost::filesystem::path& juci_home_path() const { return home; }
@ -83,7 +76,6 @@ private:
bool check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path=""); bool check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path="");
void update_config_file(); void update_config_file();
void get_source(); void get_source();
void get_directory_filter();
boost::property_tree::ptree cfg; boost::property_tree::ptree cfg;
boost::filesystem::path home; boost::filesystem::path home;

19
src/directories.cc

@ -197,21 +197,6 @@ void Directories::select(const boost::filesystem::path &path) {
JDEBUG("end"); JDEBUG("end");
} }
bool Directories::ignored(std::string path) {
std::transform(path.begin(), path.end(), path.begin(), ::tolower);
for(std::string &i : Singleton::config->directories.exceptions) {
if(i == path)
return false;
}
for(auto &i : Singleton::config->directories.ignored) {
if(path.find(i, 0) != std::string::npos)
return true;
}
return false;
}
void Directories::add_path(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &parent) { void Directories::add_path(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &parent) {
last_write_times[dir_path.string()]={parent, boost::filesystem::last_write_time(dir_path)}; last_write_times[dir_path.string()]={parent, boost::filesystem::last_write_time(dir_path)};
std::unique_ptr<Gtk::TreeNodeChildren> children; //Gtk::TreeNodeChildren is missing default constructor... std::unique_ptr<Gtk::TreeNodeChildren> children; //Gtk::TreeNodeChildren is missing default constructor...
@ -227,7 +212,6 @@ void Directories::add_path(const boost::filesystem::path& dir_path, const Gtk::T
boost::filesystem::directory_iterator end_it; boost::filesystem::directory_iterator end_it;
for(boost::filesystem::directory_iterator it(dir_path);it!=end_it;it++) { for(boost::filesystem::directory_iterator it(dir_path);it!=end_it;it++) {
auto filename=it->path().filename().string(); auto filename=it->path().filename().string();
if (!ignored(filename)) {
bool already_added=false; bool already_added=false;
if(*children) { if(*children) {
for(auto &child: *children) { for(auto &child: *children) {
@ -243,7 +227,7 @@ void Directories::add_path(const boost::filesystem::path& dir_path, const Gtk::T
not_deleted.emplace(filename); not_deleted.emplace(filename);
child->set_value(column_record.name, filename); child->set_value(column_record.name, filename);
child->set_value(column_record.path, it->path().string()); child->set_value(column_record.path, it->path().string());
if (boost::filesystem::is_directory(*it)) { if (boost::filesystem::is_directory(it->path())) {
child->set_value(column_record.id, "a"+filename); child->set_value(column_record.id, "a"+filename);
auto grandchild=tree_store->append(child->children()); auto grandchild=tree_store->append(child->children());
grandchild->set_value(column_record.name, std::string("(empty)")); grandchild->set_value(column_record.name, std::string("(empty)"));
@ -263,7 +247,6 @@ void Directories::add_path(const boost::filesystem::path& dir_path, const Gtk::T
} }
} }
} }
}
if(*children) { if(*children) {
for(auto it=children->begin();it!=children->end();) { for(auto it=children->begin();it!=children->end();) {
if(not_deleted.count(it->get_value(column_record.name))==0) { if(not_deleted.count(it->get_value(column_record.name))==0) {

1
src/directories.h

@ -38,7 +38,6 @@ public:
private: private:
void add_path(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &row); void add_path(const boost::filesystem::path& dir_path, const Gtk::TreeModel::Row &row);
bool ignored(std::string path);
Gtk::TreeView tree_view; Gtk::TreeView tree_view;
Glib::RefPtr<Gtk::TreeStore> tree_store; Glib::RefPtr<Gtk::TreeStore> tree_store;
ColumnRecord column_record; ColumnRecord column_record;

9
src/files.h

@ -1,6 +1,6 @@
#include <string> #include <string>
#define JUCI_VERSION "0.9.5" #define JUCI_VERSION "0.9.6"
const std::string configjson = const std::string configjson =
"{\n" "{\n"
@ -85,6 +85,7 @@ const std::string configjson =
" \"source_center_cursor\": \"<primary>l\",\n" " \"source_center_cursor\": \"<primary>l\",\n"
" \"source_find_documentation\": \"<primary><shift>d\",\n" " \"source_find_documentation\": \"<primary><shift>d\",\n"
" \"source_goto_declaration\": \"<primary>d\",\n" " \"source_goto_declaration\": \"<primary>d\",\n"
" \"source_goto_usage\": \"<primary>u\",\n"
" \"source_goto_method\": \"<primary>m\",\n" " \"source_goto_method\": \"<primary>m\",\n"
" \"source_rename\": \"<primary>r\",\n" " \"source_rename\": \"<primary>r\",\n"
" \"source_goto_next_diagnostic\": \"<primary>e\",\n" " \"source_goto_next_diagnostic\": \"<primary>e\",\n"
@ -117,12 +118,6 @@ const std::string configjson =
" \"@any\": \"https://www.google.com/search?btnI&q=\"\n" " \"@any\": \"https://www.google.com/search?btnI&q=\"\n"
" }\n" " }\n"
" }\n" " }\n"
" },\n"
" \"directoryfilter\": {\n"
" \"ignore\": [\n"
" ],\n"
" \"exceptions\": [\n"
" ]\n"
" }\n" " }\n"
"}\n"; "}\n";

5
src/menu.cc

@ -211,6 +211,11 @@ void Menu::init() {
+accels["source_goto_declaration"]+ //For Ubuntu... +accels["source_goto_declaration"]+ //For Ubuntu...
" </item>" " </item>"
" <item>" " <item>"
" <attribute name='label' translatable='yes'>_Go to Usage</attribute>"
" <attribute name='action'>app.source_goto_usage</attribute>"
+accels["source_goto_usage"]+ //For Ubuntu...
" </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Go to Method</attribute>" " <attribute name='label' translatable='yes'>_Go to Method</attribute>"
" <attribute name='action'>app.source_goto_method</attribute>" " <attribute name='action'>app.source_goto_method</attribute>"
+accels["source_goto_method"]+ //For Ubuntu... +accels["source_goto_method"]+ //For Ubuntu...

15
src/source.h

@ -16,14 +16,15 @@ namespace Source {
class Token { class Token {
public: public:
Token(): type(-1) {} Token(): type(-1) {}
Token(int type, const std::string &spelling, const std::string &usr): Token(Glib::RefPtr<Gsv::Language> language, int type, const std::string &spelling, const std::string &usr):
type(type), spelling(spelling), usr(usr) {} language(language), type(type), spelling(spelling), usr(usr) {}
operator bool() const {return (type>=0 && spelling.size()>0 && usr.size()>0);} operator bool() const {return (type>=0 && spelling.size()>0 && usr.size()>0);}
bool operator==(const Token &o) const {return (type==o.type && bool operator==(const Token &o) const {return (type==o.type &&
spelling==o.spelling && spelling==o.spelling &&
usr==o.usr);} usr==o.usr);}
bool operator!=(const Token &o) const {return !(*this==o);} bool operator!=(const Token &o) const {return !(*this==o);}
Glib::RefPtr<Gsv::Language> language;
int type; int type;
std::string spelling; std::string spelling;
std::string usr; std::string usr;
@ -32,11 +33,12 @@ namespace Source {
class Offset { class Offset {
public: public:
Offset() {} Offset() {}
Offset(unsigned line, unsigned index): line(line), index(index) {} Offset(unsigned line, unsigned index, const boost::filesystem::path &file_path=""): line(line), index(index), file_path(file_path) {}
bool operator==(const Offset &o) {return (line==o.line && index==o.index);} bool operator==(const Offset &o) {return (line==o.line && index==o.index);}
unsigned line; unsigned line;
unsigned index; unsigned index;
boost::filesystem::path file_path;
}; };
class FixIt { class FixIt {
@ -74,7 +76,8 @@ namespace Source {
Glib::RefPtr<Gsv::Language> language; Glib::RefPtr<Gsv::Language> language;
std::function<void()> auto_indent; std::function<void()> auto_indent;
std::function<std::pair<std::string, Offset>()> get_declaration_location; std::function<Offset()> get_declaration_location;
std::function<std::vector<std::pair<Offset, std::string> >(const Token &token)> get_usages;
std::function<void()> goto_method; std::function<void()> goto_method;
std::function<Token()> get_token; std::function<Token()> get_token;
std::function<std::vector<std::string>()> get_token_data; std::function<std::vector<std::string>()> get_token_data;
@ -82,6 +85,9 @@ namespace Source {
std::function<void()> goto_next_diagnostic; std::function<void()> goto_next_diagnostic;
std::function<void()> apply_fix_its; std::function<void()> apply_fix_its;
std::unique_ptr<SelectionDialog> selection_dialog;
sigc::connection delayed_tooltips_connection;
std::function<void(View* view, const std::string &status)> on_update_status; std::function<void(View* view, const std::string &status)> on_update_status;
std::function<void(View* view, const std::string &info)> on_update_info; std::function<void(View* view, const std::string &info)> on_update_info;
void set_status(const std::string &status); void set_status(const std::string &status);
@ -103,7 +109,6 @@ namespace Source {
virtual void show_type_tooltips(const Gdk::Rectangle &rectangle) {} virtual void show_type_tooltips(const Gdk::Rectangle &rectangle) {}
gdouble on_motion_last_x; gdouble on_motion_last_x;
gdouble on_motion_last_y; gdouble on_motion_last_y;
sigc::connection delayed_tooltips_connection;
void set_tooltip_events(); void set_tooltip_events();
std::string get_line(const Gtk::TextIter &iter); std::string get_line(const Gtk::TextIter &iter);

71
src/source_clang.cc

@ -100,9 +100,9 @@ void Source::ClangViewParse::configure() {
} }
} }
bracket_regex=std::regex("^([ \\t]*).*\\{ *$"); bracket_regex=boost::regex("^([ \\t]*).*\\{ *$");
no_bracket_statement_regex=std::regex("^([ \\t]*)(if|for|else if|catch|while) *\\(.*[^;}] *$"); no_bracket_statement_regex=boost::regex("^([ \\t]*)(if|for|else if|catch|while) *\\(.*[^;}] *$");
no_bracket_no_para_statement_regex=std::regex("^([ \\t]*)(else|try|do) *$"); no_bracket_no_para_statement_regex=boost::regex("^([ \\t]*)(else|try|do) *$");
} }
void Source::ClangViewParse::init_parse() { void Source::ClangViewParse::init_parse() {
@ -194,9 +194,9 @@ std::vector<std::string> Source::ClangViewParse::get_compilation_commands() {
} }
} }
auto clang_version_string=clang::to_string(clang_getClangVersion()); auto clang_version_string=clang::to_string(clang_getClangVersion());
const std::regex clang_version_regex("^[A-Za-z ]+([0-9.]+).*$"); const boost::regex clang_version_regex("^[A-Za-z ]+([0-9.]+).*$");
std::smatch sm; boost::smatch sm;
if(std::regex_match(clang_version_string, sm, clang_version_regex)) { if(boost::regex_match(clang_version_string, sm, clang_version_regex)) {
auto clang_version=sm[1].str(); auto clang_version=sm[1].str();
arguments.emplace_back("-I/usr/lib/clang/"+clang_version+"/include"); arguments.emplace_back("-I/usr/lib/clang/"+clang_version+"/include");
arguments.emplace_back("-I/usr/local/Cellar/llvm/"+clang_version+"/lib/clang/"+clang_version+"/include"); arguments.emplace_back("-I/usr/local/Cellar/llvm/"+clang_version+"/lib/clang/"+clang_version+"/include");
@ -464,7 +464,7 @@ bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
auto start_sentence_tabs_end_iter=get_tabs_end_iter(start_of_sentence_iter); auto start_sentence_tabs_end_iter=get_tabs_end_iter(start_of_sentence_iter);
auto tabs=get_line_before(start_sentence_tabs_end_iter); auto tabs=get_line_before(start_sentence_tabs_end_iter);
std::smatch sm; boost::smatch sm;
if(iter.backward_char() && *iter=='{') { if(iter.backward_char() && *iter=='{') {
auto found_iter=iter; auto found_iter=iter;
bool found_right_bracket=find_right_bracket_forward(iter, found_iter); bool found_right_bracket=find_right_bracket_forward(iter, found_iter);
@ -516,13 +516,13 @@ bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
iter.forward_char(); iter.forward_char();
} }
} }
else if(std::regex_match(line, sm, no_bracket_statement_regex)) { else if(boost::regex_match(line, sm, no_bracket_statement_regex)) {
get_source_buffer()->insert_at_cursor("\n"+tabs+tab); get_source_buffer()->insert_at_cursor("\n"+tabs+tab);
scroll_to(get_source_buffer()->get_insert()); scroll_to(get_source_buffer()->get_insert());
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
return true; return true;
} }
else if(std::regex_match(line, sm, no_bracket_no_para_statement_regex)) { else if(boost::regex_match(line, sm, no_bracket_no_para_statement_regex)) {
get_source_buffer()->insert_at_cursor("\n"+tabs+tab); get_source_buffer()->insert_at_cursor("\n"+tabs+tab);
scroll_to(get_source_buffer()->get_insert()); scroll_to(get_source_buffer()->get_insert());
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
@ -530,18 +530,18 @@ bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
} }
//Indenting after for instance if(...)\n...;\n //Indenting after for instance if(...)\n...;\n
else if(iter.backward_char() && *iter==';') { else if(iter.backward_char() && *iter==';') {
std::smatch sm2; boost::smatch sm2;
size_t line_nr=get_source_buffer()->get_insert()->get_iter().get_line(); size_t line_nr=get_source_buffer()->get_insert()->get_iter().get_line();
if(line_nr>0 && tabs.size()>=tab_size) { if(line_nr>0 && tabs.size()>=tab_size) {
std::string previous_line=get_line(line_nr-1); std::string previous_line=get_line(line_nr-1);
if(!std::regex_match(previous_line, sm2, bracket_regex)) { if(!boost::regex_match(previous_line, sm2, bracket_regex)) {
if(std::regex_match(previous_line, sm2, no_bracket_statement_regex)) { if(boost::regex_match(previous_line, sm2, no_bracket_statement_regex)) {
get_source_buffer()->insert_at_cursor("\n"+sm2[1].str()); get_source_buffer()->insert_at_cursor("\n"+sm2[1].str());
scroll_to(get_source_buffer()->get_insert()); scroll_to(get_source_buffer()->get_insert());
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
return true; return true;
} }
else if(std::regex_match(previous_line, sm2, no_bracket_no_para_statement_regex)) { else if(boost::regex_match(previous_line, sm2, no_bracket_no_para_statement_regex)) {
get_source_buffer()->insert_at_cursor("\n"+sm2[1].str()); get_source_buffer()->insert_at_cursor("\n"+sm2[1].str());
scroll_to(get_source_buffer()->get_insert()); scroll_to(get_source_buffer()->get_insert());
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
@ -558,7 +558,7 @@ bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
left_bracket_iter.forward_char(); left_bracket_iter.forward_char();
Gtk::TextIter start_of_left_bracket_sentence_iter; Gtk::TextIter start_of_left_bracket_sentence_iter;
if(find_start_of_closed_expression(left_bracket_iter, start_of_left_bracket_sentence_iter)) { if(find_start_of_closed_expression(left_bracket_iter, start_of_left_bracket_sentence_iter)) {
std::smatch sm; boost::smatch sm;
auto tabs_end_iter=get_tabs_end_iter(start_of_left_bracket_sentence_iter); auto tabs_end_iter=get_tabs_end_iter(start_of_left_bracket_sentence_iter);
auto tabs_start_of_sentence=get_line_before(tabs_end_iter); auto tabs_start_of_sentence=get_line_before(tabs_end_iter);
if(tabs.size()==(tabs_start_of_sentence.size()+tab_size)) { if(tabs.size()==(tabs_start_of_sentence.size()+tab_size)) {
@ -689,10 +689,10 @@ void Source::ClangViewAutocomplete::start_autocomplete() {
} }
std::string line=" "+get_line_before(); std::string line=" "+get_line_before();
if((std::count(line.begin(), line.end(), '\"')%2)!=1 && line.find("//")==std::string::npos) { if((std::count(line.begin(), line.end(), '\"')%2)!=1 && line.find("//")==std::string::npos) {
const std::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)\\]\\>])(->|\\.|::)([a-zA-Z0-9_]*)$"); const boost::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)\\]\\>])(->|\\.|::)([a-zA-Z0-9_]*)$");
const std::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$"); const boost::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$");
std::smatch sm; boost::smatch sm;
if(std::regex_match(line, sm, in_specified_namespace)) { if(boost::regex_match(line, sm, in_specified_namespace)) {
prefix_mutex.lock(); prefix_mutex.lock();
prefix=sm[3].str(); prefix=sm[3].str();
prefix_mutex.unlock(); prefix_mutex.unlock();
@ -702,7 +702,7 @@ void Source::ClangViewAutocomplete::start_autocomplete() {
else if(last_keyval=='.' && autocomplete_starting) else if(last_keyval=='.' && autocomplete_starting)
autocomplete_cancel_starting=true; autocomplete_cancel_starting=true;
} }
else if(std::regex_match(line, sm, within_namespace)) { else if(boost::regex_match(line, sm, within_namespace)) {
prefix_mutex.lock(); prefix_mutex.lock();
prefix=sm[3].str(); prefix=sm[3].str();
prefix_mutex.unlock(); prefix_mutex.unlock();
@ -984,7 +984,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
continue; continue;
auto referenced=cursor.get_referenced(); auto referenced=cursor.get_referenced();
if(referenced) if(referenced)
return Token(static_cast<int>(referenced.get_kind()), token.get_spelling(), referenced.get_usr()); return Token(this->language, static_cast<int>(referenced.get_kind()), token.get_spelling(), referenced.get_usr());
} }
} }
} }
@ -994,7 +994,8 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
rename_similar_tokens=[this](const Token &token, const std::string &text) { rename_similar_tokens=[this](const Token &token, const std::string &text) {
size_t number=0; size_t number=0;
if(source_readable) { if(source_readable && token.language &&
(token.language->get_id()=="chdr" || token.language->get_id()=="cpphdr" || token.language->get_id()=="c" || token.language->get_id()=="cpp" || token.language->get_id()=="objc")) {
auto offsets=clang_tokens->get_similar_token_offsets(static_cast<clang::CursorKind>(token.type), token.spelling, token.usr); auto offsets=clang_tokens->get_similar_token_offsets(static_cast<clang::CursorKind>(token.type), token.spelling, token.usr);
std::vector<std::pair<Glib::RefPtr<Gtk::TextMark>, Glib::RefPtr<Gtk::TextMark> > > marks; std::vector<std::pair<Glib::RefPtr<Gtk::TextMark>, Glib::RefPtr<Gtk::TextMark> > > marks;
for(auto &offset: offsets) { for(auto &offset: offsets) {
@ -1027,7 +1028,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
}); });
get_declaration_location=[this](){ get_declaration_location=[this](){
std::pair<std::string, Offset> location; Offset location;
if(source_readable) { if(source_readable) {
auto iter=get_buffer()->get_insert()->get_iter(); auto iter=get_buffer()->get_insert()->get_iter();
auto line=(unsigned)iter.get_line(); auto line=(unsigned)iter.get_line();
@ -1038,10 +1039,10 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) { if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) {
auto referenced=cursor.get_referenced(); auto referenced=cursor.get_referenced();
if(referenced) { if(referenced) {
location.first=referenced.get_source_location().get_path(); location.file_path=referenced.get_source_location().get_path();
auto clang_offset=referenced.get_source_location().get_offset(); auto clang_offset=referenced.get_source_location().get_offset();
location.second.line=clang_offset.line; location.line=clang_offset.line;
location.second.index=clang_offset.index; location.index=clang_offset.index;
break; break;
} }
} }
@ -1051,6 +1052,26 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
return location; return location;
}; };
get_usages=[this](const Token &token) {
std::vector<std::pair<Offset, std::string> > usages;
if(source_readable && token.language &&
(token.language->get_id()=="chdr" || token.language->get_id()=="cpphdr" || token.language->get_id()=="c" || token.language->get_id()=="cpp" || token.language->get_id()=="objc")) {
auto offsets=clang_tokens->get_similar_token_offsets(static_cast<clang::CursorKind>(token.type), token.spelling, token.usr);
for(auto &offset: offsets) {
auto start_iter=get_buffer()->get_iter_at_line(offset.first.line-1);
while(!start_iter.ends_line() && (*start_iter==' ' || *start_iter=='\t'))
start_iter.forward_char();
auto end_iter=start_iter;
while(!end_iter.ends_line())
end_iter.forward_char();
usages.emplace_back(Offset(offset.first.line-1, offset.first.index-1, this->file_path), get_buffer()->get_text(start_iter, end_iter));
}
}
return usages;
};
goto_method=[this](){ goto_method=[this](){
if(source_readable) { if(source_readable) {
auto iter=get_buffer()->get_insert()->get_iter(); auto iter=get_buffer()->get_insert()->get_iter();

9
src/source_clang.h

@ -5,7 +5,7 @@
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
#include <set> #include <set>
#include <regex> #include <boost/regex.hpp>
#include "clangmm.h" #include "clangmm.h"
#include "source.h" #include "source.h"
#include "terminal.h" #include "terminal.h"
@ -42,9 +42,9 @@ namespace Source {
virtual void show_diagnostic_tooltips(const Gdk::Rectangle &rectangle); virtual void show_diagnostic_tooltips(const Gdk::Rectangle &rectangle);
virtual void show_type_tooltips(const Gdk::Rectangle &rectangle); virtual void show_type_tooltips(const Gdk::Rectangle &rectangle);
std::regex bracket_regex; boost::regex bracket_regex;
std::regex no_bracket_statement_regex; boost::regex no_bracket_statement_regex;
std::regex no_bracket_no_para_statement_regex; boost::regex no_bracket_no_para_statement_regex;
std::set<int> diagnostic_offsets; std::set<int> diagnostic_offsets;
std::vector<FixIt> fix_its; std::vector<FixIt> fix_its;
@ -121,7 +121,6 @@ namespace Source {
void tag_similar_tokens(const Token &token); void tag_similar_tokens(const Token &token);
Glib::RefPtr<Gtk::TextTag> similar_tokens_tag; Glib::RefPtr<Gtk::TextTag> similar_tokens_tag;
Token last_tagged_token; Token last_tagged_token;
std::unique_ptr<SelectionDialog> selection_dialog;
bool renaming=false; bool renaming=false;
}; };

79
src/window.cc

@ -382,10 +382,15 @@ void Window::set_menu_actions() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->get_declaration_location) { if(notebook.get_current_view()->get_declaration_location) {
auto location=notebook.get_current_view()->get_declaration_location(); auto location=notebook.get_current_view()->get_declaration_location();
if(location.first.size()>0) { if(!location.file_path.empty()) {
notebook.open(location.first); boost::filesystem::path declaration_file;
auto line=static_cast<int>(location.second.line)-1; boost::system::error_code ec;
auto index=static_cast<int>(location.second.index)-1; declaration_file=boost::filesystem::canonical(location.file_path, ec);
if(ec)
declaration_file=location.file_path;
notebook.open(declaration_file);
auto line=static_cast<int>(location.line)-1;
auto index=static_cast<int>(location.index)-1;
auto buffer=notebook.get_current_view()->get_buffer(); auto buffer=notebook.get_current_view()->get_buffer();
line=std::min(line, buffer->get_line_count()-1); line=std::min(line, buffer->get_line_count()-1);
if(line>=0) { if(line>=0) {
@ -405,6 +410,71 @@ void Window::set_menu_actions() {
} }
} }
}); });
menu->add_action("source_goto_usage", [this]() {
if(notebook.get_current_page()!=-1) {
auto current_view=notebook.get_current_view();
if(current_view->get_token && current_view->get_usages) {
auto token=current_view->get_token();
if(token) {
auto iter=current_view->get_buffer()->get_insert()->get_iter();
Gdk::Rectangle visible_rect;
current_view->get_visible_rect(visible_rect);
Gdk::Rectangle iter_rect;
current_view->get_iter_location(iter, iter_rect);
iter_rect.set_width(1);
if(!visible_rect.intersects(iter_rect)) {
current_view->get_iter_at_location(iter, 0, visible_rect.get_y()+visible_rect.get_height()/3);
}
current_view->selection_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*current_view, current_view->get_buffer()->create_mark(iter)));
auto rows=std::make_shared<std::unordered_map<std::string, Source::Offset> >();
//First add usages in current file
auto usages=current_view->get_usages(token);
for(auto &usage: usages) {
auto iter=current_view->get_buffer()->get_iter_at_line_index(usage.first.line, usage.first.index);
auto row=std::to_string(iter.get_line()+1)+':'+std::to_string(iter.get_line_offset()+1)+' '+usage.second;
(*rows)[row]=usage.first;
current_view->selection_dialog->add_row(row);
}
//Then the remaining opened files
for(int page=0;page<notebook.size();page++) {
auto view=notebook.get_view(page);
if(view!=current_view) {
if(view->get_usages) {
auto usages=view->get_usages(token);
for(auto &usage: usages) {
auto iter=view->get_buffer()->get_iter_at_line_index(usage.first.line, usage.first.index);
auto row=usage.first.file_path.filename().string()+":"+std::to_string(iter.get_line()+1)+':'+std::to_string(iter.get_line_offset()+1)+' '+usage.second;
(*rows)[row]=usage.first;
current_view->selection_dialog->add_row(row);
}
}
}
}
if(rows->size()==0)
return;
current_view->selection_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) {
auto offset=rows->at(selected);
boost::filesystem::path declaration_file;
boost::system::error_code ec;
declaration_file=boost::filesystem::canonical(offset.file_path, ec);
if(ec)
declaration_file=offset.file_path;
notebook.open(declaration_file);
auto view=notebook.get_current_view();
view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(offset.line, offset.index));
while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false);
if(notebook.get_current_page()!=-1)
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
view->delayed_tooltips_connection.disconnect();
};
current_view->selection_dialog->show();
}
}
}
});
menu->add_action("source_goto_method", [this]() { menu->add_action("source_goto_method", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->goto_method) { if(notebook.get_current_view()->goto_method) {
@ -567,6 +637,7 @@ void Window::activate_menu_items(bool activate) {
menu->actions["source_indentation_auto_indent_buffer"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->auto_indent) : false); menu->actions["source_indentation_auto_indent_buffer"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->auto_indent) : false);
menu->actions["source_find_documentation"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_token_data) : false); menu->actions["source_find_documentation"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_token_data) : false);
menu->actions["source_goto_declaration"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_declaration_location) : false); menu->actions["source_goto_declaration"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_declaration_location) : false);
menu->actions["source_goto_usage"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_usages) : false);
menu->actions["source_goto_method"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_method) : false); menu->actions["source_goto_method"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_method) : false);
menu->actions["source_rename"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->rename_similar_tokens) : false); menu->actions["source_rename"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->rename_similar_tokens) : false);
menu->actions["source_goto_next_diagnostic"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_next_diagnostic) : false); menu->actions["source_goto_next_diagnostic"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_next_diagnostic) : false);

Loading…
Cancel
Save