forked from qt-creator/qt-creator
For easier testing a docker file is added. You can start "buildandrun.sh" in copilot/tests/proxy to get a simple proxy server up and running. The argument "PWDMODE" in buildandrun.sh can be set to "with" and "without" to get a proxy server that needs a password or not. The username and password are user/1234. Fixes: QTCREATORBUG-29485 Change-Id: I3859c9ad04ebd4f9349e25665ba710e23fb64dea Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
71 lines
2.2 KiB
C++
71 lines
2.2 KiB
C++
// 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
|
|
|
|
#pragma once
|
|
|
|
#include "copilothoverhandler.h"
|
|
#include "requests/checkstatus.h"
|
|
#include "requests/getcompletions.h"
|
|
#include "requests/seteditorinfo.h"
|
|
#include "requests/signinconfirm.h"
|
|
#include "requests/signininitiate.h"
|
|
#include "requests/signout.h"
|
|
|
|
#include <languageclient/client.h>
|
|
|
|
#include <utils/filepath.h>
|
|
|
|
#include <QHash>
|
|
#include <QTemporaryDir>
|
|
|
|
namespace Copilot::Internal {
|
|
|
|
class CopilotClient : public LanguageClient::Client
|
|
{
|
|
public:
|
|
CopilotClient(const Utils::FilePath &nodePath, const Utils::FilePath &distPath);
|
|
~CopilotClient() override;
|
|
|
|
void openDocument(TextEditor::TextDocument *document) override;
|
|
|
|
void scheduleRequest(TextEditor::TextEditorWidget *editor);
|
|
void requestCompletions(TextEditor::TextEditorWidget *editor);
|
|
void handleCompletions(const GetCompletionRequest::Response &response,
|
|
TextEditor::TextEditorWidget *editor);
|
|
void cancelRunningRequest(TextEditor::TextEditorWidget *editor);
|
|
|
|
void requestCheckStatus(
|
|
bool localChecksOnly,
|
|
std::function<void(const CheckStatusRequest::Response &response)> callback);
|
|
|
|
void requestSignOut(std::function<void(const SignOutRequest::Response &response)> callback);
|
|
|
|
void requestSignInInitiate(
|
|
std::function<void(const SignInInitiateRequest::Response &response)> callback);
|
|
|
|
void requestSignInConfirm(
|
|
const QString &userCode,
|
|
std::function<void(const SignInConfirmRequest::Response &response)> callback);
|
|
|
|
bool canOpenProject(ProjectExplorer::Project *project) override;
|
|
|
|
bool isEnabled(ProjectExplorer::Project *project);
|
|
|
|
void proxyAuthenticationFailed();
|
|
|
|
private:
|
|
void requestSetEditorInfo();
|
|
|
|
QMap<TextEditor::TextEditorWidget *, GetCompletionRequest> m_runningRequests;
|
|
struct ScheduleData
|
|
{
|
|
int cursorPosition = -1;
|
|
QTimer *timer = nullptr;
|
|
};
|
|
QMap<TextEditor::TextEditorWidget *, ScheduleData> m_scheduledRequests;
|
|
CopilotHoverHandler m_hoverHandler;
|
|
bool m_isAskingForPassword{false};
|
|
};
|
|
|
|
} // namespace Copilot::Internal
|