2016-09-02 19:13:30 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace LanguageServer\Client;
|
|
|
|
|
2016-10-31 10:47:21 +00:00
|
|
|
use LanguageServer\ClientHandler;
|
2018-02-28 18:05:22 +00:00
|
|
|
use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier};
|
2016-10-31 10:47:21 +00:00
|
|
|
use Sabre\Event\Promise;
|
2016-11-14 09:25:44 +00:00
|
|
|
use JsonMapper;
|
2016-09-02 19:13:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides method handlers for all textDocument/* methods
|
|
|
|
*/
|
|
|
|
class TextDocument
|
|
|
|
{
|
|
|
|
/**
|
2016-10-31 10:47:21 +00:00
|
|
|
* @var ClientHandler
|
2016-09-02 19:13:30 +00:00
|
|
|
*/
|
2016-10-31 10:47:21 +00:00
|
|
|
private $handler;
|
2016-09-02 19:13:30 +00:00
|
|
|
|
2016-11-14 09:25:44 +00:00
|
|
|
/**
|
|
|
|
* @var JsonMapper
|
|
|
|
*/
|
|
|
|
private $mapper;
|
|
|
|
|
|
|
|
public function __construct(ClientHandler $handler, JsonMapper $mapper)
|
2016-09-02 19:13:30 +00:00
|
|
|
{
|
2016-10-31 10:47:21 +00:00
|
|
|
$this->handler = $handler;
|
2016-11-14 09:25:44 +00:00
|
|
|
$this->mapper = $mapper;
|
2016-09-02 19:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Diagnostics notification are sent from the server to the client to signal results of validation runs.
|
|
|
|
*
|
|
|
|
* @param string $uri
|
|
|
|
* @param Diagnostic[] $diagnostics
|
2016-10-31 10:47:21 +00:00
|
|
|
* @return Promise <void>
|
2016-09-02 19:13:30 +00:00
|
|
|
*/
|
2016-10-31 10:47:21 +00:00
|
|
|
public function publishDiagnostics(string $uri, array $diagnostics): Promise
|
2016-09-02 19:13:30 +00:00
|
|
|
{
|
2016-10-31 10:47:21 +00:00
|
|
|
return $this->handler->notify('textDocument/publishDiagnostics', [
|
|
|
|
'uri' => $uri,
|
|
|
|
'diagnostics' => $diagnostics
|
|
|
|
]);
|
2016-09-02 19:13:30 +00:00
|
|
|
}
|
2016-11-14 09:25:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The content request is sent from a server to a client
|
|
|
|
* to request the current content of a text document identified by the URI
|
|
|
|
*
|
|
|
|
* @param TextDocumentIdentifier $textDocument The document to get the content for
|
|
|
|
* @return Promise <TextDocumentItem> The document's current content
|
|
|
|
*/
|
|
|
|
public function xcontent(TextDocumentIdentifier $textDocument): Promise
|
|
|
|
{
|
|
|
|
return $this->handler->request(
|
|
|
|
'textDocument/xcontent',
|
|
|
|
['textDocument' => $textDocument]
|
|
|
|
)->then(function ($result) {
|
|
|
|
return $this->mapper->map($result, new TextDocumentItem);
|
|
|
|
});
|
|
|
|
}
|
2016-09-02 19:13:30 +00:00
|
|
|
}
|