mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-04 01:28:58 -04:00
feat: Add code completion request progress bar
This commit is contained in:
parent
79218d8412
commit
444b679ada
@ -63,6 +63,7 @@ add_qtc_plugin(QodeAssist
|
|||||||
qodeassist.cpp
|
qodeassist.cpp
|
||||||
QodeAssistConstants.hpp
|
QodeAssistConstants.hpp
|
||||||
QodeAssisttr.h
|
QodeAssisttr.h
|
||||||
|
CompletionProgressHandler.hpp CompletionProgressHandler.cpp
|
||||||
LLMClientInterface.hpp LLMClientInterface.cpp
|
LLMClientInterface.hpp LLMClientInterface.cpp
|
||||||
templates/Templates.hpp
|
templates/Templates.hpp
|
||||||
templates/CodeLlamaFim.hpp
|
templates/CodeLlamaFim.hpp
|
||||||
|
78
CompletionProgressHandler.cpp
Normal file
78
CompletionProgressHandler.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CompletionProgressHandler.hpp"
|
||||||
|
#include <texteditor/texteditor.h>
|
||||||
|
#include <utils/tooltip/tooltip.h>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
namespace QodeAssist {
|
||||||
|
|
||||||
|
void CompletionProgressHandler::showProgress(TextEditor::TextEditorWidget *widget)
|
||||||
|
{
|
||||||
|
m_widget = widget;
|
||||||
|
m_isActive = true;
|
||||||
|
|
||||||
|
if (m_widget) {
|
||||||
|
// Используем тот же метод получения позиции что и в TextSuggestion
|
||||||
|
const QRect cursorRect = m_widget->cursorRect(m_widget->textCursor());
|
||||||
|
m_iconPosition = m_widget->viewport()->mapToGlobal(cursorRect.topLeft())
|
||||||
|
- Utils::ToolTip::offsetFromPosition();
|
||||||
|
|
||||||
|
identifyMatch(m_widget, m_widget->textCursor().position(), [this](auto priority) {
|
||||||
|
if (priority != Priority_None)
|
||||||
|
operateTooltip(m_widget, m_iconPosition);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompletionProgressHandler::hideProgress()
|
||||||
|
{
|
||||||
|
m_isActive = false;
|
||||||
|
Utils::ToolTip::hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompletionProgressHandler::identifyMatch(
|
||||||
|
TextEditor::TextEditorWidget *editorWidget, int pos, ReportPriority report)
|
||||||
|
{
|
||||||
|
if (!m_isActive || !editorWidget) {
|
||||||
|
report(Priority_None);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
report(Priority_Tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CompletionProgressHandler::operateTooltip(
|
||||||
|
TextEditor::TextEditorWidget *editorWidget, const QPoint &point)
|
||||||
|
{
|
||||||
|
if (!m_isActive || !editorWidget)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto progressLabel = new QLabel;
|
||||||
|
progressLabel->setPixmap(QPixmap(":/resources/images/qoderassist-icon.png")
|
||||||
|
.scaled(16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
|
||||||
|
QPoint showPoint = point;
|
||||||
|
showPoint.ry() -= progressLabel->sizeHint().height();
|
||||||
|
|
||||||
|
Utils::ToolTip::show(showPoint, progressLabel, editorWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QodeAssist
|
45
CompletionProgressHandler.hpp
Normal file
45
CompletionProgressHandler.hpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Petr Mironychev
|
||||||
|
*
|
||||||
|
* This file is part of QodeAssist.
|
||||||
|
*
|
||||||
|
* QodeAssist is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QodeAssist is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <texteditor/basehoverhandler.h>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
namespace QodeAssist {
|
||||||
|
|
||||||
|
class CompletionProgressHandler : public TextEditor::BaseHoverHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void showProgress(TextEditor::TextEditorWidget *widget);
|
||||||
|
void hideProgress();
|
||||||
|
void abort() override {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void identifyMatch(
|
||||||
|
TextEditor::TextEditorWidget *editorWidget, int pos, ReportPriority report) override;
|
||||||
|
void operateTooltip(TextEditor::TextEditorWidget *editorWidget, const QPoint &point) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPointer<TextEditor::TextEditorWidget> m_widget;
|
||||||
|
QPoint m_iconPosition;
|
||||||
|
bool m_isActive = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QodeAssist
|
@ -151,6 +151,7 @@ void QodeAssistClient::requestCompletions(TextEditor::TextEditorWidget *editor)
|
|||||||
{TextDocumentIdentifier(hostPathToServerUri(filePath)),
|
{TextDocumentIdentifier(hostPathToServerUri(filePath)),
|
||||||
documentVersion(filePath),
|
documentVersion(filePath),
|
||||||
Position(cursor.mainCursor())}};
|
Position(cursor.mainCursor())}};
|
||||||
|
m_progressHandler.showProgress(editor);
|
||||||
request.setResponseCallback([this, editor = QPointer<TextEditorWidget>(editor)](
|
request.setResponseCallback([this, editor = QPointer<TextEditorWidget>(editor)](
|
||||||
const GetCompletionRequest::Response &response) {
|
const GetCompletionRequest::Response &response) {
|
||||||
QTC_ASSERT(editor, return);
|
QTC_ASSERT(editor, return);
|
||||||
@ -237,6 +238,7 @@ void QodeAssistClient::handleCompletions(
|
|||||||
Text::Position pos{toTextPos(c.position())};
|
Text::Position pos{toTextPos(c.position())};
|
||||||
return TextSuggestion::Data{range, pos, c.text()};
|
return TextSuggestion::Data{range, pos, c.text()};
|
||||||
});
|
});
|
||||||
|
m_progressHandler.hideProgress();
|
||||||
if (completions.isEmpty())
|
if (completions.isEmpty())
|
||||||
return;
|
return;
|
||||||
editor->insertSuggestion(std::make_unique<LLMSuggestion>(suggestions, editor->document()));
|
editor->insertSuggestion(std::make_unique<LLMSuggestion>(suggestions, editor->document()));
|
||||||
@ -248,6 +250,7 @@ void QodeAssistClient::cancelRunningRequest(TextEditor::TextEditorWidget *editor
|
|||||||
const auto it = m_runningRequests.constFind(editor);
|
const auto it = m_runningRequests.constFind(editor);
|
||||||
if (it == m_runningRequests.constEnd())
|
if (it == m_runningRequests.constEnd())
|
||||||
return;
|
return;
|
||||||
|
m_progressHandler.hideProgress();
|
||||||
cancelRequest(it->id());
|
cancelRequest(it->id());
|
||||||
m_runningRequests.erase(it);
|
m_runningRequests.erase(it);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "CompletionProgressHandler.hpp"
|
||||||
#include "LLMClientInterface.hpp"
|
#include "LLMClientInterface.hpp"
|
||||||
#include "LSPCompletion.hpp"
|
#include "LSPCompletion.hpp"
|
||||||
#include <languageclient/client.h>
|
#include <languageclient/client.h>
|
||||||
@ -60,6 +61,7 @@ private:
|
|||||||
|
|
||||||
QElapsedTimer m_typingTimer;
|
QElapsedTimer m_typingTimer;
|
||||||
int m_recentCharCount;
|
int m_recentCharCount;
|
||||||
|
CompletionProgressHandler m_progressHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QodeAssist
|
} // namespace QodeAssist
|
||||||
|
Loading…
x
Reference in New Issue
Block a user