2018-10-17 21:52:26 +02:00
|
|
|
<?php
|
|
|
|
declare(strict_types = 1);
|
2018-11-06 03:57:36 +01:00
|
|
|
namespace Psalm\Internal\LanguageServer;
|
2018-10-17 21:52:26 +02:00
|
|
|
|
|
|
|
use JsonMapper;
|
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2018-10-17 21:52:26 +02:00
|
|
|
class LanguageClient
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handles textDocument/* methods
|
|
|
|
*
|
|
|
|
* @var Client\TextDocument
|
|
|
|
*/
|
|
|
|
public $textDocument;
|
|
|
|
|
2020-04-17 06:47:18 +02:00
|
|
|
/**
|
|
|
|
* The client handler
|
|
|
|
*
|
|
|
|
* @var ClientHandler
|
|
|
|
*/
|
|
|
|
private $handler;
|
|
|
|
|
2018-10-17 21:52:26 +02:00
|
|
|
public function __construct(ProtocolReader $reader, ProtocolWriter $writer)
|
|
|
|
{
|
2020-04-17 06:47:18 +02:00
|
|
|
$this->handler = new ClientHandler($reader, $writer);
|
2018-10-17 21:52:26 +02:00
|
|
|
$mapper = new JsonMapper;
|
|
|
|
|
2020-04-17 06:47:18 +02:00
|
|
|
$this->textDocument = new Client\TextDocument($this->handler, $mapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a log message to the client.
|
|
|
|
*
|
|
|
|
* @param string $message The message to send to the client.
|
|
|
|
* @psalm-param 1|2|3|4 $type
|
2020-09-22 06:44:31 +02:00
|
|
|
* @param int $type The log type:
|
2020-04-17 06:47:18 +02:00
|
|
|
* - 1 = Error
|
|
|
|
* - 2 = Warning
|
|
|
|
* - 3 = Info
|
|
|
|
* - 4 = Log
|
|
|
|
*/
|
2021-06-10 18:23:53 +02:00
|
|
|
public function logMessage(string $message, int $type = 4, string $method = 'window/logMessage'): void
|
2020-04-17 06:47:18 +02:00
|
|
|
{
|
|
|
|
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_logMessage
|
|
|
|
|
|
|
|
if ($type < 1 || $type > 4) {
|
|
|
|
$type = 4;
|
|
|
|
}
|
|
|
|
|
2021-06-10 18:23:53 +02:00
|
|
|
$this->handler->notify(
|
2020-04-17 06:47:18 +02:00
|
|
|
$method,
|
|
|
|
[
|
|
|
|
'type' => $type,
|
|
|
|
'message' => $message
|
|
|
|
]
|
|
|
|
);
|
2018-10-17 21:52:26 +02:00
|
|
|
}
|
|
|
|
}
|