data: Save command line info for CXX indexer commands to errors and show within errors table (issue #351)

bug id = 351
This commit is contained in:
Eberhard Graether
2017-08-09 12:16:16 +02:00
parent 1ac63f0158
commit 2e375112e6
26 changed files with 149 additions and 77 deletions
@@ -93,8 +93,14 @@ void CxxDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level lev
m_client->onErrorParsed(
location,
message,
m_commandline,
level == clang::DiagnosticsEngine::Fatal,
m_register->hasFilePath(location.filePath)
);
}
}
void CxxDiagnosticConsumer::setCommandLine(const std::string& commandline)
{
m_commandline = commandline;
}
@@ -26,11 +26,15 @@ public:
void HandleDiagnostic(clang::DiagnosticsEngine::Level level, const clang::Diagnostic& info);
void setCommandLine(const std::string& commandline);
private:
std::shared_ptr<ParserClient> m_client;
std::shared_ptr<FileRegister> m_register;
std::shared_ptr<FilePathCache> m_canonicalFilePathCache;
std::string m_commandline;
bool m_isParsingFile;
bool m_useLogging;
};
+31 -26
View File
@@ -79,38 +79,14 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand)
}
CxxCompilationDatabaseSingle compilationDatabase(compileCommand);
clang::tooling::ClangTool tool(compilationDatabase, std::vector<std::string>(1, indexerCommand->getSourceFilePath().str()));
std::shared_ptr<FilePathCache> canonicalFilePathCache = std::make_shared<FilePathCache>([](std::string fileName) -> FilePath
{
return FilePath(fileName).canonical();
}
);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, true);
tool.setDiagnosticConsumer(diagnostics.get());
ASTActionFactory actionFactory(m_client, m_fileRegister, canonicalFilePathCache, false);
tool.run(&actionFactory);
runTool(&compilationDatabase, indexerCommand->getSourceFilePath());
}
void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxManual> indexerCommand)
{
std::shared_ptr<clang::tooling::CompilationDatabase> compilationDatabase = getCompilationDatabase(indexerCommand);
clang::tooling::ClangTool tool(*compilationDatabase, std::vector<std::string>(1, indexerCommand->getSourceFilePath().str()));
std::shared_ptr<FilePathCache> canonicalFilePathCache = std::make_shared<FilePathCache>([](std::string fileName) -> FilePath
{
return FilePath(fileName).canonical();
}
);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, true);
tool.setDiagnosticConsumer(diagnostics.get());
ASTActionFactory actionFactory(m_client, m_fileRegister, canonicalFilePathCache, false);
tool.run(&actionFactory);
runTool(compilationDatabase.get(), indexerCommand->getSourceFilePath());
}
void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent)
@@ -135,6 +111,35 @@ void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr<TextAcce
);
}
void CxxParser::runTool(clang::tooling::CompilationDatabase* compilationDatabase, const FilePath& sourceFilePath)
{
clang::tooling::ClangTool tool(*compilationDatabase, std::vector<std::string>(1, sourceFilePath.str()));
std::shared_ptr<FilePathCache> canonicalFilePathCache = std::make_shared<FilePathCache>([](std::string fileName) -> FilePath
{
return FilePath(fileName).canonical();
}
);
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, true);
std::vector<clang::tooling::CompileCommand> compileCommands = compilationDatabase->getCompileCommands(sourceFilePath.str());
if (compileCommands.size() == 1)
{
std::string commandline;
for (const std::string& str : compileCommands[0].CommandLine)
{
commandline += str + " ";
}
diagnostics->setCommandLine(commandline);
}
tool.setDiagnosticConsumer(diagnostics.get());
ASTActionFactory actionFactory(m_client, m_fileRegister, canonicalFilePathCache, false);
tool.run(&actionFactory);
}
std::vector<std::string> CxxParser::getCommandlineArgumentsEssential(
const std::vector<std::string>& compilerFlags, const std::vector<FilePath>& systemHeaderSearchPaths, const std::vector<FilePath>& frameworkSearchPaths
) const {
+8 -1
View File
@@ -11,7 +11,12 @@ class IndexerCommandCxxCdb;
class IndexerCommandCxxManual;
class TaskParseCxx;
namespace clang { namespace tooling { class FixedCompilationDatabase; } }
namespace clang {
namespace tooling {
class CompilationDatabase;
class FixedCompilationDatabase;
}
}
class CxxParser: public Parser
{
@@ -24,6 +29,8 @@ public:
void buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent);
private:
void runTool(clang::tooling::CompilationDatabase* compilationDatabase, const FilePath& sourceFilePath);
std::vector<std::string> getCommandlineArgumentsEssential(
const std::vector<std::string>& compilerFlags,
const std::vector<FilePath>& systemHeaderSearchPaths,