From 936cb34d3748368dba712acf267f343c20a8108c Mon Sep 17 00:00:00 2001 From: liuzhangjian Date: Wed, 24 Jul 2024 14:51:23 +0800 Subject: [PATCH 1/5] fix: Fixed scrollbar display issue 1.Fixed an issue where the vertical scroll bar obscured the action button in the search results list for Advanced Search 2.Fixed an issue where horizontal scroll bar is not displayed in Project View Log: fix issues --- src/plugins/find/gui/advancedsearchwidget.cpp | 4 ++-- src/plugins/find/gui/searchresultitemdelegate.cpp | 5 ++++- src/plugins/project/mainframe/projectdelegate.cpp | 5 +++-- src/plugins/project/mainframe/projecttree.cpp | 15 ++++++++++++++- src/plugins/project/mainframe/projecttree.h | 1 + 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/plugins/find/gui/advancedsearchwidget.cpp b/src/plugins/find/gui/advancedsearchwidget.cpp index ea0e15a8f..23d1ee288 100644 --- a/src/plugins/find/gui/advancedsearchwidget.cpp +++ b/src/plugins/find/gui/advancedsearchwidget.cpp @@ -104,7 +104,7 @@ void AdvancedSearchWidgetPrivate::initUI() q->setBackgroundRole(QPalette::Base); QVBoxLayout *mainLayout = new QVBoxLayout(q); - mainLayout->setContentsMargins(10, 5, 10, 0); + mainLayout->setContentsMargins(10, 5, 0, 0); auto widget = createSearchParamWidget(); resultWidget = new SearchResultWidget(q); @@ -188,7 +188,7 @@ QWidget *AdvancedSearchWidgetPrivate::createSearchParamWidget() { QWidget *widget = new QWidget(q); QVBoxLayout *layout = new QVBoxLayout(widget); - layout->setContentsMargins(0, 0, 0, 0); + layout->setContentsMargins(0, 0, 10, 0); searchEdit = new DLineEdit(q); searchEdit->setPlaceholderText(AdvancedSearchWidget::tr("Search")); diff --git a/src/plugins/find/gui/searchresultitemdelegate.cpp b/src/plugins/find/gui/searchresultitemdelegate.cpp index 819acc1f9..611321b8e 100644 --- a/src/plugins/find/gui/searchresultitemdelegate.cpp +++ b/src/plugins/find/gui/searchresultitemdelegate.cpp @@ -42,6 +42,7 @@ void SearchResultItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt QStyleOptionViewItem opt = option; DStyledItemDelegate::initStyleOption(&opt, index); + opt.rect.adjust(0, 0, -10, 0); painter->setRenderHint(QPainter::Antialiasing); drawBackground(painter, opt); @@ -55,7 +56,9 @@ void SearchResultItemDelegate::paint(QPainter *painter, const QStyleOptionViewIt QSize SearchResultItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - return { 1000, 24 }; + auto size = DStyledItemDelegate::sizeHint(option, index); + size.setHeight(24); + return size; } bool SearchResultItemDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) diff --git a/src/plugins/project/mainframe/projectdelegate.cpp b/src/plugins/project/mainframe/projectdelegate.cpp index a493aeb3b..e55b61306 100644 --- a/src/plugins/project/mainframe/projectdelegate.cpp +++ b/src/plugins/project/mainframe/projectdelegate.cpp @@ -68,8 +68,9 @@ void ProjectDelegate::paint(QPainter *painter, QSize ProjectDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - Q_UNUSED(index) - return { option.rect.width(), 24 }; + auto size = BaseItemDelegate::sizeHint(option, index); + size.setHeight(24); + return size; } void ProjectDelegate::hideSpinner() diff --git a/src/plugins/project/mainframe/projecttree.cpp b/src/plugins/project/mainframe/projecttree.cpp index 01e5d8254..6aa693b1c 100644 --- a/src/plugins/project/mainframe/projecttree.cpp +++ b/src/plugins/project/mainframe/projecttree.cpp @@ -61,10 +61,14 @@ ProjectTree::ProjectTree(QWidget *parent) DStyle::setFrameRadius(this, 0); setIconSize(QSize(16, 16)); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + setTextElideMode(Qt::ElideNone); setEditTriggers(DTreeView::NoEditTriggers); //节点不能编辑 setSelectionBehavior(DTreeView::SelectRows); //一次选中整行 setSelectionMode(DTreeView::SingleSelection); //单选,配合上面的整行就是一次选单行 - this->header()->hide(); + setHeaderHidden(true); + header()->setSectionResizeMode(QHeaderView::ResizeToContents); + header()->setStretchLastSection(false); d->itemModel = new ProjectModel(this); setModel(d->itemModel); @@ -418,6 +422,15 @@ void ProjectTree::mouseMoveEvent(QMouseEvent *event) DTreeView::mouseMoveEvent(event); } +void ProjectTree::resizeEvent(QResizeEvent *event) +{ + const int columns = header()->count(); + const int minimumWidth = columns > 1 ? viewport()->width() / columns + : viewport()->width(); + header()->setMinimumSectionSize(minimumWidth); + DTreeView::resizeEvent(event); +} + DMenu *ProjectTree::childMenu(const QStandardItem *root, QStandardItem *childItem) { DMenu *menu = nullptr; diff --git a/src/plugins/project/mainframe/projecttree.h b/src/plugins/project/mainframe/projecttree.h index 9d2f67809..f120e814f 100644 --- a/src/plugins/project/mainframe/projecttree.h +++ b/src/plugins/project/mainframe/projecttree.h @@ -48,6 +48,7 @@ class ProjectTree : public DTreeView void contextMenuEvent(QContextMenuEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; + void resizeEvent(QResizeEvent *event) override; private: DMenu *childMenu(const QStandardItem *root, QStandardItem *child); From 4e42c4c589b7bf2751ec69ff1131f80e19718307 Mon Sep 17 00:00:00 2001 From: Zhang TingAn Date: Wed, 24 Jul 2024 13:27:37 +0800 Subject: [PATCH 2/5] fix: [cmake] remove "cancel" action from projcet`s menu Log: as title --- src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp b/src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp index 5832e0605..b5e2f9c36 100644 --- a/src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp +++ b/src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp @@ -636,7 +636,6 @@ void CmakeProjectGenerator::createBuildMenu(QMenu *menu) addBuildMenu("Build.Build"); addBuildMenu("Build.Rebuild"); addBuildMenu("Build.Clean"); - addBuildMenu("Build.Cancel"); addBuildMenu("Build.RunCMake"); addBuildMenu("Build.ClearCMake"); menu->addSeparator(); From 79a006bfa1979f176575a609e0f858c63b8d09bf Mon Sep 17 00:00:00 2001 From: Zhang TingAn Date: Wed, 24 Jul 2024 14:20:55 +0800 Subject: [PATCH 3/5] fix: [run] incorret arguments when run/debug application Log: as title --- src/plugins/cxx/cmake/cmakegenerator.cpp | 1 + src/plugins/cxx/cmake/project/properties/configutil.cpp | 2 +- src/tools/debugadapter/dapsession.cpp | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/cxx/cmake/cmakegenerator.cpp b/src/plugins/cxx/cmake/cmakegenerator.cpp index 46215e8bd..9742075b1 100644 --- a/src/plugins/cxx/cmake/cmakegenerator.cpp +++ b/src/plugins/cxx/cmake/cmakegenerator.cpp @@ -91,6 +91,7 @@ QMap CMakeGenerator::getDebugArguments(const dpfservice::Proj QMap param; param.insert("workspace", projectInfo.runWorkspaceDir()); param.insert("targetPath", projectInfo.runProgram()); + param.insert("arguments", projectInfo.runCustomArgs()); return param; } diff --git a/src/plugins/cxx/cmake/project/properties/configutil.cpp b/src/plugins/cxx/cmake/project/properties/configutil.cpp index 22ecc986d..d7e3856d7 100644 --- a/src/plugins/cxx/cmake/project/properties/configutil.cpp +++ b/src/plugins/cxx/cmake/project/properties/configutil.cpp @@ -236,7 +236,7 @@ bool ConfigUtil::updateProjectInfo(dpfservice::ProjectInfo &info, const ProjectC info.setRunProgram(iterRun->targetPath); QStringList arguments; if (!iterRun->arguments.isEmpty()) - arguments << iterRun->arguments; + arguments = iterRun->arguments.split(" ", QString::SkipEmptyParts); info.setRunCustomArgs(arguments); info.setRunWorkspaceDir(iterRun->workDirectory); info.setCurrentProgram(iterRun->targetName); diff --git a/src/tools/debugadapter/dapsession.cpp b/src/tools/debugadapter/dapsession.cpp index 3d7b9a79a..1607d6863 100644 --- a/src/tools/debugadapter/dapsession.cpp +++ b/src/tools/debugadapter/dapsession.cpp @@ -342,6 +342,7 @@ void DapSession::registerHanlder() QStringList arguments; arguments.push_back(request.program.value().c_str()); if (request.args.has_value()) { + arguments.insert(0, "--args"); foreach(auto arg, request.args.value()) { arguments.push_back(arg.c_str()); } From 8ffdfa5031e343a538a17a15ac2516d52d84634e Mon Sep 17 00:00:00 2001 From: liuzhangjian Date: Wed, 24 Jul 2024 09:57:02 +0800 Subject: [PATCH 4/5] fix: Fixed an issue where the completion was abnormal in some scenarios as title Log: fix issue --- .../gui/completion/codecompletionmodel.cpp | 6 +++- .../gui/completion/codecompletionwidget.cpp | 32 +++++++++++++++++++ .../gui/completion/codecompletionwidget.h | 6 ++++ src/plugins/cxx/lexer/scilexercpp.cpp | 2 +- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/plugins/codeeditor/gui/completion/codecompletionmodel.cpp b/src/plugins/codeeditor/gui/completion/codecompletionmodel.cpp index 7e8660f4e..de4c82822 100644 --- a/src/plugins/codeeditor/gui/completion/codecompletionmodel.cpp +++ b/src/plugins/codeeditor/gui/completion/codecompletionmodel.cpp @@ -126,7 +126,11 @@ lsp::Range CodeCompletionModel::range() const if (d->completionDatas.isEmpty()) return {}; - return d->completionDatas.first().textEdit.range; + const auto &item = d->completionDatas.first(); + if (item.textEdit.newText.isEmpty()) + return {}; + + return item.textEdit.range; } lsp::CompletionItem *CodeCompletionModel::item(const QModelIndex &index) const diff --git a/src/plugins/codeeditor/gui/completion/codecompletionwidget.cpp b/src/plugins/codeeditor/gui/completion/codecompletionwidget.cpp index 0e301971f..b051ae559 100644 --- a/src/plugins/codeeditor/gui/completion/codecompletionwidget.cpp +++ b/src/plugins/codeeditor/gui/completion/codecompletionwidget.cpp @@ -160,6 +160,14 @@ void CodeCompletionWidget::executeCompletionItem(const QModelIndex &index) if (!item) return; + if (!item->textEdit.newText.isEmpty()) + executeWithTextEdit(item); + else + executeWithoutTextEdit(item); +} + +void CodeCompletionWidget::executeWithTextEdit(lsp::CompletionItem *item) +{ int labelOpenParenOffset = item->label.indexOf('('); int labelClosingParenOffset = item->label.indexOf(')'); bool isMacroCall = item->kind == lsp::CompletionItem::Text && labelOpenParenOffset != -1 @@ -204,6 +212,30 @@ void CodeCompletionWidget::executeCompletionItem(const QModelIndex &index) } } +void CodeCompletionWidget::executeWithoutTextEdit(lsp::CompletionItem *item) +{ + const int pos = editor()->cursorPosition(); + const QString textToInsert(item->insertText); + int length = 0; + for (auto it = textToInsert.crbegin(), end = textToInsert.crend(); it != end; ++it) { + char character = editor()->SendScintilla(TextEditor::SCI_GETCHARAT, pos - length - 1); + if (it->toLower() != QChar(character).toLower()) { + length = 0; + break; + } + ++length; + } + + int line = editor()->SendScintilla(TextEditor::SCI_LINEFROMPOSITION, pos); + int lineStartPos = editor()->SendScintilla(TextEditor::SCI_POSITIONFROMLINE, line); + const auto &text = editor()->text(lineStartPos, pos); + static QRegularExpression identifier("[a-zA-Z_][a-zA-Z0-9_]*$"); + QRegularExpressionMatch match = identifier.match(text); + int matchLength = match.hasMatch() ? match.capturedLength(0) : 0; + length = qMax(length, matchLength); + editor()->replaceRange(pos - length, pos, textToInsert); +} + void CodeCompletionWidget::modelContentChanged() { if (!editor()->hasFocus()) diff --git a/src/plugins/codeeditor/gui/completion/codecompletionwidget.h b/src/plugins/codeeditor/gui/completion/codecompletionwidget.h index 69fcb270b..4cb37ba72 100644 --- a/src/plugins/codeeditor/gui/completion/codecompletionwidget.h +++ b/src/plugins/codeeditor/gui/completion/codecompletionwidget.h @@ -7,6 +7,10 @@ #include +namespace lsp { +struct CompletionItem; +} + class TextEditor; class CodeCompletionView; class CodeCompletionModel; @@ -48,6 +52,8 @@ public slots: QString filterString(); bool isFunctionKind(int kind); void executeCompletionItem(const QModelIndex &index); + void executeWithTextEdit(lsp::CompletionItem *item); + void executeWithoutTextEdit(lsp::CompletionItem *item); private slots: void modelContentChanged(); diff --git a/src/plugins/cxx/lexer/scilexercpp.cpp b/src/plugins/cxx/lexer/scilexercpp.cpp index 6f5685e01..de22144ca 100644 --- a/src/plugins/cxx/lexer/scilexercpp.cpp +++ b/src/plugins/cxx/lexer/scilexercpp.cpp @@ -389,7 +389,7 @@ const char *SciLexerCPP::keywords(int set) const return "and and_eq asm auto bitand bitor bool break case catch " "char class compl const const_cast continue default " "delete do double dynamic_cast else enum explicit export " - "extern false farcall float for friend goto if inline int " + "extern false farcall final float for friend goto if inline int " "long mutable namespace new not not_eq nullptr null out " "operator or or_eq override private protected public println register " "reinterpret_cast return short signed sizeof static system " From 279a16ba5296edecfff3027f129b876939c43120 Mon Sep 17 00:00:00 2001 From: Zhang TingAn Date: Mon, 22 Jul 2024 15:56:59 +0800 Subject: [PATCH 5/5] feat: [codegeex] add options of locale Log: as title --- src/plugins/codegeex/codegeexmanager.h | 1 + src/plugins/codegeex/copilot.cpp | 7 +++- src/plugins/codegeex/copilot.h | 2 ++ src/plugins/codegeex/option/detailwidget.cpp | 38 ++++++++++++++++++++ src/plugins/codegeex/option/detailwidget.h | 2 ++ 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/plugins/codegeex/codegeexmanager.h b/src/plugins/codegeex/codegeexmanager.h index 92e779a53..eb72cd1e1 100644 --- a/src/plugins/codegeex/codegeexmanager.h +++ b/src/plugins/codegeex/codegeexmanager.h @@ -40,6 +40,7 @@ namespace CodeGeeX { }; } Q_DECLARE_METATYPE(CodeGeeX::languageModel) +Q_DECLARE_METATYPE(CodeGeeX::locale) typedef QPair chatRecord; class CodeGeeXManager : public QObject diff --git a/src/plugins/codegeex/copilot.cpp b/src/plugins/codegeex/copilot.cpp index 5e22ec670..c53af6340 100644 --- a/src/plugins/codegeex/copilot.cpp +++ b/src/plugins/codegeex/copilot.cpp @@ -145,6 +145,11 @@ void Copilot::setLocale(const QString &locale) this->locale = locale; } +void Copilot::setCommitsLocale(const QString &locale) +{ + this->commitsLocale = locale; +} + void Copilot::setCurrentModel(CodeGeeX::languageModel model) { copilotApi.setModel(model); @@ -241,7 +246,7 @@ void Copilot::commits() auto diff = QString::fromUtf8(process.readAll()); QString url = QString(kUrlSSEChat) + "?stream=true"; - copilotApi.postCommand(url, diff, locale, commandCommits); + copilotApi.postCommand(url, diff, commitsLocale, commandCommits); switchToCodegeexPage(); }); diff --git a/src/plugins/codegeex/copilot.h b/src/plugins/codegeex/copilot.h index 6d0ffbd3c..3fa6a3353 100644 --- a/src/plugins/codegeex/copilot.h +++ b/src/plugins/codegeex/copilot.h @@ -27,6 +27,7 @@ class Copilot : public QObject void insterText(const QString &text); void setGenerateCodeEnabled(bool enabled); void setLocale(const QString &locale); + void setCommitsLocale(const QString &locale); void setCurrentModel(CodeGeeX::languageModel model); void handleTextChanged(); @@ -54,6 +55,7 @@ public slots: explicit Copilot(QObject *parent = nullptr); QString selectedText() const; QString locale { "zh" }; + QString commitsLocale { "zh" }; void switchToCodegeexPage(); bool responseValid(const QString &response); QString assembleCodeByCurrentFile(const QString &code); diff --git a/src/plugins/codegeex/option/detailwidget.cpp b/src/plugins/codegeex/option/detailwidget.cpp index 313d7d826..47b5b04f4 100644 --- a/src/plugins/codegeex/option/detailwidget.cpp +++ b/src/plugins/codegeex/option/detailwidget.cpp @@ -27,12 +27,16 @@ DWIDGET_USE_NAMESPACE static const char *kCodeCompletion = "codeCompletion"; static const char *kModel = "model"; +static const char *kGlobalLanguage = "globalLanguage"; +static const char *kCommitsLanguage = "commitsLanguage"; class DetailWidgetPrivate { friend class DetailWidget; DCheckBox *cbCodeCompletion = nullptr; + DComboBox *globalLanguageBox = nullptr; + DComboBox *commitsLanguageBox = nullptr; DComboBox *modelBox = nullptr; }; @@ -61,6 +65,22 @@ void DetailWidget::setupUi() completionLayout->addWidget(completionLabel); completionLayout->addWidget(d->cbCodeCompletion); + QHBoxLayout *languageLayout = new QHBoxLayout; + DLabel *languageLabel = new DLabel(QLabel::tr("Global Language Preference:"), this); + d->globalLanguageBox = new DComboBox(this); + d->globalLanguageBox->addItem("English", CodeGeeX::En); + d->globalLanguageBox->addItem("简体中文", CodeGeeX::Zh); + languageLayout->addWidget(languageLabel); + languageLayout->addWidget(d->globalLanguageBox); + + QHBoxLayout *commitsLanguageLayout = new QHBoxLayout; + DLabel *commitsLabel = new DLabel(QLabel::tr("Commits Language Preference:"), this); + d->commitsLanguageBox = new DComboBox(this); + d->commitsLanguageBox->addItem("English", CodeGeeX::En); + d->commitsLanguageBox->addItem("简体中文", CodeGeeX::Zh); + commitsLanguageLayout->addWidget(commitsLabel); + commitsLanguageLayout->addWidget(d->commitsLanguageBox); + QHBoxLayout *modelLayout = new QHBoxLayout; DLabel *modelLabel = new DLabel(QLabel::tr("model"), this); d->modelBox = new DComboBox(this); @@ -77,6 +97,8 @@ void DetailWidget::setupUi() }); vLayout->addLayout(completionLayout); + vLayout->addLayout(languageLayout); + vLayout->addLayout(commitsLanguageLayout); vLayout->addLayout(modelLayout); vLayout->addStretch(); } @@ -86,9 +108,13 @@ bool DetailWidget::getControlValue(QMap &map) CodeGeeXConfig config; config.codeCompletionEnabled = d->cbCodeCompletion->isChecked(); config.model = d->modelBox->currentData().value(); + config.globalLanguage = d->globalLanguageBox->currentData().value(); + config.commitsLanguage = d->commitsLanguageBox->currentData().value(); dataToMap(config, map); Copilot::instance()->setGenerateCodeEnabled(config.codeCompletionEnabled); + Copilot::instance()->setCommitsLocale(config.commitsLanguage == CodeGeeX::Zh ? "zh" : "cn"); + CodeGeeXManager::instance()->setLocale(config.globalLanguage); CodeGeeXManager::instance()->setCurrentModel(config.model); return true; } @@ -104,6 +130,9 @@ void DetailWidget::setControlValue(const QMap &map) if (d->modelBox->itemData(index) == config.model) d->modelBox->setCurrentIndex(index); } + + d->globalLanguageBox->setCurrentText(config.globalLanguage == CodeGeeX::Zh ? "简体中文" : "English"); + d->commitsLanguageBox->setCurrentText(config.commitsLanguage == CodeGeeX::Zh ? "简体中文" : "English"); } bool DetailWidget::dataToMap(const CodeGeeXConfig &config, QMap &map) @@ -111,6 +140,8 @@ bool DetailWidget::dataToMap(const CodeGeeXConfig &config, QMap apiKey; apiKey.insert(kCodeCompletion, config.codeCompletionEnabled); apiKey.insert(kModel, config.model); + apiKey.insert(kGlobalLanguage, config.globalLanguage); + apiKey.insert(kCommitsLanguage, config.commitsLanguage); map.insert("Detail", apiKey); @@ -126,6 +157,13 @@ bool DetailWidget::mapToData(const QMap &map, CodeGeeXConfig var = detail.value(kModel); if (var.isValid()) config.model = var.value(); + var = detail.value(kGlobalLanguage); + if (var.isValid()) + config.globalLanguage = var.value(); + var = detail.value(kCommitsLanguage); + if (var.isValid()) + config.commitsLanguage = var.value(); + return true; } diff --git a/src/plugins/codegeex/option/detailwidget.h b/src/plugins/codegeex/option/detailwidget.h index 88ef12295..eb19e83df 100644 --- a/src/plugins/codegeex/option/detailwidget.h +++ b/src/plugins/codegeex/option/detailwidget.h @@ -11,6 +11,8 @@ struct CodeGeeXConfig{ bool codeCompletionEnabled = true; + CodeGeeX::locale globalLanguage = CodeGeeX::Zh; + CodeGeeX::locale commitsLanguage = CodeGeeX::Zh; CodeGeeX::languageModel model = CodeGeeX::Lite; };