Skip to content

Commit

Permalink
fix: [completion] Optimize intelligent completion
Browse files Browse the repository at this point in the history
as title

Log: Optimize intelligent completion
  • Loading branch information
Kakueeen authored and deepin-mozart committed Oct 28, 2024
1 parent 0ad7955 commit 645610c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/base/abstractinlinecompletionprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,16 @@ AbstractInlineCompletionProvider::AbstractInlineCompletionProvider(QObject *pare
: QObject(parent)
{
}

bool AbstractInlineCompletionProvider::inlineCompletionEnabled() const
{
return false;
}

void AbstractInlineCompletionProvider::accepted()
{
}

void AbstractInlineCompletionProvider::rejected()
{
}
4 changes: 3 additions & 1 deletion src/base/abstractinlinecompletionprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<InlineCompletionItem> inlineCompletionItems() const = 0;
virtual bool inlineCompletionEnabled() const { return false; }
virtual bool inlineCompletionEnabled() const;
virtual void accepted();
virtual void rejected();

Q_SIGNALS:
void finished();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 15 additions & 4 deletions src/plugins/codeeditor/gui/texteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -848,17 +849,27 @@ 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();

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);
}
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/codegeex/codegeex/codegeexcompletionprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/codegeex/codegeex/codegeexcompletionprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class CodeGeeXCompletionProvider : public AbstractInlineCompletionProvider
void provideInlineCompletionItems(const Position &pos, const InlineCompletionContext &c) override;
QList<InlineCompletionItem> inlineCompletionItems() const override;
bool inlineCompletionEnabled() const override;
void accepted() override;
void rejected() override;

InlineCompletionContext inlineCompletionContext() const;
void setInlineCompletionEnabled(bool enabled);
Expand Down

0 comments on commit 645610c

Please sign in to comment.