88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace LanguageServer\Server;
|
|
|
|
use LanguageServer\{LanguageClient, ColumnCalculator, SymbolFinder, Project};
|
|
use LanguageServer\Protocol\{
|
|
TextDocumentItem,
|
|
TextDocumentIdentifier,
|
|
VersionedTextDocumentIdentifier,
|
|
Diagnostic,
|
|
DiagnosticSeverity,
|
|
Range,
|
|
Position,
|
|
FormattingOptions,
|
|
TextEdit
|
|
};
|
|
|
|
/**
|
|
* Provides method handlers for all textDocument/* methods
|
|
*/
|
|
class TextDocument
|
|
{
|
|
/**
|
|
* The lanugage client object to call methods on the client
|
|
*
|
|
* @var \LanguageServer\LanguageClient
|
|
*/
|
|
private $client;
|
|
|
|
private $project;
|
|
|
|
public function __construct(Project $project, LanguageClient $client)
|
|
{
|
|
$this->project = $project;
|
|
$this->client = $client;
|
|
}
|
|
|
|
/**
|
|
* The document symbol request is sent from the client to the server to list all symbols found in a given text
|
|
* document.
|
|
*
|
|
* @param \LanguageServer\Protocol\TextDocumentIdentifier $textDocument
|
|
* @return SymbolInformation[]
|
|
*/
|
|
public function documentSymbol(TextDocumentIdentifier $textDocument): array
|
|
{
|
|
return $this->project->getDocument($textDocument->uri)->getSymbols();
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @param \LanguageServer\Protocol\TextDocumentItem $textDocument The document that was opened.
|
|
* @return void
|
|
*/
|
|
public function didOpen(TextDocumentItem $textDocument)
|
|
{
|
|
$this->project->getDocument($textDocument->uri)->updateContent($textDocument->text);
|
|
}
|
|
|
|
/**
|
|
* The document change notification is sent from the client to the server to signal changes to a text document.
|
|
*
|
|
* @param \LanguageServer\Protocol\VersionedTextDocumentIdentifier $textDocument
|
|
* @param \LanguageServer\Protocol\TextDocumentContentChangeEvent[] $contentChanges
|
|
* @return void
|
|
*/
|
|
public function didChange(VersionedTextDocumentIdentifier $textDocument, array $contentChanges)
|
|
{
|
|
$this->project->getDocument($textDocument->uri)->updateContent($contentChanges[0]->text);
|
|
}
|
|
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
return $this->project->getDocument($textDocument->uri)->getFormattedText();
|
|
}
|
|
}
|