2023-01-20 07:09:01 +01:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
|
|
#include "copilotoptionspage.h"
|
|
|
|
|
|
2023-02-22 14:35:18 +01:00
|
|
|
#include "authwidget.h"
|
2023-05-23 08:58:07 +02:00
|
|
|
#include "copilotconstants.h"
|
2023-02-22 14:35:18 +01:00
|
|
|
#include "copilotsettings.h"
|
2023-02-24 11:27:24 +01:00
|
|
|
#include "copilottr.h"
|
2023-01-20 07:09:01 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
|
2023-02-22 14:35:18 +01:00
|
|
|
#include <utils/layoutbuilder.h>
|
|
|
|
|
#include <utils/pathchooser.h>
|
|
|
|
|
|
2023-06-19 17:14:34 +02:00
|
|
|
#include <QToolTip>
|
|
|
|
|
|
2023-02-22 14:35:18 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
using namespace LanguageClient;
|
|
|
|
|
|
2023-01-20 07:09:01 +01:00
|
|
|
namespace Copilot {
|
|
|
|
|
|
2023-04-20 10:40:54 +02:00
|
|
|
class CopilotOptionsPageWidget : public Core::IOptionsPageWidget
|
2023-02-22 14:35:18 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2023-04-20 10:40:54 +02:00
|
|
|
CopilotOptionsPageWidget()
|
2023-02-22 14:35:18 +01:00
|
|
|
{
|
|
|
|
|
using namespace Layouting;
|
|
|
|
|
|
2023-06-22 09:44:08 +02:00
|
|
|
auto warningLabel = new QLabel;
|
|
|
|
|
warningLabel->setWordWrap(true);
|
|
|
|
|
warningLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse
|
|
|
|
|
| Qt::LinksAccessibleByKeyboard
|
|
|
|
|
| Qt::TextSelectableByMouse);
|
|
|
|
|
warningLabel->setText(Tr::tr(
|
|
|
|
|
"Enabling %1 is subject to your agreement and abidance with your applicable "
|
|
|
|
|
"%1 terms. It is your responsibility to know and accept the requirements and "
|
|
|
|
|
"parameters of using tools like %1. This may include, but is not limited to, "
|
|
|
|
|
"ensuring you have the rights to allow %1 access to your code, as well as "
|
|
|
|
|
"understanding any implications of your use of %1 and suggestions produced "
|
|
|
|
|
"(like copyright, accuracy, etc.)." ).arg("Copilot"));
|
|
|
|
|
|
2023-02-22 14:35:18 +01:00
|
|
|
auto authWidget = new AuthWidget();
|
|
|
|
|
|
2023-06-22 09:44:08 +02:00
|
|
|
auto helpLabel = new QLabel();
|
2023-02-24 11:27:24 +01:00
|
|
|
helpLabel->setTextFormat(Qt::MarkdownText);
|
|
|
|
|
helpLabel->setWordWrap(true);
|
|
|
|
|
helpLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse
|
2023-06-19 17:23:26 +02:00
|
|
|
| Qt::LinksAccessibleByKeyboard
|
|
|
|
|
| Qt::TextSelectableByMouse);
|
2023-02-24 11:27:24 +01:00
|
|
|
helpLabel->setOpenExternalLinks(true);
|
2023-06-19 17:14:34 +02:00
|
|
|
connect(helpLabel, &QLabel::linkHovered, [](const QString &link) {
|
|
|
|
|
QToolTip::showText(QCursor::pos(), link);
|
|
|
|
|
});
|
2023-02-24 11:27:24 +01:00
|
|
|
|
2023-02-22 14:35:18 +01:00
|
|
|
// clang-format off
|
2023-06-22 08:44:09 +02:00
|
|
|
helpLabel->setText(Tr::tr(
|
|
|
|
|
"The Copilot plugin requires node.js and the Copilot neovim plugin. "
|
|
|
|
|
"If you install the neovim plugin as described in %1, "
|
|
|
|
|
"the plugin will find the agent.js file automatically.\n\n"
|
|
|
|
|
"Otherwise you need to specify the path to the %2 "
|
|
|
|
|
"file from the Copilot neovim plugin.",
|
2023-06-22 13:53:01 +02:00
|
|
|
"Markdown text for the copilot instruction label")
|
|
|
|
|
.arg("[README.md](https://github.com/github/copilot.vim)")
|
|
|
|
|
.arg("[agent.js](https://github.com/github/copilot.vim/tree/release/copilot/dist)"));
|
2023-02-24 11:27:24 +01:00
|
|
|
|
2023-02-22 14:35:18 +01:00
|
|
|
Column {
|
2023-06-22 09:44:08 +02:00
|
|
|
QString("<b>" + Tr::tr("Note:") + "</b>"), br,
|
|
|
|
|
warningLabel, br,
|
2023-05-23 08:58:07 +02:00
|
|
|
CopilotSettings::instance().enableCopilot, br,
|
2023-06-23 08:44:49 +02:00
|
|
|
authWidget, br,
|
2023-02-22 14:35:18 +01:00
|
|
|
CopilotSettings::instance().nodeJsPath, br,
|
|
|
|
|
CopilotSettings::instance().distPath, br,
|
2023-04-18 15:09:01 +02:00
|
|
|
CopilotSettings::instance().autoComplete, br,
|
2023-02-24 11:27:24 +01:00
|
|
|
helpLabel, br,
|
2023-02-22 14:35:18 +01:00
|
|
|
st
|
|
|
|
|
}.attachTo(this);
|
|
|
|
|
// clang-format on
|
2023-03-09 12:26:42 +01:00
|
|
|
|
|
|
|
|
auto updateAuthWidget = [authWidget]() {
|
|
|
|
|
authWidget->updateClient(
|
|
|
|
|
FilePath::fromUserInput(
|
|
|
|
|
CopilotSettings::instance().nodeJsPath.volatileValue().toString()),
|
|
|
|
|
FilePath::fromUserInput(
|
|
|
|
|
CopilotSettings::instance().distPath.volatileValue().toString()));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
connect(CopilotSettings::instance().nodeJsPath.pathChooser(),
|
|
|
|
|
&PathChooser::textChanged,
|
|
|
|
|
authWidget,
|
|
|
|
|
updateAuthWidget);
|
|
|
|
|
connect(CopilotSettings::instance().distPath.pathChooser(),
|
|
|
|
|
&PathChooser::textChanged,
|
|
|
|
|
authWidget,
|
|
|
|
|
updateAuthWidget);
|
|
|
|
|
updateAuthWidget();
|
2023-04-20 10:40:54 +02:00
|
|
|
|
2023-05-09 08:25:58 +02:00
|
|
|
setOnApply([] {
|
|
|
|
|
CopilotSettings::instance().apply();
|
|
|
|
|
CopilotSettings::instance().writeSettings(Core::ICore::settings());
|
|
|
|
|
});
|
2023-04-20 10:40:54 +02:00
|
|
|
}
|
2023-02-22 14:35:18 +01:00
|
|
|
};
|
|
|
|
|
|
2023-01-20 07:09:01 +01:00
|
|
|
CopilotOptionsPage::CopilotOptionsPage()
|
|
|
|
|
{
|
2023-05-23 08:58:07 +02:00
|
|
|
setId(Constants::COPILOT_GENERAL_OPTIONS_ID);
|
2023-01-20 07:09:01 +01:00
|
|
|
setDisplayName("Copilot");
|
2023-05-23 08:58:07 +02:00
|
|
|
setCategory(Constants::COPILOT_GENERAL_OPTIONS_CATEGORY);
|
|
|
|
|
setDisplayCategory(Constants::COPILOT_GENERAL_OPTIONS_DISPLAY_CATEGORY);
|
2023-02-27 18:22:57 +01:00
|
|
|
setCategoryIconPath(":/copilot/images/settingscategory_copilot.png");
|
2023-04-20 10:40:54 +02:00
|
|
|
setWidgetCreator([] { return new CopilotOptionsPageWidget; });
|
2023-01-20 07:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CopilotOptionsPage &CopilotOptionsPage::instance()
|
|
|
|
|
{
|
|
|
|
|
static CopilotOptionsPage settingsPage;
|
|
|
|
|
return settingsPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Copilot
|