2019-01-31 08:46:23 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
2021-04-30 08:12:33 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
|
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-10 11:40:56 +02:00
|
|
|
void sendContent(const LanguageServerProtocol::IContent &content);
|
2022-05-11 14:01:49 +02:00
|
|
|
void start() { startImpl(); }
|
2019-01-31 08:46:23 +01:00
|
|
|
|
|
|
|
|
void resetBuffer();
|
|
|
|
|
|
|
|
|
|
signals:
|
2022-05-10 11:40:56 +02:00
|
|
|
void contentReceived(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
|
|
|
|
|
public:
|
2021-02-19 08:57:45 +01:00
|
|
|
StdIOClientInterface();
|
2019-01-31 08:46:23 +01:00
|
|
|
~StdIOClientInterface() override;
|
|
|
|
|
|
|
|
|
|
StdIOClientInterface(const StdIOClientInterface &) = delete;
|
|
|
|
|
StdIOClientInterface(StdIOClientInterface &&) = delete;
|
|
|
|
|
StdIOClientInterface &operator=(const StdIOClientInterface &) = delete;
|
|
|
|
|
StdIOClientInterface &operator=(StdIOClientInterface &&) = delete;
|
|
|
|
|
|
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);
|
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;
|
2019-01-31 08:46:23 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void readError();
|
|
|
|
|
void readOutput();
|
2021-05-28 14:48:25 +02:00
|
|
|
void onProcessFinished();
|
2019-01-31 08:46:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace LanguageClient
|