Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.0.8 #6

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ add_qtc_plugin(QodeAssist
QodeAssist.qrc
LSPCompletion.hpp
LLMSuggestion.hpp LLMSuggestion.cpp
QodeAssistHoverHandler.hpp QodeAssistHoverHandler.cpp
QodeAssistClient.hpp QodeAssistClient.cpp
QodeAssistUtils.hpp
DocumentContextReader.hpp DocumentContextReader.cpp
QodeAssistData.hpp
utils/CounterTooltip.hpp utils/CounterTooltip.cpp
)
48 changes: 46 additions & 2 deletions LLMSuggestion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@

#include "LLMSuggestion.hpp"

#include <QTextCursor>
#include <QtWidgets/qtoolbar.h>
#include <texteditor/texteditor.h>
#include <utils/stringutils.h>
#include <utils/tooltip/tooltip.h>

namespace QodeAssist {

LLMSuggestion::LLMSuggestion(const Completion &completion, QTextDocument *origin)
: m_completion(completion)
, m_linesCount(0)
{
int startPos = completion.range().start().toPositionInDocument(origin);
int endPos = completion.range().end().toPositionInDocument(origin);
Expand Down Expand Up @@ -63,8 +70,35 @@ bool LLMSuggestion::apply()

bool LLMSuggestion::applyWord(TextEditor::TextEditorWidget *widget)
{
Q_UNUSED(widget)
return apply();
return applyNextLine(widget);
}

bool LLMSuggestion::applyNextLine(TextEditor::TextEditorWidget *widget)
{
const QString text = m_completion.text();
QStringList lines = text.split('\n');

if (m_linesCount < lines.size())
m_linesCount++;

showTooltip(widget, m_linesCount);

return m_linesCount == lines.size() && !Utils::ToolTip::isVisible();
}

void LLMSuggestion::onCounterFinished(int count)
{
Utils::ToolTip::hide();
m_linesCount = 0;
QTextCursor cursor = m_completion.range().toSelection(m_start.document());
cursor.beginEditBlock();
cursor.removeSelectedText();

QStringList lines = m_completion.text().split('\n');
QString textToInsert = lines.mid(0, count).join('\n');

cursor.insertText(textToInsert);
cursor.endEditBlock();
}

void LLMSuggestion::reset()
Expand All @@ -77,4 +111,14 @@ int LLMSuggestion::position()
return m_start.position();
}

void LLMSuggestion::showTooltip(TextEditor::TextEditorWidget *widget, int count)
{
Utils::ToolTip::hide();
QPoint pos = widget->mapToGlobal(widget->cursorRect().topRight());
pos += QPoint(-10, -50);
m_counterTooltip = new CounterTooltip(count);
Utils::ToolTip::show(pos, m_counterTooltip, widget);
connect(m_counterTooltip, &CounterTooltip::finished, this, &LLMSuggestion::onCounterFinished);
}

} // namespace QodeAssist
14 changes: 12 additions & 2 deletions LLMSuggestion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,37 @@

#pragma once

#include <QObject>
#include "LSPCompletion.hpp"
#include <texteditor/textdocumentlayout.h>

#include "LSPCompletion.hpp"
#include "utils/CounterTooltip.hpp"

namespace QodeAssist {

class LLMSuggestion final : public TextEditor::TextSuggestion
class LLMSuggestion final : public QObject, public TextEditor::TextSuggestion
{
Q_OBJECT
public:
LLMSuggestion(const Completion &completion, QTextDocument *origin);

bool apply() final;
bool applyWord(TextEditor::TextEditorWidget *widget) final;
bool applyNextLine(TextEditor::TextEditorWidget *widget);
void reset() final;
int position() final;

const Completion &completion() const { return m_completion; }

void showTooltip(TextEditor::TextEditorWidget *widget, int count);
void onCounterFinished(int count);

private:
Completion m_completion;
QTextCursor m_start;
int m_linesCount;

CounterTooltip *m_counterTooltip = nullptr;
};

} // namespace QodeAssist
4 changes: 4 additions & 0 deletions LSPCompletion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class Completion : public LanguageServerProtocol::JsonObject
{
return typedValue<LanguageServerProtocol::Position>(LanguageServerProtocol::positionKey);
}
void setRange(const LanguageServerProtocol::Range &range)
{
insert(LanguageServerProtocol::rangeKey, range);
}
LanguageServerProtocol::Range range() const
{
return typedValue<LanguageServerProtocol::Range>(LanguageServerProtocol::rangeKey);
Expand Down
2 changes: 1 addition & 1 deletion QodeAssist.json.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Name" : "QodeAssist",
"Version" : "0.0.7",
"Version" : "0.0.8",
"CompatVersion" : "${IDE_VERSION_COMPAT}",
"Vendor" : "Petr Mironychev",
"Copyright" : "(C) ${IDE_COPYRIGHT_YEAR} Petr Mironychev, (C) ${IDE_COPYRIGHT_YEAR} The Qt Company Ltd",
Expand Down
6 changes: 0 additions & 6 deletions QodeAssistClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ void QodeAssistClient::handleCompletions(const GetCompletionRequest::Response &r
return;
editor->insertSuggestion(
std::make_unique<LLMSuggestion>(completions.first(), editor->document()));
editor->addHoverHandler(&m_hoverHandler);
}
}

Expand Down Expand Up @@ -237,11 +236,6 @@ void QodeAssistClient::cleanupConnections()
disconnect(m_documentOpenedConnection);
disconnect(m_documentClosedConnection);

for (IEditor *editor : DocumentModel::editorsForOpenedDocuments()) {
if (auto textEditor = qobject_cast<BaseTextEditor *>(editor))
textEditor->editorWidget()->removeHoverHandler(&m_hoverHandler);
}

