2016-08-23 09:21:37 +00:00
|
|
|
<?php
|
2016-09-30 09:54:49 +00:00
|
|
|
declare(strict_types = 1);
|
2016-08-23 09:21:37 +00:00
|
|
|
|
2016-09-02 19:13:30 +00:00
|
|
|
namespace LanguageServer\Server;
|
2016-08-23 09:21:37 +00:00
|
|
|
|
2016-09-30 09:30:08 +00:00
|
|
|
use LanguageServer\{LanguageClient, ColumnCalculator, SymbolFinder, Project};
|
2016-09-02 19:13:30 +00:00
|
|
|
use LanguageServer\Protocol\{
|
|
|
|
TextDocumentItem,
|
|
|
|
TextDocumentIdentifier,
|
|
|
|
VersionedTextDocumentIdentifier,
|
|
|
|
Diagnostic,
|
|
|
|
DiagnosticSeverity,
|
|
|
|
Range,
|
2016-09-06 10:54:34 +00:00
|
|
|
Position,
|
|
|
|
FormattingOptions,
|
|
|
|
TextEdit
|
2016-09-02 19:13:30 +00:00
|
|
|
};
|
2016-08-25 13:27:14 +00:00
|
|
|
|
2016-08-23 09:21:37 +00:00
|
|
|
/**
|
|
|
|
* Provides method handlers for all textDocument/* methods
|
|
|
|
*/
|
2016-09-02 19:13:30 +00:00
|
|
|
class TextDocument
|
2016-08-23 09:21:37 +00:00
|
|
|
{
|
2016-09-02 19:13:30 +00:00
|
|
|
/**
|
|
|
|
* The lanugage client object to call methods on the client
|
|
|
|
*
|
2016-09-04 10:27:56 +00:00
|
|
|
* @var \LanguageServer\LanguageClient
|
2016-09-02 19:13:30 +00:00
|
|
|
*/
|
|
|
|
private $client;
|
|
|
|
|
2016-09-30 09:30:08 +00:00
|
|
|
private $project;
|
|
|
|
|
|
|
|
public function __construct(Project $project, LanguageClient $client)
|
2016-08-25 13:27:14 +00:00
|
|
|
{
|
2016-09-30 09:30:08 +00:00
|
|
|
$this->project = $project;
|
2016-09-02 19:13:30 +00:00
|
|
|
$this->client = $client;
|
2016-08-25 13:27:14 +00:00
|
|
|
}
|
|
|
|
|
2016-08-23 09:21:37 +00:00
|
|
|
/**
|
|
|
|
* The document symbol request is sent from the client to the server to list all symbols found in a given text
|
|
|
|
* document.
|
|
|
|
*
|
2016-09-04 10:27:56 +00:00
|
|
|
* @param \LanguageServer\Protocol\TextDocumentIdentifier $textDocument
|
2016-08-23 09:21:37 +00:00
|
|
|
* @return SymbolInformation[]
|
|
|
|
*/
|
2016-08-25 13:27:14 +00:00
|
|
|
public function documentSymbol(TextDocumentIdentifier $textDocument): array
|
2016-08-23 09:21:37 +00:00
|
|
|
{
|
2016-09-30 09:30:08 +00:00
|
|
|
return $this->project->getDocument($textDocument->uri)->getSymbols();
|
2016-08-25 13:27:14 +00:00
|
|
|
}
|
2016-08-23 09:21:37 +00:00
|
|
|
|
2016-08-25 13:27:14 +00:00
|
|
|
/**
|
|
|
|
* The document open notification is sent from the client to the server to signal newly opened text documents. The
|
|
|
|
* document's truth is now managed by the client and the server must not try to read the document's truth using the
|
|
|
|
* document's uri.
|
|
|
|
*
|
2016-09-04 10:27:56 +00:00
|
|
|
* @param \LanguageServer\Protocol\TextDocumentItem $textDocument The document that was opened.
|
2016-08-25 13:27:14 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function didOpen(TextDocumentItem $textDocument)
|
|
|
|
{
|
2016-09-30 09:30:08 +00:00
|
|
|
$this->project->getDocument($textDocument->uri)->updateContent($textDocument->text);
|
2016-08-25 13:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The document change notification is sent from the client to the server to signal changes to a text document.
|
|
|
|
*
|
2016-09-04 10:27:56 +00:00
|
|
|
* @param \LanguageServer\Protocol\VersionedTextDocumentIdentifier $textDocument
|
|
|
|
* @param \LanguageServer\Protocol\TextDocumentContentChangeEvent[] $contentChanges
|
2016-08-25 13:27:14 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function didChange(VersionedTextDocumentIdentifier $textDocument, array $contentChanges)
|
|
|
|
{
|
2016-09-30 09:30:08 +00:00
|
|
|
$this->project->getDocument($textDocument->uri)->updateContent($contentChanges[0]->text);
|
2016-08-25 13:27:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 10:54:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The document formatting request is sent from the server to the client to format a whole document.
|
|
|
|
*
|
|
|
|
* @param TextDocumentIdentifier $textDocument The document to format
|
|
|
|
* @param FormattingOptions $options The format options
|
|
|
|
* @return TextEdit[]
|
|
|
|
*/
|
|
|
|
public function formatting(TextDocumentIdentifier $textDocument, FormattingOptions $options)
|
|
|
|
{
|
2016-09-30 09:30:08 +00:00
|
|
|
return $this->project->getDocument($textDocument->uri)->getFormattedText();
|
2016-09-06 10:54:34 +00:00
|
|
|
}
|
2016-08-23 09:21:37 +00:00
|
|
|
}
|