From 0e636ad5d51cc475567f9af823358dea49313f44 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 23 May 2016 13:53:36 +0200 Subject: [PATCH 01/18] Added source_test testing Source::View::cleanup_whitespace_characters. Removed the now reduntant example_test, and moved comment to source_test. --- src/source.cc | 52 ++++++++++---------- src/source.h | 1 + tests/CMakeLists.txt | 26 +++++----- tests/{cmake_test.cc => cmake_build_test.cc} | 2 +- tests/example_test.cc | 16 ------ tests/source_test.cc | 43 ++++++++++++++++ tests/stubs/selectiondialog.cc | 20 ++++++++ tests/stubs/terminal.cc | 4 ++ tests/stubs/tooltips.cc | 7 +++ 9 files changed, 117 insertions(+), 54 deletions(-) rename tests/{cmake_test.cc => cmake_build_test.cc} (93%) delete mode 100644 tests/example_test.cc create mode 100644 tests/source_test.cc create mode 100644 tests/stubs/selectiondialog.cc create mode 100644 tests/stubs/tooltips.cc diff --git a/src/source.cc b/src/source.cc index 69e90f8..dd05d36 100644 --- a/src/source.cc +++ b/src/source.cc @@ -371,6 +371,31 @@ void Source::View::set_tab_char_and_size(char tab_char, unsigned tab_size) { tab+=tab_char; } +void Source::View::cleanup_whitespace_characters() { + auto buffer=get_buffer(); + buffer->begin_user_action(); + for(int line=0;lineget_line_count();line++) { + auto iter=buffer->get_iter_at_line(line); + auto end_iter=iter; + while(!end_iter.ends_line()) + end_iter.forward_char(); + if(iter==end_iter) + continue; + iter=end_iter; + while(!iter.starts_line() && (*iter==' ' || *iter=='\t' || iter.ends_line())) + iter.backward_char(); + if(*iter!=' ' && *iter!='\t') + iter.forward_char(); + if(iter==end_iter) + continue; + buffer->erase(iter, end_iter); + } + auto iter=buffer->end(); + if(!iter.starts_line()) + buffer->insert(buffer->end(), "\n"); + buffer->end_user_action(); +} + Gsv::DrawSpacesFlags Source::View::parse_show_whitespace_characters(const std::string &text) { namespace qi = boost::spirit::qi; @@ -398,31 +423,8 @@ Gsv::DrawSpacesFlags Source::View::parse_show_whitespace_characters(const std::s bool Source::View::save(const std::vector &views) { if(file_path.empty() || !get_buffer()->get_modified()) return false; - //Remove trailing whitespace characters on save, and add trailing newline if missing - if(Config::get().source.cleanup_whitespace_characters) { - auto buffer=get_buffer(); - buffer->begin_user_action(); - for(int line=0;lineget_line_count();line++) { - auto iter=buffer->get_iter_at_line(line); - auto end_iter=iter; - while(!end_iter.ends_line()) - end_iter.forward_char(); - if(iter==end_iter) - continue; - iter=end_iter; - while(!iter.starts_line() && (*iter==' ' || *iter=='\t' || iter.ends_line())) - iter.backward_char(); - if(*iter!=' ' && *iter!='\t') - iter.forward_char(); - if(iter==end_iter) - continue; - buffer->erase(iter, end_iter); - } - auto iter=buffer->end(); - if(!iter.starts_line()) - buffer->insert(buffer->end(), "\n"); - buffer->end_user_action(); - } + if(Config::get().source.cleanup_whitespace_characters) + cleanup_whitespace_characters(); if(filesystem::write(file_path, get_buffer())) { last_read_time=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); diff --git a/src/source.h b/src/source.h index f7ad28d..ffdade5 100644 --- a/src/source.h +++ b/src/source.h @@ -161,6 +161,7 @@ namespace Source { guint previous_non_modifier_keyval=0; guint last_keyval=0; private: + void cleanup_whitespace_characters(); Gsv::DrawSpacesFlags parse_show_whitespace_characters(const std::string &text); GtkSourceSearchContext *search_context; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f9fc5d5..fee7b5b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ add_definitions(-DBOOST_LOG_DYN_LINK) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-access-control -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") @@ -12,6 +12,7 @@ if(APPLE) endif() find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) +find_package(ASPELL REQUIRED) set(LIBCLANGMM_INCLUDE_DIR ../libclangmm/src) include(FindPkgConfig) @@ -21,6 +22,7 @@ set(global_includes ${Boost_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} ${GTKSVMM_INCLUDE_DIRS} + ${ASPELL_INCLUDE_DIR} ../src ../tiny-process-library ) @@ -29,6 +31,7 @@ set(global_libraries ${GTKMM_LIBRARIES} ${GTKSVMM_LIBRARIES} ${Boost_LIBRARIES} + ${ASPELL_LIBRARIES} ) set(stub_sources @@ -36,22 +39,21 @@ set(stub_sources stubs/dialogs.cc stubs/dispatcher.cc stubs/info.cc + stubs/selectiondialog.cc stubs/terminal.cc + stubs/tooltips.cc ) include_directories(${global_includes}) add_library(stubs_library ${stub_sources}) -add_executable(cmake_test cmake_test.cc +add_executable(cmake_build_test cmake_build_test.cc ../src/filesystem.cc ../src/cmake.cc ../src/project_build.cc) -target_link_libraries(cmake_test ${global_libraries} stubs_library) -add_test(cmake_test cmake_test) - -#Added for example only, and requires display server to work -#However, it is possible to use the Broadway backend if the test is run in a pure terminal environment: -#broadwayd& -#make test -add_executable(example_test example_test.cc) -target_link_libraries(example_test ${global_libraries} stubs_library) -add_test(example_test example_test) +target_link_libraries(cmake_build_test ${global_libraries} stubs_library) +add_test(cmake_build_test cmake_build_test) + +add_executable(source_test source_test.cc + ../src/source.cc) +target_link_libraries(source_test ${global_libraries} stubs_library) +add_test(source_test source_test) diff --git a/tests/cmake_test.cc b/tests/cmake_build_test.cc similarity index 93% rename from tests/cmake_test.cc rename to tests/cmake_build_test.cc index b6786b5..a9a3ab8 100644 --- a/tests/cmake_test.cc +++ b/tests/cmake_build_test.cc @@ -15,7 +15,7 @@ int main() { auto functions_parameters=cmake.get_functions_parameters("project"); g_assert(functions_parameters.at(0).second.at(0)=="juci"); - g_assert(cmake.get_executable(tests_path/"cmake_test.cc").filename()=="cmake_test"); + g_assert(cmake.get_executable(tests_path/"cmake_build_test.cc").filename()=="cmake_build_test"); auto build=Project::Build::create(tests_path); g_assert(dynamic_cast(build.get())); diff --git a/tests/example_test.cc b/tests/example_test.cc deleted file mode 100644 index 2f50b4c..0000000 --- a/tests/example_test.cc +++ /dev/null @@ -1,16 +0,0 @@ -#include "terminal.h" -#include "info.h" -#include - -//In case one has to test functions that include Terminal::print or Info::print -//Requires display server to work -//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment: -//broadwayd& -//make test - -int main() { - auto app=Gtk::Application::create(); - Terminal::get().print("some message"); - Info::get().print("some message"); - g_assert(true); -} diff --git a/tests/source_test.cc b/tests/source_test.cc new file mode 100644 index 0000000..237b2d5 --- /dev/null +++ b/tests/source_test.cc @@ -0,0 +1,43 @@ +#include +#include "source.h" +#include "filesystem.h" + +int filesystem::read(const std::string &path, Glib::RefPtr text_buffer) { + return 0; +} + +int filesystem::read_non_utf8(const std::string &path, Glib::RefPtr text_buffer) { + return 0; +} + +bool filesystem::write(const std::string &path, Glib::RefPtr text_buffer) { + return false; +} + +std::string hello_world=R"(#include + +int main() { + std::cout << "hello world\n"; +})"; + +std::string hello_world_cleaned=R"(#include + +int main() { + std::cout << "hello world\n"; +} +)"; + +//Requires display server to work +//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment: +//broadwayd& +//make test + +int main() { + auto app=Gtk::Application::create(); + Gsv::init(); + + Source::View source_view("", Glib::RefPtr()); + source_view.get_buffer()->set_text(hello_world); + source_view.cleanup_whitespace_characters(); + g_assert(source_view.get_buffer()->get_text()==hello_world_cleaned); +} diff --git a/tests/stubs/selectiondialog.cc b/tests/stubs/selectiondialog.cc new file mode 100644 index 0000000..2b14137 --- /dev/null +++ b/tests/stubs/selectiondialog.cc @@ -0,0 +1,20 @@ +#include "selectiondialog.h" + +ListViewText::ListViewText(bool use_markup) {} + +SelectionDialogBase::SelectionDialogBase(Gtk::TextView& text_view, Glib::RefPtr start_mark, bool show_search_entry, bool use_markup): + text_view(text_view), list_view_text(use_markup) {} + +void SelectionDialogBase::show() {} + +void SelectionDialogBase::hide() {} + +void SelectionDialogBase::add_row(const std::string& row) {} + +SelectionDialog::SelectionDialog(Gtk::TextView& text_view, Glib::RefPtr start_mark, bool show_search_entry, bool use_markup) : + SelectionDialogBase(text_view, start_mark, show_search_entry, use_markup) {} + +SelectionDialogBase::~SelectionDialogBase() {} + +bool SelectionDialog::on_key_press(GdkEventKey* key) { return true; } +bool CompletionDialog::on_key_press(GdkEventKey* key) { return true;} diff --git a/tests/stubs/terminal.cc b/tests/stubs/terminal.cc index f96f60a..0eb09ef 100644 --- a/tests/stubs/terminal.cc +++ b/tests/stubs/terminal.cc @@ -10,6 +10,10 @@ int Terminal::process(const std::string &command, const boost::filesystem::path return 0; } +int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, const std::string &command, const boost::filesystem::path &path) { + return 0; +} + size_t Terminal::print(const std::string &message, bool bold) { return 0; } diff --git a/tests/stubs/tooltips.cc b/tests/stubs/tooltips.cc new file mode 100644 index 0000000..a7d73d9 --- /dev/null +++ b/tests/stubs/tooltips.cc @@ -0,0 +1,7 @@ +#include "tooltips.h" + +Tooltip::~Tooltip() {} + +Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle(); + +void Tooltips::hide() {} From 3ed4a2d3ae320cac281e40f97fd2386f96646889 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 23 May 2016 16:34:03 +0200 Subject: [PATCH 02/18] Disable tests when compiling with clang++ on Tavis CI --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93ec00c..56125b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,9 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|OpenBSD|NetBSD") DESTINATION "${CMAKE_INSTALL_PREFIX}/share/applications") endif() -if(ENABLE_TESTING) - enable_testing() - add_subdirectory(tests) +if(NOT (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (NOT $ENV{distribution} STREQUAL ""))) + if(ENABLE_TESTING) + enable_testing() + add_subdirectory(tests) + endif() endif() From fd56c4d1e9dcac259231f3eafc2640206e3febff Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 24 May 2016 09:34:46 +0200 Subject: [PATCH 03/18] Updated tiny-process-library submodule --- .gitmodules | 7 +++---- tiny-process-library | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index c3d9377..80ec1e2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,6 @@ -[submodule "tiny-process-library"] - path = tiny-process-library - url = https://github.com/eidheim/tiny-process-library - branch = v1.0.4 [submodule "libclangmm"] path = libclangmm url = https://github.com/cppit/libclangmm +[submodule "tiny-process-library"] + path = tiny-process-library + url = https://github.com/eidheim/tiny-process-library diff --git a/tiny-process-library b/tiny-process-library index 245e36b..48dd510 160000 --- a/tiny-process-library +++ b/tiny-process-library @@ -1 +1 @@ -Subproject commit 245e36b83670c4bcf19b36c245d0e175d57be178 +Subproject commit 48dd51030c7a539af802195a8da478a950247afe From 0d2b93b1e101730da6bf03dd841d17e360c022fa Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 24 May 2016 19:02:14 +0200 Subject: [PATCH 04/18] Improved goto declaration --- src/source.h | 2 +- src/source_clang.cc | 44 +++++++++++++++++++++++++++++++++++--------- src/window.cc | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/source.h b/src/source.h index ffdade5..97f78e4 100644 --- a/src/source.h +++ b/src/source.h @@ -73,7 +73,7 @@ namespace Source { Glib::RefPtr language; std::function auto_indent; - std::function get_declaration_location; + std::function &views)> get_declaration_location; std::function &views)> get_implementation_location; std::function >(const std::vector &views)> get_usages; std::function goto_method; diff --git a/src/source_clang.cc b/src/source_clang.cc index d2112b3..3a5f7a2 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -965,11 +965,10 @@ Source::ClangViewAutocomplete(file_path, language) { } }); - get_declaration_location=[this](){ - Offset location; + get_declaration_location=[this](const std::vector &views){ if(!parsed) { Info::get().print("Buffer is parsing"); - return location; + return Offset(); } auto iter=get_buffer()->get_insert()->get_iter(); auto line=static_cast(iter.get_line()); @@ -980,16 +979,43 @@ Source::ClangViewAutocomplete(file_path, language) { if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) { auto referenced=cursor.get_referenced(); if(referenced) { - location.file_path=referenced.get_source_location().get_path(); - auto clang_offset=referenced.get_source_location().get_offset(); - location.line=clang_offset.line; - location.index=clang_offset.index; - break; + auto file_path=referenced.get_source_location().get_path(); + + //if declaration is implementation instead, attempt to find declaration + if(file_path==this->file_path && this->language && this->language->get_id()!="chdr" && this->language->get_id()!="cpphdr") { + auto identifier=Identifier(referenced.get_kind(), token.get_spelling(), referenced.get_usr()); + + std::vector search_views; + for(auto &view: views) { + if(view->language && (view->language->get_id()=="chdr" || view->language->get_id()=="cpphdr")) + search_views.emplace_back(view); + } + search_views.emplace_back(this); + wait_parsing(search_views); + for(auto &view: search_views) { + if(auto clang_view=dynamic_cast(view)) { + for(auto &token: *clang_view->clang_tokens) { + auto cursor=token.get_cursor(); + if(token.get_kind()==clang::TokenKind::Token_Identifier && cursor.has_type()) { + auto referenced=cursor.get_referenced(); + if(referenced && identifier.kind==referenced.get_kind() && + identifier.spelling==token.get_spelling() && identifier.usr==referenced.get_usr()) { + auto offset=referenced.get_source_location().get_offset(); + return Offset(offset.line, offset.index, referenced.get_source_location().get_path()); + } + } + } + } + } + } + + auto offset=referenced.get_source_location().get_offset(); + return Offset(offset.line, offset.index, file_path); } } } } - return location; + return Offset(); }; get_implementation_location=[this](const std::vector &views){ diff --git a/src/window.cc b/src/window.cc index b7582ab..48796b0 100644 --- a/src/window.cc +++ b/src/window.cc @@ -435,7 +435,7 @@ void Window::set_menu_actions() { menu.add_action("source_goto_declaration", [this]() { if(notebook.get_current_page()!=-1) { 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(notebook.source_views); if(location) { boost::filesystem::path declaration_file; boost::system::error_code ec; From b60d6f5a2f63da673c383bb4fbbcf3e59a82fdb6 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 23 May 2016 17:29:05 +0200 Subject: [PATCH 05/18] CMakeLists.txt cleanup --- CMakeLists.txt | 30 ++++++++++++++++--- .../FindLibClang.cmake | 0 .../FindPlantuml.cmake | 0 src/CMakeLists.txt | 26 ++-------------- src/cmake/Modules/FindLibClangmm.cmake | 20 ------------- tests/CMakeLists.txt | 20 +------------ 6 files changed, 29 insertions(+), 67 deletions(-) rename {src/cmake/Modules => cmake_modules}/FindLibClang.cmake (100%) rename {src/cmake/Modules => cmake_modules}/FindPlantuml.cmake (100%) delete mode 100644 src/cmake/Modules/FindLibClangmm.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 56125b4..f8fb174 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,16 +3,38 @@ cmake_minimum_required (VERSION 2.8.4) set(project_name juci) project (${project_name}) -add_subdirectory("src") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") +if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") +endif() -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|OpenBSD|NetBSD") - install(FILES "${CMAKE_SOURCE_DIR}/share/juci.desktop" - DESTINATION "${CMAKE_INSTALL_PREFIX}/share/applications") +if(APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup") #TODO: fix this + link_directories(/usr/local/lib /usr/local/opt/gettext/lib) + include_directories(/usr/local/opt/gettext/include) + set(CMAKE_MACOSX_RPATH 1) + set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig") endif() +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/") +find_package(LibClang REQUIRED) +find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) +find_package(ASPELL REQUIRED) +include(FindPkgConfig) +pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) +pkg_check_modules(GTKSVMM gtksourceviewmm-3.0 REQUIRED) + +add_subdirectory("src") + +#TODO: instead of the if-expression below, disable tests on Travis CI for clang++ builds if(NOT (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (NOT $ENV{distribution} STREQUAL ""))) if(ENABLE_TESTING) enable_testing() add_subdirectory(tests) endif() endif() + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|OpenBSD|NetBSD") + install(FILES "${CMAKE_SOURCE_DIR}/share/juci.desktop" + DESTINATION "${CMAKE_INSTALL_PREFIX}/share/applications") +endif() diff --git a/src/cmake/Modules/FindLibClang.cmake b/cmake_modules/FindLibClang.cmake similarity index 100% rename from src/cmake/Modules/FindLibClang.cmake rename to cmake_modules/FindLibClang.cmake diff --git a/src/cmake/Modules/FindPlantuml.cmake b/cmake_modules/FindPlantuml.cmake similarity index 100% rename from src/cmake/Modules/FindPlantuml.cmake rename to cmake_modules/FindPlantuml.cmake diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 682cbda..4e56656 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,15 +1,3 @@ -add_definitions(-DBOOST_LOG_DYN_LINK) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/") - -if(APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup") - link_directories(/usr/local/lib /usr/local/opt/gettext/lib) - include_directories(/usr/local/opt/gettext/include) - set(CMAKE_MACOSX_RPATH 1) - set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig") -endif() - if(UNIX) #Checking if compiling on Ubuntu that for instance has a buggy menu system find_program(LSB_RELEASE_BIN lsb_release) if(LSB_RELEASE_BIN) @@ -25,12 +13,6 @@ if(MSYS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSYS_PROCESS_USE_SH") endif() -find_package(LibClang REQUIRED) -find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) -find_package(ASPELL REQUIRED) -set(LIBCLANGMM_INCLUDE_DIR ../libclangmm/src) -set(TINY_PROCESS_INCLUDE_DIR ../tiny-process-library) - string(REPLACE libclang liblldb LIBLLDB_LIBRARIES "${LIBCLANG_LIBRARIES}") if(EXISTS "${LIBLLDB_LIBRARIES}") set(LIBLLDB_FOUND TRUE) @@ -45,18 +27,14 @@ else() message("liblldb not found. Building juCi++ without debugging support") endif() -include(FindPkgConfig) -pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) -pkg_check_modules(GTKSVMM gtksourceviewmm-3.0 REQUIRED) - set(global_includes ${Boost_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} ${GTKSVMM_INCLUDE_DIRS} ${LIBCLANG_INCLUDE_DIRS} - ${LIBCLANGMM_INCLUDE_DIR} ${ASPELL_INCLUDE_DIR} - ${TINY_PROCESS_INCLUDE_DIR} + ../libclangmm/src + ../tiny-process-library ) set(global_libraries diff --git a/src/cmake/Modules/FindLibClangmm.cmake b/src/cmake/Modules/FindLibClangmm.cmake deleted file mode 100644 index b44b45d..0000000 --- a/src/cmake/Modules/FindLibClangmm.cmake +++ /dev/null @@ -1,20 +0,0 @@ -# LCL_FOUND - Libclangmm is available -# LCL_INCLUDE_DIRS - The libclangmm include directories -# LCL_LIBRARIES - - -find_package(PkgConfig) - -find_path(LCL_INCLUDE_DIR clangmm.h - PATH_SUFFIXES libclangmm -) - -find_library(LCL_LIBRARY NAMES clangmm) - -set(LCL_LIBRARIES ${LCL_LIBRARY} ) -set(LCL_INCLUDE_DIRS ${LCL_INCLUDE_DIR} ) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LCL DEFAULT_MSG - LCL_LIBRARY LCL_INCLUDE_DIR) - -mark_as_advanced(LCL_INCLUDE_DIR LCL_LIBRARY ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fee7b5b..2f78419 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,22 +1,4 @@ -add_definitions(-DBOOST_LOG_DYN_LINK) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-access-control -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") - -if(APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup") - link_directories(/usr/local/lib /usr/local/opt/gettext/lib) - include_directories(/usr/local/opt/gettext/include) - set(CMAKE_MACOSX_RPATH 1) - set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig") -endif() - -find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) -find_package(ASPELL REQUIRED) -set(LIBCLANGMM_INCLUDE_DIR ../libclangmm/src) - -include(FindPkgConfig) -pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-access-control -DJUCI_TESTS_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\"") set(global_includes ${Boost_INCLUDE_DIRS} From c8f72431ed7d87aa06e8c59089201159801b261b Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 24 May 2016 21:38:07 +0200 Subject: [PATCH 06/18] Added source_clang test, and tests cleanup --- CMakeLists.txt | 20 +++++- src/CMakeLists.txt | 65 ++++++------------- tests/CMakeLists.txt | 27 ++++---- tests/clang_project/CMakeLists.txt | 1 + .../clang_project/build/compile_commands.json | 7 ++ tests/clang_project/main.cpp | 5 ++ tests/source_clang_test.cc | 43 ++++++++++++ tests/source_test.cc | 12 ---- tests/stubs/dispatcher.cc | 5 -- tests/stubs/selectiondialog.cc | 6 ++ tests/stubs/terminal.cc | 14 ++++ tests/stubs/tooltips.cc | 11 +++- 12 files changed, 139 insertions(+), 77 deletions(-) create mode 100644 tests/clang_project/CMakeLists.txt create mode 100644 tests/clang_project/build/compile_commands.json create mode 100644 tests/clang_project/main.cpp create mode 100644 tests/source_clang_test.cc delete mode 100644 tests/stubs/dispatcher.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index f8fb174..eecdb95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ -cmake_minimum_required (VERSION 2.8.4) +cmake_minimum_required (VERSION 2.8.8) set(project_name juci) project (${project_name}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") -if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) +if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") endif() @@ -18,6 +18,22 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/") find_package(LibClang REQUIRED) + +#Find liblldb with the same version as the version of libclang found +string(REPLACE libclang liblldb LIBLLDB_LIBRARIES "${LIBCLANG_LIBRARIES}") +if(EXISTS "${LIBLLDB_LIBRARIES}") + set(LIBLLDB_FOUND TRUE) +elseif(EXISTS "${LIBLLDB_LIBRARIES}.1") + set(LIBLLDB_LIBRARIES "${LIBLLDB_LIBRARIES}.1") + set(LIBLLDB_FOUND TRUE) +endif() +if(LIBLLDB_FOUND) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_ENABLE_DEBUG") +else() + set(LIBLLDB_LIBRARIES "") + message("liblldb not found. Building juCi++ without debugging support") +endif() + find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) find_package(ASPELL REQUIRED) include(FindPkgConfig) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e56656..50994b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,20 +13,6 @@ if(MSYS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSYS_PROCESS_USE_SH") endif() -string(REPLACE libclang liblldb LIBLLDB_LIBRARIES "${LIBCLANG_LIBRARIES}") -if(EXISTS "${LIBLLDB_LIBRARIES}") - set(LIBLLDB_FOUND TRUE) -elseif(EXISTS "${LIBLLDB_LIBRARIES}.1") - set(LIBLLDB_LIBRARIES "${LIBLLDB_LIBRARIES}.1") - set(LIBLLDB_FOUND TRUE) -endif() -if(LIBLLDB_FOUND) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_ENABLE_DEBUG") -else() - set(LIBLLDB_LIBRARIES "") - message("liblldb not found. Building juCi++ without debugging support") -endif() - set(global_includes ${Boost_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} @@ -38,54 +24,40 @@ set(global_includes ) set(global_libraries - ${LIBCLANG_LIBRARIES} ${GTKMM_LIBRARIES} ${GTKSVMM_LIBRARIES} ${Boost_LIBRARIES} - ${ASPELL_LIBRARIES} + ${LIBCLANG_LIBRARIES} ${LIBLLDB_LIBRARIES} + ${ASPELL_LIBRARIES} ) set(project_files - cmake.cc - cmake.h config.cc - config.h dialogs.cc - dialogs.h directories.cc - directories.h - dispatcher.cc - dispatcher.h entrybox.cc - entrybox.h - files.h - filesystem.cc - filesystem.h - info.h info.cc juci.cc - juci.h menu.cc - menu.h notebook.cc - notebook.h project.cc - project.h - project_build.h - project_build.cc selectiondialog.cc - selectiondialog.h - source.cc - source.h - source_clang.cc - source_clang.h terminal.cc - terminal.h tooltips.cc - tooltips.h window.cc - window.h + + ../tiny-process-library/process.cpp +) + +#Files used both in ../src and ../tests +set(project_shared_files + cmake.cc + dispatcher.cc + filesystem.cc + project_build.cc + source.cc + source_clang.cc ../libclangmm/src/CodeCompleteResults.cc ../libclangmm/src/CompilationDatabase.cc @@ -101,11 +73,10 @@ set(project_files ../libclangmm/src/Tokens.cc ../libclangmm/src/TranslationUnit.cc ../libclangmm/src/Utility.cc - - ../tiny-process-library/process.cpp) +) if(LIBLLDB_FOUND) - list(APPEND project_files debug_clang.h debug_clang.cc) + list(APPEND project_shared_files debug_clang.cc) endif() if(MSYS) @@ -116,11 +87,13 @@ endif() include_directories(${global_includes}) +add_library(project_shared ${project_shared_files}) + if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (NOT $ENV{distribution} STREQUAL "")) add_library(${project_name} OBJECT ${project_files}) else() add_executable(${project_name} ${project_files}) - target_link_libraries(${project_name} ${global_libraries}) + target_link_libraries(${project_name} ${global_libraries} project_shared) install(TARGETS ${project_name} RUNTIME DESTINATION bin ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2f78419..e04a37a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,38 +4,43 @@ set(global_includes ${Boost_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} ${GTKSVMM_INCLUDE_DIRS} + ${LIBCLANG_INCLUDE_DIRS} ${ASPELL_INCLUDE_DIR} - ../src + ../libclangmm/src ../tiny-process-library + ../src ) set(global_libraries ${GTKMM_LIBRARIES} ${GTKSVMM_LIBRARIES} ${Boost_LIBRARIES} + ${LIBCLANG_LIBRARIES} + ${LIBLLDB_LIBRARIES} ${ASPELL_LIBRARIES} ) -set(stub_sources +set(stub_files stubs/config.cc stubs/dialogs.cc - stubs/dispatcher.cc stubs/info.cc stubs/selectiondialog.cc stubs/terminal.cc stubs/tooltips.cc ) -include_directories(${global_includes}) +add_library(stubs ${stub_files}) -add_library(stubs_library ${stub_sources}) +include_directories(${global_includes}) -add_executable(cmake_build_test cmake_build_test.cc - ../src/filesystem.cc ../src/cmake.cc ../src/project_build.cc) -target_link_libraries(cmake_build_test ${global_libraries} stubs_library) +add_executable(cmake_build_test cmake_build_test.cc) +target_link_libraries(cmake_build_test ${global_libraries} project_shared stubs) add_test(cmake_build_test cmake_build_test) -add_executable(source_test source_test.cc - ../src/source.cc) -target_link_libraries(source_test ${global_libraries} stubs_library) +add_executable(source_test source_test.cc) +target_link_libraries(source_test ${global_libraries} project_shared stubs) add_test(source_test source_test) + +add_executable(source_clang_test source_clang_test.cc) +target_link_libraries(source_clang_test ${global_libraries} project_shared stubs) +add_test(source_clang_test source_clang_test) diff --git a/tests/clang_project/CMakeLists.txt b/tests/clang_project/CMakeLists.txt new file mode 100644 index 0000000..335f619 --- /dev/null +++ b/tests/clang_project/CMakeLists.txt @@ -0,0 +1 @@ +set(project_name hello) diff --git a/tests/clang_project/build/compile_commands.json b/tests/clang_project/build/compile_commands.json new file mode 100644 index 0000000..8c1f911 --- /dev/null +++ b/tests/clang_project/build/compile_commands.json @@ -0,0 +1,7 @@ +[ +{ + "directory": "build", + "command": "c++ -std=c++1y -Wall -Wextra -Wno-unused-parameter main.cpp", + "file": "main.cpp" +} +] \ No newline at end of file diff --git a/tests/clang_project/main.cpp b/tests/clang_project/main.cpp new file mode 100644 index 0000000..811f08b --- /dev/null +++ b/tests/clang_project/main.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + std::cout << "hello world\n"; +} diff --git a/tests/source_clang_test.cc b/tests/source_clang_test.cc new file mode 100644 index 0000000..64c4222 --- /dev/null +++ b/tests/source_clang_test.cc @@ -0,0 +1,43 @@ +#include +#include "source_clang.h" +#include "config.h" +#include "filesystem.h" + +std::string hello_world_error=R"(#include + +int main() { + std::cout << "hello world\n" +} +)"; + +//Requires display server to work +//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment: +//broadwayd& +//make test + +int main() { + auto app=Gtk::Application::create(); + Gsv::init(); + + Config::get().project.default_build_path="./build"; + Source::ClangView *clang_view=new Source::ClangView(boost::filesystem::canonical(std::string(JUCI_TESTS_PATH)+"/clang_project/main.cpp"), + Gsv::LanguageManager::get_default()->get_language("cpp")); + while(!clang_view->parsed) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + } + g_assert(clang_view->diagnostics.size()==0); + clang_view->get_buffer()->set_text(hello_world_error); + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + while(!clang_view->parsed) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + } + g_assert(clang_view->diagnostics.size()>0); + + clang_view->async_delete(); + clang_view->delete_thread.join(); + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); +} diff --git a/tests/source_test.cc b/tests/source_test.cc index 237b2d5..8c1a733 100644 --- a/tests/source_test.cc +++ b/tests/source_test.cc @@ -2,18 +2,6 @@ #include "source.h" #include "filesystem.h" -int filesystem::read(const std::string &path, Glib::RefPtr text_buffer) { - return 0; -} - -int filesystem::read_non_utf8(const std::string &path, Glib::RefPtr text_buffer) { - return 0; -} - -bool filesystem::write(const std::string &path, Glib::RefPtr text_buffer) { - return false; -} - std::string hello_world=R"(#include int main() { diff --git a/tests/stubs/dispatcher.cc b/tests/stubs/dispatcher.cc deleted file mode 100644 index 8c04845..0000000 --- a/tests/stubs/dispatcher.cc +++ /dev/null @@ -1,5 +0,0 @@ -#include "dispatcher.h" - -Dispatcher::Dispatcher() {} - -Dispatcher::~Dispatcher() {} diff --git a/tests/stubs/selectiondialog.cc b/tests/stubs/selectiondialog.cc index 2b14137..f8b9d67 100644 --- a/tests/stubs/selectiondialog.cc +++ b/tests/stubs/selectiondialog.cc @@ -17,4 +17,10 @@ SelectionDialog::SelectionDialog(Gtk::TextView& text_view, Glib::RefPtr start_mark): + SelectionDialogBase(text_view, start_mark, false, false) {} + bool CompletionDialog::on_key_press(GdkEventKey* key) { return true;} + +bool CompletionDialog::on_key_release(GdkEventKey* key) {return true;} diff --git a/tests/stubs/terminal.cc b/tests/stubs/terminal.cc index 0eb09ef..43f97c6 100644 --- a/tests/stubs/terminal.cc +++ b/tests/stubs/terminal.cc @@ -1,5 +1,17 @@ #include "terminal.h" +Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {} + +Terminal::InProgress::~InProgress() {} + +std::shared_ptr Terminal::print_in_progress(std::string start_msg) { + return std::make_shared(""); +} + +void Terminal::InProgress::done(const std::string& msg) {} + +void Terminal::InProgress::cancel(const std::string &msg) {} + Terminal::Terminal() {} bool Terminal::on_motion_notify_event(GdkEventMotion* motion_event) {return false;} @@ -17,3 +29,5 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c size_t Terminal::print(const std::string &message, bool bold) { return 0; } + +void Terminal::async_print(const std::string &message, bool bold) {} diff --git a/tests/stubs/tooltips.cc b/tests/stubs/tooltips.cc index a7d73d9..909e5d9 100644 --- a/tests/stubs/tooltips.cc +++ b/tests/stubs/tooltips.cc @@ -1,7 +1,16 @@ #include "tooltips.h" +Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle(); + +Tooltip::Tooltip(std::function()> create_tooltip_buffer, + Gtk::TextView& text_view, + Glib::RefPtr start_mark, + Glib::RefPtr end_mark): text_view(text_view) {} + Tooltip::~Tooltip() {} -Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle(); +void Tooltips::show(Gdk::Rectangle const&, bool) {} + +void Tooltips::show(bool) {} void Tooltips::hide() {} From df925395cc5ca31d2421789812a145415f6dd453 Mon Sep 17 00:00:00 2001 From: "U-ole-PC\\ole" Date: Wed, 25 May 2016 10:29:24 +0200 Subject: [PATCH 07/18] Fixes undefined reference error on MSYS2 and Ubuntu --- src/CMakeLists.txt | 7 ++++--- tests/CMakeLists.txt | 17 ++++++++++------- tests/clang_project/CMakeLists.txt | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50994b8..8e8e0b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ set(global_includes ${ASPELL_INCLUDE_DIR} ../libclangmm/src ../tiny-process-library + . ) set(global_libraries @@ -87,13 +88,13 @@ endif() include_directories(${global_includes}) -add_library(project_shared ${project_shared_files}) +add_library(project_shared OBJECT ${project_shared_files}) if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (NOT $ENV{distribution} STREQUAL "")) add_library(${project_name} OBJECT ${project_files}) else() - add_executable(${project_name} ${project_files}) - target_link_libraries(${project_name} ${global_libraries} project_shared) + add_executable(${project_name} ${project_files} $) + target_link_libraries(${project_name} ${global_libraries}) install(TARGETS ${project_name} RUNTIME DESTINATION bin ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e04a37a..7443baf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,18 +29,21 @@ set(stub_files stubs/tooltips.cc ) -add_library(stubs ${stub_files}) +add_library(stubs OBJECT ${stub_files}) include_directories(${global_includes}) -add_executable(cmake_build_test cmake_build_test.cc) -target_link_libraries(cmake_build_test ${global_libraries} project_shared stubs) +add_executable(cmake_build_test cmake_build_test.cc + $ $) +target_link_libraries(cmake_build_test ${global_libraries}) add_test(cmake_build_test cmake_build_test) -add_executable(source_test source_test.cc) -target_link_libraries(source_test ${global_libraries} project_shared stubs) +add_executable(source_test source_test.cc + $ $) +target_link_libraries(source_test ${global_libraries}) add_test(source_test source_test) -add_executable(source_clang_test source_clang_test.cc) -target_link_libraries(source_clang_test ${global_libraries} project_shared stubs) +add_executable(source_clang_test source_clang_test.cc + $ $) +target_link_libraries(source_clang_test ${global_libraries}) add_test(source_clang_test source_clang_test) diff --git a/tests/clang_project/CMakeLists.txt b/tests/clang_project/CMakeLists.txt index 335f619..dade4ec 100644 --- a/tests/clang_project/CMakeLists.txt +++ b/tests/clang_project/CMakeLists.txt @@ -1 +1 @@ -set(project_name hello) +project(hello) From 1443b08e50359d980a816c68ca6159b012f248bf Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 25 May 2016 12:42:08 +0200 Subject: [PATCH 08/18] Added some more tests to source_clang_test, and fixed test error on OS X --- tests/clang_project/CMakeLists.txt | 2 +- tests/clang_project/main.cpp | 14 ++++++--- tests/source_clang_test.cc | 50 ++++++++++++++++++------------ 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/tests/clang_project/CMakeLists.txt b/tests/clang_project/CMakeLists.txt index dade4ec..d64d309 100644 --- a/tests/clang_project/CMakeLists.txt +++ b/tests/clang_project/CMakeLists.txt @@ -1 +1 @@ -project(hello) +project(test) diff --git a/tests/clang_project/main.cpp b/tests/clang_project/main.cpp index 811f08b..d1c3ab6 100644 --- a/tests/clang_project/main.cpp +++ b/tests/clang_project/main.cpp @@ -1,5 +1,11 @@ -#include - -int main() { - std::cout << "hello world\n"; +class Test { +public: + void function(); +}; + +void Test::function() {} + +int main() { + Test test; + test.function(); } diff --git a/tests/source_clang_test.cc b/tests/source_clang_test.cc index 64c4222..f85197a 100644 --- a/tests/source_clang_test.cc +++ b/tests/source_clang_test.cc @@ -3,10 +3,9 @@ #include "config.h" #include "filesystem.h" -std::string hello_world_error=R"(#include - -int main() { - std::cout << "hello world\n" +std::string main_error=R"(int main() { + int number=2; + number=3 } )"; @@ -15,6 +14,11 @@ int main() { //broadwayd& //make test +void flush_events() { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); +} + int main() { auto app=Gtk::Application::create(); Gsv::init(); @@ -22,22 +26,30 @@ int main() { Config::get().project.default_build_path="./build"; Source::ClangView *clang_view=new Source::ClangView(boost::filesystem::canonical(std::string(JUCI_TESTS_PATH)+"/clang_project/main.cpp"), Gsv::LanguageManager::get_default()->get_language("cpp")); - while(!clang_view->parsed) { - while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); - } - g_assert(clang_view->diagnostics.size()==0); - clang_view->get_buffer()->set_text(hello_world_error); - while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); - while(!clang_view->parsed) { - while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); - } - g_assert(clang_view->diagnostics.size()>0); + while(!clang_view->parsed) + flush_events(); + g_assert_cmpuint(clang_view->diagnostics.size(), ==, 0); + + clang_view->place_cursor_at_line_index(10-1, 8-1); + flush_events(); + auto location=clang_view->get_declaration_location({clang_view}); + g_assert_cmpuint(location.line, ==, 3); + clang_view->place_cursor_at_line_index(location.line-1, location.index-1); + flush_events(); + location=clang_view->get_implementation_location({clang_view}); + g_assert_cmpuint(location.line, ==, 6); + clang_view->place_cursor_at_line_index(location.line-1, location.index-1); + flush_events(); + location=clang_view->get_declaration_location({clang_view}); + g_assert_cmpuint(location.line, ==, 3); + + clang_view->get_buffer()->set_text(main_error); + flush_events(); + while(!clang_view->parsed) + flush_events(); + g_assert_cmpuint(clang_view->diagnostics.size(), >, 0); clang_view->async_delete(); clang_view->delete_thread.join(); - while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + flush_events(); } From f2ed3b1e5bf4eb5c207b94388c43e8976dcb6dc7 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 25 May 2016 16:31:31 +0200 Subject: [PATCH 09/18] Added more tests to source_clang_test --- src/source.h | 2 +- src/source_clang.cc | 27 ++++++++-------------- src/window.cc | 23 ++++++++++++++++--- tests/clang_project/main.cpp | 10 +++++--- tests/source_clang_test.cc | 44 ++++++++++++++++++++++++++++++++---- 5 files changed, 77 insertions(+), 29 deletions(-) diff --git a/src/source.h b/src/source.h index 97f78e4..e29a22f 100644 --- a/src/source.h +++ b/src/source.h @@ -76,7 +76,7 @@ namespace Source { std::function &views)> get_declaration_location; std::function &views)> get_implementation_location; std::function >(const std::vector &views)> get_usages; - std::function goto_method; + std::function >()> get_methods; std::function()> get_token_data; std::function get_token_spelling; std::function >(const std::vector &views, const std::string &text)> rename_similar_tokens; diff --git a/src/source_clang.cc b/src/source_clang.cc index 3a5f7a2..1353b39 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -1112,18 +1112,16 @@ Source::ClangViewAutocomplete(file_path, language) { return usages; }; - goto_method=[this](){ + get_methods=[this](){ + std::vector > methods; if(!parsed) { Info::get().print("Buffer is parsing"); - return; + return methods; } - auto iter=get_iter_for_dialog(); - selection_dialog=std::unique_ptr(new SelectionDialog(*this, get_buffer()->create_mark(iter), true, true)); - auto rows=std::make_shared >(); - auto methods=clang_tokens->get_cxx_methods(); - if(methods.size()==0) - return; - for(auto &method: methods) { + auto cxx_methods=clang_tokens->get_cxx_methods(); + if(cxx_methods.size()==0) + return methods; + for(auto &method: cxx_methods) { std::string row=std::to_string(method.second.line)+": "+Glib::Markup::escape_text(method.first); //Add bold method token size_t token_end_pos=row.find('('); @@ -1153,16 +1151,9 @@ Source::ClangViewAutocomplete(file_path, language) { (row[pos]>='0' && row[pos]<='9') || row[pos]=='_' || row[pos]=='~') && pos>0); row.insert(token_end_pos, ""); row.insert(pos+1, ""); - (*rows)[row]=method.second; - selection_dialog->add_row(row); + methods.emplace_back(Offset(method.second.line, method.second.index), row); } - selection_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) { - auto offset=rows->at(selected); - get_buffer()->place_cursor(get_buffer()->get_iter_at_line_index(offset.line-1, offset.index-1)); - scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5); - delayed_tooltips_connection.disconnect(); - }; - selection_dialog->show(); + return methods; }; get_token_data=[this]() { diff --git a/src/window.cc b/src/window.cc index 48796b0..c459829 100644 --- a/src/window.cc +++ b/src/window.cc @@ -517,8 +517,25 @@ void Window::set_menu_actions() { }); menu.add_action("source_goto_method", [this]() { if(notebook.get_current_page()!=-1) { - if(notebook.get_current_view()->goto_method) { - notebook.get_current_view()->goto_method(); + auto view=notebook.get_current_view(); + if(view->get_methods) { + auto methods=notebook.get_current_view()->get_methods(); + if(!methods.empty()) { + auto iter=view->get_iter_for_dialog(); + view->selection_dialog=std::unique_ptr(new SelectionDialog(*view, view->get_buffer()->create_mark(iter), true, true)); + auto rows=std::make_shared >(); + for(auto &method: methods) { + (*rows)[method.second]=method.first; + view->selection_dialog->add_row(method.second); + } + view->selection_dialog->on_select=[view, rows](const std::string& selected, bool hide_window) { + auto offset=rows->at(selected); + view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(offset.line-1, offset.index-1)); + view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); + view->delayed_tooltips_connection.disconnect(); + }; + view->selection_dialog->show(); + } } } }); @@ -790,7 +807,7 @@ void Window::activate_menu_items(bool activate) { menu.actions["source_goto_declaration"]->set_enabled(activate ? static_cast(notebook.get_current_view()->get_declaration_location) : false); menu.actions["source_goto_implementation"]->set_enabled(activate ? static_cast(notebook.get_current_view()->get_implementation_location) : false); menu.actions["source_goto_usage"]->set_enabled(activate ? static_cast(notebook.get_current_view()->get_usages) : false); - menu.actions["source_goto_method"]->set_enabled(activate ? static_cast(notebook.get_current_view()->goto_method) : false); + menu.actions["source_goto_method"]->set_enabled(activate ? static_cast(notebook.get_current_view()->get_methods) : false); menu.actions["source_rename"]->set_enabled(activate ? static_cast(notebook.get_current_view()->rename_similar_tokens) : false); menu.actions["source_goto_next_diagnostic"]->set_enabled(activate ? static_cast(notebook.get_current_view()->goto_next_diagnostic) : false); menu.actions["source_apply_fix_its"]->set_enabled(activate ? static_cast(notebook.get_current_view()->apply_fix_its) : false); diff --git a/tests/clang_project/main.cpp b/tests/clang_project/main.cpp index d1c3ab6..f4fe93a 100644 --- a/tests/clang_project/main.cpp +++ b/tests/clang_project/main.cpp @@ -1,11 +1,15 @@ -class Test { +class TestClass { public: + TestClass(); + ~TestClass() {} void function(); }; -void Test::function() {} +TestClass::TestClass() {} + +void TestClass::function() {} int main() { - Test test; + TestClass test; test.function(); } diff --git a/tests/source_clang_test.cc b/tests/source_clang_test.cc index f85197a..9acb5af 100644 --- a/tests/source_clang_test.cc +++ b/tests/source_clang_test.cc @@ -30,19 +30,55 @@ int main() { flush_events(); g_assert_cmpuint(clang_view->diagnostics.size(), ==, 0); - clang_view->place_cursor_at_line_index(10-1, 8-1); + //test get_declaration and get_implementation + clang_view->place_cursor_at_line_index(14-1, 8-1); flush_events(); auto location=clang_view->get_declaration_location({clang_view}); - g_assert_cmpuint(location.line, ==, 3); + g_assert_cmpuint(location.line, ==, 5); + clang_view->place_cursor_at_line_index(location.line-1, location.index-1); flush_events(); location=clang_view->get_implementation_location({clang_view}); - g_assert_cmpuint(location.line, ==, 6); + g_assert_cmpuint(location.line, ==, 10); + clang_view->place_cursor_at_line_index(location.line-1, location.index-1); flush_events(); location=clang_view->get_declaration_location({clang_view}); - g_assert_cmpuint(location.line, ==, 3); + g_assert_cmpuint(location.line, ==, 5); + + //test get_usages and get_methods + auto locations=clang_view->get_usages({clang_view}); + flush_events(); + g_assert_cmpuint(locations.size(), >, 0); + + locations=clang_view->get_methods(); + flush_events(); + g_assert_cmpuint(locations.size(), >, 0); + + //Test rename class (error if not constructor and destructor is renamed as well) + auto saved_main=clang_view->get_buffer()->get_text(); + clang_view->place_cursor_at_line_index(1-1, 7-1); + flush_events(); + auto token=clang_view->get_token(clang_view->get_buffer()->get_insert()->get_iter()); + g_assert_cmpstr(token.c_str(), ==, "TestClass"); + location=clang_view->get_declaration_location({clang_view}); + g_assert_cmpuint(location.line, ==, 1); + clang_view->rename_similar_tokens({clang_view}, "RenamedTestClass"); + flush_events(); + while(!clang_view->parsed) + flush_events(); + flush_events(); + auto iter=clang_view->get_buffer()->get_insert()->get_iter(); + iter.backward_char(); + token=clang_view->get_token(iter); + g_assert_cmpstr(token.c_str(), ==, "RenamedTestClass"); + flush_events(); + g_assert_cmpuint(clang_view->diagnostics.size(), ==, 0); + clang_view->get_buffer()->set_text(saved_main); + flush_events(); + clang_view->save({clang_view}); + //test error clang_view->get_buffer()->set_text(main_error); flush_events(); while(!clang_view->parsed) From 969cd8399799c2e7141705efbdc7f5927dff15c8 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 25 May 2016 18:10:39 +0200 Subject: [PATCH 10/18] Cleanup of source_clang_test --- tests/source_clang_test.cc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/source_clang_test.cc b/tests/source_clang_test.cc index 9acb5af..52d02c1 100644 --- a/tests/source_clang_test.cc +++ b/tests/source_clang_test.cc @@ -32,55 +32,44 @@ int main() { //test get_declaration and get_implementation clang_view->place_cursor_at_line_index(14-1, 8-1); - flush_events(); auto location=clang_view->get_declaration_location({clang_view}); g_assert_cmpuint(location.line, ==, 5); clang_view->place_cursor_at_line_index(location.line-1, location.index-1); - flush_events(); location=clang_view->get_implementation_location({clang_view}); g_assert_cmpuint(location.line, ==, 10); clang_view->place_cursor_at_line_index(location.line-1, location.index-1); - flush_events(); location=clang_view->get_declaration_location({clang_view}); g_assert_cmpuint(location.line, ==, 5); //test get_usages and get_methods auto locations=clang_view->get_usages({clang_view}); - flush_events(); g_assert_cmpuint(locations.size(), >, 0); locations=clang_view->get_methods(); - flush_events(); g_assert_cmpuint(locations.size(), >, 0); //Test rename class (error if not constructor and destructor is renamed as well) auto saved_main=clang_view->get_buffer()->get_text(); clang_view->place_cursor_at_line_index(1-1, 7-1); - flush_events(); auto token=clang_view->get_token(clang_view->get_buffer()->get_insert()->get_iter()); g_assert_cmpstr(token.c_str(), ==, "TestClass"); location=clang_view->get_declaration_location({clang_view}); g_assert_cmpuint(location.line, ==, 1); clang_view->rename_similar_tokens({clang_view}, "RenamedTestClass"); - flush_events(); while(!clang_view->parsed) flush_events(); - flush_events(); auto iter=clang_view->get_buffer()->get_insert()->get_iter(); iter.backward_char(); token=clang_view->get_token(iter); g_assert_cmpstr(token.c_str(), ==, "RenamedTestClass"); - flush_events(); g_assert_cmpuint(clang_view->diagnostics.size(), ==, 0); clang_view->get_buffer()->set_text(saved_main); - flush_events(); clang_view->save({clang_view}); //test error clang_view->get_buffer()->set_text(main_error); - flush_events(); while(!clang_view->parsed) flush_events(); g_assert_cmpuint(clang_view->diagnostics.size(), >, 0); From c3f4a1c31f157a3fa67a88c56c623095b56c9b2b Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 26 May 2016 13:51:49 +0200 Subject: [PATCH 11/18] Removed redundant if expression --- src/source_clang.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/source_clang.cc b/src/source_clang.cc index 1353b39..c6e5900 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -1119,8 +1119,6 @@ Source::ClangViewAutocomplete(file_path, language) { return methods; } auto cxx_methods=clang_tokens->get_cxx_methods(); - if(cxx_methods.size()==0) - return methods; for(auto &method: cxx_methods) { std::string row=std::to_string(method.second.line)+": "+Glib::Markup::escape_text(method.first); //Add bold method token From bb711f70d09bd04cac8d547274b0e33de6ae9538 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 26 May 2016 15:19:29 +0200 Subject: [PATCH 12/18] Add process_test, and fixits test in source_view_test --- src/CMakeLists.txt | 9 ++++--- src/source.h | 2 +- src/source_clang.cc | 31 +++-------------------- src/window.cc | 34 +++++++++++++++++++++++--- tests/CMakeLists.txt | 5 ++++ tests/process_test.cc | 50 ++++++++++++++++++++++++++++++++++++++ tests/source_clang_test.cc | 1 + 7 files changed, 96 insertions(+), 36 deletions(-) create mode 100644 tests/process_test.cc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8e8e0b1..2539e96 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,7 @@ set(global_libraries set(project_files config.cc dialogs.cc + dialogs_unix.cc directories.cc entrybox.cc info.cc @@ -47,8 +48,6 @@ set(project_files terminal.cc tooltips.cc window.cc - - ../tiny-process-library/process.cpp ) #Files used both in ../src and ../tests @@ -74,6 +73,8 @@ set(project_shared_files ../libclangmm/src/Tokens.cc ../libclangmm/src/TranslationUnit.cc ../libclangmm/src/Utility.cc + + ../tiny-process-library/process.cpp ) if(LIBLLDB_FOUND) @@ -81,9 +82,9 @@ if(LIBLLDB_FOUND) endif() if(MSYS) - list(APPEND project_files dialogs_unix.cc ../tiny-process-library/process_win.cpp) + list(APPEND project_shared_files ../tiny-process-library/process_win.cpp) else() - list(APPEND project_files dialogs_unix.cc ../tiny-process-library/process_unix.cpp) + list(APPEND project_shared_files ../tiny-process-library/process_unix.cpp) endif() include_directories(${global_includes}) diff --git a/src/source.h b/src/source.h index e29a22f..5acfde1 100644 --- a/src/source.h +++ b/src/source.h @@ -81,7 +81,7 @@ namespace Source { std::function get_token_spelling; std::function >(const std::vector &views, const std::string &text)> rename_similar_tokens; std::function goto_next_diagnostic; - std::function apply_fix_its; + std::function()> get_fix_its; std::unique_ptr autocomplete_dialog; std::unique_ptr selection_dialog; diff --git a/src/source_clang.cc b/src/source_clang.cc index c6e5900..23beff5 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -1275,37 +1275,12 @@ Source::ClangViewAutocomplete(file_path, language) { } }; - apply_fix_its=[this]() { + get_fix_its=[this]() { if(!parsed) { Info::get().print("Buffer is parsing"); - return; - } - std::vector, Glib::RefPtr > > fix_it_marks; - for(auto &fix_it: fix_its) { - auto start_iter=get_buffer()->get_iter_at_line_index(fix_it.offsets.first.line-1, fix_it.offsets.first.index-1); - auto end_iter=get_buffer()->get_iter_at_line_index(fix_it.offsets.second.line-1, fix_it.offsets.second.index-1); - fix_it_marks.emplace_back(get_buffer()->create_mark(start_iter), get_buffer()->create_mark(end_iter)); - } - size_t c=0; - get_buffer()->begin_user_action(); - for(auto &fix_it: fix_its) { - if(fix_it.type==FixIt::Type::INSERT) { - get_buffer()->insert(fix_it_marks[c].first->get_iter(), fix_it.source); - } - if(fix_it.type==FixIt::Type::REPLACE) { - get_buffer()->erase(fix_it_marks[c].first->get_iter(), fix_it_marks[c].second->get_iter()); - get_buffer()->insert(fix_it_marks[c].first->get_iter(), fix_it.source); - } - if(fix_it.type==FixIt::Type::ERASE) { - get_buffer()->erase(fix_it_marks[c].first->get_iter(), fix_it_marks[c].second->get_iter()); - } - c++; + return std::vector(); } - for(auto &mark_pair: fix_it_marks) { - get_buffer()->delete_mark(mark_pair.first); - get_buffer()->delete_mark(mark_pair.second); - } - get_buffer()->end_user_action(); + return fix_its; }; } diff --git a/src/window.cc b/src/window.cc index c459829..dc0099c 100644 --- a/src/window.cc +++ b/src/window.cc @@ -552,8 +552,36 @@ void Window::set_menu_actions() { }); menu.add_action("source_apply_fix_its", [this]() { if(notebook.get_current_page()!=-1) { - if(notebook.get_current_view()->apply_fix_its) { - notebook.get_current_view()->apply_fix_its(); + auto view=notebook.get_current_view(); + if(view->get_fix_its) { + auto buffer=view->get_buffer(); + auto fix_its=view->get_fix_its(); + std::vector, Glib::RefPtr > > fix_it_marks; + for(auto &fix_it: fix_its) { + auto start_iter=buffer->get_iter_at_line_index(fix_it.offsets.first.line-1, fix_it.offsets.first.index-1); + auto end_iter=buffer->get_iter_at_line_index(fix_it.offsets.second.line-1, fix_it.offsets.second.index-1); + fix_it_marks.emplace_back(buffer->create_mark(start_iter), buffer->create_mark(end_iter)); + } + size_t c=0; + buffer->begin_user_action(); + for(auto &fix_it: fix_its) { + if(fix_it.type==Source::FixIt::Type::INSERT) { + buffer->insert(fix_it_marks[c].first->get_iter(), fix_it.source); + } + if(fix_it.type==Source::FixIt::Type::REPLACE) { + buffer->erase(fix_it_marks[c].first->get_iter(), fix_it_marks[c].second->get_iter()); + buffer->insert(fix_it_marks[c].first->get_iter(), fix_it.source); + } + if(fix_it.type==Source::FixIt::Type::ERASE) { + buffer->erase(fix_it_marks[c].first->get_iter(), fix_it_marks[c].second->get_iter()); + } + c++; + } + for(auto &mark_pair: fix_it_marks) { + buffer->delete_mark(mark_pair.first); + buffer->delete_mark(mark_pair.second); + } + buffer->end_user_action(); } } }); @@ -810,7 +838,7 @@ void Window::activate_menu_items(bool activate) { menu.actions["source_goto_method"]->set_enabled(activate ? static_cast(notebook.get_current_view()->get_methods) : false); menu.actions["source_rename"]->set_enabled(activate ? static_cast(notebook.get_current_view()->rename_similar_tokens) : false); menu.actions["source_goto_next_diagnostic"]->set_enabled(activate ? static_cast(notebook.get_current_view()->goto_next_diagnostic) : false); - menu.actions["source_apply_fix_its"]->set_enabled(activate ? static_cast(notebook.get_current_view()->apply_fix_its) : false); + menu.actions["source_apply_fix_its"]->set_enabled(activate ? static_cast(notebook.get_current_view()->get_fix_its) : false); #ifdef JUCI_ENABLE_DEBUG if(notebook.get_current_page()!=-1) { auto view=notebook.get_current_view(); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7443baf..31c8f4d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,6 +33,11 @@ add_library(stubs OBJECT ${stub_files}) include_directories(${global_includes}) +add_executable(process_test process_test.cc + $ $) +target_link_libraries(process_test ${global_libraries}) +add_test(process_test process_test) + add_executable(cmake_build_test cmake_build_test.cc $ $) target_link_libraries(cmake_build_test ${global_libraries}) diff --git a/tests/process_test.cc b/tests/process_test.cc new file mode 100644 index 0000000..7cd9cb6 --- /dev/null +++ b/tests/process_test.cc @@ -0,0 +1,50 @@ +#include +#include "process.hpp" + +int main() { + auto output=std::make_shared(); + auto error=std::make_shared(); + { + Process process("echo Test", "", [output](const char *bytes, size_t n) { + *output+=std::string(bytes, n); + }); + g_assert(process.get_exit_status()==0); + g_assert(output->substr(0, 4)=="Test"); + output->clear(); + } + + { + Process process("echo Test && ls an_incorrect_path", "", [output](const char *bytes, size_t n) { + *output+=std::string(bytes, n); + }, [error](const char *bytes, size_t n) { + *error+=std::string(bytes, n); + }); + g_assert(process.get_exit_status()>0); + g_assert(output->substr(0, 4)=="Test"); + g_assert(!error->empty()); + output->clear(); + error->clear(); + } + + { + Process process("bash", "", [output](const char *bytes, size_t n) { + *output+=std::string(bytes, n); + }, nullptr, true); + process.write("echo Test\n"); + process.write("exit\n"); + g_assert(process.get_exit_status()==0); + g_assert(output->substr(0, 4)=="Test"); + output->clear(); + } + + { + Process process("cat", "", [output](const char *bytes, size_t n) { + *output+=std::string(bytes, n); + }, nullptr, true); + process.write("Test\n"); + process.close_stdin(); + g_assert(process.get_exit_status()==0); + g_assert(output->substr(0, 4)=="Test"); + output->clear(); + } +} diff --git a/tests/source_clang_test.cc b/tests/source_clang_test.cc index 52d02c1..4ed2e8d 100644 --- a/tests/source_clang_test.cc +++ b/tests/source_clang_test.cc @@ -73,6 +73,7 @@ int main() { while(!clang_view->parsed) flush_events(); g_assert_cmpuint(clang_view->diagnostics.size(), >, 0); + g_assert_cmpuint(clang_view->get_fix_its().size(), >, 0); clang_view->async_delete(); clang_view->delete_thread.join(); From 41760f606c296c231a35127a7ad12622ad18b437 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 27 May 2016 09:48:04 +0200 Subject: [PATCH 13/18] Added preference item tab_indents_line (default: true) fixes #226, and now uses raw string literals in src/files.h --- src/config.cc | 7 +- src/config.h | 1 + src/files.h | 639 +++++++++++++++++++++++++------------------------- src/source.cc | 9 +- 4 files changed, 337 insertions(+), 319 deletions(-) diff --git a/src/config.cc b/src/config.cc index e97df05..469a2f2 100644 --- a/src/config.cc +++ b/src/config.cc @@ -49,7 +49,7 @@ void Config::load() { catch(const std::exception &e) { ::Terminal::get().print("Error: could not parse "+config_json+": "+e.what()+"\n", true); std::stringstream ss; - ss << configjson; + ss << default_config_file; boost::property_tree::read_json(ss, cfg); retrieve_config(); } @@ -63,7 +63,7 @@ void Config::find_or_create_config_files() { boost::filesystem::create_directories(config_dir); // io exp captured by calling method if (!boost::filesystem::exists(config_json)) - filesystem::write(config_json, configjson); + filesystem::write(config_json, default_config_file); auto juci_style_path = home/"styles"; boost::filesystem::create_directories(juci_style_path); // io exp captured by calling method @@ -160,7 +160,7 @@ void Config::update_config_file() { try { if(cfg.get("version")!=JUCI_VERSION) { std::stringstream ss; - ss << configjson; + ss << default_config_file; boost::property_tree::read_json(ss, default_cfg); cfg_ok=false; if(cfg.count("version")>0) @@ -196,6 +196,7 @@ void Config::get_source() { source.default_tab_char = source_json.get("default_tab_char"); source.default_tab_size = source_json.get("default_tab_size"); source.auto_tab_char_and_size = source_json.get("auto_tab_char_and_size"); + source.tab_indents_line = source_json.get("tab_indents_line"); source.wrap_lines = source_json.get("wrap_lines"); diff --git a/src/config.h b/src/config.h index 7212836..60d318e 100644 --- a/src/config.h +++ b/src/config.h @@ -64,6 +64,7 @@ public: bool auto_tab_char_and_size; char default_tab_char; unsigned default_tab_size; + bool tab_indents_line; bool wrap_lines; bool highlight_current_line; bool show_line_numbers; diff --git a/src/files.h b/src/files.h index 906c44c..028e2e5 100644 --- a/src/files.h +++ b/src/files.h @@ -2,331 +2,342 @@ #define JUCI_FILES_H_ #include -#define JUCI_VERSION "1.1.3-3" - -const std::string configjson = -"{\n" -" \"version\": \""+std::string(JUCI_VERSION)+"\",\n" -" \"default_window_size\": {\n" -" \"width\": 800,\n" -" \"height\": 600\n" -" },\n" -" \"gtk_theme\": {\n" -" \"name_comment\": \"Use \\\"\\\" for default theme, At least these two exist on all systems: Adwaita, Raleigh\",\n" -" \"name\": \"\",\n" -" \"variant_comment\": \"Use \\\"\\\" for default variant, and \\\"dark\\\" for dark theme variant. Note that not all themes support dark variant, but for instance Adwaita does\",\n" -" \"variant\": \"\"\n" -" },\n" -" \"terminal\": {\n" -" \"history_size\": 1000,\n" -" \"font_comment\": \"Use \\\"\\\" to use source.font with slightly smaller size\",\n" -" \"font\": \"\"\n" -" },\n" -" \"source\": {\n" -" \"style_comment\": \"Use \\\"\\\" for default style, and for instance juci-dark or juci-dark-blue together with dark gtk_theme variant. Styles from normal gtksourceview install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango\",\n" -" \"style\": \"juci-light\",\n" -" \"font_comment\": \"Use \\\"\\\" for default font, and for instance \\\"Monospace 12\\\" to also set size\",\n" +#define JUCI_VERSION "1.1.3-4" + +const std::string default_config_file = R"RAW({ + "version": ")RAW"+std::string(JUCI_VERSION)+R"RAW(", + "default_window_size": { + "width": 800, + "height": 600 + }, + "gtk_theme": { + "name_comment": "Use \"\" for default theme, At least these two exist on all systems: Adwaita, Raleigh", + "name": "", + "variant_comment": "Use \"\" for default variant, and \"dark\" for dark theme variant. Note that not all themes support dark variant, but for instance Adwaita does", + "variant": "" + }, + "terminal": { + "history_size": 1000, + "font_comment": "Use \"\" to use source.font with slightly smaller size", + "font": "" + }, + "source": { + "style_comment": "Use \"\" for default style, and for instance juci-dark or juci-dark-blue together with dark gtk_theme variant. Styles from normal gtksourceview install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango", + "style": "juci-light", + "font_comment": "Use \"\" for default font, and for instance \"Monospace 12\" to also set size",)RAW" #ifdef __APPLE__ -" \"font\": \"Menlo 11\",\n" +R"RAW( + "font": "Menlo 11",)RAW" #else #ifdef _WIN32 -" \"font\": \"Consolas\",\n" +R"RAW( + "font": "Consolas",)RAW" #else -" \"font\": \"Monospace\",\n" +R"RAW( + "font": "Monospace",)RAW" #endif #endif -" \"cleanup_whitespace_characters_comment\": \"Remove trailing whitespace characters on save, and add trailing newline if missing\",\n" -" \"cleanup_whitespace_characters\": false,\n" -" \"show_whitespace_characters_comment\": \"Determines what kind of whitespaces should be drawn. Use comma-separated list of: space, tab, newline, nbsp, leading, text, trailing or all\",\n" -" \"show_whitespace_characters\": \"\",\n" -" \"show_map\": true,\n" -" \"map_font_size\": \"1\",\n" -" \"spellcheck_language_comment\": \"Use \\\"\\\" to set language from your locale settings\",\n" -" \"spellcheck_language\": \"en_US\",\n" -" \"auto_tab_char_and_size_comment\": \"Use false to always use default tab char and size\",\n" -" \"auto_tab_char_and_size\": true,\n" -" \"default_tab_char_comment\": \"Use \\\"\\t\\\" for regular tab\",\n" -" \"default_tab_char\": \" \",\n" -" \"default_tab_size\": 2,\n" -" \"wrap_lines\": false,\n" -" \"highlight_current_line\": true,\n" -" \"show_line_numbers\": true,\n" -" \"clang_types\": {\n" -" \"8\": \"def:function\",\n" -" \"21\": \"def:function\",\n" -" \"22\": \"def:identifier\",\n" -" \"24\": \"def:function\",\n" -" \"25\": \"def:function\",\n" -" \"43\": \"def:type\",\n" -" \"44\": \"def:type\",\n" -" \"45\": \"def:type\",\n" -" \"46\": \"def:identifier\",\n" -" \"109\": \"def:string\",\n" -" \"702\": \"def:statement\",\n" -" \"705\": \"def:comment\"\n" -" },\n" -" \"clang_format_style_comment\": \"IndentWidth, AccessModifierOffset and UseTab are set automatically. See http://clang.llvm.org/docs/ClangFormatStyleOptions.html\",\n" -" \"clang_format_style\": \"ColumnLimit: 0, MaxEmptyLinesToKeep: 2\"\n" -" },\n" -" \"keybindings\": {\n" -" \"preferences\": \"comma\",\n" -" \"quit\": \"q\",\n" -" \"new_file\": \"n\",\n" -" \"new_folder\": \"n\",\n" -" \"open_file\": \"o\",\n" -" \"open_folder\": \"o\",\n" -" \"save\": \"s\",\n" -" \"save_as\": \"s\",\n" -" \"print\": \"p\",\n" -" \"edit_undo\": \"z\",\n" -" \"edit_redo\": \"z\",\n" -" \"edit_cut\": \"x\",\n" -" \"edit_copy\": \"c\",\n" -" \"edit_paste\": \"v\",\n" -" \"edit_find\": \"f\",\n" -" \"edit_set_tab\": \"\",\n" -" \"source_spellcheck\": \"\",\n" -" \"source_spellcheck_clear\": \"\",\n" -" \"source_spellcheck_next_error\": \"e\",\n" -" \"source_indentation_set_buffer_tab\": \"\",\n" -" \"source_indentation_auto_indent_buffer\": \"i\",\n" -" \"source_goto_line\": \"g\",\n" -" \"source_center_cursor\": \"l\",\n" -" \"source_find_documentation\": \"d\",\n" -" \"source_goto_declaration\": \"d\",\n" -" \"source_goto_implementation\": \"i\",\n" -" \"source_goto_usage\": \"u\",\n" -" \"source_goto_method\": \"m\",\n" -" \"source_rename\": \"r\",\n" -" \"source_goto_next_diagnostic\": \"e\",\n" -" \"source_apply_fix_its\": \"space\",\n" -" \"project_set_run_arguments\": \"\",\n" -" \"compile_and_run\": \"Return\",\n" -" \"compile\": \"Return\",\n" -" \"run_command\": \"Return\",\n" -" \"kill_last_running\": \"Escape\",\n" -" \"force_kill_last_running\": \"Escape\",\n" -" \"debug_set_run_arguments\": \"\",\n" -" \"debug_start_continue\": \"y\",\n" -" \"debug_stop\": \"y\",\n" -" \"debug_kill\": \"k\",\n" -" \"debug_step_over\": \"j\",\n" -" \"debug_step_into\": \"t\",\n" -" \"debug_step_out\": \"t\",\n" -" \"debug_backtrace\": \"j\",\n" -" \"debug_show_variables\": \"b\",\n" -" \"debug_run_command\": \"Return\",\n" -" \"debug_toggle_breakpoint\": \"b\",\n" -" \"debug_goto_stop\": \"l\",\n" +R"RAW( + "cleanup_whitespace_characters_comment": "Remove trailing whitespace characters on save, and add trailing newline if missing", + "cleanup_whitespace_characters": false, + "show_whitespace_characters_comment": "Determines what kind of whitespaces should be drawn. Use comma-separated list of: space, tab, newline, nbsp, leading, text, trailing or all", + "show_whitespace_characters": "", + "show_map": true, + "map_font_size": "1", + "spellcheck_language_comment": "Use \"\" to set language from your locale settings", + "spellcheck_language": "en_US", + "auto_tab_char_and_size_comment": "Use false to always use default tab char and size", + "auto_tab_char_and_size": true, + "default_tab_char_comment": "Use \"\t\" for regular tab", + "default_tab_char": " ", + "default_tab_size": 2, + "tab_indents_line": true, + "wrap_lines": false, + "highlight_current_line": true, + "show_line_numbers": true, + "clang_types": { + "8": "def:function", + "21": "def:function", + "22": "def:identifier", + "24": "def:function", + "25": "def:function", + "43": "def:type", + "44": "def:type", + "45": "def:type", + "46": "def:identifier", + "109": "def:string", + "702": "def:statement", + "705": "def:comment" + }, + "clang_format_style_comment": "IndentWidth, AccessModifierOffset and UseTab are set automatically. See http://clang.llvm.org/docs/ClangFormatStyleOptions.html", + "clang_format_style": "ColumnLimit: 0, MaxEmptyLinesToKeep: 2" + }, + "keybindings": { + "preferences": "comma", + "quit": "q", + "new_file": "n", + "new_folder": "n", + "open_file": "o", + "open_folder": "o", + "save": "s", + "save_as": "s", + "print": "p", + "edit_undo": "z", + "edit_redo": "z", + "edit_cut": "x", + "edit_copy": "c", + "edit_paste": "v", + "edit_find": "f", + "edit_set_tab": "", + "source_spellcheck": "", + "source_spellcheck_clear": "", + "source_spellcheck_next_error": "e", + "source_indentation_set_buffer_tab": "", + "source_indentation_auto_indent_buffer": "i", + "source_goto_line": "g", + "source_center_cursor": "l", + "source_find_documentation": "d", + "source_goto_declaration": "d", + "source_goto_implementation": "i", + "source_goto_usage": "u", + "source_goto_method": "m", + "source_rename": "r", + "source_goto_next_diagnostic": "e", + "source_apply_fix_its": "space", + "project_set_run_arguments": "", + "compile_and_run": "Return", + "compile": "Return", + "run_command": "Return", + "kill_last_running": "Escape", + "force_kill_last_running": "Escape", + "debug_set_run_arguments": "", + "debug_start_continue": "y", + "debug_stop": "y", + "debug_kill": "k", + "debug_step_over": "j", + "debug_step_into": "t", + "debug_step_out": "t", + "debug_backtrace": "j", + "debug_show_variables": "b", + "debug_run_command": "Return", + "debug_toggle_breakpoint": "b", + "debug_goto_stop": "l",)RAW" #ifdef __linux -" \"next_tab\": \"Tab\",\n" -" \"previous_tab\": \"Tab\",\n" +R"RAW( + "next_tab": "Tab", + "previous_tab": "Tab",)RAW" #else -" \"next_tab\": \"Right\",\n" -" \"previous_tab\": \"Left\",\n" +R"RAW( + "next_tab": "Right", + "previous_tab": "Left",)RAW" #endif -" \"close_tab\": \"w\"\n" -" },\n" -" \"project\": {\n" -" \"default_build_path_comment\": \"Use to insert the project top level directory name\",\n" -" \"default_build_path\": \"./build\",\n" -" \"debug_build_path_comment\": \"Use to insert the project top level directory name, and to insert your default_build_path setting.\",\n" -" \"debug_build_path\": \"/debug\",\n" +R"RAW( + "close_tab": "w" + }, + "project": { + "default_build_path_comment": "Use to insert the project top level directory name", + "default_build_path": "./build", + "debug_build_path_comment": "Use to insert the project top level directory name, and to insert your default_build_path setting.", + "debug_build_path": "/debug",)RAW" #ifdef _WIN32 -" \"cmake_command\": \"cmake -G\\\"MSYS Makefiles\\\"\",\n" +R"RAW( + "cmake_command": "cmake -G\"MSYS Makefiles\"",)RAW" #else -" \"cmake_command\": \"cmake\",\n" +R"RAW( + "cmake_command": "cmake",)RAW" #endif -" \"make_command\": \"cmake --build .\",\n" -" \"save_on_compile_or_run\": true,\n" -" \"clear_terminal_on_compile\": true\n" -" },\n" -" \"documentation_searches\": {\n" -" \"clang\": {\n" -" \"separator\": \"::\",\n" -" \"queries\": {\n" -" \"@empty\": \"https://www.google.com/search?btnI&q=c%2B%2B+\",\n" -" \"std\": \"https://www.google.com/search?btnI&q=site:http://www.cplusplus.com/reference/+\",\n" -" \"boost\": \"https://www.google.com/search?btnI&q=site:http://www.boost.org/doc/libs/1_59_0/+\",\n" -" \"Gtk\": \"https://www.google.com/search?btnI&q=site:https://developer.gnome.org/gtkmm/stable/+\",\n" -" \"@any\": \"https://www.google.com/search?btnI&q=\"\n" -" }\n" -" }\n" -" }\n" -"}\n"; - -const std::string juci_light_style = -"\n" -"\n" -"\n" -" juCi++ team\n" -" <_description>Default juCi++ style\n" -"\n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -"\n" -"