forked from qt-creator/qt-creator
LanguageClient: Move the BaseMessage to JsonRpcMessage conversion
... to the client interface. JsonRpcMessages are the only messages used so far and no other types of messages are currently used by any of the supported Language Servers. If a client is going to need special message parsing it can still implement a specialized client interface and overwrite parseCurrentMessage. This is the preparation to move receiving and parsing data passed to and from the language server out of the GUI thread. Change-Id: Ibd4cd95daab7efff947273ca9e7d457de0286f47 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -46,8 +46,9 @@ BaseClientInterface::~BaseClientInterface()
|
||||
m_buffer.close();
|
||||
}
|
||||
|
||||
void BaseClientInterface::sendMessage(const BaseMessage &message)
|
||||
void BaseClientInterface::sendContent(const IContent &content)
|
||||
{
|
||||
const BaseMessage message = content.toBaseMessage();
|
||||
sendData(message.header());
|
||||
sendData(message.content);
|
||||
}
|
||||
@@ -78,8 +79,7 @@ void BaseClientInterface::parseData(const QByteArray &data)
|
||||
emit error(parseError);
|
||||
if (!m_currentMessage.isComplete())
|
||||
break;
|
||||
emit messageReceived(m_currentMessage);
|
||||
m_currentMessage = BaseMessage();
|
||||
parseCurrentMessage();
|
||||
}
|
||||
if (m_buffer.atEnd()) {
|
||||
m_buffer.close();
|
||||
@@ -88,6 +88,17 @@ void BaseClientInterface::parseData(const QByteArray &data)
|
||||
}
|
||||
}
|
||||
|
||||
void BaseClientInterface::parseCurrentMessage()
|
||||
{
|
||||
if (m_currentMessage.mimeType == JsonRpcMessage::jsonRpcMimeType()) {
|
||||
emit contentReceived(JsonRpcMessage(m_currentMessage));
|
||||
} else {
|
||||
emit error(tr("Cannot handle mimetype of message %1")
|
||||
.arg(QString::fromUtf8(m_currentMessage.mimeType)));
|
||||
}
|
||||
m_currentMessage = BaseMessage();
|
||||
}
|
||||
|
||||
StdIOClientInterface::StdIOClientInterface()
|
||||
{
|
||||
m_process.setProcessMode(ProcessMode::Writer);
|
||||
|
||||
Reference in New Issue
Block a user