2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2019-01-31 08:46:23 +01:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-02-19 08:57:45 +01:00
|
|
|
#include "languageclient_global.h"
|
|
|
|
|
|
2022-05-10 11:40:56 +02:00
|
|
|
#include <languageserverprotocol/jsonrpcmessages.h>
|
2019-01-31 08:46:23 +01:00
|
|
|
|
2022-05-25 15:24:09 +02:00
|
|
|
#include <utils/environment.h>
|
2021-04-30 08:12:33 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2022-12-06 10:10:16 +01:00
|
|
|
#include <utils/temporaryfile.h>
|
2021-04-30 08:12:33 +02:00
|
|
|
|
2019-01-31 08:46:23 +01:00
|
|
|
#include <QBuffer>
|
|
|
|
|
|
|
|
|
|
namespace LanguageClient {
|
|
|
|
|
|
|
|
|
|
class StdIOSettings;
|
|
|
|
|
|
2021-02-19 08:57:45 +01:00
|
|
|
class LANGUAGECLIENT_EXPORT BaseClientInterface : public QObject
|
2019-01-31 08:46:23 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
BaseClientInterface();
|
|
|
|
|
|
2021-02-19 08:57:45 +01:00
|
|
|
~BaseClientInterface() override;
|
2019-01-31 08:46:23 +01:00
|
|
|
|
2022-05-12 09:51:39 +02:00
|
|
|
void sendMessage(const LanguageServerProtocol::JsonRpcMessage message);
|
2022-05-11 14:01:49 +02:00
|
|
|
void start() { startImpl(); }
|
2019-01-31 08:46:23 +01:00
|
|
|
|
2022-12-15 07:23:55 +01:00
|
|
|
virtual Utils::FilePath serverDeviceTemplate() const = 0;
|
|
|
|
|
|
2019-01-31 08:46:23 +01:00
|
|
|
void resetBuffer();
|
|
|
|
|
|
|
|
|
|
signals:
|
2022-05-12 09:51:39 +02:00
|
|
|
void messageReceived(const LanguageServerProtocol::JsonRpcMessage message);
|
2019-01-31 08:46:23 +01:00
|
|
|
void finished();
|
|
|
|
|
void error(const QString &message);
|
2022-05-11 14:01:49 +02:00
|
|
|
void started();
|
2019-01-31 08:46:23 +01:00
|
|
|
|
|
|
|
|
protected:
|
2022-05-11 14:01:49 +02:00
|
|
|
virtual void startImpl() { emit started(); }
|
2019-01-31 08:46:23 +01:00
|
|
|
virtual void sendData(const QByteArray &data) = 0;
|
|
|
|
|
void parseData(const QByteArray &data);
|
2022-05-10 11:40:56 +02:00
|
|
|
virtual void parseCurrentMessage();
|
2019-01-31 08:46:23 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QBuffer m_buffer;
|
|
|
|
|
LanguageServerProtocol::BaseMessage m_currentMessage;
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-19 08:57:45 +01:00
|
|
|
class LANGUAGECLIENT_EXPORT StdIOClientInterface : public BaseClientInterface
|
2019-01-31 08:46:23 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2023-04-23 10:34:37 +02:00
|
|
|
Q_DISABLE_COPY_MOVE(StdIOClientInterface)
|
|
|
|
|
|
2019-01-31 08:46:23 +01:00
|
|
|
public:
|
2022-12-06 10:10:16 +01:00
|
|
|
StdIOClientInterface();
|
2019-01-31 08:46:23 +01:00
|
|
|
~StdIOClientInterface() override;
|
|
|
|
|
|
2022-05-11 14:01:49 +02:00
|
|
|
void startImpl() override;
|
2019-01-31 08:46:23 +01:00
|
|
|
|
2021-02-19 08:57:45 +01:00
|
|
|
// These functions only have an effect if they are called before start
|
2021-04-30 08:25:10 +02:00
|
|
|
void setCommandLine(const Utils::CommandLine &cmd);
|
2022-01-18 17:40:19 +01:00
|
|
|
void setWorkingDirectory(const Utils::FilePath &workingDirectory);
|
2022-05-25 15:24:09 +02:00
|
|
|
void setEnvironment(const Utils::Environment &environment);
|
2019-01-31 08:46:23 +01:00
|
|
|
|
2022-12-15 07:23:55 +01:00
|
|
|
Utils::FilePath serverDeviceTemplate() const override;
|
|
|
|
|
|
2019-01-31 08:46:23 +01:00
|
|
|
protected:
|
|
|
|
|
void sendData(const QByteArray &data) final;
|
2022-05-11 14:01:49 +02:00
|
|
|
Utils::CommandLine m_cmd;
|
|
|
|
|
Utils::FilePath m_workingDirectory;
|
|
|
|
|
Utils::QtcProcess *m_process = nullptr;
|
2022-05-25 15:24:09 +02:00
|
|
|
Utils::Environment m_env;
|
2019-01-31 08:46:23 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void readError();
|
|
|
|
|
void readOutput();
|
2022-12-06 10:10:16 +01:00
|
|
|
|
|
|
|
|
Utils::TemporaryFile m_logFile;
|
2019-01-31 08:46:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace LanguageClient
|