diff --git a/src/Parsers/CppParser/cppdocumentparser.cpp b/src/Parsers/CppParser/cppdocumentparser.cpp index 60bdb47..cffa94f 100644 --- a/src/Parsers/CppParser/cppdocumentparser.cpp +++ b/src/Parsers/CppParser/cppdocumentparser.cpp @@ -393,13 +393,11 @@ CppDocumentParser::CppDocumentParser( QObject* parent ) CppEditor::CppModelManager* modelManager = CppEditor::CppModelManager::instance(); connect( modelManager, &CppEditor::CppModelManager::documentUpdated, this, &CppDocumentParser::parseCppDocumentOnUpdate, Qt::DirectConnection ); - connect( qApp, &QApplication::aboutToQuit, this, [=]() { - /* Disconnect any signals that might still get emitted. */ - modelManager->disconnect( this ); - SpellCheckerCore::instance()->disconnect( this ); - this->disconnect( SpellCheckerCore::instance() ); - }, Qt::DirectConnection ); - + connect( qApp, &QApplication::aboutToQuit, this, [=, this]() { + /* Disconnect any signals that might still get emitted. */ + modelManager->disconnect( this ); + SpellCheckerCore::instance()->disconnect( this ); + this->disconnect( SpellCheckerCore::instance() ); }, Qt::DirectConnection ); Core::Context context( CppEditor::Constants::CPPEDITOR_ID ); Core::ActionContainer* cppEditorContextMenu = Core::ActionManager::createMenu( CppEditor::Constants::M_CONTEXT ); Core::ActionContainer* contextMenu = Core::ActionManager::createMenu( Constants::CONTEXT_MENU_ID ); diff --git a/src/Parsers/CppParser/cppdocumentprocessor.cpp b/src/Parsers/CppParser/cppdocumentprocessor.cpp index 67b7979..bb86baf 100644 --- a/src/Parsers/CppParser/cppdocumentprocessor.cpp +++ b/src/Parsers/CppParser/cppdocumentprocessor.cpp @@ -155,6 +155,23 @@ void CppDocumentProcessor::process( CppDocumentProcessor::Promise& promise ) return; } + if (d->settings.whatToCheck.testFlag(CppParserSettings::CheckIdentifiers)) { + /* Parse identifiers (consider merging all the 3 loops, because we now touch each token) */ + unsigned int tokenCount = d->trUnit->tokenCount(); + for ( unsigned int tokenIndex = 0; tokenIndex < tokenCount; ++tokenIndex ) { + const CPlusPlus::Token &token{ d->trUnit->tokenAt( tokenIndex ) }; + const CPlusPlus::Identifier *identifier{ token.identifier }; + if ( identifier ) { + wordTokens.push_back( parseToken( token, WordTokens::Type::Identifier ) ); + } + } + } + + if (promise.isCanceled() == true) { + promise.future().cancel(); + return; + } + /* At this point the DocPtr can be released since it will no longer be * Used */ d->docPtr->releaseSourceAndAST(); diff --git a/src/Parsers/CppParser/cppdocumentprocessor.h b/src/Parsers/CppParser/cppdocumentprocessor.h index dabab4a..cf1cd47 100644 --- a/src/Parsers/CppParser/cppdocumentprocessor.h +++ b/src/Parsers/CppParser/cppdocumentprocessor.h @@ -56,7 +56,8 @@ struct WordTokens enum class Type { Comment = 0, Doxygen, - Literal + Literal, + Identifier, }; HashWords::key_type hash; diff --git a/src/Parsers/CppParser/cppparseroptionswidget.cpp b/src/Parsers/CppParser/cppparseroptionswidget.cpp index 12a7650..ae432a8 100644 --- a/src/Parsers/CppParser/cppparseroptionswidget.cpp +++ b/src/Parsers/CppParser/cppparseroptionswidget.cpp @@ -37,12 +37,12 @@ CppParserOptionsWidget::CppParserOptionsWidget( const CppParserSettings* const s ui->labelDescriptionEmail->setText( ui->labelDescriptionEmail->text().arg( QLatin1String( SpellChecker::Parsers::CppParser::Constants::EMAIL_ADDRESS_REGEXP_PATTERN ) ) ); ui->labelDescriptionWebsites->setText( ui->labelDescriptionWebsites->text().arg( QLatin1String( SpellChecker::Parsers::CppParser::Constants::WEBSITE_ADDRESS_REGEXP_PATTERN ) ) ); /* Set up the options for What to Check */ - ui->radioButtonWhatComments->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CheckComments ); - ui->radioButtonWhatLiterals->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CheckStringLiterals ); - ui->radioButtonWhatBoth->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CheckBoth ); - connect( ui->radioButtonWhatComments, &QRadioButton::toggled, this, &CppParserOptionsWidget::radioButtonWhatToggled ); - connect( ui->radioButtonWhatLiterals, &QRadioButton::toggled, this, &CppParserOptionsWidget::radioButtonWhatToggled ); - connect( ui->radioButtonWhatBoth, &QRadioButton::toggled, this, &CppParserOptionsWidget::radioButtonWhatToggled ); + ui->checkBoxWhatComments->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CheckComments ); + ui->checkBoxWhatLiterals->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CheckStringLiterals ); + ui->checkBoxWhatIdentifiers->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CheckIdentifiers ); + connect( ui->checkBoxWhatComments, &QAbstractButton::toggled, this, &CppParserOptionsWidget::checkBoxWhatToggled ); + connect( ui->checkBoxWhatLiterals, &QAbstractButton::toggled, this, &CppParserOptionsWidget::checkBoxWhatToggled ); + connect( ui->checkBoxWhatIdentifiers, &QAbstractButton::toggled, this, &CppParserOptionsWidget::checkBoxWhatToggled ); /* Set up the options for Comments to Check */ ui->radioButtonCommentsC->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CommentsC ); ui->radioButtonCommentsCpp->setProperty( ENUM_VAL_PROPERTY, CppParserSettings::CommentsCpp ); @@ -101,11 +101,9 @@ const CppParserSettings& CppParserOptionsWidget::settings() } // -------------------------------------------------- -void CppParserOptionsWidget::radioButtonWhatToggled() +void CppParserOptionsWidget::checkBoxWhatToggled() { - if( static_cast( sender() )->isChecked() == true ) { - m_settings.whatToCheck = static_cast( sender()->property( ENUM_VAL_PROPERTY ).toInt() ); - } + m_settings.whatToCheck.setFlag( static_cast( sender()->property( ENUM_VAL_PROPERTY ).toInt() ), static_cast( sender() )->isChecked() ); } // -------------------------------------------------- @@ -154,9 +152,10 @@ void CppParserOptionsWidget::updateWithSettings( const CppParserSettings* const ui->checkBoxRemoveEmailAddresses->setChecked( settings->removeEmailAddresses ); ui->checkBoxIgnoreKeywords->setChecked( !settings->checkQtKeywords ); ui->checkBoxIgnoreCaps->setChecked( !settings->checkAllCapsWords ); - QRadioButton* whatButtons[] = { nullptr, ui->radioButtonWhatComments, ui->radioButtonWhatLiterals, ui->radioButtonWhatBoth }; - whatButtons[settings->whatToCheck]->setChecked( true ); - QRadioButton* commentButtons[] = { nullptr, ui->radioButtonCommentsC, ui->radioButtonCommentsCpp, ui->radioButtonCommentsBoth }; + ui->checkBoxWhatComments->setChecked( settings->whatToCheck.testFlag( CppParserSettings::CheckComments ) ); + ui->checkBoxWhatLiterals->setChecked( settings->whatToCheck.testFlag( CppParserSettings::CheckStringLiterals ) ); + ui->checkBoxWhatIdentifiers->setChecked( settings->whatToCheck.testFlag( CppParserSettings::CheckIdentifiers ) ); + QRadioButton *commentButtons[] = { nullptr, ui->radioButtonCommentsC, ui->radioButtonCommentsCpp, ui->radioButtonCommentsBoth }; commentButtons[settings->commentsToCheck]->setChecked( true ); QRadioButton* numberButtons[] = { ui->radioButtonNumbersRemove, ui->radioButtonNumbersSplit, ui->radioButtonNumbersLeave }; numberButtons[settings->wordsWithNumberOption]->setChecked( true ); diff --git a/src/Parsers/CppParser/cppparseroptionswidget.h b/src/Parsers/CppParser/cppparseroptionswidget.h index 29dcdfa..801232d 100644 --- a/src/Parsers/CppParser/cppparseroptionswidget.h +++ b/src/Parsers/CppParser/cppparseroptionswidget.h @@ -45,7 +45,7 @@ class CppParserOptionsWidget const CppParserSettings& settings(); public slots: - void radioButtonWhatToggled(); + void checkBoxWhatToggled(); void radioButtonCommentsToggled(); void radioButtonNumbersToggled(); void radioButtonUnderscoresToggled(); diff --git a/src/Parsers/CppParser/cppparseroptionswidget.ui b/src/Parsers/CppParser/cppparseroptionswidget.ui index 59c1c3b..55303d7 100644 --- a/src/Parsers/CppParser/cppparseroptionswidget.ui +++ b/src/Parsers/CppParser/cppparseroptionswidget.ui @@ -54,10 +54,10 @@ QScrollArea { padding: 3px } - QFrame::NoFrame + QFrame::Shape::NoFrame - QFrame::Sunken + QFrame::Shadow::Sunken true @@ -68,7 +68,7 @@ 0 0 801 - 1638 + 1843 @@ -106,25 +106,25 @@ - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 - + - Comments only + Comments - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -148,7 +148,7 @@ - Only Comments will be checked for spelling mistakes. This includes normal and doxygen comments. Eg: /* Comment to Check */ + Comments will be checked for spelling mistakes. This includes normal and doxygen comments. Eg: /* Comment to Check */ true @@ -156,19 +156,19 @@ - + - String Literals only + String Literals - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -192,27 +192,20 @@ - Only String Literals will be checked for spelling mistakes. A String Literal is a string inside inverted commas. Eg: "String to Check". + String Literals will be checked for spelling mistakes. A String Literal is a string inside inverted commas. Eg: "String to Check". true - - - - Comments and String Literals - - - - + - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -222,10 +215,17 @@ - - + + + + Identifiers + + + + + - + 0 0 @@ -236,13 +236,26 @@ - Comments and String Literals will be checked. - - - true + Identifiers, such as variable, type, and function names. + + + + Qt::Orientation::Horizontal + + + QSizePolicy::Policy::Fixed + + + + 40 + 0 + + + + @@ -259,7 +272,7 @@ - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -274,10 +287,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -318,10 +331,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -362,10 +375,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -411,7 +424,7 @@ First Comment - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter false @@ -421,7 +434,7 @@ - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -436,10 +449,10 @@ - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -487,7 +500,7 @@ A multi-line C++ comment will not behave as expected since all lines are interpr Email Addresses - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter false @@ -497,7 +510,7 @@ A multi-line C++ comment will not behave as expected since all lines are interpr - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -512,10 +525,10 @@ A multi-line C++ comment will not behave as expected since all lines are interpr - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -562,7 +575,7 @@ The match pattern used is: %1 Qt Keywords - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter false @@ -572,7 +585,7 @@ The match pattern used is: %1 - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -587,10 +600,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -637,7 +650,7 @@ The match pattern used is: %1 - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -673,10 +686,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -702,7 +715,7 @@ The match pattern used is: %1 - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -717,10 +730,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -761,10 +774,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -805,10 +818,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -855,7 +868,7 @@ The match pattern used is: %1 - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -870,10 +883,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -914,10 +927,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -958,10 +971,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -1008,7 +1021,7 @@ The match pattern used is: %1 - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -1023,10 +1036,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -1067,10 +1080,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -1111,10 +1124,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -1161,7 +1174,7 @@ The match pattern used is: %1 - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -1176,10 +1189,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -1226,7 +1239,7 @@ The match pattern used is: %1 - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -1241,10 +1254,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -1285,10 +1298,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -1329,10 +1342,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -1379,7 +1392,7 @@ The match pattern used is: %1 - QFormLayout::AllNonFixedFieldsGrow + QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow 0 @@ -1394,10 +1407,10 @@ The match pattern used is: %1 - Qt::Horizontal + Qt::Orientation::Horizontal - QSizePolicy::Fixed + QSizePolicy::Policy::Fixed @@ -1440,9 +1453,8 @@ The match pattern used is: %1 checkBoxDescriptions - radioButtonWhatComments - radioButtonWhatLiterals - radioButtonWhatBoth + checkBoxWhatComments + checkBoxWhatLiterals scrollArea radioButtonCommentsC radioButtonCommentsCpp @@ -1771,70 +1783,6 @@ The match pattern used is: %1 - - checkBoxDescriptions - toggled(bool) - label_21 - setHidden(bool) - - - 281 - 24 - - - 325 - 146 - - - - - radioButtonWhatComments - toggled(bool) - groupBox_11 - setEnabled(bool) - - - 324 - 72 - - - 321 - 213 - - - - - radioButtonWhatLiterals - toggled(bool) - groupBox_11 - setDisabled(bool) - - - 424 - 103 - - - 386 - 205 - - - - - radioButtonWhatBoth - toggled(bool) - groupBox_11 - setEnabled(bool) - - - 431 - 133 - - - 410 - 206 - - - checkBoxDescriptions toggled(bool) @@ -1899,53 +1847,5 @@ The match pattern used is: %1 - - radioButtonWhatBoth - toggled(bool) - groupBox_13 - setEnabled(bool) - - - 152 - 128 - - - 120 - 298 - - - - - radioButtonWhatLiterals - toggled(bool) - groupBox_13 - setDisabled(bool) - - - 143 - 95 - - - 156 - 313 - - - - - radioButtonWhatComments - toggled(bool) - groupBox_13 - setEnabled(bool) - - - 92 - 68 - - - 96 - 298 - - - diff --git a/src/Parsers/CppParser/cppparsersettings.cpp b/src/Parsers/CppParser/cppparsersettings.cpp index 9699c93..fdc56be 100644 --- a/src/Parsers/CppParser/cppparsersettings.cpp +++ b/src/Parsers/CppParser/cppparsersettings.cpp @@ -113,7 +113,7 @@ void CppParserSettings::saveToSetting(Utils::QtcSettings *settings ) const void CppParserSettings::setDefaults() { - whatToCheck = CheckBoth; + whatToCheck = { CheckComments | CheckStringLiterals }; commentsToCheck = CommentsBoth; removeEmailAddresses = true; checkQtKeywords = false; diff --git a/src/Parsers/CppParser/cppparsersettings.h b/src/Parsers/CppParser/cppparsersettings.h index 211b3ca..58723b7 100644 --- a/src/Parsers/CppParser/cppparsersettings.h +++ b/src/Parsers/CppParser/cppparsersettings.h @@ -40,10 +40,10 @@ class CppParserSettings ~CppParserSettings(); enum WhatToCheck { - Tokens_NONE = 0, /*!< Invalid option needed for QFLAGS. */ - CheckComments = 1 << 0, /*!< Check Comments. */ - CheckStringLiterals = 1 << 1, /*!< Check String Literals */ - CheckBoth = CheckComments | CheckStringLiterals + Tokens_NONE = 0, /*!< Invalid option needed for QFLAGS. */ + CheckComments = 1 << 0, /*!< Check Comments. */ + CheckStringLiterals = 1 << 1, /*!< Check String Literals */ + CheckIdentifiers = 1 << 2, /*!< Check Identifiers */ }; Q_DECLARE_FLAGS( WhatToCheckOptions, WhatToCheck )