From 6c6458209099ae56b7cbd24b54e79fc0d5693573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sun, 22 Mar 2015 22:17:19 +0100 Subject: [PATCH] BAB-38 working tokens --- juci/source.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/juci/source.cc b/juci/source.cc index a6a4270..ed2e263 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -185,7 +185,20 @@ void Source::Controller::OnOpenFile(const string &filepath) { int start_offset = buffer()->begin().get_offset(); int end_offset = buffer()->end().get_offset(); - clang::TranslationUnit tu(true, filepath); + std::string project_path = + filepath.substr(0, filepath.find_last_of('/')); + + clang::CompilationDatabase db(project_path); + clang::CompileCommands commands(filepath, &db); + std::vector cmds = commands.get_commands(); + std::vector arguments; + for (auto &i : cmds) { + std::vector lol = i.get_command_as_args(); + for (int a = 1; a < lol.size()-4; a++) { + arguments.emplace_back(lol[a].c_str()); + } + } + clang::TranslationUnit tu(true, filepath, arguments); clang::SourceLocation start(&tu, filepath, start_offset); clang::SourceLocation end(&tu, filepath, end_offset); clang::SourceRange range(&start, &end); @@ -197,10 +210,8 @@ void Source::Controller::OnOpenFile(const string &filepath) { unsigned line; unsigned column; loc.get_location_info(NULL, &line, &column, NULL); - std::cout << "Token line: " << line; - std::cout << ", column: " << column; - std::cout << ", kind: " << t.kind() << std::endl; } + // model().SetSourceLocations(tu.getSourceLocations()); // view().OnOpenFile(model().getSourceLocations(), model().theme()); }