qDeleteAll(m_scheduledRequests);
m_scheduledRequests.clear();
}
Expand Down
2 changes: 0 additions & 2 deletions QodeAssistClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <languageclient/client.h>

#include "LSPCompletion.hpp"
#include "QodeAssistHoverHandler.hpp"

namespace QodeAssist {

Expand All @@ -54,7 +53,6 @@ class QodeAssistClient : public LanguageClient::Client

QHash<TextEditor::TextEditorWidget *, GetCompletionRequest> m_runningRequests;
QHash<TextEditor::TextEditorWidget *, QTimer *> m_scheduledRequests;
QodeAssistHoverHandler m_hoverHandler;
QMetaObject::Connection m_documentOpenedConnection;
QMetaObject::Connection m_documentClosedConnection;
};
Expand Down
114 changes: 0 additions & 114 deletions QodeAssistHoverHandler.cpp

This file was deleted.

19 changes: 3 additions & 16 deletions QodeAssistSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ QodeAssistSettings::QodeAssistSettings()
temperature.setDefaultValue(0.2);
temperature.setRange(0.0, 10.0);

selectModels.m_buttonText = Tr::tr("Select Models");
selectModels.m_buttonText = Tr::tr("Select Model");

ollamaLivetime.setSettingsKey(Constants::OLLAMA_LIVETIME);
ollamaLivetime.setLabelText(
Expand Down Expand Up @@ -145,9 +145,6 @@ QodeAssistSettings::QodeAssistSettings()
frequencyPenalty.setDefaultValue(0.0);
frequencyPenalty.setRange(-2.0, 2.0);

providerPaths.setSettingsKey(Constants::PROVIDER_PATHS);
providerPaths.setLabelText(Tr::tr("Provider Paths:"));

startSuggestionTimer.setSettingsKey(Constants::START_SUGGESTION_TIMER);
startSuggestionTimer.setLabelText(Tr::tr("Start Suggestion Timer:"));
startSuggestionTimer.setRange(10, 10000);
Expand Down Expand Up @@ -219,7 +216,7 @@ QodeAssistSettings::QodeAssistSettings()
enableLogging,
Row{Stretch{1}, resetToDefaults}}}},
Group{title(Tr::tr("LLM Providers")),
Form{Column{llmProviders, Row{url, endPoint}, providerPaths}}},
Form{Column{llmProviders, Row{url, endPoint}}}},
Group{title(Tr::tr("LLM Model Settings")),
Form{Column{Row{selectModels, modelName}}}},
Group{title(Tr::tr("FIM Prompt Settings")),
Expand Down Expand Up @@ -306,7 +303,7 @@ QStringList QodeAssistSettings::getInstalledModels()
{
auto *provider = LLMProvidersManager::instance().getCurrentProvider();
if (provider) {
auto env = getEnvironmentWithProviderPaths();
Utils::Environment env = Utils::Environment::systemEnvironment();
return provider->getInstalledModels(env);
}
return {};
Expand All @@ -331,16 +328,6 @@ void QodeAssistSettings::showModelSelectionDialog()
}
}

Utils::Environment QodeAssistSettings::getEnvironmentWithProviderPaths() const
{
Utils::Environment env = Utils::Environment::systemEnvironment();
const QStringList additionalPaths = providerPaths.volatileValue();
for (const QString &path : additionalPaths) {
env.prependOrSetPath(path);
}
return env;
}

void QodeAssistSettings::resetSettingsToDefaults()
{
QMessageBox::StandardButton reply;
Expand Down
2 changes: 0 additions & 2 deletions QodeAssistSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ class QodeAssistSettings : public Utils::AspectContainer
Utils::BoolAspect useFrequencyPenalty{this};
Utils::DoubleAspect frequencyPenalty{this};

Utils::StringListAspect providerPaths{this};

Utils::IntegerAspect startSuggestionTimer{this};
Utils::IntegerAspect maxFileThreshold{this};

Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ QodeAssist has been tested with the following language models, all trained for F
Ollama:
- [starcoder2](https://ollama.com/library/starcoder2)
- [codellama](https://ollama.com/library/codellama)
- DeepSeek-Coder-V2-Lite-Base

LM studio:
- [second-state/StarCoder2-7B-GGUF](https://huggingface.co/second-state/StarCoder2-7B-GGUF)
Expand All @@ -30,7 +31,7 @@ If you've successfully used a model that's not listed here, please let us know b
- [ ] Add chat functionality
- [ ] Support for more providers and models

## Installation Plugin
## Plugin installation using Ollama as an example

1. Install QtCreator 14.0
2. Install [Ollama](https://ollama.com). Make sure to review the system requirements before installation.
Expand All @@ -50,14 +51,19 @@ ollama run starcoder2:7b
1. Open Qt Creator settings
2. Navigate to the "Qode Assist" tab
3. Choose your LLM provider (e.g., Ollama)
- If you haven't added the provider to your system PATH, specify the path to the provider executable in the "Provider Paths" field
4. Select the installed model
- If you need to enter the model name manually, it indicates that the plugin cannot locate the provider's executable file. However, this doesn't affect the plugin's functionality – it will still work correctly. This autoselector input option is provided for your convenience, allowing you to easily select and use different models
4. Select the installed model by the "Select Model" button
- For LM Studio you will see current load model
5. Choose the prompt template that corresponds to your model
6. Apply the settings

You're all set! QodeAssist is now ready to use in Qt Creator.

## Hotkeys
- To insert the full suggestion, you can use the TAB key
- To insert line by line, you can use the "Move cursor word right" shortcut:
- On Mac: Option + Right Arrow
- On Windows: Alt + Right Arrow

## Support the development of QodeAssist
If you find QodeAssist helpful, there are several ways you can support the project:

Expand Down
Loading