From 63087913bd531be5a8bbf8cebd345b376b1cb6b7 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 18 Apr 2017 22:11:20 +0200 Subject: [PATCH] data: Option to run only C/C++ preprocessor when indexing (issue 297) * Added as checkbox to indexing start dialog * Only shown for C/C++ projects * Files will be marked incomplete --- src/lib/component/view/DialogView.cpp | 8 +- src/lib/component/view/DialogView.h | 24 +++-- src/lib/data/indexer/Indexer.h | 2 +- src/lib/data/indexer/IndexerCommand.h | 3 + src/lib/project/Project.cpp | 46 ++++++---- src/lib/project/Project.h | 2 +- src/lib_cxx/CMakeLists.txt | 3 +- .../data/indexer/IndexerCommandCxx.cpp | 46 ++++++++++ src/lib_cxx/data/indexer/IndexerCommandCxx.h | 39 ++++++++ .../data/indexer/IndexerCommandCxxCdb.cpp | 20 +---- .../data/indexer/IndexerCommandCxxCdb.h | 13 +-- .../data/indexer/IndexerCommandCxxManual.cpp | 20 +---- .../data/indexer/IndexerCommandCxxManual.h | 14 +-- src/lib_cxx/data/parser/cxx/ASTAction.cpp | 31 ------- src/lib_cxx/data/parser/cxx/ASTAction.h | 31 +++++-- .../data/parser/cxx/ASTActionFactory.cpp | 16 +++- .../data/parser/cxx/ASTActionFactory.h | 8 +- src/lib_cxx/data/parser/cxx/CxxParser.cpp | 6 +- src/lib_gui/CMakeLists.txt | 2 + src/lib_gui/qt/element/QtHelpButton.cpp | 33 +++++++ src/lib_gui/qt/element/QtHelpButton.h | 21 +++++ src/lib_gui/qt/element/QtIconButton.cpp | 25 +++++- src/lib_gui/qt/element/QtIconButton.h | 6 ++ src/lib_gui/qt/view/QtDialogView.cpp | 15 ++-- src/lib_gui/qt/view/QtDialogView.h | 4 +- src/lib_gui/qt/window/QtIndexingDialog.cpp | 89 ++++++++++++------- src/lib_gui/qt/window/QtIndexingDialog.h | 10 ++- .../QtProjectWizzardContent.cpp | 32 ------- .../project_wizzard/QtProjectWizzardContent.h | 18 +--- .../data/indexer/IndexerCommandJava.cpp | 9 ++ .../data/indexer/IndexerCommandJava.h | 8 +- 31 files changed, 373 insertions(+), 231 deletions(-) create mode 100644 src/lib_cxx/data/indexer/IndexerCommandCxx.cpp create mode 100644 src/lib_cxx/data/indexer/IndexerCommandCxx.h delete mode 100644 src/lib_cxx/data/parser/cxx/ASTAction.cpp create mode 100644 src/lib_gui/qt/element/QtHelpButton.cpp create mode 100644 src/lib_gui/qt/element/QtHelpButton.h diff --git a/src/lib/component/view/DialogView.cpp b/src/lib/component/view/DialogView.cpp index 415f00c3..60d4936e 100644 --- a/src/lib/component/view/DialogView.cpp +++ b/src/lib/component/view/DialogView.cpp @@ -25,10 +25,10 @@ void DialogView::hideProgressDialog() { } -DialogView::IndexMode DialogView::startIndexingDialog( - size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, bool forceRefresh, bool needsFullRefresh -){ - return INDEX_ABORT; +DialogView::IndexingOptions DialogView::startIndexingDialog( + size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, DialogView::IndexingOptions options) +{ + return IndexingOptions(); } void DialogView::updateIndexingDialog(size_t fileCount, size_t totalFileCount, std::string sourcePath) diff --git a/src/lib/component/view/DialogView.h b/src/lib/component/view/DialogView.h index 9bb03e67..d5d6a7cf 100644 --- a/src/lib/component/view/DialogView.h +++ b/src/lib/component/view/DialogView.h @@ -11,11 +11,23 @@ class StorageAccess; class DialogView { public: - enum IndexMode + struct IndexingOptions { - INDEX_ABORT, - INDEX_REFRESH, - INDEX_FULL + IndexingOptions() + : startIndexing(false) + , fullRefreshVisible(false) + , fullRefresh(false) + , preprocessorOnlyVisible(false) + , preprocessorOnly(false) + {} + + bool startIndexing; + + bool fullRefreshVisible; + bool fullRefresh; + + bool preprocessorOnlyVisible; + bool preprocessorOnly; }; DialogView(StorageAccess* storageAccess); @@ -27,8 +39,8 @@ public: virtual void showProgressDialog(const std::string& title, const std::string& message, int progress); virtual void hideProgressDialog(); - virtual IndexMode startIndexingDialog( - size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, bool forceRefresh, bool needsFullRefresh); + virtual IndexingOptions startIndexingDialog( + size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, IndexingOptions options); virtual void updateIndexingDialog(size_t fileCount, size_t totalFileCount, std::string sourcePath); virtual void finishedIndexingDialog( size_t indexedFileCount, size_t totalIndexedFileCount, size_t completedFileCount, size_t totalFileCount, diff --git a/src/lib/data/indexer/Indexer.h b/src/lib/data/indexer/Indexer.h index 1f2248c5..1b73e112 100644 --- a/src/lib/data/indexer/Indexer.h +++ b/src/lib/data/indexer/Indexer.h @@ -57,7 +57,7 @@ std::shared_ptr Indexer::in parserClient->resetStorage(); - if (parserClient->hasFatalErrors()) + if (parserClient->hasFatalErrors() || indexerCommand->preprocessorOnly()) { storage->setAllFilesIncomplete(); } diff --git a/src/lib/data/indexer/IndexerCommand.h b/src/lib/data/indexer/IndexerCommand.h index 74657bfa..9a2ac43f 100644 --- a/src/lib/data/indexer/IndexerCommand.h +++ b/src/lib/data/indexer/IndexerCommand.h @@ -21,6 +21,9 @@ public: bool cancelOnFatalErrors() const; void setCancelOnFatalErrors(bool cancelOnFatalErrors); + virtual bool preprocessorOnly() const = 0; + virtual void setPreprocessorOnly(bool preprocessorOnly) = 0; + private: FilePath m_sourceFilePath; std::set m_indexedPaths; diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index 90e4f7a3..02fcbd08 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -336,33 +336,45 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh) } std::set filesToIndex; - for (std::shared_ptr sourceGroup: m_sourceGroups) { sourceGroup->fetchSourceFilePathsToIndex(staticSourceFilePaths); utility::append(filesToIndex, sourceGroup->getSourceFilePathsToIndex()); } + + bool hasCXXSourceGroup = false; + for (std::shared_ptr sourceGroup: m_sourceGroups) + { + if (sourceGroup->getLanguage() == LANGUAGE_C || sourceGroup->getLanguage() == LANGUAGE_CPP) + { + hasCXXSourceGroup = true; + break; + } + } + bool fullRefresh = forceRefresh | needsFullRefresh; + bool preprocessorOnly = false; if (Application::getInstance()->hasGUI()) { - DialogView::IndexMode mode = Application::getInstance()->getDialogView()->startIndexingDialog( - filesToClean.size(), filesToIndex.size(), allSourceFilePaths.size(), - forceRefresh, needsFullRefresh - ); + DialogView::IndexingOptions options; + options.fullRefreshVisible = !needsFullRefresh; + options.fullRefresh = forceRefresh; - switch (mode) + options.preprocessorOnlyVisible = hasCXXSourceGroup; + options.preprocessorOnly = false; + + options = Application::getInstance()->getDialogView()->startIndexingDialog( + filesToClean.size(), filesToIndex.size(), allSourceFilePaths.size(), options); + + if (!options.startIndexing) { - case DialogView::INDEX_ABORT: - return false; - case DialogView::INDEX_REFRESH: - fullRefresh = false; - break; - case DialogView::INDEX_FULL: - fullRefresh = true; - break; + return false; } + + fullRefresh = options.fullRefresh | needsFullRefresh; + preprocessorOnly = options.preprocessorOnly; } if (fullRefresh) @@ -379,12 +391,12 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh) MessageStatus((fullRefresh ? "Reindexing Project" : "Refreshing Project"), false, true).dispatch(); - buildIndex(filesToClean, fullRefresh); + buildIndex(filesToClean, fullRefresh, preprocessorOnly); return true; } -void Project::buildIndex(const std::set& filesToClean, bool fullRefresh) +void Project::buildIndex(const std::set& filesToClean, bool fullRefresh, bool preprocessorOnly) { MessageClearErrorCount().dispatch(); @@ -414,6 +426,8 @@ void Project::buildIndex(const std::set& filesToClean, bool fullRefres for (std::shared_ptr command: sourceGroup->getIndexerCommands(fullRefresh)) { command->setCancelOnFatalErrors(cancelIndexingOnFatalErrors); + command->setPreprocessorOnly(preprocessorOnly); + indexerCommandList->addCommand(command); } } diff --git a/src/lib/project/Project.h b/src/lib/project/Project.h index fe7ff5e9..24814eec 100644 --- a/src/lib/project/Project.h +++ b/src/lib/project/Project.h @@ -47,7 +47,7 @@ public: // todo: make private again private: bool requestIndex(bool forceRefresh, bool needsFullRefresh); - void buildIndex(const std::set& filesToClean, bool fullRefresh); + void buildIndex(const std::set& filesToClean, bool fullRefresh, bool preprocessorOnly); std::shared_ptr m_settings; StorageAccessProxy* const m_storageAccessProxy; diff --git a/src/lib_cxx/CMakeLists.txt b/src/lib_cxx/CMakeLists.txt index 9bc63df4..5423a9cb 100644 --- a/src/lib_cxx/CMakeLists.txt +++ b/src/lib_cxx/CMakeLists.txt @@ -2,6 +2,8 @@ add_files( LIB_CXX_FILES + data/indexer/IndexerCommandCxx.cpp + data/indexer/IndexerCommandCxx.h data/indexer/IndexerCommandCxxCdb.cpp data/indexer/IndexerCommandCxxCdb.h data/indexer/IndexerCommandCxxManual.cpp @@ -33,7 +35,6 @@ add_files( data/parser/cxx/name_resolver/CxxTypeNameResolver.cpp data/parser/cxx/name_resolver/CxxTypeNameResolver.h - data/parser/cxx/ASTAction.cpp data/parser/cxx/ASTAction.h data/parser/cxx/ASTActionFactory.cpp data/parser/cxx/ASTActionFactory.h diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp new file mode 100644 index 00000000..59755f1e --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCommandCxx.cpp @@ -0,0 +1,46 @@ +#include "data/indexer/IndexerCommandCxx.h" + +IndexerCommandCxx::IndexerCommandCxx( + const FilePath& sourceFilePath, + const std::set& indexedPaths, + const std::set& excludedPaths, + const std::vector& systemHeaderSearchPaths, + const std::vector& frameworkSearchPaths, + const std::vector& compilerFlags +) + : IndexerCommand(sourceFilePath, indexedPaths, excludedPaths) + , m_systemHeaderSearchPaths(systemHeaderSearchPaths) + , m_frameworkSearchPaths(frameworkSearchPaths) + , m_compilerFlags(compilerFlags) + , m_preprocessorOnly(false) +{ +} + +IndexerCommandCxx::~IndexerCommandCxx() +{ +} + +std::vector IndexerCommandCxx::getSystemHeaderSearchPaths() const +{ + return m_systemHeaderSearchPaths; +} + +std::vector IndexerCommandCxx::getFrameworkSearchPaths() const +{ + return m_frameworkSearchPaths; +} + +std::vector IndexerCommandCxx::getCompilerFlags() const +{ + return m_compilerFlags; +} + +bool IndexerCommandCxx::preprocessorOnly() const +{ + return m_preprocessorOnly; +} + +void IndexerCommandCxx::setPreprocessorOnly(bool preprocessorOnly) +{ + m_preprocessorOnly = preprocessorOnly; +} diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxx.h b/src/lib_cxx/data/indexer/IndexerCommandCxx.h new file mode 100644 index 00000000..b8800d5f --- /dev/null +++ b/src/lib_cxx/data/indexer/IndexerCommandCxx.h @@ -0,0 +1,39 @@ +#ifndef INDEXER_COMMAND_CXX_H +#define INDEXER_COMMAND_CXX_H + +#include +#include + +#include "data/indexer/IndexerCommand.h" +#include "utility/file/FilePath.h" + +class IndexerCommandCxx + : public IndexerCommand +{ +public: + IndexerCommandCxx( + const FilePath& sourceFilePath, + const std::set& indexedPaths, + const std::set& excludedPaths, + const std::vector& systemHeaderSearchPaths, + const std::vector& frameworkSearchPaths, + const std::vector& compilerFlags); + + virtual ~IndexerCommandCxx(); + + std::vector getSystemHeaderSearchPaths() const; + std::vector getFrameworkSearchPaths() const; + std::vector getCompilerFlags() const; + + bool preprocessorOnly() const override; + void setPreprocessorOnly(bool preprocessorOnly) override; + +private: + std::vector m_systemHeaderSearchPaths; + std::vector m_frameworkSearchPaths; + std::vector m_compilerFlags; + + bool m_preprocessorOnly; +}; + +#endif // INDEXER_COMMAND_CXXL_H diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp index 9faffae5..2c040725 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.cpp @@ -35,11 +35,8 @@ IndexerCommandCxxCdb::IndexerCommandCxxCdb( const std::vector& systemHeaderSearchPaths, const std::vector& frameworkSearchPaths ) - : IndexerCommand(sourceFilePath, indexedPaths, excludedPaths) + : IndexerCommandCxx(sourceFilePath, indexedPaths, excludedPaths, systemHeaderSearchPaths, frameworkSearchPaths, compilerFlags) , m_workingDirectory(workingDirectory) - , m_compilerFlags(compilerFlags) - , m_systemHeaderSearchPaths(systemHeaderSearchPaths) - , m_frameworkSearchPaths(frameworkSearchPaths) { } @@ -56,18 +53,3 @@ FilePath IndexerCommandCxxCdb::getWorkingDirectory() const { return m_workingDirectory; } - -std::vector IndexerCommandCxxCdb::getCompilerFlags() const -{ - return m_compilerFlags; -} - -std::vector IndexerCommandCxxCdb::getSystemHeaderSearchPaths() const -{ - return m_systemHeaderSearchPaths; -} - -std::vector IndexerCommandCxxCdb::getFrameworkSearchPaths() const -{ - return m_frameworkSearchPaths; -} diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h index c64a0b54..fcfed9eb 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxCdb.h @@ -1,9 +1,7 @@ #ifndef INDEXER_COMMAND_CXX_CDB_H #define INDEXER_COMMAND_CXX_CDB_H -#include - -#include "data/indexer/IndexerCommand.h" +#include "data/indexer/IndexerCommandCxx.h" #include "utility/file/FilePath.h" namespace clang @@ -14,7 +12,8 @@ namespace clang } } -class IndexerCommandCxxCdb: public IndexerCommand +class IndexerCommandCxxCdb + : public IndexerCommandCxx { public: static std::vector getSourceFilesFromCDB(const FilePath& compilationDatabasePath); @@ -34,15 +33,9 @@ public: virtual std::string getKindString() const; FilePath getWorkingDirectory() const; - std::vector getCompilerFlags() const; - std::vector getSystemHeaderSearchPaths() const; - std::vector getFrameworkSearchPaths() const; private: FilePath m_workingDirectory; - std::vector m_compilerFlags; - std::vector m_systemHeaderSearchPaths; - std::vector m_frameworkSearchPaths; }; #endif // INDEXER_COMMAND_CXX_CDB_H diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp index 3b6b3500..6fa8c1b3 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.cpp @@ -15,11 +15,8 @@ IndexerCommandCxxManual::IndexerCommandCxxManual( const std::vector& frameworkSearchPaths, const std::vector& compilerFlags ) - : IndexerCommand(sourceFilePath, indexedPaths, excludedPaths) + : IndexerCommandCxx(sourceFilePath, indexedPaths, excludedPaths, systemHeaderSearchPaths, frameworkSearchPaths, compilerFlags) , m_languageStandard(languageStandard) - , m_systemHeaderSearchPaths(systemHeaderSearchPaths) - , m_frameworkSearchPaths(frameworkSearchPaths) - , m_compilerFlags(compilerFlags) { } @@ -36,18 +33,3 @@ std::string IndexerCommandCxxManual::getLanguageStandard() const { return m_languageStandard; } - -std::vector IndexerCommandCxxManual::getSystemHeaderSearchPaths() const -{ - return m_systemHeaderSearchPaths; -} - -std::vector IndexerCommandCxxManual::getFrameworkSearchPaths() const -{ - return m_frameworkSearchPaths; -} - -std::vector IndexerCommandCxxManual::getCompilerFlags() const -{ - return m_compilerFlags; -} diff --git a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h index c1ab5f85..e72270ca 100644 --- a/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h +++ b/src/lib_cxx/data/indexer/IndexerCommandCxxManual.h @@ -1,13 +1,11 @@ #ifndef INDEXER_COMMAND_CXX_MANUAL_H #define INDEXER_COMMAND_CXX_MANUAL_H -#include -#include - -#include "data/indexer/IndexerCommand.h" +#include "data/indexer/IndexerCommandCxx.h" #include "utility/file/FilePath.h" -class IndexerCommandCxxManual: public IndexerCommand +class IndexerCommandCxxManual + : public IndexerCommandCxx { public: static std::string getIndexerKindString(); @@ -25,15 +23,9 @@ public: virtual std::string getKindString() const; std::string getLanguageStandard() const; - std::vector getSystemHeaderSearchPaths() const; - std::vector getFrameworkSearchPaths() const; - std::vector getCompilerFlags() const; private: std::string m_languageStandard; - std::vector m_systemHeaderSearchPaths; - std::vector m_frameworkSearchPaths; - std::vector m_compilerFlags; }; #endif // INDEXER_COMMAND_CXX_MANUAL_H diff --git a/src/lib_cxx/data/parser/cxx/ASTAction.cpp b/src/lib_cxx/data/parser/cxx/ASTAction.cpp deleted file mode 100644 index 5e6c7d47..00000000 --- a/src/lib_cxx/data/parser/cxx/ASTAction.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "data/parser/cxx/ASTAction.h" - -#include "clang/Lex/Preprocessor.h" - -#include "data/parser/cxx/CommentHandler.h" -#include "data/parser/cxx/PreprocessorCallbacks.h" - -ASTAction::ASTAction(std::shared_ptr client, std::shared_ptr fileRegister) - : m_client(client) - , m_fileRegister(fileRegister) - , m_commentHandler(client, fileRegister) -{ -} - -ASTAction::~ASTAction() -{ -} - -std::unique_ptr ASTAction::CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile) -{ - return std::unique_ptr(new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_fileRegister)); -} - -bool ASTAction::BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::StringRef filePath) -{ - clang::Preprocessor& preprocessor = compiler.getPreprocessor(); - preprocessor.addPPCallbacks( - llvm::make_unique(compiler.getSourceManager(), m_client, m_fileRegister)); - preprocessor.addCommentHandler(&m_commentHandler); - return true; -} diff --git a/src/lib_cxx/data/parser/cxx/ASTAction.h b/src/lib_cxx/data/parser/cxx/ASTAction.h index c73565a7..65c9dbe5 100644 --- a/src/lib_cxx/data/parser/cxx/ASTAction.h +++ b/src/lib_cxx/data/parser/cxx/ASTAction.h @@ -5,27 +5,46 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" +#include "clang/Lex/Preprocessor.h" #include "data/parser/cxx/ASTConsumer.h" #include "data/parser/cxx/CommentHandler.h" +#include "data/parser/cxx/PreprocessorCallbacks.h" #include "utility/file/FileRegister.h" -class ASTAction : public clang::ASTFrontendAction +template +class ASTAction + : public ASTActionBase { public: - explicit ASTAction(std::shared_ptr client, std::shared_ptr fileRegister); - virtual ~ASTAction(); + explicit ASTAction(std::shared_ptr client, std::shared_ptr fileRegister) + : m_client(client) + , m_fileRegister(fileRegister) + , m_commentHandler(client, fileRegister) + {} + + virtual ~ASTAction() {} protected: - virtual std::unique_ptr CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile); + virtual std::unique_ptr CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile) + { + return std::unique_ptr( + new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_fileRegister)); + } - virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::StringRef filePath); + virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler, llvm::StringRef filePath) + { + clang::Preprocessor& preprocessor = compiler.getPreprocessor(); + preprocessor.addPPCallbacks( + llvm::make_unique(compiler.getSourceManager(), m_client, m_fileRegister)); + preprocessor.addCommentHandler(&m_commentHandler); + return true; + } private: std::shared_ptr m_client; std::shared_ptr m_fileRegister; CommentHandler m_commentHandler; - }; #endif // AST_ACTION_H diff --git a/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp b/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp index 2565a352..a9fb1ed0 100644 --- a/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp +++ b/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp @@ -1,8 +1,13 @@ #include "data/parser/cxx/ASTActionFactory.h" -ASTActionFactory::ASTActionFactory(std::shared_ptr client, std::shared_ptr fileRegister) +#include "clang/Frontend/FrontendActions.h" + +ASTActionFactory::ASTActionFactory( + std::shared_ptr client, std::shared_ptr fileRegister, bool preprocessorOnly +) : m_client(client) , m_fileRegister(fileRegister) + , m_preprocessorOnly(preprocessorOnly) { } @@ -12,5 +17,12 @@ ASTActionFactory::~ASTActionFactory() clang::FrontendAction* ASTActionFactory::create() { - return new ASTAction(m_client, m_fileRegister); + if (m_preprocessorOnly) + { + return new ASTAction(m_client, m_fileRegister); + } + else + { + return new ASTAction(m_client, m_fileRegister); + } } diff --git a/src/lib_cxx/data/parser/cxx/ASTActionFactory.h b/src/lib_cxx/data/parser/cxx/ASTActionFactory.h index 9bbb45b4..7a7ee837 100644 --- a/src/lib_cxx/data/parser/cxx/ASTActionFactory.h +++ b/src/lib_cxx/data/parser/cxx/ASTActionFactory.h @@ -6,10 +6,12 @@ #include "data/parser/cxx/ASTAction.h" #include "utility/file/FileRegister.h" -class ASTActionFactory : public clang::tooling::FrontendActionFactory +class ASTActionFactory + : public clang::tooling::FrontendActionFactory { public: - explicit ASTActionFactory(std::shared_ptr client, std::shared_ptr fileRegister); + explicit ASTActionFactory( + std::shared_ptr client, std::shared_ptr fileRegister, bool preprocessorOnly); virtual ~ASTActionFactory(); virtual clang::FrontendAction* create(); @@ -17,6 +19,8 @@ public: private: std::shared_ptr m_client; std::shared_ptr m_fileRegister; + + bool m_preprocessorOnly; }; #endif // AST_ACTION_FACTORY diff --git a/src/lib_cxx/data/parser/cxx/CxxParser.cpp b/src/lib_cxx/data/parser/cxx/CxxParser.cpp index 5362fbd7..d617a824 100644 --- a/src/lib_cxx/data/parser/cxx/CxxParser.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxParser.cpp @@ -84,7 +84,7 @@ void CxxParser::buildIndex(std::shared_ptr indexerCommand) std::shared_ptr diagnostics = getDiagnostics(true); tool.setDiagnosticConsumer(diagnostics.get()); - ASTActionFactory actionFactory(m_client, m_fileRegister); + ASTActionFactory actionFactory(m_client, m_fileRegister, indexerCommand->preprocessorOnly()); tool.run(&actionFactory); } @@ -97,14 +97,14 @@ void CxxParser::buildIndex(std::shared_ptr indexerComma std::shared_ptr diagnostics = getDiagnostics(true); tool.setDiagnosticConsumer(diagnostics.get()); - ASTActionFactory actionFactory(m_client, m_fileRegister); + ASTActionFactory actionFactory(m_client, m_fileRegister, indexerCommand->preprocessorOnly()); tool.run(&actionFactory); } void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr fileContent) { std::shared_ptr diagnostics = getDiagnostics(false); - ASTActionFactory actionFactory(m_client, m_fileRegister); + ASTActionFactory actionFactory(m_client, m_fileRegister, false); std::vector args = getCommandlineArgumentsEssential(std::vector(1, "-std=c++1z"), std::vector(), std::vector()); diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index 1e67a01f..477152f0 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -34,6 +34,8 @@ add_files( qt/element/QtDirectoryListBox.h qt/element/QtFontPicker.cpp qt/element/QtFontPicker.h + qt/element/QtHelpButton.cpp + qt/element/QtHelpButton.h qt/element/QtIconButton.cpp qt/element/QtIconButton.h qt/element/QtLineEdit.cpp diff --git a/src/lib_gui/qt/element/QtHelpButton.cpp b/src/lib_gui/qt/element/QtHelpButton.cpp new file mode 100644 index 00000000..273f4875 --- /dev/null +++ b/src/lib_gui/qt/element/QtHelpButton.cpp @@ -0,0 +1,33 @@ +#include "qt/element/QtHelpButton.h" + +#include + +#include "utility/ResourcePaths.h" + +QtHelpButton::QtHelpButton(const QString& helpText, QWidget* parent) + : QtIconButton( + (ResourcePaths::getGuiPath() + "window/help.png").c_str(), + (ResourcePaths::getGuiPath() + "window/help_hover.png").c_str(), + parent) + , m_helpText(helpText) +{ + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + setMouseTracking(true); + + setToolTip("help"); + + leaveEvent(nullptr); + + connect(this, SIGNAL(clicked()), this, SLOT(handleHelpPress())); +} + +void QtHelpButton::handleHelpPress() +{ + QMessageBox msgBox; + msgBox.setText("Help"); + msgBox.setInformativeText(m_helpText); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.exec(); +} diff --git a/src/lib_gui/qt/element/QtHelpButton.h b/src/lib_gui/qt/element/QtHelpButton.h new file mode 100644 index 00000000..aba5f89c --- /dev/null +++ b/src/lib_gui/qt/element/QtHelpButton.h @@ -0,0 +1,21 @@ +#ifndef QT_HELP_BUTTON_H +#define QT_HELP_BUTTON_H + +#include "qt/element/QtIconButton.h" + +class QtHelpButton + : public QtIconButton +{ + Q_OBJECT + +public: + QtHelpButton(const QString& helpText, QWidget* parent = nullptr); + +private slots: + void handleHelpPress(); + +private: + QString m_helpText; +}; + +#endif // QT_HELP_BUTTON_H diff --git a/src/lib_gui/qt/element/QtIconButton.cpp b/src/lib_gui/qt/element/QtIconButton.cpp index a2521a0e..a24b098a 100644 --- a/src/lib_gui/qt/element/QtIconButton.cpp +++ b/src/lib_gui/qt/element/QtIconButton.cpp @@ -1,9 +1,12 @@ #include "qt/element/QtIconButton.h" +#include "qt/utility/utilityQt.h" + QtIconButton::QtIconButton(QString iconPath, QString hoveredIconPath, QWidget* parent) : QPushButton("", parent) , m_iconPath(iconPath) , m_hoveredIconPath(hoveredIconPath) + , m_color(Qt::transparent) { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac @@ -14,11 +17,17 @@ QtIconButton::QtIconButton(QString iconPath, QString hoveredIconPath, QWidget* p leaveEvent(nullptr); } +void QtIconButton::setColor(QColor color) +{ + m_color = color; + leaveEvent(nullptr); +} + void QtIconButton::enterEvent(QEvent *event) { if (m_hoveredIconPath.size()) { - setIcon(QIcon(QPixmap(m_hoveredIconPath))); + setIconFromPath(m_hoveredIconPath); } } @@ -26,6 +35,18 @@ void QtIconButton::leaveEvent(QEvent *event) { if (m_iconPath.size()) { - setIcon(QIcon(QPixmap(m_iconPath))); + setIconFromPath(m_iconPath); } } + +void QtIconButton::setIconFromPath(QString path) +{ + QPixmap pixmap = QPixmap(path); + + if (m_color != Qt::transparent) + { + pixmap = utility::colorizePixmap(pixmap, m_color); + } + + setIcon(QIcon(pixmap)); +} diff --git a/src/lib_gui/qt/element/QtIconButton.h b/src/lib_gui/qt/element/QtIconButton.h index b9be39cf..2cf8e489 100644 --- a/src/lib_gui/qt/element/QtIconButton.h +++ b/src/lib_gui/qt/element/QtIconButton.h @@ -9,13 +9,19 @@ class QtIconButton public: QtIconButton(QString iconPath, QString hoveredIconPath, QWidget* parent = nullptr); + void setColor(QColor color); + protected: void enterEvent(QEvent *event); void leaveEvent(QEvent *event); private: + void setIconFromPath(QString path); + QString m_iconPath; QString m_hoveredIconPath; + + QColor m_color; }; #endif // QT_ICON_BUTTON_H diff --git a/src/lib_gui/qt/view/QtDialogView.cpp b/src/lib_gui/qt/view/QtDialogView.cpp index 9aa1027e..4cbd202e 100644 --- a/src/lib_gui/qt/view/QtDialogView.cpp +++ b/src/lib_gui/qt/view/QtDialogView.cpp @@ -111,23 +111,20 @@ void QtDialogView::hideProgressDialog() } -DialogView::IndexMode QtDialogView::startIndexingDialog( - size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, bool forceRefresh, bool needsFullRefresh) +DialogView::IndexingOptions QtDialogView::startIndexingDialog( + size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, DialogView::IndexingOptions options) { - IndexMode result = INDEX_ABORT; + DialogView::IndexingOptions result; m_resultReady = false; m_onQtThread( [=, &result]() { QtIndexingDialog* window = createWindow(); - window->setupStart(cleanFileCount, indexFileCount, totalFileCount, forceRefresh, needsFullRefresh, - [&](bool start, bool fullRefresh) + window->setupStart(cleanFileCount, indexFileCount, totalFileCount, options, + [&](DialogView::IndexingOptions o) { - if (start) - { - result = (!fullRefresh && !needsFullRefresh ? INDEX_REFRESH : INDEX_FULL); - } + result = o; m_resultReady = true; setUIBlocked(false); diff --git a/src/lib_gui/qt/view/QtDialogView.h b/src/lib_gui/qt/view/QtDialogView.h index 854318b0..6523911d 100644 --- a/src/lib_gui/qt/view/QtDialogView.h +++ b/src/lib_gui/qt/view/QtDialogView.h @@ -34,8 +34,8 @@ public: virtual void showProgressDialog(const std::string& title, const std::string& message, int progress) override; virtual void hideProgressDialog() override; - virtual DialogView::IndexMode startIndexingDialog(size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, - bool forceRefresh, bool needsFullRefresh) override; + virtual DialogView::IndexingOptions startIndexingDialog( + size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, DialogView::IndexingOptions options) override; virtual void updateIndexingDialog(size_t fileCount, size_t totalFileCount, std::string sourcePath) override; virtual void finishedIndexingDialog( size_t indexedFileCount, size_t totalIndexedFileCount, size_t completedFileCount, size_t totalFileCount, diff --git a/src/lib_gui/qt/window/QtIndexingDialog.cpp b/src/lib_gui/qt/window/QtIndexingDialog.cpp index e76d94ae..9be9ca41 100644 --- a/src/lib_gui/qt/window/QtIndexingDialog.cpp +++ b/src/lib_gui/qt/window/QtIndexingDialog.cpp @@ -7,6 +7,7 @@ #include #include "qt/utility/utilityQt.h" +#include "qt/element/QtHelpButton.h" #include "qt/element/QtProgressBar.h" #include "utility/messaging/type/MessageInterruptTasks.h" #include "utility/ResourcePaths.h" @@ -22,11 +23,11 @@ QtIndexingDialog::QtIndexingDialog(QWidget* parent) , m_messageLabel(nullptr) , m_filePathLabel(nullptr) , m_errorLabel(nullptr) - , m_checkBox(nullptr) + , m_fullRefreshCheckBox(nullptr) + , m_preprocessorOnlyCheckBox(nullptr) , m_sizeHint(QSize(450, 450)) - , m_callback([](bool, bool){}) + , m_callback([](DialogView::IndexingOptions){}) { - // setWindowFlags(Qt::WindowStaysOnTopHint); setSizeGripStyle(false); } @@ -42,7 +43,7 @@ QtIndexingDialog::DialogType QtIndexingDialog::getType() const void QtIndexingDialog::setupStart( size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, - bool forceRefresh, bool needsFullRefresh, std::function callback) + DialogView::IndexingOptions options, std::function callback) { QBoxLayout* layout = createLayout(); @@ -59,46 +60,65 @@ void QtIndexingDialog::setupStart( layout->addStretch(); - if (needsFullRefresh) + if (options.fullRefreshVisible) + { + m_fullRefreshCheckBox = new QCheckBox("full refresh", this); + m_fullRefreshCheckBox->setObjectName("message"); + + connect(m_fullRefreshCheckBox, static_cast(&QCheckBox::toggled), + [=](bool checked = false) + { + clearLabel->setVisible(!checked); + indexLabel->setVisible(!checked); + fullLabel->setVisible(checked); + } + ); + + m_fullRefreshCheckBox->setChecked(!options.fullRefresh); + m_fullRefreshCheckBox->setChecked(options.fullRefresh); + + QHBoxLayout* subLayout = new QHBoxLayout(); + subLayout->addStretch(); + subLayout->addWidget(m_fullRefreshCheckBox); + + layout->addLayout(subLayout); + } + else { clearLabel->hide(); indexLabel->hide(); } - else + + if (options.preprocessorOnlyVisible) { - m_checkBox = new QCheckBox("full refresh", this); - m_checkBox->setObjectName("message"); + m_preprocessorOnlyCheckBox = new QCheckBox("C/C++ preprocessor only", this); + m_preprocessorOnlyCheckBox->setObjectName("message"); + m_preprocessorOnlyCheckBox->setChecked(options.preprocessorOnly); - connect(m_checkBox, static_cast(&QCheckBox::toggled), - [=](bool checked = false) - { - if (checked) - { - clearLabel->hide(); - indexLabel->hide(); - fullLabel->show(); - } - else - { - clearLabel->show(); - indexLabel->show(); - fullLabel->hide(); - } - } - ); + QtHelpButton* button = new QtHelpButton( + "Run only the C/C++ preprocessor on the files. This will quickly show include errors and help fix problems " + "in the project setup faster.\n\nThe files will not be indexed and show up as incomplete."); + button->setColor(Qt::white); - m_checkBox->setChecked(!forceRefresh); - m_checkBox->setChecked(forceRefresh); + QHBoxLayout* subLayout = new QHBoxLayout(); + subLayout->addStretch(); + subLayout->addWidget(m_preprocessorOnlyCheckBox); + subLayout->addSpacing(10); + subLayout->addWidget(button); - layout->addWidget(m_checkBox, 0, Qt::AlignRight); - layout->addSpacing(30); + layout->addLayout(subLayout); + } + + if (m_fullRefreshCheckBox || m_preprocessorOnlyCheckBox) + { + layout->addSpacing(20); } addButtons(layout); updateNextButton("Start"); updateCloseButton("Cancel"); - m_sizeHint = QSize(350, 250); + m_sizeHint = QSize(350, 270); m_callback = callback; finishSetup(); @@ -277,7 +297,11 @@ void QtIndexingDialog::handleNext() { if (m_type == DIALOG_MESSAGE) { - m_callback(true, !m_checkBox || m_checkBox->isChecked()); + DialogView::IndexingOptions options; + options.startIndexing = true; + options.fullRefresh = m_fullRefreshCheckBox && m_fullRefreshCheckBox->isChecked(); + options.preprocessorOnly = m_preprocessorOnlyCheckBox && m_preprocessorOnlyCheckBox->isChecked(); + m_callback(options); } QtWindow::handleNext(); @@ -287,7 +311,8 @@ void QtIndexingDialog::handleClose() { if (m_type == DIALOG_MESSAGE) { - m_callback(false, false); + DialogView::IndexingOptions options; + m_callback(options); } if (m_type == DIALOG_INDEXING) diff --git a/src/lib_gui/qt/window/QtIndexingDialog.h b/src/lib_gui/qt/window/QtIndexingDialog.h index 9d0bad64..de358dcb 100644 --- a/src/lib_gui/qt/window/QtIndexingDialog.h +++ b/src/lib_gui/qt/window/QtIndexingDialog.h @@ -3,6 +3,7 @@ #include +#include "component/view/DialogView.h" #include "qt/window/QtWindow.h" class QCheckBox; @@ -29,7 +30,7 @@ public: DialogType getType() const; void setupStart(size_t cleanFileCount, size_t indexFileCount, size_t totalFileCount, - bool forceRefresh, bool needsFullRefresh, std::function callback); + DialogView::IndexingOptions options, std::function callback); void setupIndexing(); void setupReport( size_t indexedFileCount, size_t totalIndexedFileCount, size_t completedFileCount, size_t totalFileCount, float time); @@ -77,11 +78,14 @@ private: QLabel* m_messageLabel; QLabel* m_filePathLabel; QPushButton* m_errorLabel; - QCheckBox* m_checkBox; + + // start indexing + QCheckBox* m_fullRefreshCheckBox; + QCheckBox* m_preprocessorOnlyCheckBox; QSize m_sizeHint; - std::function m_callback; + std::function m_callback; QString m_sourcePath; }; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp index bc25e129..83767d61 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp @@ -2,41 +2,9 @@ #include -#include - #include "qt/window/QtTextEditDialog.h" -#include "utility/ResourcePaths.h" #include "utility/utilityString.h" -QtHelpButton::QtHelpButton(const QString& helpText, QWidget* parent) - : QtIconButton( - (ResourcePaths::getGuiPath() + "window/help.png").c_str(), - (ResourcePaths::getGuiPath() + "window/help_hover.png").c_str(), - parent) - , m_helpText(helpText) -{ - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - setMouseTracking(true); - - setToolTip("help"); - - leaveEvent(nullptr); - - connect(this, SIGNAL(clicked()), this, SLOT(handleHelpPress())); -} - -void QtHelpButton::handleHelpPress() -{ - QMessageBox msgBox; - msgBox.setText("Help"); - msgBox.setInformativeText(m_helpText); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); -} - - QtProjectWizzardContent::QtProjectWizzardContent(QtProjectWizzardWindow* window) : QWidget(window) , m_window(window) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h index 09d59ab2..024bea52 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h @@ -6,29 +6,13 @@ #include #include -#include "qt/element/QtIconButton.h" +#include "qt/element/QtHelpButton.h" #include "qt/utility/QtThreadedFunctor.h" #include "qt/window/project_wizzard/QtProjectWizzardWindow.h" #include "settings/ProjectSettings.h" class QtTextEditDialog; -class QtHelpButton - : public QtIconButton -{ - Q_OBJECT - -public: - QtHelpButton(const QString& helpText, QWidget* parent = nullptr); - -private slots: - void handleHelpPress(); - -private: - QString m_helpText; -}; - - class QtProjectWizzardContent : public QWidget { diff --git a/src/lib_java/data/indexer/IndexerCommandJava.cpp b/src/lib_java/data/indexer/IndexerCommandJava.cpp index 27fa8a75..0f2bdecf 100644 --- a/src/lib_java/data/indexer/IndexerCommandJava.cpp +++ b/src/lib_java/data/indexer/IndexerCommandJava.cpp @@ -29,3 +29,12 @@ std::vector IndexerCommandJava::getClassPath() const { return m_classPath; } + +bool IndexerCommandJava::preprocessorOnly() const +{ + return false; +} + +void IndexerCommandJava::setPreprocessorOnly(bool preprocessorOnly) +{ +} diff --git a/src/lib_java/data/indexer/IndexerCommandJava.h b/src/lib_java/data/indexer/IndexerCommandJava.h index 681d4fb0..6a8024ac 100644 --- a/src/lib_java/data/indexer/IndexerCommandJava.h +++ b/src/lib_java/data/indexer/IndexerCommandJava.h @@ -6,7 +6,8 @@ #include "data/indexer/IndexerCommand.h" #include "utility/file/FilePath.h" -class IndexerCommandJava: public IndexerCommand +class IndexerCommandJava + : public IndexerCommand { public: static std::string getIndexerKindString(); @@ -18,10 +19,13 @@ public: const std::vector& classPath); virtual ~IndexerCommandJava(); - virtual std::string getKindString() const; + std::string getKindString() const override; std::vector getClassPath() const; + bool preprocessorOnly() const override; + void setPreprocessorOnly(bool preprocessorOnly) override; + private: std::vector m_classPath; };