diff options
-rw-r--r-- | share/qtcreator/templates/wizards/projects/qtquickapplication/wizard.json | 6 | ||||
-rw-r--r-- | src/libs/utils/scopedtimer.cpp | 41 | ||||
-rw-r--r-- | src/libs/utils/scopedtimer.h | 24 | ||||
-rw-r--r-- | src/plugins/clangcodemodel/clangmodelmanagersupport.cpp | 22 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelsettings.cpp | 16 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelsettings.h | 5 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppcodemodelsettingspage.cpp | 27 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimplugin.cpp | 19 | ||||
-rw-r--r-- | tests/auto/utils/text/text.qbs | 2 | ||||
-rw-r--r-- | tests/auto/utils/utils.qbs | 1 |
10 files changed, 132 insertions, 31 deletions
diff --git a/share/qtcreator/templates/wizards/projects/qtquickapplication/wizard.json b/share/qtcreator/templates/wizards/projects/qtquickapplication/wizard.json index 8b4165fa35..dbfe93bbca 100644 --- a/share/qtcreator/templates/wizards/projects/qtquickapplication/wizard.json +++ b/share/qtcreator/templates/wizards/projects/qtquickapplication/wizard.json @@ -81,7 +81,11 @@ "type": "ComboBox", "data": { - "items": [ "6.2", "6.4", "6.5" ], + "items": [ + { "trKey": "Qt 6.2", "value": "6.2" }, + { "trKey": "Qt 6.4", "value": "6.4" }, + { "trKey": "Qt 6.5", "value": "6.5" } + ], "index": 1 } } diff --git a/src/libs/utils/scopedtimer.cpp b/src/libs/utils/scopedtimer.cpp index 97b8beffda..6a4522e28d 100644 --- a/src/libs/utils/scopedtimer.cpp +++ b/src/libs/utils/scopedtimer.cpp @@ -3,7 +3,6 @@ #include "scopedtimer.h" -#include <QByteArray> #include <QDebug> #include <QTime> @@ -15,25 +14,31 @@ static QString currentTime() { return QTime::currentTime().toString(Qt::ISODateW using namespace std::chrono; +static const char s_scoped[] = "SCOPED TIMER"; +static const char s_scopedCumulative[] = "STATIC SCOPED TIMER"; + class ScopedTimerPrivate { public: - const char *m_fileName = nullptr; - const int m_line = 0; - std::atomic<int64_t> *m_cumulative = nullptr; + QString header() const { + const char *scopedTimerType = m_data.m_cumulative ? s_scopedCumulative : s_scoped; + const QString prefix = QLatin1String(scopedTimerType) + " [" + currentTime() + "] "; + const QString infix = m_data.m_message.isEmpty() + ? QLatin1String(m_data.m_fileName) + ':' + QString::number(m_data.m_line) + : m_data.m_message; + return prefix + infix + ' '; + } + + const ScopedTimerData m_data; const time_point<system_clock, nanoseconds> m_start = system_clock::now(); }; -static const char s_scoped[] = "SCOPED TIMER"; -static const char s_scopedCumulative[] = "STATIC SCOPED TIMER"; - -ScopedTimer::ScopedTimer(const char *fileName, int line, std::atomic<int64_t> *cumulative) - : d(new ScopedTimerPrivate{fileName, line, cumulative}) +ScopedTimer::ScopedTimer(const ScopedTimerData &data) + : d(new ScopedTimerPrivate{data}) { - if (d->m_cumulative) + if (d->m_data.m_cumulative) return; - qDebug().noquote().nospace() << s_scoped << " [" << currentTime() << "] in " << d->m_fileName - << ':' << d->m_line << " started"; + qDebug().noquote().nospace() << d->header() << "started"; } static int64_t toMs(int64_t ns) { return ns / 1000000; } @@ -42,8 +47,8 @@ ScopedTimer::~ScopedTimer() { const auto elapsed = duration_cast<nanoseconds>(system_clock::now() - d->m_start); QString suffix; - if (d->m_cumulative) { - const int64_t nsOld = d->m_cumulative->fetch_add(elapsed.count()); + if (d->m_data.m_cumulative) { + const int64_t nsOld = d->m_data.m_cumulative->fetch_add(elapsed.count()); const int64_t msOld = toMs(nsOld); const int64_t nsNew = nsOld + elapsed.count(); const int64_t msNew = toMs(nsNew); @@ -52,13 +57,11 @@ ScopedTimer::~ScopedTimer() if (nsOld != 0 && msOld / 10 == msNew / 10) return; - suffix = " cumulative timeout: " + QString::number(msNew) + "ms"; + suffix = "cumulative timeout: " + QString::number(msNew) + "ms"; } else { - suffix = " stopped with timeout: " + QString::number(toMs(elapsed.count())) + "ms"; + suffix = "stopped with timeout: " + QString::number(toMs(elapsed.count())) + "ms"; } - const char *header = d->m_cumulative ? s_scopedCumulative : s_scoped; - qDebug().noquote().nospace() << header << " [" << currentTime() << "] in " << d->m_fileName - << ':' << d->m_line << suffix; + qDebug().noquote().nospace() << d->header() << suffix; } } // namespace Utils diff --git a/src/libs/utils/scopedtimer.h b/src/libs/utils/scopedtimer.h index e6ec42e6f4..d66ef15841 100644 --- a/src/libs/utils/scopedtimer.h +++ b/src/libs/utils/scopedtimer.h @@ -5,6 +5,8 @@ #include "utils_global.h" +#include <QString> + #include <atomic> #include <memory> @@ -12,10 +14,19 @@ namespace Utils { class ScopedTimerPrivate; +class QTCREATOR_UTILS_EXPORT ScopedTimerData +{ +public: + QString m_message; + const char *m_fileName = nullptr; + int m_line = 0; + std::atomic<int64_t> *m_cumulative = nullptr; +}; + class QTCREATOR_UTILS_EXPORT ScopedTimer { public: - ScopedTimer(const char *fileName, int line, std::atomic<int64_t> *cumulative = nullptr); + ScopedTimer(const ScopedTimerData &data); ~ScopedTimer(); private: @@ -24,15 +35,18 @@ private: } // Utils +// The "message" argument of QTC_SCOPED_TIMER() and QTC_STATIC_SCOPED_TIMER() macros is optional. +// When provided, it should evaluate to QString. + #define QTC_CONCAT_HELPER(x, y) x ## y #define QTC_CONCAT(x, y) QTC_CONCAT_HELPER(x, y) -#define QTC_SCOPED_TIMER() ::Utils::ScopedTimer QTC_CONCAT(_qtc_scoped_timer_, __LINE__)\ -(__FILE__, __LINE__) +#define QTC_SCOPED_TIMER(message) ::Utils::ScopedTimer QTC_CONCAT(_qtc_scoped_timer_, __LINE__)\ +({{message}, __FILE__, __LINE__}) // The macro below expands as follows (in one line): // static std::atomic<int64_t> _qtc_static_scoped_timer___LINE__ = 0; // ScopedTimer _qtc_scoped_timer___LINE__(__FILE__, __LINE__, &_qtc_static_scoped_timer___LINE__) -#define QTC_STATIC_SCOPED_TIMER() static std::atomic<int64_t> \ +#define QTC_STATIC_SCOPED_TIMER(message) static std::atomic<int64_t> \ QTC_CONCAT(_qtc_static_scoped_timer_, __LINE__) = 0; \ ::Utils::ScopedTimer QTC_CONCAT(_qtc_scoped_timer_, __LINE__)\ -(__FILE__, __LINE__, &QTC_CONCAT(_qtc_static_scoped_timer_, __LINE__)) +({{message}, __FILE__, __LINE__, &QTC_CONCAT(_qtc_static_scoped_timer_, __LINE__)}) diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index 1dd66db3cd..8aea72ce0e 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -352,10 +352,24 @@ void ClangModelManagerSupport::findUsages(const CursorInEditor &cursor) const void ClangModelManagerSupport::switchHeaderSource(const FilePath &filePath, bool inNextSplit) { - if (ClangdClient * const client = clientForFile(filePath)) - client->switchHeaderSource(filePath, inNextSplit); - else - CppModelManager::switchHeaderSource(inNextSplit, CppModelManager::Backend::Builtin); + if (ClangdClient * const client = clientForFile(filePath)) { + switch (ClangdProjectSettings(client->project()).settings().headerSourceSwitchMode) { + case ClangdSettings::HeaderSourceSwitchMode::BuiltinOnly: + CppModelManager::switchHeaderSource(inNextSplit, CppModelManager::Backend::Builtin); + return; + case ClangdSettings::HeaderSourceSwitchMode::ClangdOnly: + client->switchHeaderSource(filePath, inNextSplit); + return; + case ClangdSettings::HeaderSourceSwitchMode::Both: + const FilePath otherFile = correspondingHeaderOrSource(filePath); + if (!otherFile.isEmpty()) + openEditor(otherFile, inNextSplit); + else + client->switchHeaderSource(filePath, inNextSplit); + return; + } + } + CppModelManager::switchHeaderSource(inNextSplit, CppModelManager::Backend::Builtin); } void ClangModelManagerSupport::checkUnused(const Link &link, SearchResult *search, diff --git a/src/plugins/cppeditor/cppcodemodelsettings.cpp b/src/plugins/cppeditor/cppcodemodelsettings.cpp index 5919a97b84..2f4fdffab2 100644 --- a/src/plugins/cppeditor/cppcodemodelsettings.cpp +++ b/src/plugins/cppeditor/cppcodemodelsettings.cpp @@ -64,6 +64,9 @@ static QString useClangdKey() { return QLatin1String("UseClangdV7"); } static QString clangdPathKey() { return QLatin1String("ClangdPath"); } static QString clangdIndexingKey() { return QLatin1String("ClangdIndexing"); } static QString clangdIndexingPriorityKey() { return QLatin1String("ClangdIndexingPriority"); } +static QString clangdHeaderSourceSwitchModeKey() { + return QLatin1String("ClangdHeaderSourceSwitchMode"); +} static QString clangdHeaderInsertionKey() { return QLatin1String("ClangdHeaderInsertion"); } static QString clangdThreadLimitKey() { return QLatin1String("ClangdThreadLimit"); } static QString clangdDocumentThresholdKey() { return QLatin1String("ClangdDocumentThreshold"); } @@ -229,6 +232,16 @@ QString ClangdSettings::priorityToDisplayString(const IndexingPriority &priority return {}; } +QString ClangdSettings::headerSourceSwitchModeToDisplayString(HeaderSourceSwitchMode mode) +{ + switch (mode) { + case HeaderSourceSwitchMode::BuiltinOnly: return Tr::tr("Use Built-in Only"); + case HeaderSourceSwitchMode::ClangdOnly: return Tr::tr("Use Clangd Only"); + case HeaderSourceSwitchMode::Both: return Tr::tr("Try Both"); + } + return {}; +} + ClangdSettings &ClangdSettings::instance() { static ClangdSettings settings; @@ -528,6 +541,7 @@ QVariantMap ClangdSettings::Data::toMap() const : QString()); map.insert(clangdIndexingKey(), indexingPriority != IndexingPriority::Off); map.insert(clangdIndexingPriorityKey(), int(indexingPriority)); + map.insert(clangdHeaderSourceSwitchModeKey(), int(headerSourceSwitchMode)); map.insert(clangdHeaderInsertionKey(), autoIncludeHeaders); map.insert(clangdThreadLimitKey(), workerThreadLimit); map.insert(clangdDocumentThresholdKey(), documentUpdateThreshold); @@ -549,6 +563,8 @@ void ClangdSettings::Data::fromMap(const QVariantMap &map) const auto it = map.find(clangdIndexingKey()); if (it != map.end() && !it->toBool()) indexingPriority = IndexingPriority::Off; + headerSourceSwitchMode = HeaderSourceSwitchMode(map.value(clangdHeaderSourceSwitchModeKey(), + int(headerSourceSwitchMode)).toInt()); autoIncludeHeaders = map.value(clangdHeaderInsertionKey(), false).toBool(); workerThreadLimit = map.value(clangdThreadLimitKey(), 0).toInt(); documentUpdateThreshold = map.value(clangdDocumentThresholdKey(), 500).toInt(); diff --git a/src/plugins/cppeditor/cppcodemodelsettings.h b/src/plugins/cppeditor/cppcodemodelsettings.h index 7bfdc2e85e..c22fb88faa 100644 --- a/src/plugins/cppeditor/cppcodemodelsettings.h +++ b/src/plugins/cppeditor/cppcodemodelsettings.h @@ -84,9 +84,11 @@ class CPPEDITOR_EXPORT ClangdSettings : public QObject Q_OBJECT public: enum class IndexingPriority { Off, Background, Normal, Low, }; + enum class HeaderSourceSwitchMode { BuiltinOnly, ClangdOnly, Both }; static QString priorityToString(const IndexingPriority &priority); static QString priorityToDisplayString(const IndexingPriority &priority); + static QString headerSourceSwitchModeToDisplayString(HeaderSourceSwitchMode mode); class CPPEDITOR_EXPORT Data { @@ -103,6 +105,7 @@ public: && s1.diagnosticConfigId == s2.diagnosticConfigId && s1.workerThreadLimit == s2.workerThreadLimit && s1.indexingPriority == s2.indexingPriority + && s1.headerSourceSwitchMode == s2.headerSourceSwitchMode && s1.autoIncludeHeaders == s2.autoIncludeHeaders && s1.documentUpdateThreshold == s2.documentUpdateThreshold && s1.sizeThresholdEnabled == s2.sizeThresholdEnabled @@ -123,6 +126,7 @@ public: qint64 sizeThresholdInKb = 1024; bool useClangd = true; IndexingPriority indexingPriority = IndexingPriority::Low; + HeaderSourceSwitchMode headerSourceSwitchMode = HeaderSourceSwitchMode::Both; bool autoIncludeHeaders = false; bool sizeThresholdEnabled = false; bool haveCheckedHardwareReqirements = false; @@ -143,6 +147,7 @@ public: static void setCustomDiagnosticConfigs(const ClangDiagnosticConfigs &configs); Utils::FilePath clangdFilePath() const; IndexingPriority indexingPriority() const { return m_data.indexingPriority; } + HeaderSourceSwitchMode headerSourceSwitchMode() const { return m_data.headerSourceSwitchMode; } bool autoIncludeHeaders() const { return m_data.autoIncludeHeaders; } int workerThreadLimit() const { return m_data.workerThreadLimit; } int documentUpdateThreshold() const { return m_data.documentUpdateThreshold; } diff --git a/src/plugins/cppeditor/cppcodemodelsettingspage.cpp b/src/plugins/cppeditor/cppcodemodelsettingspage.cpp index 00224f5d90..88f5bf0de8 100644 --- a/src/plugins/cppeditor/cppcodemodelsettingspage.cpp +++ b/src/plugins/cppeditor/cppcodemodelsettingspage.cpp @@ -192,6 +192,7 @@ class ClangdSettingsWidget::Private public: QCheckBox useClangdCheckBox; QComboBox indexingComboBox; + QComboBox headerSourceSwitchComboBox; QCheckBox autoIncludeHeadersCheckBox; QCheckBox sizeThresholdCheckBox; QSpinBox threadLimitSpinBox; @@ -220,6 +221,12 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD "cores unused.</p>" "<p>Normal Priority: Reduced priority compared to interactive work.</p>" "Low Priority: Same priority as other clangd work."); + const QString headerSourceSwitchToolTip = Tr::tr( + "<p>Which C/C++ backend to use when switching between header and source file." + "<p>The clangd implementation has more capabilities, but also has some bugs not present " + "in the built-in variant." + "<p>When \"Try Both\" is selected, clangd will be employed only if the built-in variant " + "does not find anything."); const QString workerThreadsToolTip = Tr::tr( "Number of worker threads used by clangd. Background indexing also uses this many " "worker threads."); @@ -249,6 +256,15 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD d->indexingComboBox.setCurrentIndex(d->indexingComboBox.count() - 1); } d->indexingComboBox.setToolTip(indexingToolTip); + using SwitchMode = ClangdSettings::HeaderSourceSwitchMode; + for (SwitchMode mode : {SwitchMode::BuiltinOnly, SwitchMode::ClangdOnly, SwitchMode::Both}) { + d->headerSourceSwitchComboBox.addItem( + ClangdSettings::headerSourceSwitchModeToDisplayString(mode), int(mode)); + if (mode == settings.headerSourceSwitchMode()) + d->headerSourceSwitchComboBox.setCurrentIndex( + d->headerSourceSwitchComboBox.count() - 1); + } + d->headerSourceSwitchComboBox.setToolTip(headerSourceSwitchToolTip); d->autoIncludeHeadersCheckBox.setText(Tr::tr("Insert header files on completion")); d->autoIncludeHeadersCheckBox.setChecked(settings.autoIncludeHeaders()); d->autoIncludeHeadersCheckBox.setToolTip(autoIncludeToolTip); @@ -294,6 +310,13 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD indexingPriorityLabel->setToolTip(indexingToolTip); formLayout->addRow(indexingPriorityLabel, indexingPriorityLayout); + const auto headerSourceSwitchLayout = new QHBoxLayout; + headerSourceSwitchLayout->addWidget(&d->headerSourceSwitchComboBox); + headerSourceSwitchLayout->addStretch(1); + const auto headerSourceSwitchLabel = new QLabel(Tr::tr("Header/source switch mode:")); + headerSourceSwitchLabel->setToolTip(headerSourceSwitchToolTip); + formLayout->addRow(headerSourceSwitchLabel, headerSourceSwitchLayout); + const auto threadLimitLayout = new QHBoxLayout; threadLimitLayout->addWidget(&d->threadLimitSpinBox); threadLimitLayout->addStretch(1); @@ -449,6 +472,8 @@ ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsD this, &ClangdSettingsWidget::settingsDataChanged); connect(&d->indexingComboBox, &QComboBox::currentIndexChanged, this, &ClangdSettingsWidget::settingsDataChanged); + connect(&d->headerSourceSwitchComboBox, &QComboBox::currentIndexChanged, + this, &ClangdSettingsWidget::settingsDataChanged); connect(&d->autoIncludeHeadersCheckBox, &QCheckBox::toggled, this, &ClangdSettingsWidget::settingsDataChanged); connect(&d->threadLimitSpinBox, &QSpinBox::valueChanged, @@ -479,6 +504,8 @@ ClangdSettings::Data ClangdSettingsWidget::settingsData() const data.executableFilePath = d->clangdChooser.filePath(); data.indexingPriority = ClangdSettings::IndexingPriority( d->indexingComboBox.currentData().toInt()); + data.headerSourceSwitchMode = ClangdSettings::HeaderSourceSwitchMode( + d->headerSourceSwitchComboBox.currentData().toInt()); data.autoIncludeHeaders = d->autoIncludeHeadersCheckBox.isChecked(); data.workerThreadLimit = d->threadLimitSpinBox.value(); data.documentUpdateThreshold = d->documentUpdateThreshold.value(); diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index be06ece7f4..4935492132 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -514,6 +514,8 @@ public: void handleDelayedQuit(bool forced, Core::IEditor *editor); void userActionTriggered(int key); + void updateAllHightLights(); + void switchToFile(int n); int currentFile() const; @@ -557,6 +559,8 @@ public: MiniBuffer *m_miniBuffer = nullptr; FakeVimPluginRunData *runData = nullptr; + QString m_lastHighlight; + int m_savedCursorFlashTime = 0; }; @@ -1252,6 +1256,16 @@ void FakeVimPluginPrivate::userActionTriggered(int key) } } +void FakeVimPluginPrivate::updateAllHightLights() +{ + const QList<IEditor *> editors = EditorManager::visibleEditors(); + for (IEditor *editor : editors) { + QWidget *w = editor->widget(); + if (auto find = Aggregation::query<IFindSupport>(w)) + find->highlightAll(m_lastHighlight, FindRegularExpression | FindCaseSensitively); + } +} + void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor) { if (auto textEditor = TextEditorWidget::fromEditor(editor)) { @@ -1598,7 +1612,8 @@ void FakeVimPluginPrivate::editorOpened(IEditor *editor) tew->clearSuggestion(); }); - handler->highlightMatches.set([](const QString &needle) { + handler->highlightMatches.set([this](const QString &needle) { + m_lastHighlight = needle; for (IEditor *editor : EditorManager::visibleEditors()) { QWidget *w = editor->widget(); if (auto find = Aggregation::query<IFindSupport>(w)) @@ -2034,9 +2049,11 @@ void FakeVimPluginPrivate::handleExCommand(FakeVimHandler *handler, bool *handle } else if (cmd.matches("sp", "split")) { // :sp[lit] triggerAction(Core::Constants::SPLIT); + updateAllHightLights(); } else if (cmd.matches("vs", "vsplit")) { // :vs[plit] triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE); + updateAllHightLights(); } else if (cmd.matches("mak", "make")) { // :mak[e][!] [arguments] triggerAction(ProjectExplorer::Constants::BUILD); diff --git a/tests/auto/utils/text/text.qbs b/tests/auto/utils/text/text.qbs index 828dec8d11..91b2cdb695 100644 --- a/tests/auto/utils/text/text.qbs +++ b/tests/auto/utils/text/text.qbs @@ -1,7 +1,7 @@ import qbs QtcAutotest { - name: "Utils::Text autotest" + name: "Text autotest" Depends { name: "Utils" } files: "tst_text.cpp" } diff --git a/tests/auto/utils/utils.qbs b/tests/auto/utils/utils.qbs index e267f009f7..9f5a580435 100644 --- a/tests/auto/utils/utils.qbs +++ b/tests/auto/utils/utils.qbs @@ -20,6 +20,7 @@ Project { "settings/settings.qbs", "stringutils/stringutils.qbs", "templateengine/templateengine.qbs", + "text/text.qbs", "treemodel/treemodel.qbs", "unixdevicefileaccess/unixdevicefileaccess.qbs", ] |