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

Upgrade #45

Closed
wants to merge 29 commits into from
Closed
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
69 changes: 40 additions & 29 deletions .github/workflows/build_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ on:
- main
env:
PLUGIN_NAME: QodeAssist
QT_VERSION: 6.7.3
QT_CREATOR_VERSION: 14.0.2
QT_CREATOR_SNAPSHOT: NO
QT_VERSION: 6.8.1
QT_CREATOR_VERSION: 15.0.0
QT_CREATOR_VERSION_INTERNAL: 15.0.0
MACOS_DEPLOYMENT_TARGET: "11.0"
CMAKE_VERSION: "3.29.6"
NINJA_VERSION: "1.12.1"
Expand Down Expand Up @@ -124,30 +124,27 @@ jobs:
string(REPLACE "." "" qt_version_dotless "${qt_version}")
if ("${{ runner.os }}" STREQUAL "Windows")
set(url_os "windows_x86")
set(qt_package_arch_suffix "win64_msvc2019_64")
set(qt_dir_prefix "${qt_version}/msvc2019_64")
set(qt_package_suffix "-Windows-Windows_10_22H2-MSVC2019-Windows-Windows_10_22H2-X86_64")
set(qt_package_arch_suffix "win64_msvc2022_64")
set(qt_dir_prefix "${qt_version}/msvc2022_64")
set(qt_package_suffix "-Windows-Windows_11_23H2-MSVC2022-Windows-Windows_11_23H2-X86_64")
elseif ("${{ runner.os }}" STREQUAL "Linux")
set(url_os "linux_x64")
if (qt_version VERSION_LESS "6.7.0")
set(qt_package_arch_suffix "gcc_64")
else()
set(qt_package_arch_suffix "linux_gcc_64")
endif()
set(qt_package_arch_suffix "linux_gcc_64")
set(qt_dir_prefix "${qt_version}/gcc_64")
set(qt_package_suffix "-Linux-RHEL_8_8-GCC-Linux-RHEL_8_8-X86_64")
set(qt_package_suffix "-Linux-RHEL_8_10-GCC-Linux-RHEL_8_10-X86_64")
elseif ("${{ runner.os }}" STREQUAL "macOS")
set(url_os "mac_x64")
set(qt_package_arch_suffix "clang_64")
set(qt_dir_prefix "${qt_version}/macos")
set(qt_package_suffix "-MacOS-MacOS_13-Clang-MacOS-MacOS_13-X86_64-ARM64")
set(qt_package_suffix "-MacOS-MacOS_14-Clang-MacOS-MacOS_14-X86_64-ARM64")
endif()

set(qt_base_url "https://download.qt.io/online/qtsdkrepository/${url_os}/desktop/qt6_${qt_version_dotless}")
set(qt_base_url "${qt_base_url}/qt6_${qt_version_dotless}/qt.qt6.${qt_version_dotless}.${qt_package_arch_suffix}")
file(DOWNLOAD "${qt_base_url}/Updates.xml" ./Updates.xml SHOW_PROGRESS)

file(READ ./Updates.xml updates_xml)
string(REGEX MATCH "<Name>qt.qt6.*<Version>([0-9+-.]+)</Version>" updates_xml_output "${updates_xml}")
string(REGEX MATCH "<Version>([0-9+-.]+)</Version>" updates_xml_output "${updates_xml}")
set(qt_package_version ${CMAKE_MATCH_1})

file(MAKE_DIRECTORY qt6)
Expand All @@ -163,30 +160,44 @@ jobs:
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ../${archive} WORKING_DIRECTORY qt6)
endfunction()

if ("${{ runner.os }}" STREQUAL "Windows")
set(timestamp "202411221531")
elseif ("${{ runner.os }}" STREQUAL "Linux")
set(timestamp "202411221531")
elseif ("${{ runner.os }}" STREQUAL "macOS")
set(timestamp "202411221530")
endif()

