1
0
Fork 0

refactor: use protocol package (#661)

Adapts the Language Server to use the extracted php language server protocol
pull/676/head
dantleech 2018-09-09 13:37:35 +01:00 committed by Felix Becker
parent 3d8318bd03
commit 18c6ccd137
98 changed files with 189 additions and 1820 deletions

View File

@ -24,6 +24,7 @@
"php": "^7.0",
"composer/xdebug-handler": "^1.0",
"felixfbecker/advanced-json-rpc": "^3.0.0",
"felixfbecker/language-server-protocol": "^1.0.1",
"jetbrains/phpstorm-stubs": "dev-master",
"microsoft/tolerant-php-parser": "0.0.*",
"netresearch/jsonmapper": "^1.0",

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Client;
use LanguageServer\ClientHandler;
use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier};
use LanguageServerProtocol\{TextDocumentItem, TextDocumentIdentifier};
use Sabre\Event\Promise;
use JsonMapper;

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Client;
use LanguageServer\ClientHandler;
use LanguageServer\Protocol\TextDocumentIdentifier;
use LanguageServerProtocol\TextDocumentIdentifier;
use Sabre\Event\Promise;
use JsonMapper;

View File

@ -41,12 +41,12 @@ class ClientHandler
{
$id = $this->idGenerator->generate();
return $this->protocolWriter->write(
new Protocol\Message(
new Message(
new AdvancedJsonRpc\Request($id, $method, (object)$params)
)
)->then(function () use ($id) {
$promise = new Promise;
$listener = function (Protocol\Message $msg) use ($id, $promise, &$listener) {
$listener = function (Message $msg) use ($id, $promise, &$listener) {
if (AdvancedJsonRpc\Response::isResponse($msg->body) && $msg->body->id === $id) {
// Received a response
$this->protocolReader->removeListener('message', $listener);
@ -72,7 +72,7 @@ class ClientHandler
public function notify(string $method, $params): Promise
{
return $this->protocolWriter->write(
new Protocol\Message(
new Message(
new AdvancedJsonRpc\Notification($method, (object)$params)
)
);

View File

@ -4,7 +4,8 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Index\ReadableIndex;
use LanguageServer\Protocol\{
use LanguageServer\Factory\CompletionItemFactory;
use LanguageServerProtocol\{
TextEdit,
Range,
Position,
@ -246,7 +247,7 @@ class CompletionProvider
foreach ($this->index->getDefinitions() as $fqn => $def) {
foreach ($prefixes as $prefix) {
if (substr($fqn, 0, strlen($prefix)) === $prefix && $def->isMember) {
$list->items[] = CompletionItem::fromDefinition($def);
$list->items[] = CompletionItemFactory::fromDefinition($def);
}
}
}
@ -279,7 +280,7 @@ class CompletionProvider
foreach ($this->index->getDefinitions() as $fqn => $def) {
foreach ($prefixes as $prefix) {
if (substr(strtolower($fqn), 0, strlen($prefix)) === strtolower($prefix) && $def->isMember) {
$list->items[] = CompletionItem::fromDefinition($def);
$list->items[] = CompletionItemFactory::fromDefinition($def);
}
}
}
@ -337,7 +338,7 @@ class CompletionProvider
foreach ($aliases as $alias => $fqn) {
// Suggest symbols that have been `use`d and match the prefix
if (substr($alias, 0, $prefixLen) === $prefix && ($def = $this->index->getDefinition($fqn))) {
$list->items[] = CompletionItem::fromDefinition($def);
$list->items[] = CompletionItemFactory::fromDefinition($def);
}
}
}
@ -370,7 +371,7 @@ class CompletionProvider
// Only suggest classes for `new`
&& (!isset($creation) || $def->canBeInstantiated)
) {
$item = CompletionItem::fromDefinition($def);
$item = CompletionItemFactory::fromDefinition($def);
// Find the shortest name to reference the symbol
if ($namespaceNode && ($alias = array_search($fqn, $aliases, true)) !== false) {
// $alias is the name under which this definition is aliased in the current namespace

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\ContentRetriever;
use LanguageServer\LanguageClient;
use LanguageServer\Protocol\{TextDocumentIdentifier, TextDocumentItem};
use LanguageServerProtocol\{TextDocumentIdentifier, TextDocumentItem};
use Sabre\Event\Promise;
/**

View File

@ -5,7 +5,7 @@ namespace LanguageServer;
use LanguageServer\Index\ReadableIndex;
use phpDocumentor\Reflection\{Types, Type, Fqsen, TypeResolver};
use LanguageServer\Protocol\SymbolInformation;
use LanguageServerProtocol\SymbolInformation;
use Generator;
/**

View File

@ -4,7 +4,8 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Index\ReadableIndex;
use LanguageServer\Protocol\SymbolInformation;
use LanguageServer\Factory\SymbolInformationFactory;
use LanguageServerProtocol\SymbolInformation;
use Microsoft\PhpParser;
use Microsoft\PhpParser\Node;
use Microsoft\PhpParser\FunctionLike;
@ -36,7 +37,7 @@ class DefinitionResolver
private $docBlockFactory;
/**
* Creates SignatureInformation
* Creates SignatureInformation instances
*
* @var SignatureInformationFactory
*/
@ -233,7 +234,7 @@ class DefinitionResolver
}
}
$def->symbolInformation = SymbolInformation::fromNode($node, $fqn);
$def->symbolInformation = SymbolInformationFactory::fromNode($node, $fqn);
if ($def->symbolInformation !== null) {
$def->type = $this->getTypeFromNode($node);

View File

@ -0,0 +1,36 @@
<?php
namespace LanguageServer\Factory;
use LanguageServer\Definition;
use LanguageServerProtocol\CompletionItem;
use LanguageServerProtocol\CompletionItemKind;
use LanguageServerProtocol\SymbolKind;
class CompletionItemFactory
{
/**
* Creates a CompletionItem for a Definition
*
* @param Definition $def
* @return CompletionItem|null
*/
public static function fromDefinition(Definition $def)
{
$item = new CompletionItem;
$item->label = $def->symbolInformation->name;
$item->kind = CompletionItemKind::fromSymbolKind($def->symbolInformation->kind);
if ($def->type) {
$item->detail = (string)$def->type;
} else if ($def->symbolInformation->containerName) {
$item->detail = $def->symbolInformation->containerName;
}
if ($def->documentation) {
$item->documentation = $def->documentation;
}
if ($def->isStatic && $def->symbolInformation->kind === SymbolKind::PROPERTY) {
$item->insertText = '$' . $def->symbolInformation->name;
}
return $item;
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace LanguageServer\Factory;
use LanguageServerProtocol\Location;
use LanguageServerProtocol\Position;
use LanguageServerProtocol\Range;
use Microsoft\PhpParser\Node;
use Microsoft\PhpParser\PositionUtilities;
class LocationFactory
{
/**
* Returns the location of the node
*
* @param Node $node
* @return self
*/
public static function fromNode(Node $node): Location
{
$range = PositionUtilities::getRangeFromPosition(
$node->getStart(),
$node->getWidth(),
$node->getFileContents()
);
return new Location($node->getUri(), new Range(
new Position($range->start->line, $range->start->character),
new Position($range->end->line, $range->end->character)
));
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace LanguageServer\Factory;
use LanguageServerProtocol\Position;
use LanguageServerProtocol\Range;
use Microsoft\PhpParser\Node;
use Microsoft\PhpParser\PositionUtilities;
class RangeFactory
{
/**
* Returns the range the node spans
*
* @param Node $node
* @return self
*/
public static function fromNode(Node $node)
{
$range = PositionUtilities::getRangeFromPosition(
$node->getStart(),
$node->getWidth(),
$node->getFileContents()
);
return new Range(
new Position($range->start->line, $range->start->character),
new Position($range->end->line, $range->end->character)
);
}
}

View File

@ -1,44 +1,16 @@
<?php
namespace LanguageServer\Protocol;
namespace LanguageServer\Factory;
use Microsoft\PhpParser;
use LanguageServerProtocol\Location;
use LanguageServerProtocol\SymbolInformation;
use LanguageServerProtocol\SymbolKind;
use Microsoft\PhpParser\Node;
use Microsoft\PhpParser\ResolvedName;
use LanguageServer\Factory\LocationFactory;
/**
* Represents information about programming constructs like variables, classes,
* interfaces etc.
*/
class SymbolInformation
class SymbolInformationFactory
{
/**
* The name of this symbol.
*
* @var string
*/
public $name;
/**
* The kind of this symbol.
*
* @var int
*/
public $kind;
/**
* The location of this symbol.
*
* @var Location
*/
public $location;
/**
* The name of the symbol containing this symbol.
*
* @var string|null
*/
public $containerName;
/**
* Converts a Node to a SymbolInformation
*
@ -48,7 +20,7 @@ class SymbolInformation
*/
public static function fromNode($node, string $fqn = null)
{
$symbol = new self;
$symbol = new SymbolInformation();
if ($node instanceof Node\Statement\ClassDeclaration) {
$symbol->kind = SymbolKind::CLASS_;
} else if ($node instanceof Node\Statement\TraitDeclaration) {
@ -98,7 +70,7 @@ class SymbolInformation
$symbol->name = $node->getName();
} else if (isset($node->name)) {
if ($node->name instanceof Node\QualifiedName) {
$symbol->name = (string)PhpParser\ResolvedName::buildName($node->name->nameParts, $node->getFileContents());
$symbol->name = (string)ResolvedName::buildName($node->name->nameParts, $node->getFileContents());
} else {
$symbol->name = ltrim((string)$node->name->getText($node->getFileContents()), "$");
}
@ -108,7 +80,7 @@ class SymbolInformation
return null;
}
$symbol->location = Location::fromNode($node);
$symbol->location = LocationFactory::fromNode($node);
if ($fqn !== null) {
$parts = preg_split('/(::|->|\\\\)/', $fqn);
array_pop($parts);
@ -116,18 +88,4 @@ class SymbolInformation
}
return $symbol;
}
/**
* @param string $name
* @param int $kind
* @param Location $location
* @param string $containerName
*/
public function __construct($name = null, $kind = null, $location = null, $containerName = null)
{
$this->name = $name;
$this->kind = $kind;
$this->location = $location;
$this->containerName = $containerName;
}
}

View File

@ -6,7 +6,7 @@ namespace LanguageServer;
use LanguageServer\Cache\Cache;
use LanguageServer\FilesFinder\FilesFinder;
use LanguageServer\Index\{DependenciesIndex, Index};
use LanguageServer\Protocol\MessageType;
use LanguageServerProtocol\MessageType;
use Webmozart\PathUtil\Path;
use Sabre\Event\Promise;
use function Sabre\Event\coroutine;

View File

@ -3,15 +3,15 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
ServerCapabilities,
ClientCapabilities,
TextDocumentSyncKind,
Message,
InitializeResult,
CompletionOptions,
SignatureHelpOptions
};
use LanguageServer\Message;
use LanguageServer\FilesFinder\{FilesFinder, ClientFilesFinder, FileSystemFilesFinder};
use LanguageServer\ContentRetriever\{ContentRetriever, ClientContentRetriever, FileSystemContentRetriever};
use LanguageServer\Index\{DependenciesIndex, GlobalIndex, Index, ProjectIndex, StubsIndex};

View File

@ -1,9 +1,10 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Protocol;
namespace LanguageServer;
use AdvancedJsonRpc\Message as MessageBody;
use LanguageServer\Message;
class Message
{

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Index\Index;
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
Diagnostic, Position, Range
};
use Microsoft\PhpParser;

View File

@ -1,27 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class ClientCapabilities
{
/**
* The client supports workspace/xfiles requests
*
* @var bool|null
*/
public $xfilesProvider;
/**
* The client supports textDocument/xcontent requests
*
* @var bool|null
*/
public $xcontentProvider;
/**
* The client supports xcache/* requests
*
* @var bool|null
*/
public $xcacheProvider;
}

View File

@ -1,17 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Contains additional diagnostic information about the context in which
* a code action is run.
*/
class CodeActionContext
{
/**
* An array of diagnostics.
*
* @var Diagnostic[]
*/
public $diagnostics;
}

View File

@ -1,35 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* A code lens represents a command that should be shown along with
* source text, like the number of references, a way to run tests, etc.
*
* A code lens is _unresolved_ when no command is associated to it. For performance
* reasons the creation of a code lens and resolving should be done in two stages.
*/
class CodeLens
{
/**
* The range in which this code lens is valid. Should only span a single line.
*
* @var Range
*/
public $range;
/**
* The command this code lens represents.
*
* @var Command|null
*/
public $command;
/**
* A data entry field that is preserved on a code lens item between
* a code lens and a code lens resolve request.
*
* @var mixed|null
*/
public $data;
}

View File

@ -1,16 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Code Lens options.
*/
class CodeLensOptions
{
/**
* Code lens has a resolve provider as well.
*
* @var bool|null
*/
public $resolveProvider;
}

View File

@ -1,32 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Represents a reference to a command. Provides a title which will be used to represent a command in the UI and,
* optionally, an array of arguments which will be passed to the command handler function when invoked.
*/
class Command
{
/**
* Title of the command, like `save`.
*
* @var string
*/
public $title;
/**
* The identifier of the actual command handler.
*
* @var string
*/
public $command;
/**
* Arguments that the command handler should be
* invoked with.
*
* @var mixed[]|null
*/
public $arguments;
}

View File

@ -1,30 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Contains additional information about the context in which a completion request is triggered.
*/
class CompletionContext
{
/**
* How the completion was triggered.
*
* @var int
*/
public $triggerKind;
/**
* The trigger character (a single character) that has trigger code complete.
* Is null if `triggerKind !== CompletionTriggerKind::TRIGGER_CHARACTER`
*
* @var string|null
*/
public $triggerCharacter;
public function __construct(int $triggerKind = null, string $triggerCharacter = null)
{
$this->triggerKind = $triggerKind;
$this->triggerCharacter = $triggerCharacter;
}
}

View File

@ -1,164 +0,0 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Protocol;
use LanguageServer\Definition;
class CompletionItem
{
/**
* The label of this completion item. By default
* also the text that is inserted when selecting
* this completion.
*
* @var string
*/
public $label;
/**
* The kind of this completion item. Based of the kind
* an icon is chosen by the editor.
*
* @var int|null
*/
public $kind;
/**
* A human-readable string with additional information
* about this item, like type or symbol information.
*
* @var string|null
*/
public $detail;
/**
* A human-readable string that represents a doc-comment.
*
* @var string|null
*/
public $documentation;
/**
* A string that shoud be used when comparing this item
* with other items. When `falsy` the label is used.
*
* @var string|null
*/
public $sortText;
/**
* A string that should be used when filtering a set of
* completion items. When `falsy` the label is used.
*
* @var string|null
*/
public $filterText;
/**
* A string that should be inserted a document when selecting
* this completion. When `falsy` the label is used.
*
* @var string|null
*/
public $insertText;
/**
* An edit which is applied to a document when selecting
* this completion. When an edit is provided the value of
* insertText is ignored.
*
* @var TextEdit|null
*/
public $textEdit;
/**
* An optional array of additional text edits that are applied when
* selecting this completion. Edits must not overlap with the main edit
* nor with themselves.
*
* @var TextEdit[]|null
*/
public $additionalTextEdits;
/**
* An optional command that is executed *after* inserting this completion. *Note* that
* additional modifications to the current document should be described with the
* additionalTextEdits-property.
*
* @var Command|null
*/
public $command;
/**
* An data entry field that is preserved on a completion item between
* a completion and a completion resolve request.
*
* @var mixed
*/
public $data;
/**
* @param string $label
* @param int|null $kind
* @param string|null $detail
* @param string|null $documentation
* @param string|null $sortText
* @param string|null $filterText
* @param string|null $insertText
* @param TextEdit|null $textEdit
* @param TextEdit[]|null $additionalTextEdits
* @param Command|null $command
* @param mixed|null $data
*/
public function __construct(
string $label = null,
int $kind = null,
string $detail = null,
string $documentation = null,
string $sortText = null,
string $filterText = null,
string $insertText = null,
TextEdit $textEdit = null,
array $additionalTextEdits = null,
Command $command = null,
$data = null
) {
$this->label = $label;
$this->kind = $kind;
$this->detail = $detail;
$this->documentation = $documentation;
$this->sortText = $sortText;
$this->filterText = $filterText;
$this->insertText = $insertText;
$this->textEdit = $textEdit;
$this->additionalTextEdits = $additionalTextEdits;
$this->command = $command;
$this->data = $data;
}
/**
* Creates a CompletionItem for a Definition
*
* @param Definition $def
* @return self
*/
public static function fromDefinition(Definition $def): self
{
$item = new CompletionItem;
$item->label = $def->symbolInformation->name;
$item->kind = CompletionItemKind::fromSymbolKind($def->symbolInformation->kind);
if ($def->type) {
$item->detail = (string)$def->type;
} else if ($def->symbolInformation->containerName) {
$item->detail = $def->symbolInformation->containerName;
}
if ($def->documentation) {
$item->documentation = $def->documentation;
}
if ($def->isStatic && $def->symbolInformation->kind === SymbolKind::PROPERTY) {
$item->insertText = '$' . $def->symbolInformation->name;
}
return $item;
}
}

View File

@ -1,70 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* The kind of a completion entry.
*/
abstract class CompletionItemKind
{
const TEXT = 1;
const METHOD = 2;
const FUNCTION = 3;
const CONSTRUCTOR = 4;
const FIELD = 5;
const VARIABLE = 6;
const CLASS_ = 7;
const INTERFACE = 8;
const MODULE = 9;
const PROPERTY = 10;
const UNIT = 11;
const VALUE = 12;
const ENUM = 13;
const KEYWORD = 14;
const SNIPPET = 15;
const COLOR = 16;
const FILE = 17;
const REFERENCE = 18;
/**
* Returns the CompletionItemKind for a SymbolKind
*
* @param int $kind A SymbolKind
* @return int The CompletionItemKind
*/
public static function fromSymbolKind(int $kind): int
{
switch ($kind) {
case SymbolKind::PROPERTY:
case SymbolKind::FIELD:
return self::PROPERTY;
case SymbolKind::METHOD:
return self::METHOD;
case SymbolKind::CLASS_:
return self::CLASS_;
case SymbolKind::INTERFACE:
return self::INTERFACE;
case SymbolKind::FUNCTION:
return self::FUNCTION;
case SymbolKind::NAMESPACE:
case SymbolKind::MODULE:
case SymbolKind::PACKAGE:
return self::MODULE;
case SymbolKind::FILE:
return self::FILE;
case SymbolKind::STRING:
return self::TEXT;
case SymbolKind::NUMBER:
case SymbolKind::BOOLEAN:
case SymbolKind::ARRAY:
return self::VALUE;
case SymbolKind::ENUM:
return self::ENUM;
case SymbolKind::CONSTRUCTOR:
return self::CONSTRUCTOR;
case SymbolKind::VARIABLE:
case SymbolKind::CONSTANT:
return self::VARIABLE;
}
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Represents a collection of completion items to be presented in
* the editor.
*/
class CompletionList
{
/**
* This list it not complete. Further typing should result in recomputing this
* list.
*
* @var bool
*/
public $isIncomplete;
/**
* The completion items.
*
* @var CompletionItem[]
*/
public $items;
/**
* @param CompletionItem[] $items The completion items.
* @param bool $isIncomplete This list it not complete. Further typing should result in recomputing this list.
*/
public function __construct(array $items = [], bool $isIncomplete = false)
{
$this->items = $items;
$this->isIncomplete = $isIncomplete;
}
}

View File

@ -1,24 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Completion options.
*/
class CompletionOptions
{
/*
* The server provides support to resolve additional information for a completion
* item.
*
* @var bool|null
*/
public $resolveProvider;
/**
* The characters that trigger completion automatically.
*
* @var string[]|null
*/
public $triggerCharacters;
}

View File

@ -1,16 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class CompletionTriggerKind
{
/**
* Completion was triggered by invoking it manuall or using API.
*/
const INVOKED = 1;
/**
* Completion was triggered by a trigger character.
*/
const TRIGGER_CHARACTER = 2;
}

View File

@ -1,31 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* An event describing a change to a text document. If range and rangeLength are
* omitted the new text is considered to be the full content of the document.
*/
class ContentChangeEvent
{
/**
* The range of the document that changed.
*
* @var Range|null
*/
public $range;
/**
* The length of the range that got replaced.
*
* @var int|null
*/
public $rangeLength;
/**
* The new text of the document.
*
* @var string
*/
public $text;
}

View File

@ -1,27 +0,0 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Protocol;
class DependencyReference
{
/**
* @var mixed
*/
public $hints;
/**
* @var object
*/
public $attributes;
/**
* @param object $attributes
* @param mixed $hints
*/
public function __construct($attributes = null, $hints = null)
{
$this->attributes = $attributes ?? new \stdClass;
$this->hints = $hints;
}
}

View File

@ -1,63 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Represents a diagnostic, such as a compiler error or warning. Diagnostic objects are only valid in the scope of a
* resource.
*/
class Diagnostic
{
/**
* The range at which the message applies.
*
* @var Range
*/
public $range;
/**
* The diagnostic's severity. Can be omitted. If omitted it is up to the
* client to interpret diagnostics as error, warning, info or hint.
*
* @var int|null
*/
public $severity;
/**
* The diagnostic's code. Can be omitted.
*
* @var int|string|null
*/
public $code;
/**
* A human-readable string describing the source of this
* diagnostic, e.g. 'typescript' or 'super lint'.
*
* @var string|null
*/
public $source;
/**
* The diagnostic's message.
*
* @var string
*/
public $message;
/**
* @param string $message The diagnostic's message
* @param Range $range The range at which the message applies
* @param int $code The diagnostic's code
* @param int $severity DiagnosticSeverity
* @param string $source A human-readable string describing the source of this diagnostic
*/
public function __construct(string $message = null, Range $range = null, int $code = null, int $severity = null, string $source = null)
{
$this->message = $message;
$this->range = $range;
$this->code = $code;
$this->severity = $severity;
$this->source = $source;
}
}

View File

@ -1,26 +0,0 @@
<?php
namespace LanguageServer\Protocol;
abstract class DiagnosticSeverity
{
/**
* Reports an error.
*/
const ERROR = 1;
/**
* Reports a warning.
*/
const WARNING = 2;
/**
* Reports an information.
*/
const INFORMATION = 3;
/**
* Reports a hint.
*/
const HINT = 4;
}

View File

@ -1,25 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* A document highlight is a range inside a text document which deserves
* special attention. Usually a document highlight is visualized by changing
* the background color of its range.
*/
class DocumentHighlight
{
/**
* The range this highlight applies to.
*
* @var Range
*/
public $range;
/**
* The highlight kind, default is DocumentHighlightKind::TEXT.
*
* @var int|null
*/
public $kind;
}

View File

@ -1,24 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* A document highlight kind.
*/
abstract class DocumentHighlightKind
{
/**
* A textual occurrance.
*/
const TEXT = 1;
/**
* Read-access of a symbol, like reading a variable.
*/
const READ = 2;
/**
* Write-access of a symbol, like writing to a variable.
*/
const WRITE = 3;
}

View File

@ -1,23 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Format document on type options
*/
class DocumentOnTypeFormattingOptions
{
/**
* A character on which formatting should be triggered, like `}`.
*
* @var string
*/
public $firstTriggerCharacter;
/**
* More trigger characters.
*
* @var string[]|null
*/
public $moreTriggerCharacter;
}

View File

@ -1,17 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Enum
*/
abstract class ErrorCode
{
const PARSE_ERROR = -32700;
const INVALID_REQUEST = -32600;
const METHOD_NOT_FOUND = -32601;
const INVALID_PARAMS = -32602;
const INTERNAL_ERROR = -32603;
const SERVER_ERROR_START = -32099;
const SERVER_ERROR_END = -32000;
}

View File

@ -1,24 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* The file event type. Enum
*/
abstract class FileChangeType
{
/**
* The file got created.
*/
const CREATED = 1;
/**
* The file got changed.
*/
const CHANGED = 2;
/**
* The file got deleted.
*/
const DELETED = 3;
}

View File

@ -1,33 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* An event describing a file change.
*/
class FileEvent
{
/**
* The file's URI.
*
* @var string
*/
public $uri;
/**
* The change type.
*
* @var int
*/
public $type;
/**
* @param string $uri
* @param int $type
*/
public function __construct(string $uri, int $type)
{
$this->uri = $uri;
$this->type = $type;
}
}

View File

@ -1,25 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Value-object describing what options formatting should use.
*/
class FormattingOptions
{
/**
* Size of a tab in spaces.
*
* @var int
*/
public $tabSize;
/**
* Prefer spaces over tabs.
*
* @var bool
*/
public $insertSpaces;
// Can be extended with further properties.
}

View File

@ -1,33 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* The result of a hover request.
*/
class Hover
{
/**
* The hover's content
*
* @var string|MarkedString|string[]|MarkedString[]
*/
public $contents;
/**
* An optional range
*
* @var Range|null
*/
public $range;
/**
* @param string|MarkedString|string[]|MarkedString[] $contents The hover's content
* @param Range $range An optional range
*/
public function __construct($contents = null, $range = null)
{
$this->contents = $contents;
$this->range = $range;
}
}

View File

@ -1,21 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class InitializeResult
{
/**
* The capabilities the language server provides.
*
* @var LanguageServer\Protocol\ServerCapabilities
*/
public $capabilities;
/**
* @param LanguageServer\Protocol\ServerCapabilities $capabilities
*/
public function __construct(ServerCapabilities $capabilities = null)
{
$this->capabilities = $capabilities ?? new ServerCapabilities();
}
}

View File

@ -1,43 +0,0 @@
<?php
namespace LanguageServer\Protocol;
use Microsoft\PhpParser;
use Microsoft\PhpParser\Node;
/**
* Represents a location inside a resource, such as a line inside a text file.
*/
class Location
{
/**
* @var string
*/
public $uri;
/**
* @var Range
*/
public $range;
/**
* Returns the location of the node
*
* @param Node $node
* @return self
*/
public static function fromNode($node)
{
$range = PhpParser\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents());
return new self($node->getUri(), new Range(
new Position($range->start->line, $range->start->character),
new Position($range->end->line, $range->end->character)
));
}
public function __construct(string $uri = null, Range $range = null)
{
$this->uri = $uri;
$this->range = $range;
}
}

View File

@ -1,22 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class MarkedString
{
/**
* @var string
*/
public $language;
/**
* @var string
*/
public $value;
public function __construct(string $language = null, string $value = null)
{
$this->language = $language;
$this->value = $value;
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class MessageActionItem
{
/**
* A short title like 'Retry', 'Open Log' etc.
*
* @var string
*/
public $title;
}

View File

@ -1,29 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Enum
*/
abstract class MessageType
{
/**
* An error message.
*/
const ERROR = 1;
/**
* A warning message.
*/
const WARNING = 2;
/**
* An information message.
*/
const INFO = 3;
/**
* A log message.
*/
const LOG = 4;
}

View File

@ -1,25 +0,0 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Protocol;
/**
* Uniquely identifies a Composer package
*/
class PackageDescriptor
{
/**
* The package name
*
* @var string
*/
public $name;
/**
* @param string $name The package name
*/
public function __construct(string $name = null)
{
$this->name = $name;
}
}

View File

@ -1,39 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Represents a parameter of a callable-signature. A parameter can
* have a label and a doc-comment.
*/
class ParameterInformation
{
/**
* The label of this signature. Will be shown in
* the UI.
*
* @var string
*/
public $label;
/**
* The human-readable doc-comment of this signature. Will be shown
* in the UI but can be omitted.
*
* @var string|null
*/
public $documentation;
/**
* Create ParameterInformation
*
* @param string $label The label of this signature. Will be shown in the UI.
* @param string $documentation The human-readable doc-comment of this signature. Will be shown in the UI but can
* be omitted.
*/
public function __construct(string $label, string $documentation = null)
{
$this->label = $label;
$this->documentation = $documentation;
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Position in a text document expressed as zero-based line and character offset.
*/
class Position
{
/**
* Line position in a document (zero-based).
*
* @var int
*/
public $line;
/**
* Character offset on a line in a document (zero-based).
*
* @var int
*/
public $character;
public function __construct(int $line = null, int $character = null)
{
$this->line = $line;
$this->character = $character;
}
/**
* Compares this position to another position
* Returns
* - 0 if the positions match
* - a negative number if $this is before $position
* - a positive number otherwise
*
* @param Position $position
* @return int
*/
public function compare(Position $position): int
{
if ($this->line === $position->line && $this->character === $position->character) {
return 0;
}
if ($this->line !== $position->line) {
return $this->line - $position->line;
}
return $this->character - $position->character;
}
/**
* Returns the offset of the position in a string
*
* @param string $content
* @return int
*/
public function toOffset(string $content): int
{
$lines = explode("\n", $content);
$slice = array_slice($lines, 0, $this->line);
return array_sum(array_map('strlen', $slice)) + count($slice) + $this->character;
}
}

View File

@ -1,59 +0,0 @@
<?php
namespace LanguageServer\Protocol;
use Microsoft\PhpParser;
use Microsoft\PhpParser\Node;
/**
* A range in a text document expressed as (zero-based) start and end positions.
*/
class Range
{
/**
* The range's start position.
*
* @var Position
*/
public $start;
/**
* The range's end position.
*
* @var Position
*/
public $end;
/**
* Returns the range the node spans
*
* @param Node $node
* @return self
*/
public static function fromNode(Node $node)
{
$range = PhpParser\PositionUtilities::getRangeFromPosition($node->getStart(), $node->getWidth(), $node->getFileContents());
return new self(
new Position($range->start->line, $range->start->character),
new Position($range->end->line, $range->end->character)
);
}
public function __construct(Position $start = null, Position $end = null)
{
$this->start = $start;
$this->end = $end;
}
/**
* Checks if a position is within the range
*
* @param Position $position
* @return bool
*/
public function includes(Position $position): bool
{
return $this->start->compare($position) <= 0 && $this->end->compare($position) >= 0;
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class ReferenceContext
{
/**
* Include the declaration of the current symbol.
*
* @var bool
*/
public $includeDeclaration;
}

View File

@ -1,36 +0,0 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Protocol;
/**
* Metadata about the symbol that can be used to identify or locate its
* definition.
*/
class ReferenceInformation
{
/**
* The location in the workspace where the `symbol` is referenced.
*
* @var Location
*/
public $reference;
/**
* Metadata about the symbol that can be used to identify or locate its
* definition.
*
* @var SymbolDescriptor
*/
public $symbol;
/**
* @param Location $reference The location in the workspace where the `symbol` is referenced.
* @param SymbolDescriptor $symbol Metadata about the symbol that can be used to identify or locate its definition.
*/
public function __construct(Location $reference = null, SymbolDescriptor $symbol = null)
{
$this->reference = $reference;
$this->symbol = $symbol;
}
}

View File

@ -1,132 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class ServerCapabilities
{
/**
* Defines how text documents are synced.
*
* @var int|null
*/
public $textDocumentSync;
/**
* The server provides hover support.
*
* @var bool|null
*/
public $hoverProvider;
/**
* The server provides completion support.
*
* @var CompletionOptions|null
*/
public $completionProvider;
/**
* The server provides signature help support.
*
* @var SignatureHelpOptions|null
*/
public $signatureHelpProvider;
/**
* The server provides goto definition support.
*
* @var bool|null
*/
public $definitionProvider;
/**
* The server provides find references support.
*
* @var bool|null
*/
public $referencesProvider;
/**
* The server provides document highlight support.
*
* @var bool|null
*/
public $documentHighlightProvider;
/**
* The server provides document symbol support.
*
* @var bool|null
*/
public $documentSymbolProvider;
/**
* The server provides workspace symbol support.
*
* @var bool|null
*/
public $workspaceSymbolProvider;
/**
* The server provides code actions.
*
* @var bool|null
*/
public $codeActionProvider;
/**
* The server provides code lens.
*
* @var CodeLensOptions|null
*/
public $codeLensProvider;
/**
* The server provides document formatting.
*
* @var bool|null
*/
public $documentFormattingProvider;
/**
* The server provides document range formatting.
*
* @var bool|null
*/
public $documentRangeFormattingProvider;
/**
* The server provides document formatting on typing.
*
* @var DocumentOnTypeFormattingOptions|null
*/
public $documentOnTypeFormattingProvider;
/**
* The server provides rename support.
*
* @var bool|null
*/
public $renameProvider;
/**
* The server provides workspace references exporting support.
*
* @var bool|null
*/
public $xworkspaceReferencesProvider;
/**
* The server provides extended text document definition support.
*
* @var bool|null
*/
public $xdefinitionProvider;
/**
* The server provides workspace dependencies support.
*
* @var bool|null
*/
public $dependenciesProvider;
}

View File

@ -1,46 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Signature help represents the signature of something
* callable. There can be multiple signature but only one
* active and only one active parameter.
*/
class SignatureHelp
{
/**
* One or more signatures.
*
* @var SignatureInformation[]
*/
public $signatures;
/**
* The active signature.
*
* @var int|null
*/
public $activeSignature;
/**
* The active parameter of the active signature.
*
* @var int|null
*/
public $activeParameter;
/**
* Create a SignatureHelp
*
* @param SignatureInformation[] $signatures List of signature information
* @param int|null $activeSignature The active signature, zero based
* @param int|null $activeParameter The active parameter, zero based
*/
public function __construct(array $signatures = [], $activeSignature = null, int $activeParameter = null)
{
$this->signatures = $signatures;
$this->activeSignature = $activeSignature;
$this->activeParameter = $activeParameter;
}
}

View File

@ -1,16 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Signature help options.
*/
class SignatureHelpOptions
{
/**
* The characters that trigger signature help automatically.
*
* @var string[]|null
*/
public $triggerCharacters;
}

View File

@ -1,49 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Represents the signature of something callable. A signature
* can have a label, like a function-name, a doc-comment, and
* a set of parameters.
*/
class SignatureInformation
{
/**
* The label of this signature. Will be shown in
* the UI.
*
* @var string
*/
public $label;
/**
* The human-readable doc-comment of this signature. Will be shown
* in the UI but can be omitted.
*
* @var string|null
*/
public $documentation;
/**
* The parameters of this signature.
*
* @var ParameterInformation[]|null
*/
public $parameters;
/**
* Create a SignatureInformation
*
* @param string $label The label of this signature. Will be shown in the UI.
* @param ParameterInformation[]|null The parameters of this signature
* @param string|null The human-readable doc-comment of this signature. Will be shown in the UI
* but can be omitted.
*/
public function __construct(string $label, array $parameters = null, string $documentation = null)
{
$this->label = $label;
$this->parameters = $parameters;
$this->documentation = $documentation;
}
}

View File

@ -1,34 +0,0 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Protocol;
/**
* Uniquely identifies a symbol
*/
class SymbolDescriptor
{
/**
* The fully qualified structural element name, a globally unique identifier for the symbol.
*
* @var string
*/
public $fqsen;
/**
* Identifies the Composer package the symbol is defined in (if any)
*
* @var PackageDescriptor|null
*/
public $package;
/**
* @param string $fqsen The fully qualified structural element name, a globally unique identifier for the symbol.
* @param PackageDescriptor $package Identifies the Composer package the symbol is defined in
*/
public function __construct(string $fqsen = null, PackageDescriptor $package = null)
{
$this->fqsen = $fqsen;
$this->package = $package;
}
}

View File

@ -1,28 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* A symbol kind.
*/
abstract class SymbolKind
{
const FILE = 1;
const MODULE = 2;
const NAMESPACE = 3;
const PACKAGE = 4;
const CLASS_ = 5;
const METHOD = 6;
const PROPERTY = 7;
const FIELD = 8;
const CONSTRUCTOR = 9;
const ENUM = 10;
const INTERFACE = 11;
const FUNCTION = 12;
const VARIABLE = 13;
const CONSTANT = 14;
const STRING = 15;
const NUMBER = 16;
const BOOLEAN = 17;
const ARRAY = 18;
}

View File

@ -1,32 +0,0 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Protocol;
class SymbolLocationInformation
{
/**
* The location where the symbol is defined, if any.
*
* @var Location|null
*/
public $location;
/**
* Metadata about the symbol that can be used to identify or locate its
* definition.
*
* @var SymbolDescriptor
*/
public $symbol;
/**
* @param SymbolDescriptor $symbol The location where the symbol is defined, if any
* @param Location $location Metadata about the symbol that can be used to identify or locate its definition
*/
public function __construct(SymbolDescriptor $symbol = null, Location $location = null)
{
$this->symbol = $symbol;
$this->location = $location;
}
}

View File

@ -1,31 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* An event describing a change to a text document. If range and rangeLength are omitted
* the new text is considered to be the full content of the document.
*/
class TextDocumentContentChangeEvent
{
/**
* The range of the document that changed.
*
* @var Range|null
*/
public $range;
/**
* The length of the range that got replaced.
*
* @var int|null
*/
public $rangeLength;
/**
* The new text of the document.
*
* @var string
*/
public $text;
}

View File

@ -1,21 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class TextDocumentIdentifier
{
/**
* The text document's URI.
*
* @var string
*/
public $uri;
/**
* @param string $uri The text document's URI.
*/
public function __construct(string $uri = null)
{
$this->uri = $uri;
}
}

View File

@ -1,38 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* An item to transfer a text document from the client to the server.
*/
class TextDocumentItem
{
/**
* The text document's URI.
*
* @var string
*/
public $uri;
/**
* The text document's language identifier.
*
* @var string
*/
public $languageId;
/**
* The version number of this document (it will strictly increase after each
* change, including undo/redo).
*
* @var int
*/
public $version;
/**
* The content of the opened text document.
*
* @var string
*/
public $text;
}

View File

@ -1,25 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* Defines how the host (editor) should sync document changes to the language server.
*/
abstract class TextDocumentSyncKind
{
/**
* Documents should not be synced at all.
*/
const NONE = 0;
/**
* Documents are synced by always sending the full content of the document.
*/
const FULL = 1;
/*
* Documents are synced by sending the full content on open. After that only
* incremental updates to the document are sent.
*/
const INCREMENTAL = 2;
}

View File

@ -1,31 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* A textual edit applicable to a text document.
*/
class TextEdit
{
/**
* The range of the text document to be manipulated. To insert
* text into a document create a range where start === end.
*
* @var Range
*/
public $range;
/**
* The string to be inserted. For delete operations use an
* empty string.
*
* @var string
*/
public $newText;
public function __construct(Range $range = null, string $newText = null)
{
$this->range = $range;
$this->newText = $newText;
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class VersionedTextDocumentIdentifier extends TextDocumentIdentifier
{
/**
* The version number of this document.
*
* @var int
*/
public $version;
}

View File

@ -1,16 +0,0 @@
<?php
namespace LanguageServer\Protocol;
/**
* A workspace edit represents changes to many resources managed in the workspace.
*/
class WorkspaceEdit
{
/**
* Holds changes to existing resources. Associative Array from URI to TextEdit
*
* @var TextEdit[]
*/
public $changes;
}

View File

@ -3,7 +3,7 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Protocol\Message;
use LanguageServer\Message;
use AdvancedJsonRpc\Message as MessageBody;
use Sabre\Event\{Loop, Emitter};

View File

@ -3,7 +3,7 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Protocol\Message;
use LanguageServer\Message;
use Sabre\Event\{
Loop,
Promise

View File

@ -3,7 +3,7 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Protocol\Message;
use LanguageServer\Message;
use Sabre\Event\Promise;
interface ProtocolWriter

View File

@ -7,7 +7,9 @@ use LanguageServer\{
CompletionProvider, SignatureHelpProvider, LanguageClient, PhpDocument, PhpDocumentLoader, DefinitionResolver
};
use LanguageServer\Index\ReadableIndex;
use LanguageServer\Protocol\{
use LanguageServer\Factory\LocationFactory;
use LanguageServer\Factory\RangeFactory;
use LanguageServerProtocol\{
FormattingOptions,
Hover,
Location,
@ -108,7 +110,7 @@ class TextDocument
* 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
* @param \LanguageServerProtocol\TextDocumentIdentifier $textDocument
* @return Promise <SymbolInformation[]>
*/
public function documentSymbol(TextDocumentIdentifier $textDocument): Promise
@ -127,7 +129,7 @@ class TextDocument
* 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.
* @param \LanguageServerProtocol\TextDocumentItem $textDocument The document that was opened.
* @return void
*/
public function didOpen(TextDocumentItem $textDocument)
@ -141,8 +143,8 @@ class TextDocument
/**
* 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
* @param \LanguageServerProtocol\VersionedTextDocumentIdentifier $textDocument
* @param \LanguageServerProtocol\TextDocumentContentChangeEvent[] $contentChanges
* @return void
*/
public function didChange(VersionedTextDocumentIdentifier $textDocument, array $contentChanges)
@ -157,7 +159,7 @@ class TextDocument
* The document's truth now exists where the document's uri points to (e.g. if the document's uri is a file uri the
* truth now exists on disk).
*
* @param \LanguageServer\Protocol\TextDocumentIdentifier $textDocument The document that was closed
* @param \LanguageServerProtocol\TextDocumentIdentifier $textDocument The document that was closed
* @return void
*/
public function didClose(TextDocumentIdentifier $textDocument)
@ -208,7 +210,7 @@ class TextDocument
if ($descendantNode instanceof Node\Expression\Variable &&
$descendantNode->getName() === $node->getName()
) {
$locations[] = Location::fromNode($descendantNode);
$locations[] = LocationFactory::fromNode($descendantNode);
}
}
} else {
@ -233,7 +235,7 @@ class TextDocument
$refs = $document->getReferenceNodesByFqn($fqn);
if ($refs !== null) {
foreach ($refs as $ref) {
$locations[] = Location::fromNode($ref);
$locations[] = LocationFactory::fromNode($ref);
}
}
}
@ -332,7 +334,7 @@ class TextDocument
}
yield waitForEvent($this->index, 'definition-added');
}
$range = Range::fromNode($node);
$range = RangeFactory::fromNode($node);
if ($def === null) {
return new Hover([], $range);
}

View File

@ -5,7 +5,8 @@ namespace LanguageServer\Server;
use LanguageServer\{LanguageClient, PhpDocumentLoader};
use LanguageServer\Index\{ProjectIndex, DependenciesIndex, Index};
use LanguageServer\Protocol\{
use LanguageServer\Factory\LocationFactory;
use LanguageServerProtocol\{
FileChangeType,
FileEvent,
SymbolInformation,
@ -150,7 +151,7 @@ class Workspace
$doc = yield $this->documentLoader->getOrLoad($uri);
foreach ($doc->getReferenceNodesByFqn($fqn) as $node) {
$refInfo = new ReferenceInformation;
$refInfo->reference = Location::fromNode($node);
$refInfo->reference = LocationFactory::fromNode($node);
$refInfo->symbol = $query;
$refInfos[] = $refInfo;
}

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Index\ReadableIndex;
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
Position,
SignatureHelp,
ParameterInformation

View File

@ -3,7 +3,7 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Protocol\{SignatureInformation, ParameterInformation};
use LanguageServerProtocol\{SignatureInformation, ParameterInformation};
use Microsoft\PhpParser\FunctionLike;
class SignatureInformationFactory

View File

@ -3,7 +3,8 @@ declare(strict_types = 1);
namespace LanguageServer;
use LanguageServer\Protocol\{Diagnostic, DiagnosticSeverity, Range, Position};
use LanguageServer\Factory\RangeFactory;
use LanguageServerProtocol\{Diagnostic, DiagnosticSeverity, Range, Position};
use phpDocumentor\Reflection\DocBlockFactory;
use Microsoft\PhpParser;
use Microsoft\PhpParser\Node;
@ -100,7 +101,7 @@ class TreeAnalyzer
if ($method && $method->isStatic()) {
$this->diagnostics[] = new Diagnostic(
"\$this can not be used in static methods.",
Range::fromNode($node),
RangeFactory::fromNode($node),
null,
DiagnosticSeverity::ERROR,
'php'

View File

@ -5,7 +5,7 @@ namespace LanguageServer\Tests;
use PHPUnit\Framework\TestCase;
use LanguageServer\ClientHandler;
use LanguageServer\Protocol\Message;
use LanguageServer\Message;
use AdvancedJsonRpc;
use Sabre\Event\Loop;

View File

@ -9,7 +9,7 @@ use LanguageServer\{
DefinitionResolver, TreeAnalyzer
};
use LanguageServer\Index\{Index};
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
Diagnostic, DiagnosticSeverity, Position, Range
};
use function LanguageServer\pathToUri;

View File

@ -5,8 +5,8 @@ namespace LanguageServer\Tests;
use PHPUnit\Framework\TestCase;
use LanguageServer\LanguageServer;
use LanguageServer\Protocol\{
Message,
use LanguageServer\Message;
use LanguageServerProtocol\{
ClientCapabilities,
TextDocumentSyncKind,
MessageType,

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Tests;
use LanguageServer\{ProtocolReader, ProtocolWriter};
use LanguageServer\Protocol\Message;
use LanguageServer\Message;
use Sabre\Event\{Loop, Emitter, Promise};
/**

View File

@ -9,7 +9,7 @@ use LanguageServer\{
use LanguageServer\Index\{
Index
};
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
Position
};
use Microsoft\PhpParser;

View File

@ -5,7 +5,7 @@ namespace LanguageServer\Tests;
use PHPUnit\Framework\TestCase;
use LanguageServer\{LanguageServer, ProtocolStreamReader, ProtocolStreamWriter};
use LanguageServer\Protocol\Message;
use LanguageServer\Message;
use AdvancedJsonRpc\{Request as RequestBody, Response as ResponseBody};
use Sabre\Event\Loop;

View File

@ -5,7 +5,7 @@ namespace LanguageServer\Tests;
use PHPUnit\Framework\TestCase;
use LanguageServer\ProtocolStreamWriter;
use LanguageServer\Protocol\Message;
use LanguageServer\Message;
use AdvancedJsonRpc\{Request as RequestBody};
use Sabre\Event\Loop;

View File

@ -10,7 +10,7 @@ use LanguageServer\{
};
use LanguageServer\Index\{ProjectIndex, DependenciesIndex, Index};
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Protocol\{Position, Location, Range};
use LanguageServerProtocol\{Position, Location, Range};
use function LanguageServer\pathToUri;
abstract class ServerTestCase extends TestCase

View File

@ -10,7 +10,7 @@ use LanguageServer\{
};
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
TextDocumentIdentifier,
TextEdit,
Range,

View File

@ -10,7 +10,7 @@ use LanguageServer\{
};
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Location};
use LanguageServerProtocol\{TextDocumentIdentifier, Position, Range, Location};
class GlobalFallbackTest extends ServerTestCase
{

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Tests\Server\TextDocument\Definition;
use LanguageServer\Tests\Server\ServerTestCase;
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Location, Range};
use LanguageServerProtocol\{TextDocumentIdentifier, Position, Location, Range};
use function LanguageServer\pathToUri;
class GlobalTest extends ServerTestCase

View File

@ -3,7 +3,7 @@ declare(strict_types = 1);
namespace LanguageServer\Tests\Server\TextDocument\Definition;
use LanguageServer\Protocol\{TextDocumentIdentifier, Location};
use LanguageServerProtocol\{TextDocumentIdentifier, Location};
use function LanguageServer\pathToUri;
class NamespacedTest extends GlobalTest

View File

@ -10,7 +10,7 @@ use LanguageServer\{
};
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
VersionedTextDocumentIdentifier,
TextDocumentContentChangeEvent,
Range,

View File

@ -10,7 +10,7 @@ use LanguageServer\{
};
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\Protocol\{TextDocumentItem, TextDocumentIdentifier};
use LanguageServerProtocol\{TextDocumentItem, TextDocumentIdentifier};
class DidCloseTest extends TestCase
{

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument;
use LanguageServer\Tests\Server\ServerTestCase;
use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\{Server, LanguageClient, Project};
use LanguageServer\Protocol\{TextDocumentIdentifier, SymbolInformation, SymbolKind, Position, Location, Range};
use LanguageServerProtocol\{TextDocumentIdentifier, SymbolInformation, SymbolKind, Position, Location, Range};
use function LanguageServer\pathToUri;
class DocumentSymbolTest extends ServerTestCase

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server\TextDocument;
use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\Tests\Server\ServerTestCase;
use LanguageServer\{Server, LanguageClient, Project};
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, Range, Hover, MarkedString};
use LanguageServerProtocol\{TextDocumentIdentifier, Position, Range, Hover, MarkedString};
use function LanguageServer\pathToUri;
class HoverTest extends ServerTestCase

View File

@ -10,7 +10,7 @@ use LanguageServer\{
};
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Protocol\{TextDocumentItem, DiagnosticSeverity};
use LanguageServerProtocol\{TextDocumentItem, DiagnosticSeverity};
use Sabre\Event\Promise;
use JsonMapper;

View File

@ -10,7 +10,7 @@ use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Index\{
DependenciesIndex, Index, ProjectIndex
};
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
Location, Position, Range, ReferenceContext, TextDocumentIdentifier
};
use LanguageServer\Tests\MockProtocolStream;

View File

@ -3,7 +3,7 @@ declare(strict_types = 1);
namespace LanguageServer\Tests\Server\TextDocument\References;
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
use LanguageServerProtocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
use LanguageServer\Tests\Server\ServerTestCase;
use function LanguageServer\pathToUri;

View File

@ -3,7 +3,7 @@ declare(strict_types = 1);
namespace LanguageServer\Tests\Server\TextDocument\References;
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
use LanguageServerProtocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
use function LanguageServer\pathToUri;
class NamespacedTest extends GlobalTest

View File

@ -10,7 +10,7 @@ use LanguageServer\{
};
use LanguageServer\Index\{Index, ProjectIndex, DependenciesIndex};
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
TextDocumentIdentifier,
TextEdit,
Range,

View File

@ -6,7 +6,8 @@ namespace LanguageServer\Tests\Server\Workspace;
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\{DefinitionResolver, LanguageClient, PhpDocumentLoader, Server};
use LanguageServer\Index\{DependenciesIndex, Index, ProjectIndex};
use LanguageServer\Protocol\{FileChangeType, FileEvent, Message};
use LanguageServerProtocol\{FileChangeType, FileEvent};
use LanguageServer\Message;
use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\Tests\Server\ServerTestCase;
use LanguageServer\Server\Workspace;

View File

@ -6,7 +6,7 @@ namespace LanguageServer\Tests\Server\Workspace;
use LanguageServer\Tests\MockProtocolStream;
use LanguageServer\Tests\Server\ServerTestCase;
use LanguageServer\{Server, Client, LanguageClient, Project, PhpDocument};
use LanguageServer\Protocol\{
use LanguageServerProtocol\{
TextDocumentItem,
TextDocumentIdentifier,
SymbolInformation,

View File

@ -13,7 +13,7 @@ use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlockFactory;
use PHPUnit\Framework\TestCase;
use LanguageServer\ClientHandler;
use LanguageServer\Protocol\Message;
use LanguageServer\Message;
use AdvancedJsonRpc;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
@ -64,7 +64,7 @@ class ValidationTest extends TestCase
try {
$this->assertEquals($expectedValues['definitions'], $actualValues['definitions']);
$this->assertEquals((array)$expectedValues['references'], (array)$actualValues['references'], 'references don\'t match.');
$this->assertEquals((array)$expectedValues['references'], (array)$actualValues['references'], sprintf('references match in "%s"', $outputFile));
} catch (\Throwable $e) {
$outputFile = getExpectedValuesFile($testCaseFile);
file_put_contents($outputFile, json_encode($actualValues, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));

View File

@ -1,3 +1,3 @@
<?php
namespace B;
use LanguageServer\Protocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};
use LanguageServerProtocol\{TextDocumentIdentifier, Position, ReferenceContext, Location, Range};

View File

@ -1,24 +1,21 @@
{
"references": {
"LanguageServer\\Protocol": [
"LanguageServerProtocol": [
"./namespaces5.php"
],
"LanguageServer": [
"LanguageServerProtocol\\TextDocumentIdentifier": [
"./namespaces5.php"
],
"LanguageServer\\Protocol\\TextDocumentIdentifier": [
"LanguageServerProtocol\\Position": [
"./namespaces5.php"
],
"LanguageServer\\Protocol\\Position": [
"LanguageServerProtocol\\ReferenceContext": [
"./namespaces5.php"
],
"LanguageServer\\Protocol\\ReferenceContext": [
"LanguageServerProtocol\\Location": [
"./namespaces5.php"
],
"LanguageServer\\Protocol\\Location": [
"./namespaces5.php"
],
"LanguageServer\\Protocol\\Range": [
"LanguageServerProtocol\\Range": [
"./namespaces5.php"
]
},