forked from qt-creator/qt-creator
Copilot: Various coverity warning fixes
Change-Id: I5d86606611369f4bc11f9f21e308139bba700eb0 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -14,12 +14,22 @@ using namespace Utils;
|
|||||||
namespace Copilot {
|
namespace Copilot {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
CopilotPlugin::~CopilotPlugin()
|
||||||
|
{
|
||||||
|
if (m_client)
|
||||||
|
m_client->shutdown();
|
||||||
|
|
||||||
|
m_client = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void CopilotPlugin::initialize()
|
void CopilotPlugin::initialize()
|
||||||
{
|
{
|
||||||
CopilotSettings::instance().readSettings(Core::ICore::settings());
|
CopilotSettings::instance().readSettings(Core::ICore::settings());
|
||||||
|
|
||||||
m_client = new CopilotClient();
|
m_client = new CopilotClient();
|
||||||
|
|
||||||
|
connect(m_client, &CopilotClient::finished, this, [this]() { m_client = nullptr; });
|
||||||
|
|
||||||
connect(&CopilotSettings::instance(), &CopilotSettings::applied, this, [this]() {
|
connect(&CopilotSettings::instance(), &CopilotSettings::applied, this, [this]() {
|
||||||
if (m_client)
|
if (m_client)
|
||||||
m_client->shutdown();
|
m_client->shutdown();
|
||||||
|
|||||||
@@ -16,14 +16,13 @@ class CopilotPlugin : public ExtensionSystem::IPlugin
|
|||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Copilot.json")
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Copilot.json")
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CopilotPlugin() {}
|
~CopilotPlugin();
|
||||||
~CopilotPlugin() override {}
|
|
||||||
|
|
||||||
void initialize() override;
|
void initialize() override;
|
||||||
void extensionsInitialized() override;
|
void extensionsInitialized() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CopilotClient *m_client;
|
CopilotClient *m_client{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -37,12 +37,16 @@ DocumentWatcher::DocumentWatcher(CopilotClient *client, TextDocument *textDocume
|
|||||||
|
|
||||||
void DocumentWatcher::getSuggestion()
|
void DocumentWatcher::getSuggestion()
|
||||||
{
|
{
|
||||||
auto editor = Core::EditorManager::instance()->activateEditorForDocument(m_textDocument);
|
Core::IEditor *editor = Core::EditorManager::instance()->activateEditorForDocument(
|
||||||
auto textEditorWidget = qobject_cast<TextEditor::TextEditorWidget *>(editor->widget());
|
m_textDocument);
|
||||||
if (!editor || !textEditorWidget)
|
if (!editor)
|
||||||
|
return;
|
||||||
|
TextEditor::TextEditorWidget *textEditorWidget = qobject_cast<TextEditor::TextEditorWidget *>(
|
||||||
|
editor->widget());
|
||||||
|
if (!textEditorWidget)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto cursor = textEditorWidget->multiTextCursor();
|
Utils::MultiTextCursor cursor = textEditorWidget->multiTextCursor();
|
||||||
if (cursor.hasMultipleCursors() || cursor.hasSelection())
|
if (cursor.hasMultipleCursors() || cursor.hasSelection())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -61,31 +65,24 @@ void DocumentWatcher::getSuggestion()
|
|||||||
const std::optional<GetCompletionResponse> result = response.result();
|
const std::optional<GetCompletionResponse> result = response.result();
|
||||||
QTC_ASSERT(result, return);
|
QTC_ASSERT(result, return);
|
||||||
|
|
||||||
const auto list = result->completions().toList();
|
const QList<Completion> list = result->completions().toList();
|
||||||
|
|
||||||
if (list.isEmpty())
|
if (list.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto cursor = textEditorWidget->multiTextCursor();
|
Utils::MultiTextCursor cursor = textEditorWidget->multiTextCursor();
|
||||||
if (cursor.hasMultipleCursors() || cursor.hasSelection())
|
if (cursor.hasMultipleCursors() || cursor.hasSelection())
|
||||||
return;
|
return;
|
||||||
if (cursor.cursors().first().position() != currentCursorPos)
|
if (cursor.cursors().first().position() != currentCursorPos)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto firstCompletion = list.first();
|
const Completion firstCompletion = list.first();
|
||||||
const QString content = firstCompletion.text().mid(
|
const QString content = firstCompletion.text().mid(
|
||||||
firstCompletion.position().character());
|
firstCompletion.position().character());
|
||||||
|
|
||||||
m_isEditing = true;
|
m_isEditing = true;
|
||||||
textEditorWidget->insertSuggestion(content);
|
textEditorWidget->insertSuggestion(content);
|
||||||
m_isEditing = false;
|
m_isEditing = false;
|
||||||
/*
|
|
||||||
m_isEditing = true;
|
|
||||||
const auto &block = m_textDocument->document()->findBlockByLineNumber(
|
|
||||||
firstCompletion.position().line());
|
|
||||||
m_textDocument->insertSuggestion(content, block);
|
|
||||||
m_isEditing = false;
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user