From 645610c85be3b34d3e04582533cb6b0800c1c1b4 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Mon, 28 Oct 2024 13:56:46 +0800 Subject: [PATCH] fix: [completion] Optimize intelligent completion as title Log: Optimize intelligent completion --- src/base/abstractinlinecompletionprovider.cpp | 13 +++++++++++++ src/base/abstractinlinecompletionprovider.h | 4 +++- .../gui/completion/codecompletionwidget.cpp | 1 + src/plugins/codeeditor/gui/texteditor.cpp | 19 +++++++++++++++---- .../codegeex/codegeexcompletionprovider.cpp | 10 ++++++++++ .../codegeex/codegeexcompletionprovider.h | 2 ++ 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/base/abstractinlinecompletionprovider.cpp b/src/base/abstractinlinecompletionprovider.cpp index 53b4c7705..6685a8449 100644 --- a/src/base/abstractinlinecompletionprovider.cpp +++ b/src/base/abstractinlinecompletionprovider.cpp @@ -8,3 +8,16 @@ AbstractInlineCompletionProvider::AbstractInlineCompletionProvider(QObject *pare : QObject(parent) { } + +bool AbstractInlineCompletionProvider::inlineCompletionEnabled() const +{ + return false; +} + +void AbstractInlineCompletionProvider::accepted() +{ +} + +void AbstractInlineCompletionProvider::rejected() +{ +} diff --git a/src/base/abstractinlinecompletionprovider.h b/src/base/abstractinlinecompletionprovider.h index b26a844e8..edf6899c0 100644 --- a/src/base/abstractinlinecompletionprovider.h +++ b/src/base/abstractinlinecompletionprovider.h @@ -44,7 +44,9 @@ class AbstractInlineCompletionProvider : public QObject virtual QString providerName() const = 0; virtual void provideInlineCompletionItems(const Position &pos, const InlineCompletionContext &contex) = 0; virtual QList inlineCompletionItems() const = 0; - virtual bool inlineCompletionEnabled() const { return false; } + virtual bool inlineCompletionEnabled() const; + virtual void accepted(); + virtual void rejected(); Q_SIGNALS: void finished(); diff --git a/src/plugins/codeeditor/gui/completion/codecompletionwidget.cpp b/src/plugins/codeeditor/gui/completion/codecompletionwidget.cpp index 08c59f459..2997039b6 100644 --- a/src/plugins/codeeditor/gui/completion/codecompletionwidget.cpp +++ b/src/plugins/codeeditor/gui/completion/codecompletionwidget.cpp @@ -39,6 +39,7 @@ void CodeCompletionWidget::initUI() proxyModel->setSourceModel(completionModel); completionView->setModel(proxyModel); completionView->setFixedWidth(500); + completionView->setMaximumHeight(200); completionView->setVisible(false); completionExtWidget = new CodeCompletionExtendWidget(this); diff --git a/src/plugins/codeeditor/gui/texteditor.cpp b/src/plugins/codeeditor/gui/texteditor.cpp index 1b8a903e3..45faf8929 100644 --- a/src/plugins/codeeditor/gui/texteditor.cpp +++ b/src/plugins/codeeditor/gui/texteditor.cpp @@ -8,6 +8,7 @@ #include "common/common.h" #include "common/tooltip/tooltip.h" #include "settings/settingsdefine.h" +#include "utils/resourcemanager.h" #include "services/editor/editor_define.h" @@ -848,8 +849,13 @@ void TextEditor::focusOutEvent(QFocusEvent *event) void TextEditor::keyPressEvent(QKeyEvent *event) { - if (event->key() == Qt::Key_Tab && d->inlineCompletionCache.first != -1) - return d->applyInlineCompletion(); + if (event->key() == Qt::Key_Tab && d->inlineCompletionCache.first != -1) { + d->applyInlineCompletion(); + auto providerList = ResourceManager::instance()->inlineCompletionProviders(); + for (const auto provider : providerList) + provider->accepted(); + return; + } if (event->key() == Qt::Key_Escape && d->lineWidgetContainer->isVisible()) return closeLineWidget(); @@ -857,8 +863,13 @@ void TextEditor::keyPressEvent(QKeyEvent *event) if (d->completionWidget->processKeyPressEvent(event)) return; - if (event->key() == Qt::Key_Escape && d->inlineCompletionCache.first != -1) - return d->cancelInlineCompletion(); + if (event->key() == Qt::Key_Escape && d->inlineCompletionCache.first != -1) { + d->cancelInlineCompletion(); + auto providerList = ResourceManager::instance()->inlineCompletionProviders(); + for (const auto provider : providerList) + provider->rejected(); + return; + } QsciScintilla::keyPressEvent(event); } diff --git a/src/plugins/codegeex/codegeex/codegeexcompletionprovider.cpp b/src/plugins/codegeex/codegeex/codegeexcompletionprovider.cpp index 5f406a4e9..5aa7702c3 100644 --- a/src/plugins/codegeex/codegeex/codegeexcompletionprovider.cpp +++ b/src/plugins/codegeex/codegeex/codegeexcompletionprovider.cpp @@ -59,6 +59,16 @@ bool CodeGeeXCompletionProvider::inlineCompletionEnabled() const return completionEnabled; } +void CodeGeeXCompletionProvider::accepted() +{ + completionItems.clear(); +} + +void CodeGeeXCompletionProvider::rejected() +{ + completionItems.clear(); +} + AbstractInlineCompletionProvider::InlineCompletionContext CodeGeeXCompletionProvider::inlineCompletionContext() const { return context; diff --git a/src/plugins/codegeex/codegeex/codegeexcompletionprovider.h b/src/plugins/codegeex/codegeex/codegeexcompletionprovider.h index f49b8d85a..ac5d67312 100644 --- a/src/plugins/codegeex/codegeex/codegeexcompletionprovider.h +++ b/src/plugins/codegeex/codegeex/codegeexcompletionprovider.h @@ -20,6 +20,8 @@ class CodeGeeXCompletionProvider : public AbstractInlineCompletionProvider void provideInlineCompletionItems(const Position &pos, const InlineCompletionContext &c) override; QList inlineCompletionItems() const override; bool inlineCompletionEnabled() const override; + void accepted() override; + void rejected() override; InlineCompletionContext inlineCompletionContext() const; void setInlineCompletionEnabled(bool enabled);