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 Internal {
|
||||
|
||||
CopilotPlugin::~CopilotPlugin()
|
||||
{
|
||||
if (m_client)
|
||||
m_client->shutdown();
|
||||
|
||||
m_client = nullptr;
|
||||
}
|
||||
|
||||
void CopilotPlugin::initialize()
|
||||
{
|
||||
CopilotSettings::instance().readSettings(Core::ICore::settings());
|
||||
|
||||
m_client = new CopilotClient();
|
||||
|
||||
connect(m_client, &CopilotClient::finished, this, [this]() { m_client = nullptr; });
|
||||
|
||||
connect(&CopilotSettings::instance(), &CopilotSettings::applied, this, [this]() {
|
||||
if (m_client)
|
||||
m_client->shutdown();
|
||||
|
||||
@@ -16,14 +16,13 @@ class CopilotPlugin : public ExtensionSystem::IPlugin
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Copilot.json")
|
||||
|
||||
public:
|
||||
CopilotPlugin() {}
|
||||
~CopilotPlugin() override {}
|
||||
~CopilotPlugin();
|
||||
|
||||
void initialize() override;
|
||||
void extensionsInitialized() override;
|
||||
|
||||
private:
|
||||
CopilotClient *m_client;
|
||||
CopilotClient *m_client{nullptr};
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -37,12 +37,16 @@ DocumentWatcher::DocumentWatcher(CopilotClient *client, TextDocument *textDocume
|
||||
|
||||
void DocumentWatcher::getSuggestion()
|
||||
{
|
||||
auto editor = Core::EditorManager::instance()->activateEditorForDocument(m_textDocument);
|
||||
auto textEditorWidget = qobject_cast<TextEditor::TextEditorWidget *>(editor->widget());
|
||||
if (!editor || !textEditorWidget)
|
||||
Core::IEditor *editor = Core::EditorManager::instance()->activateEditorForDocument(
|
||||
m_textDocument);
|
||||
if (!editor)
|
||||
return;
|
||||
TextEditor::TextEditorWidget *textEditorWidget = qobject_cast<TextEditor::TextEditorWidget *>(
|
||||
editor->widget());
|
||||
if (!textEditorWidget)
|
||||
return;
|
||||
|
||||
auto cursor = textEditorWidget->multiTextCursor();
|
||||
Utils::MultiTextCursor cursor = textEditorWidget->multiTextCursor();
|
||||
if (cursor.hasMultipleCursors() || cursor.hasSelection())
|
||||
return;
|
||||
|
||||
@@ -61,31 +65,24 @@ void DocumentWatcher::getSuggestion()
|
||||
const std::optional<GetCompletionResponse> result = response.result();
|
||||
QTC_ASSERT(result, return);
|
||||
|
||||
const auto list = result->completions().toList();
|
||||
const QList<Completion> list = result->completions().toList();
|
||||
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
auto cursor = textEditorWidget->multiTextCursor();
|
||||
Utils::MultiTextCursor cursor = textEditorWidget->multiTextCursor();
|
||||
if (cursor.hasMultipleCursors() || cursor.hasSelection())
|
||||
return;
|
||||
if (cursor.cursors().first().position() != currentCursorPos)
|
||||
return;
|
||||
|
||||
const auto firstCompletion = list.first();
|
||||
const Completion firstCompletion = list.first();
|
||||
const QString content = firstCompletion.text().mid(
|
||||
firstCompletion.position().character());
|
||||
|
||||
m_isEditing = true;
|
||||
textEditorWidget->insertSuggestion(content);
|
||||
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