Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge from develop #816

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions src/plugins/codeeditor/gui/completion/codecompletionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/codeeditor/gui/completion/codecompletionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#include <QFrame>

namespace lsp {
struct CompletionItem;
}

class TextEditor;
class CodeCompletionView;
class CodeCompletionModel;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/plugins/codegeex/codegeexmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace CodeGeeX {
};
}
Q_DECLARE_METATYPE(CodeGeeX::languageModel)
Q_DECLARE_METATYPE(CodeGeeX::locale)

typedef QPair<QString, QString> chatRecord;
class CodeGeeXManager : public QObject
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/codegeex/copilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
});

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/codegeex/copilot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
38 changes: 38 additions & 0 deletions src/plugins/codegeex/option/detailwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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);
Expand All @@ -77,6 +97,8 @@ void DetailWidget::setupUi()
});

vLayout->addLayout(completionLayout);
vLayout->addLayout(languageLayout);
vLayout->addLayout(commitsLanguageLayout);
vLayout->addLayout(modelLayout);
vLayout->addStretch();
}
Expand All @@ -86,9 +108,13 @@ bool DetailWidget::getControlValue(QMap<QString, QVariant> &map)
CodeGeeXConfig config;
config.codeCompletionEnabled = d->cbCodeCompletion->isChecked();
config.model = d->modelBox->currentData().value<CodeGeeX::languageModel>();
config.globalLanguage = d->globalLanguageBox->currentData().value<CodeGeeX::locale>();
config.commitsLanguage = d->commitsLanguageBox->currentData().value<CodeGeeX::locale>();
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;
}
Expand All @@ -104,13 +130,18 @@ void DetailWidget::setControlValue(const QMap<QString, QVariant> &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<QString, QVariant> &map)
{
QMap<QString, QVariant> 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);

Expand All @@ -126,6 +157,13 @@ bool DetailWidget::mapToData(const QMap<QString, QVariant> &map, CodeGeeXConfig
var = detail.value(kModel);
if (var.isValid())
config.model = var.value<CodeGeeX::languageModel>();
var = detail.value(kGlobalLanguage);
if (var.isValid())
config.globalLanguage = var.value<CodeGeeX::locale>();
var = detail.value(kCommitsLanguage);
if (var.isValid())
config.commitsLanguage = var.value<CodeGeeX::locale>();


return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/codegeex/option/detailwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

struct CodeGeeXConfig{
bool codeCompletionEnabled = true;
CodeGeeX::locale globalLanguage = CodeGeeX::Zh;
CodeGeeX::locale commitsLanguage = CodeGeeX::Zh;
CodeGeeX::languageModel model = CodeGeeX::Lite;
};

Expand Down
1 change: 1 addition & 0 deletions src/plugins/cxx/cmake/cmakegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ QMap<QString, QVariant> CMakeGenerator::getDebugArguments(const dpfservice::Proj
QMap<QString, QVariant> param;
param.insert("workspace", projectInfo.runWorkspaceDir());
param.insert("targetPath", projectInfo.runProgram());
param.insert("arguments", projectInfo.runCustomArgs());

return param;
}
Expand Down
1 change: 0 additions & 1 deletion src/plugins/cxx/cmake/project/cmakeprojectgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/cxx/cmake/project/properties/configutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/cxx/lexer/scilexercpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/find/gui/advancedsearchwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/find/gui/searchresultitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/project/mainframe/projectdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 14 additions & 1 deletion src/plugins/project/mainframe/projecttree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/project/mainframe/projecttree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/tools/debugadapter/dapsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,9 @@
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());

Check warning on line 347 in src/tools/debugadapter/dapsession.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::transform algorithm instead of a raw loop.
}
}
d->debugger->initDebugger(request.name.value().c_str(), arguments);
Expand Down
Loading