From 58e5533a745ea0b8cb6310706f283f200a37ae14 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 26 Oct 2018 10:58:30 +0200 Subject: [PATCH] Added log.libclang to preferences that when enabled outputs diagnostics to standard output. Also set excludeDeclarationsFromPCH when creating clangmm::Index-instances --- CMakeLists.txt | 2 +- lib/libclangmm | 2 +- src/config.cc | 1 + src/config.h | 1 + src/files.h | 2 ++ src/source_clang.cc | 32 +++++++++++++++++--------------- src/source_clang.h | 2 -- src/usages_clang.cc | 4 ++-- tests/usages_clang_test.cc | 6 +++--- 9 files changed, 28 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b1c935..5eb23eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.8.8) project(juci) -set(JUCI_VERSION "1.4.6") +set(JUCI_VERSION "1.4.6.1") set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim ") diff --git a/lib/libclangmm b/lib/libclangmm index 2b2f2ea..5e0c392 160000 --- a/lib/libclangmm +++ b/lib/libclangmm @@ -1 +1 @@ -Subproject commit 2b2f2ead1f685a9efb28ee2c0ff3cbe452a724dd +Subproject commit 5e0c39279e07d5e78973b4dd36160d245d30a580 diff --git a/src/config.cc b/src/config.cc index 1952383..114b814 100644 --- a/src/config.cc +++ b/src/config.cc @@ -202,5 +202,6 @@ void Config::read(const boost::property_tree::ptree &cfg) { terminal.history_size = cfg.get("terminal.history_size"); terminal.font = cfg.get("terminal.font"); + log.libclang = cfg.get("log.libclang"); log.language_server = cfg.get("log.language_server"); } diff --git a/src/config.h b/src/config.h index 529b7a0..ee5a0f4 100644 --- a/src/config.h +++ b/src/config.h @@ -96,6 +96,7 @@ public: class Log { public: + bool libclang; bool language_server; }; diff --git a/src/files.h b/src/files.h index 4d55ce8..b87c47c 100644 --- a/src/files.h +++ b/src/files.h @@ -193,6 +193,8 @@ const std::string default_config_file = R"RAW({ } }, "log": { + "libclang_comment": "Outputs diagnostics for new C/C++ buffers", + "libclang": false, "language_server": false } } diff --git a/src/source_clang.cc b/src/source_clang.cc index d625696..fef8b33 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -14,8 +14,6 @@ #include "selection_dialog.h" #include "usages_clang.h" -clangmm::Index Source::ClangViewParse::clang_index(0, 0); - const std::regex include_regex(R"(^[ \t]*#[ \t]*include[ \t]*[<"]([^<>"]+)[>"].*$)"); Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const Glib::RefPtr &language) @@ -98,20 +96,24 @@ void Source::ClangViewParse::parse_initialize() { parse_state = ParseState::PROCESSING; parse_process_state = ParseProcessState::STARTING; - auto buffer = get_buffer()->get_text(); - //Remove includes for first parse for initial syntax highlighting - std::size_t pos = 0; - while((pos = buffer.find("#include", pos)) != std::string::npos) { - auto start_pos = pos; - pos = buffer.find('\n', pos + 8); - if(pos == std::string::npos) - break; - if(start_pos == 0 || buffer[start_pos - 1] == '\n') { - buffer.replace(start_pos, pos - start_pos, pos - start_pos, ' '); + auto buffer_ = get_buffer()->get_text(); + auto &buffer_raw = const_cast(buffer_.raw()); + + if(!Config::get().log.libclang) { + // Remove includes for first parse for initial syntax highlighting + std::size_t pos = 0; + while((pos = buffer_raw.find("#include", pos)) != std::string::npos) { + auto start_pos = pos; + pos = buffer_raw.find('\n', pos + 8); + if(pos == std::string::npos) + break; + if(start_pos == 0 || buffer_raw[start_pos - 1] == '\n') { + buffer_raw.replace(start_pos, pos - start_pos, pos - start_pos, ' '); + } + pos++; } - pos++; } - auto &buffer_raw = const_cast(buffer.raw()); + if(language && (language->get_id() == "chdr" || language->get_id() == "cpphdr")) clangmm::remove_include_guard(buffer_raw); @@ -120,7 +122,7 @@ void Source::ClangViewParse::parse_initialize() { Info::get().print(file_path.filename().string() + ": could not find a supported build system"); build->update_default(); auto arguments = CompileCommands::get_arguments(build->get_default_path(), file_path); - clang_tu = std::make_unique(clang_index, file_path.string(), arguments, buffer_raw); + clang_tu = std::make_unique(std::make_shared(1, Config::get().log.libclang), file_path.string(), arguments, &buffer_raw); clang_tokens = clang_tu->get_tokens(); clang_tokens_offsets.clear(); clang_tokens_offsets.reserve(clang_tokens->size()); diff --git a/src/source_clang.h b/src/source_clang.h index d5d7f88..3634ea5 100644 --- a/src/source_clang.h +++ b/src/source_clang.h @@ -53,8 +53,6 @@ namespace Source { void update_diagnostics(); std::vector clang_diagnostics; - - static clangmm::Index clang_index; }; class ClangViewAutocomplete : public virtual ClangViewParse { diff --git a/src/usages_clang.cc b/src/usages_clang.cc index eafb1dd..1e5ea17 100644 --- a/src/usages_clang.cc +++ b/src/usages_clang.cc @@ -228,7 +228,6 @@ std::vector Usages::Clang::get_usages(const boost::filesy path = *it; ++it; } - clangmm::Index index(0, 0); { static std::mutex mutex; @@ -254,7 +253,8 @@ std::vector Usages::Clang::get_usages(const boost::filesy flags |= CXTranslationUnit_KeepGoing; #endif - clangmm::TranslationUnit translation_unit(index, path.string(), arguments, buffer, flags); + static auto index = std::make_shared(1, 0); + clangmm::TranslationUnit translation_unit(index, path.string(), arguments, &buffer, flags); { static std::mutex mutex; diff --git a/tests/usages_clang_test.cc b/tests/usages_clang_test.cc index f6432de..d7f2301 100644 --- a/tests/usages_clang_test.cc +++ b/tests/usages_clang_test.cc @@ -17,14 +17,14 @@ int main() { g_assert(build->project_path == project_path); { - clangmm::Index index(0, 0); + auto index = std::make_shared(1, 0); auto path = project_path / "main.cpp"; std::ifstream stream(path.string(), std::ifstream::binary); assert(stream); std::string buffer; buffer.assign(std::istreambuf_iterator(stream), std::istreambuf_iterator()); auto arguments = CompileCommands::get_arguments(build_path, path); - clangmm::TranslationUnit translation_unit(index, path.string(), arguments, buffer); + clangmm::TranslationUnit translation_unit(index, path.string(), arguments, &buffer); auto tokens = translation_unit.get_tokens(); clangmm::Token *found_token = nullptr; for(auto &token : *tokens) { @@ -109,7 +109,7 @@ int main() { std::ifstream stream(path.string(), std::ifstream::binary); std::string buffer; buffer.assign(std::istreambuf_iterator(stream), std::istreambuf_iterator()); - clangmm::TranslationUnit translation_unit(index, path.string(), arguments, buffer); + clangmm::TranslationUnit translation_unit(index, path.string(), arguments, &buffer); Usages::Clang::add_usages(project_path, build_path, path, usages, visited, spelling, cursor, &translation_unit, true); Usages::Clang::add_usages_from_includes(project_path, build_path, usages, visited, spelling, cursor, &translation_unit, true); assert(usages.size() == 3);