Browse Source

Added log.libclang to preferences that when enabled outputs diagnostics to standard output. Also set excludeDeclarationsFromPCH when creating clangmm::Index-instances

merge-requests/393/head
eidheim 7 years ago
parent
commit
58e5533a74
  1. 2
      CMakeLists.txt
  2. 2
      lib/libclangmm
  3. 1
      src/config.cc
  4. 1
      src/config.h
  5. 2
      src/files.h
  6. 20
      src/source_clang.cc
  7. 2
      src/source_clang.h
  8. 4
      src/usages_clang.cc
  9. 6
      tests/usages_clang_test.cc

2
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 <eidheim@gmail.com>")

2
lib/libclangmm

@ -1 +1 @@
Subproject commit 2b2f2ead1f685a9efb28ee2c0ff3cbe452a724dd
Subproject commit 5e0c39279e07d5e78973b4dd36160d245d30a580

1
src/config.cc

@ -202,5 +202,6 @@ void Config::read(const boost::property_tree::ptree &cfg) {
terminal.history_size = cfg.get<int>("terminal.history_size");
terminal.font = cfg.get<std::string>("terminal.font");
log.libclang = cfg.get<bool>("log.libclang");
log.language_server = cfg.get<bool>("log.language_server");
}

1
src/config.h

@ -96,6 +96,7 @@ public:
class Log {
public:
bool libclang;
bool language_server;
};

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

20
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<Gsv::Language> &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();
auto buffer_ = get_buffer()->get_text();
auto &buffer_raw = const_cast<std::string &>(buffer_.raw());
if(!Config::get().log.libclang) {
// Remove includes for first parse for initial syntax highlighting
std::size_t pos = 0;
while((pos = buffer.find("#include", pos)) != std::string::npos) {
while((pos = buffer_raw.find("#include", pos)) != std::string::npos) {
auto start_pos = pos;
pos = buffer.find('\n', pos + 8);
pos = buffer_raw.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, ' ');
if(start_pos == 0 || buffer_raw[start_pos - 1] == '\n') {
buffer_raw.replace(start_pos, pos - start_pos, pos - start_pos, ' ');
}
pos++;
}
auto &buffer_raw = const_cast<std::string &>(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<clangmm::TranslationUnit>(clang_index, file_path.string(), arguments, buffer_raw);
clang_tu = std::make_unique<clangmm::TranslationUnit>(std::make_shared<clangmm::Index>(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());

2
src/source_clang.h

@ -53,8 +53,6 @@ namespace Source {
void update_diagnostics();
std::vector<clangmm::Diagnostic> clang_diagnostics;
static clangmm::Index clang_index;
};
class ClangViewAutocomplete : public virtual ClangViewParse {

4
src/usages_clang.cc

@ -228,7 +228,6 @@ std::vector<Usages::Clang::Usages> 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::Usages> 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<clangmm::Index>(1, 0);
clangmm::TranslationUnit translation_unit(index, path.string(), arguments, &buffer, flags);
{
static std::mutex mutex;

6
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<clangmm::Index>(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<char>(stream), std::istreambuf_iterator<char>());
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<char>(stream), std::istreambuf_iterator<char>());
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);

Loading…
Cancel
Save