forked from qt-creator/qt-creator
Copilot: Allow user to disable Copilot
Fixes: QTCREATORBUG-29179 Change-Id: I274de1f13f773fb61b376643b61056b6f14dabaf Reviewed-by: BogDan Vatra <bogdan@kdab.com> Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
@@ -2,8 +2,11 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "copilotsettings.h"
|
||||
#include "copilotconstants.h"
|
||||
#include "copilottr.h"
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
|
||||
@@ -11,6 +14,15 @@ using namespace Utils;
|
||||
|
||||
namespace Copilot {
|
||||
|
||||
static void initEnableAspect(BoolAspect &enableCopilot)
|
||||
{
|
||||
enableCopilot.setSettingsKey(Constants::ENABLE_COPILOT);
|
||||
enableCopilot.setDisplayName(Tr::tr("Enable Copilot"));
|
||||
enableCopilot.setLabelText(Tr::tr("Enable Copilot"));
|
||||
enableCopilot.setToolTip(Tr::tr("Enables the Copilot integration."));
|
||||
enableCopilot.setDefaultValue(true);
|
||||
}
|
||||
|
||||
CopilotSettings &CopilotSettings::instance()
|
||||
{
|
||||
static CopilotSettings settings;
|
||||
@@ -32,7 +44,7 @@ CopilotSettings::CopilotSettings()
|
||||
FilePath::fromUserInput(
|
||||
"~/AppData/Local/nvim/pack/github/start/copilot.vim/copilot/dist/agent.js")};
|
||||
|
||||
const FilePath distFromVim = Utils::findOrDefault(searchDirs, &FilePath::exists);
|
||||
const FilePath distFromVim = findOrDefault(searchDirs, &FilePath::exists);
|
||||
|
||||
nodeJsPath.setExpectedKind(PathChooser::ExistingCommand);
|
||||
nodeJsPath.setDefaultFilePath(nodeFromPath);
|
||||
@@ -55,10 +67,52 @@ CopilotSettings::CopilotSettings()
|
||||
"https://github.com/github/copilot.vim#getting-started for installation instructions."));
|
||||
|
||||
autoComplete.setDisplayName(Tr::tr("Auto Complete"));
|
||||
autoComplete.setSettingsKey("Copilot.Autocomplete");
|
||||
autoComplete.setLabelText(Tr::tr("Request completions automatically"));
|
||||
autoComplete.setDefaultValue(true);
|
||||
autoComplete.setToolTip(Tr::tr("Automatically request suggestions for the current text cursor "
|
||||
"position after changes to the document"));
|
||||
|
||||
initEnableAspect(enableCopilot);
|
||||
}
|
||||
|
||||
CopilotProjectSettings::CopilotProjectSettings(ProjectExplorer::Project *project, QObject *parent)
|
||||
: AspectContainer(parent)
|
||||
{
|
||||
setAutoApply(true);
|
||||
|
||||
useGlobalSettings.setSettingsKey(Constants::COPILOT_USE_GLOBAL_SETTINGS);
|
||||
useGlobalSettings.setDefaultValue(true);
|
||||
|
||||
initEnableAspect(enableCopilot);
|
||||
|
||||
QVariantMap map = project->namedSettings(Constants::COPILOT_PROJECT_SETTINGS_ID).toMap();
|
||||
fromMap(map);
|
||||
|
||||
connect(&enableCopilot, &BoolAspect::valueChanged, this, [this, project] { save(project); });
|
||||
connect(&useGlobalSettings, &BoolAspect::valueChanged, this, [this, project] { save(project); });
|
||||
}
|
||||
|
||||
void CopilotProjectSettings::setUseGlobalSettings(bool useGlobal)
|
||||
{
|
||||
useGlobalSettings.setValue(useGlobal);
|
||||
}
|
||||
|
||||
bool CopilotProjectSettings::isEnabled() const
|
||||
{
|
||||
if (useGlobalSettings())
|
||||
return CopilotSettings::instance().enableCopilot();
|
||||
return enableCopilot();
|
||||
}
|
||||
|
||||
void CopilotProjectSettings::save(ProjectExplorer::Project *project)
|
||||
{
|
||||
QVariantMap map;
|
||||
toMap(map);
|
||||
project->setNamedSettings(Constants::COPILOT_PROJECT_SETTINGS_ID, map);
|
||||
|
||||
// This triggers a restart of the Copilot language server.
|
||||
CopilotSettings::instance().apply();
|
||||
}
|
||||
|
||||
} // namespace Copilot
|
||||
|
||||
Reference in New Issue
Block a user