foreach(package qtbase qtdeclarative)
downloadAndExtract(
"${qt_base_url}/qt.qt6.${qt_version_dotless}.${qt_package_arch_suffix}/${qt_package_version}${package}${qt_package_suffix}.7z"
"${qt_base_url}/${qt_version}-0-${timestamp}${package}${qt_package_suffix}.7z"
${package}.7z
)
endforeach()

foreach(package qt5compat qtshadertools)
downloadAndExtract(
"${qt_base_url}/qt.qt6.${qt_version_dotless}.${package}.${qt_package_arch_suffix}/${qt_package_version}${package}${qt_package_suffix}.7z"
${package}.7z
)
endforeach()
set(qt_addons_url "${qt_base_url}/../qt.qt6.${qt_version_dotless}.addons")
downloadAndExtract(
"${qt_addons_url}.qt5compat.${qt_package_arch_suffix}/${qt_version}-0-${timestamp}qt5compat${qt_package_suffix}.7z"
qt5compat.7z
)

downloadAndExtract(
"${qt_addons_url}.qtshadertools.${qt_package_arch_suffix}/${qt_version}-0-${timestamp}qtshadertools${qt_package_suffix}.7z"
qtshadertools.7z
)

message("Downloading libicu")
function(downloadAndExtractLibicu url archive)
message("Downloading ${url} to ${qt_version}/gcc_64/lib")
file(DOWNLOAD "${url}" ./${archive} SHOW_PROGRESS)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ../../../${archive} WORKING_DIRECTORY ${qt_version}/gcc_64/lib)
endfunction()

# uic depends on libicu*.so
if ("${{ runner.os }}" STREQUAL "Linux")
if (qt_version VERSION_LESS "6.7.0")
set(uic_suffix "Rhel7.2-x64")
else()
set(uic_suffix "Rhel8.6-x86_64")
endif()
downloadAndExtract(
"${qt_base_url}/qt.qt6.${qt_version_dotless}.${qt_package_arch_suffix}/${qt_package_version}icu-linux-${uic_suffix}.7z"
icu.7z
downloadAndExtractLibicu(
"${qt_base_url}/${qt_version}-0-${timestamp}icu-linux-Rhel8.6-x86_64.7z"
"icu.7z"
)
endif()

Expand Down
72 changes: 30 additions & 42 deletions LLMSuggestion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@

namespace QodeAssist {

LLMSuggestion::LLMSuggestion(const Completion &completion, QTextDocument *origin)
: m_completion(completion)
LLMSuggestion::LLMSuggestion(const TextEditor::TextSuggestion::Data &data, QTextDocument *origin)
: TextEditor::TextSuggestion(data, origin)
, m_linesCount(0)
, m_suggestion(data)
{
int startPos = completion.range().start().toPositionInDocument(origin);
int endPos = completion.range().end().toPositionInDocument(origin);
int startPos = data.range.begin.toPositionInDocument(origin);
int endPos = data.range.end.toPositionInDocument(origin);

startPos = qBound(0, startPos, origin->characterCount() - 1);
endPos = qBound(startPos, endPos, origin->characterCount() - 1);

m_start = QTextCursor(origin);
m_start.setPosition(startPos);
m_start.setKeepPositionOnInsert(true);

QTextCursor cursor(origin);
cursor.setPosition(startPos);
cursor.setPosition(endPos, QTextCursor::KeepAnchor);
Expand All @@ -51,39 +48,30 @@ LLMSuggestion::LLMSuggestion(const Completion &completion, QTextDocument *origin
int startPosInBlock = startPos - block.position();
int endPosInBlock = endPos - block.position();

blockText.replace(startPosInBlock, endPosInBlock - startPosInBlock, completion.text());

document()->setPlainText(blockText);
blockText.replace(startPosInBlock, endPosInBlock - startPosInBlock, data.text);

setCurrentPosition(m_start.position());
replacementDocument()->setPlainText(blockText);
}

bool LLMSuggestion::apply()
{
QTextCursor cursor = m_completion.range().toSelection(m_start.document());
cursor.beginEditBlock();
cursor.removeSelectedText();
cursor.insertText(m_completion.text());
cursor.endEditBlock();
return true;
return TextEditor::TextSuggestion::apply();
}

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

bool LLMSuggestion::applyNextLine(TextEditor::TextEditorWidget *widget)
bool LLMSuggestion::applyLine(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 TextEditor::TextSuggestion::applyLine(widget);
}

return m_linesCount == lines.size() && !Utils::ToolTip::isVisible();
void LLMSuggestion::reset()
{
reset();
m_linesCount = 0;
}

void LLMSuggestion::onCounterFinished(int count)
Expand All @@ -101,24 +89,24 @@ void LLMSuggestion::onCounterFinished(int count)
cursor.endEditBlock();
}

void LLMSuggestion::reset()
{
m_start.removeSelectedText();
}
// void LLMSuggestion::reset()
// {
// m_start.removeSelectedText();
// }

int LLMSuggestion::position()
{
return m_start.position();
}
// 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);
// 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
15 changes: 7 additions & 8 deletions LLMSuggestion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ class LLMSuggestion final : public QObject, public TextEditor::TextSuggestion
{
Q_OBJECT
public:
LLMSuggestion(const Completion &completion, QTextDocument *origin);
LLMSuggestion(const TextEditor::TextSuggestion::Data &data, 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; }
bool apply() override;
bool applyWord(TextEditor::TextEditorWidget *widget) override;
bool applyLine(TextEditor::TextEditorWidget *widget) override;
void reset();

void showTooltip(TextEditor::TextEditorWidget *widget, int count);
void onCounterFinished(int count);
Expand All @@ -50,6 +47,8 @@ class LLMSuggestion final : public QObject, public TextEditor::TextSuggestion
int m_linesCount;

CounterTooltip *m_counterTooltip = nullptr;
int m_startPosition;
TextEditor::TextSuggestion::Data m_suggestion;
};

} // namespace QodeAssist
5 changes: 4 additions & 1 deletion QodeAssist.json.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"Id" : "qodeassist",
"Name" : "QodeAssist",
"Version" : "0.3.10",
"Version" : "0.4.0",
"CompatVersion" : "${IDE_VERSION_COMPAT}",
"Vendor" : "Petr Mironychev",
"VendorId" : "petrmironychev",
"Copyright" : "(C) ${IDE_COPYRIGHT_YEAR} Petr Mironychev, (C) ${IDE_COPYRIGHT_YEAR} The Qt Company Ltd",
"License" : "GNU General Public License Usage

Expand All @@ -12,5 +14,6 @@ Alternatively, this file may be used under the terms of the GNU General Public L
"- One of the supported LLM providers installed (e.g., Ollama or LM Studio)",
"- A compatible large language model downloaded for your chosen provider (e.g., CodeLlama, StarCoder2)"],
"Url" : "https://github.com/Palm1r/QodeAssist",
"DocumentationUrl" : "",
${IDE_PLUGIN_DEPENDENCIES}
}
13 changes: 12 additions & 1 deletion QodeAssistClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,19 @@ void QodeAssistClient::handleCompletions(const GetCompletionRequest::Response &r
}
if (completions.isEmpty())
return;

auto suggestions = Utils::transform(completions, [](const Completion &c) {
auto toTextPos = [](const LanguageServerProtocol::Position pos) {
return Text::Position{pos.line() + 1, pos.character()};
};

Text::Range range{toTextPos(c.range().start()), toTextPos(c.range().end())};
Text::Position pos{toTextPos(c.position())};
return TextSuggestion::Data{range, pos, c.text()};
});

editor->insertSuggestion(
std::make_unique<LLMSuggestion>(completions.first(), editor->document()));
std::make_unique<LLMSuggestion>(suggestions.first(), editor->document()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion settings/ButtonAspect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ButtonAspect : public Utils::BaseAspect
: Utils::BaseAspect(container)
{}

void addToLayout(Layouting::Layout &parent) override
void addToLayoutImpl(Layouting::Layout &parent) override
{
auto button = new QPushButton(m_buttonText);
connect(button, &QPushButton::clicked, this, &ButtonAspect::clicked);
Expand Down
Loading