1
0
Fork 0
pull/6/head
Felix Becker 2016-08-22 22:40:16 +02:00
parent 64e496fac9
commit 3b02010097
109 changed files with 1569 additions and 106 deletions

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# PHP Language Server
> A pure PHP implementation of the [Language Server Protocol](https://github.com/Microsoft/language-server-protocol).
[![Version](https://img.shields.io/packagist/v/felixfbecker/language-server.svg)]() [![License](https://img.shields.io/packagist/l/felixfbecker/language-server.svg)]()

View File

@ -0,0 +1,17 @@
<?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;
}

35
src/Protocol/CodeLens.php Normal file
View File

@ -0,0 +1,35 @@
<?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,6 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\Methods\Initialize\ServerCapabilities; namespace LanguageServer\Protocol;
/** /**
* Code Lens options. * Code Lens options.

32
src/Protocol/Command.php Normal file
View File

@ -0,0 +1,32 @@
<?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,6 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol;
class CompletionItem class CompletionItem
{ {
@ -17,7 +17,7 @@ class CompletionItem
* The kind of this completion item. Based of the kind * The kind of this completion item. Based of the kind
* an icon is chosen by the editor. * an icon is chosen by the editor.
* *
* @var number|null * @var int|null
*/ */
public $kind; public $kind;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol;
/** /**
* The kind of a completion entry. * The kind of a completion entry.
@ -8,12 +8,12 @@ namespace LanguageServer\Protocol\TextDocument;
abstract class CompletionItemKind { abstract class CompletionItemKind {
const TEXT = 1; const TEXT = 1;
const METHOD = 2; const METHOD = 2;
const _FUNCTION = 3; const FUNCTION = 3;
const CONSTRUCTOR = 4; const CONSTRUCTOR = 4;
const FIELD = 5; const FIELD = 5;
const VARIABLE = 6; const VARIABLE = 6;
const _CLASS = 7; const _CLASS = 7;
const _INTERFACE = 8; const INTERFACE = 8;
const MODULE = 9; const MODULE = 9;
const PROPERTY = 10; const PROPERTY = 10;
const UNIT = 11; const UNIT = 11;

View File

@ -1,9 +1,9 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol;
/** /**
* Represents a collection of [completion items](#CompletionItem) to be presented in * Represents a collection of completion items to be presented in
* the editor. * the editor.
*/ */
class CompletionList class CompletionList

View File

@ -1,6 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\Methods\Initialize\ServerCapabilities; namespace LanguageServer\Protocol;
/** /**
* Completion options. * Completion options.

View File

@ -1,6 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol;
/** /**
* An event describing a change to a text document. If range and rangeLength are * An event describing a change to a text document. If range and rangeLength are
@ -8,7 +8,6 @@ namespace LanguageServer\Protocol\TextDocument;
*/ */
class ContentChangeEvent class ContentChangeEvent
{ {
/** /**
* The range of the document that changed. * The range of the document that changed.
* *

View File

@ -0,0 +1,47 @@
<?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;
}

View File

@ -0,0 +1,26 @@
<?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

@ -0,0 +1,25 @@
<?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 DocumentHighlightKind
{
/**
* The range this highlight applies to.
*
* @var Range
*/
public $range;
/**
* The highlight kind, default is DocumentHighlightKind::TEXT.
*
* @var int|null
*/
public $kind;
}

View File

@ -0,0 +1,24 @@
<?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,6 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\Methods\Initialize\ServerCapabilities; namespace LanguageServer\Protocol;
/** /**
* Format document on type options * Format document on type options

View File

@ -1,5 +1,7 @@
<?php <?php
namespace LanguageServer\Protocol;
/** /**
* Enum * Enum
*/ */

View File

@ -1,6 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol;
/** /**
* An event describing a file change. * An event describing a file change.

View File

@ -0,0 +1,25 @@
<?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.
}

19
src/Protocol/Location.php Normal file
View File

@ -0,0 +1,19 @@
<?php
namespace LanguageServer\Protocol;
/**
* Represents a location inside a resource, such as a line inside a text file.
*/
class Location
{
/**
* @var string
*/
public $uri;
/**
* @var Range
*/
public $range;
}

View File

@ -1,5 +1,10 @@
<?php <?php
namespace LanguageServer\Protocol;
/**
* A general message as defined by JSON-RPC. The language server protocol always uses "2.0" as the jsonrpc version.
*/
abstract class Message abstract class Message
{ {
/** /**
@ -8,4 +13,37 @@ abstract class Message
* @var string * @var string
*/ */
public $jsonrpc; public $jsonrpc;
/**
* Parses a request body and returns the appropiate Message subclass
*
* @param string $body The raw request body
* @param string $fallbackClass The class to fall back to if the body is not a Notification and the method is
* unknown (Request::class or Response::class)
*/
public static function parse(string $body, string $fallbackClass): self
{
$decoded = json_decode($body);
// The appropiate Request/Notification subclasses are namespaced according to the method
// example: textDocument/didOpen -> LanguageServer\Protocol\Methods\TextDocument\DidOpenNotification
$class = __NAMESPACE__ . '\\Methods\\' . implode('\\', array_map('ucfirst', explode('/', $decoded->method))) . (isset($decoded->id) ? 'Request' : 'Notification');
// If the Request/Notification type is unknown, instantiate a basic Request or Notification class
// (this is the reason Request and Notification are not abstract)
if (!class_exists($class)) {
fwrite(STDERR, "Unknown method {$decoded->method}\n");
if (!isset($decoded->id)) {
$class = Notification::class;
} else {
$class = $fallbackClass;
}
}
// JsonMapper will take care of recursively using the right classes for $params etc.
$mapper = new JsonMapper();
$message = $mapper->map($decoded, new $class);
return $message;
}
} }

View File

@ -1,8 +1,8 @@
<?php <?php
namespace LanguageServer\Protocol\Window; namespace LanguageServer\Protocol;
class ShowMessageParams class MessageActionItem
{ {
/** /**
* A short title like 'Retry', 'Open Log' etc. * A short title like 'Retry', 'Open Log' etc.

View File

@ -1,5 +1,7 @@
<?php <?php
namespace LanguageServer\Protocol;
/** /**
* Enum * Enum
*/ */

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods;
use LanguageServer\Protocol\Notification;
class CancelRequestNotification extends Notification
{
/**
* @var CancelParams
*/
public $params;
}

View File

@ -0,0 +1,15 @@
<?php
namespace LanguageServer\Protocol\Methods;
use LanguageServer\Protocol\Params;
class CancelRequestParams extends Params
{
/**
* The request id to cancel.
*
* @var int|string
*/
public $id;
}

View File

@ -0,0 +1,17 @@
<?php
namespace LanguageServer\Protocol\Methods\CodeLens;
use LanguageServer\Protocol\Request;
/**
* The code lens resolve request is sent from the client to the server to resolve the command for a given code lens
* item.
*/
class ResolveRequest extends Request
{
/**
* @var LanguageServer\Protocol\CodeLens
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\CodeLens;
use LanguageServer\Protocol\Response;
class ResolveResponse extends Response
{
/**
* @var LanguageServer\Protocol\CodeLens
*/
public $result;
}

View File

@ -1,15 +1,17 @@
<?php <?php
namespace LanguageServer\Protocol\Methods\CompletionItem\ResolveRequest; namespace LanguageServer\Protocol\Methods\CompletionItem;
use LanguageServer\Protocol\Request;
/** /**
* The request is sent from the client to the server to resolve additional * The request is sent from the client to the server to resolve additional
* information for a given completion item. * information for a given completion item.
*/ */
class CompletionItemResolveRequest class ResolveRequest extends Request
{ {
/** /**
* @var CompletionItem * @var LanguageServer\Protocol\CompletionItem
*/ */
public $params; public $params;
} }

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\CompletionItem;
use LanguageServer\Protocol\Response;
class ResolveResponse extends Response
{
/**
* @var LanguageServer\Protocol\CompletionItem
*/
public $result;
}

View File

@ -0,0 +1,16 @@
<?php
namespace LanguageServer\Protocol\Methods;
use LanguageServer\Protocol\Notification;
/**
* A notification to ask the server to exit its process.
*/
class ExitNotification extends Notification
{
/**
* @var null
*/
public $params;
}

View File

@ -15,7 +15,7 @@ class InitializeParams
/** /**
* The process Id of the parent process that started the server. * The process Id of the parent process that started the server.
* *
* @var number * @var int
*/ */
public $processId; public $processId;

View File

@ -1,11 +1,13 @@
<?php <?php
namespace LanguageServer\Protocol\Methods\InitializeRequest; namespace LanguageServer\Protocol\Methods\Initialize;
/* use LanguageServer\Protocol\Request;
/**
* The initialize request is sent as the first request from the client to the server. * The initialize request is sent as the first request from the client to the server.
*/ */
class CompletionItemResolveRequest class InitializeRequest extends Request
{ {
/** /**
* @var InitializeParams * @var InitializeParams

View File

@ -9,7 +9,7 @@ class InitializeResponse extends Response
/** /**
* The capabilities the language server provides. * The capabilities the language server provides.
* *
* @var ServerCapabilities * @var LanguageServer\Protocol\ServerCapabilities
*/ */
public $capabilites; public $capabilites;
} }

View File

@ -0,0 +1,18 @@
<?php
namespace LanguageServer\Protocol\Methods;
use LanguageServer\Protocol\Request;
/**
* The shutdown request is sent from the client to the server. It asks the server to shut down, but to not exit
* (otherwise the response might not be delivered correctly to the client). There is a separate exit notification that
* asks the server to exit.
*/
class ShutdownRequest extends Request
{
/**
* @var null
*/
public $params;
}

View File

@ -0,0 +1,18 @@
<?php
namespace LanguageServer\Protocol\Methods;
use LanguageServer\Protocol\Request;
/**
* The shutdown request is sent from the client to the server. It asks the server to shut down, but to not exit
* (otherwise the response might not be delivered correctly to the client). There is a separate exit notification that
* asks the server to exit.
*/
class ShutdownRequest extends Request
{
/**
* @var null
*/
public $result;
}

View File

@ -2,11 +2,16 @@
namespace LanguageServer\Protocol\Telementry; namespace LanguageServer\Protocol\Telementry;
use LanguageServer\Protocol\Notification;
/** /**
* The telemetry notification is sent from the server to the client to ask the client * The telemetry notification is sent from the server to the client to ask the client
* to log a telemetry event. * to log a telemetry event.
*/ */
class EventParams class EventNotification extends Notification
{ {
/**
* @var mixed
*/
public $params;
} }

View File

@ -0,0 +1,32 @@
<?php
namespace LanguageServer\Protocol\TextDocument;
use LanguageServer\Protocol\Params;
/**
* Params for the CodeActionRequest
*/
class CodeActionParams extends Params
{
/**
* The document in which the command was invoked.
*
* @var LanguageServer\Protocol\TextDocumentIdentifier
*/
public $textDocument;
/**
* The range for which the command was invoked.
*
* @var LanguageServer\Protocol\Range
*/
public $range;
/**
* Context carrying additional information.
*
* @var LanguageServer\Protocol\CodeActionContext
*/
public $context;
}

View File

@ -0,0 +1,18 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The code action request is sent from the client to the server to compute commands for a given text document and
* range. The request is triggered when the user moves the cursor into a problem marker in the editor or presses the
* lightbulb associated with a marker.
*/
class CodeActionRequest extends Request
{
/**
* @var CodeActionParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class CodeActionResponse extends Response
{
/**
* @var LanguageServer\Protocol\Command[]
*/
public $result;
}

View File

@ -0,0 +1,15 @@
<?php
namespace LanguageServer\Protocol\TextDocument;
use LanguageServer\Protocol\Params;
class CodeLensParams extends Params
{
/**
* The document to request code lens for.
*
* @var TextDocumentIdentifier
*/
public $textDocument;
}

View File

@ -0,0 +1,16 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The code lens request is sent from the client to the server to compute code lenses for a given text document.
*/
class CodeLensRequest extends Request
{
/**
* @var CodeLensParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class CodeLensResponse extends Response
{
/**
* @var LanguageServer\Protocol\CodeLens[]
*/
public $result;
}

View File

@ -1,17 +1,13 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response; use LanguageServer\Protocol\Response;
/** class CompletionResponse extends Response
* Diagnostics notification are sent from the server to the client to signal results
* of validation runs.
*/
class PublishDiagnosticsParams extends Response
{ {
/** /**
* @var CompletionItem[]|CompletionList * @var LanguageServer\Protocol\CompletionItem[]|LanguageServer\Protocol\CompletionList
*/ */
public $result; public $result;
} }

View File

@ -0,0 +1,17 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The goto definition request is sent from the client to the server to resolve the definition location of a symbol at a
* given text document position.
*/
class DefinitionRequest extends Request
{
/**
* @var PositionParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class DefinitionResponse extends Response
{
/**
* @var LanguageServer\Protocol\Location[]|LanguageServer\Protocol\Location
*/
public $result;
}

View File

@ -0,0 +1,16 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Notification;
/**
* The document change notification is sent from the client to the server to signal changes to a text document.
*/
class DidChangeNotification extends Notification
{
/**
* @var DidChangeParams
*/
public $params;
}

View File

@ -1,26 +1,24 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol\Methods\TextDocument;
/** use LanguageServer\Protocol\Params;
* The log message notification is sent from the server to the client to ask the
* client to log a particular message. class DidChangeParams extends Params
*/
class DidChangeParams
{ {
/** /**
* The document that did change. The version number points * The document that did change. The version int points
* to the version after all provided content changes have * to the version after all provided content changes have
* been applied. * been applied.
* *
* @var VersionedTextDocumentIdentifier * @var LanguageServer\Protocol\VersionedTextDocumentIdentifier
*/ */
public $textDocument; public $textDocument;
/** /**
* The actual content changes. * The actual content changes.
* *
* @var ContentChangeEvent[] * @var LanguageServer\Protocol\TextDocumentContentChangeEvent[]
*/ */
public $contentChanges; public $contentChanges;
} }

View File

@ -0,0 +1,17 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Notification;
/**
* The watched files notification is sent from the client to the server when the client detects changes to files watched
* by the language client.
*/
class DidChangeWatchedFilesNotification extends Notification
{
/**
* @var DidChangeWatchedFilesParams
*/
public $params;
}

View File

@ -1,19 +1,15 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Params; use LanguageServer\Protocol\Params;
/**
* The watched files notification is sent from the client to the server when the
* client detects changes to files watched by the language client.
*/
class DidChangeWatchedFilesParams extends Params class DidChangeWatchedFilesParams extends Params
{ {
/** /**
* The actual file events. * The actual file events.
* *
* @var FileEvent[] * @var LanguageServer\Protocol\FileEvent[]
*/ */
public $changes; public $changes;
} }

View File

@ -0,0 +1,18 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Notification;
/**
* The document close notification is sent from the client to the server when the document got closed in the client. 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).
*/
class DidCloseNotification extends Notification
{
/**
* @var DidCloseParams
*/
public $params;
}

View File

@ -1,21 +1,15 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Params; use LanguageServer\Protocol\Params;
/**
* The document close notification is sent from the client to the server when the
* document got closed in the client. 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).
*/
class DidCloseTextDocumentParams extends Params class DidCloseTextDocumentParams extends Params
{ {
/** /**
* The document that was closed. * The document that was closed.
* *
* @var TextDocumentIdentifier * @var LanguageServer\Protocol\TextDocumentIdentifier
*/ */
public $textDocument; public $textDocument;
} }

View File

@ -0,0 +1,18 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Notification;
/**
* 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.
*/
class DidOpenNotification extends Notification
{
/**
* @var DidOpenParams
*/
public $params;
}

View File

@ -0,0 +1,15 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Params;
class DidOpenTextDocumentParams extends Params
{
/**
* The document that was opened.
*
* @var LanguageServer\Protocol\TextDocumentItem
*/
public $textDocument;
}

View File

@ -1,6 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Params; use LanguageServer\Protocol\Params;
@ -13,7 +13,7 @@ class DidSaveTextDocumentParams extends Params
/** /**
* The document that was closed. * The document that was closed.
* *
* @var TextDocumentIdentifier * @var LanguageServer\Protocol\TextDocumentIdentifier
*/ */
public $textDocument; public $textDocument;
} }

View File

@ -0,0 +1,20 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The document highlight request is sent from the client to the server to resolve a document highlights for a given
* text document position. For programming languages this usually highlights all references to the symbol scoped to this
* file. However we kept 'textDocument/documentHighlight' and 'textDocument/references' separate requests since the
* first one is allowed to be more fuzzy. Symbol matches usually have a DocumentHighlightKind of Read or Write whereas
* fuzzy or textual matches use Textas the kind.
*/
class ReferencesRequest extends Request
{
/**
* @var PositionParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class ReferencesResponse extends Response
{
/**
* @var LanguageServer\Protocol\DocumentHighlight[]
*/
public $result;
}

View File

@ -0,0 +1,15 @@
<?php
namespace LanguageServer\Protocol\TextDocument;
use LanguageServer\Protocol\Params;
class DocumentSymbolParams extends Params
{
/**
* The text document.
*
* @var LanguageServer\Protocol\TextDocumentIdentifier
*/
public $textDocument;
}

View File

@ -0,0 +1,16 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The document symbol request is sent from the client to the server to list all symbols found in a given text document.
*/
class DocumentSymbolRequest extends Request
{
/**
* @var DocumentSymbolParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class DocumentSymbolResponse extends Response
{
/**
* @var LanguageServer\Protocol\SymbolInformation[]
*/
public $result;
}

View File

@ -0,0 +1,22 @@
<?php
namespace LanguageServer\Protocol\TextDocument;
use LanguageServer\Protocol\Params;
class FormattingParams extends Params
{
/**
* The document to format.
*
* @var LanguageServer\Protocol\TextDocumentIdentifier
*/
public $textDocument;
/**
* The format options.
*
* @var LanguageServer\Protocol\FormattingOptions
*/
public $options;
}

View File

@ -0,0 +1,16 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The document formatting request is sent from the server to the client to format a whole document.
*/
class FormattingRequest extends Request
{
/**
* @var FormattingParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class FormattingResponse extends Response
{
/**
* @var LanguageServer\Protocol\TextEdit[]
*/
public $result;
}

View File

@ -1,13 +1,13 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response; use LanguageServer\Protocol\Response;
class HoverResponse extends Response class HoverResponse extends Response
{ {
/** /**
* @var Hover * @var LanguageServer\Protocol\Hover
*/ */
public $result; public $result;
} }

View File

@ -0,0 +1,36 @@
<?php
namespace LanguageServer\Protocol\TextDocument;
use LanguageServer\Protocol\Params;
class OnTypeFormattingParams extends Params
{
/**
* The document to format.
*
* @var LanguageServer\Protocol\TextDocumentIdentifier
*/
public $textDocument;
/**
* The position at which this request was sent.
*
* @var LanguageServer\Protocol\Position
*/
public $position;
/**
* The character that has been typed.
*
* @var string
*/
public $ch;
/**
* The format options.
*
* @var LanguageServer\Protocol\FormattingOptions
*/
public $options;
}

View File

@ -0,0 +1,17 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The document on type formatting request is sent from the client to the server to format parts of the document during
* typing.
*/
class OnTypeFormattingRequest extends Request
{
/**
* @var OnTypeFormattingParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class OnTypeFormattingResponse extends Response
{
/**
* @var LanguageServer\Protocol\TextEdit[]
*/
public $result;
}

View File

@ -1,26 +1,26 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\RequestParams; use LanguageServer\Protocol\Params;
/* /**
* A parameter literal used in requests to pass a text document and a position inside * A parameter literal used in requests to pass a text document and a position inside
* that document. * that document.
*/ */
class TextDocumentPositionParams extends RequestParams class TextDocumentPositionParams extends Params
{ {
/** /**
* The text document. * The text document.
* *
* @var TextDocumentIdentifier * @var LanguageServer\Protocol\TextDocumentIdentifier
*/ */
public $textDocument; public $textDocument;
/** /**
* The position inside the text document. * The position inside the text document.
* *
* @var Position * @var LanguageServer\Protocol\Position
*/ */
public $position; public $position;
} }

View File

@ -0,0 +1,16 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Notification;
/**
* Diagnostics notification are sent from the server to the client to signal results of validation runs.
*/
class PublishDiagnosticsNotification extends Notification
{
/**
* @var PublishDiagnosticsParams
*/
public $params;
}

View File

@ -0,0 +1,22 @@
<?php
namespace LanguageServer\Protocol\TextDocument;
use LanguageServer\Protocol\Params;
class PublishDiagnosticsParams extends Params
{
/**
* The URI for which diagnostic information is reported.
*
* @var string
*/
public $uri;
/**
* An array of diagnostic information items.
*
* @var LanguageServer\Protocol\Diagnostic[]
*/
public $diagnostics;
}

View File

@ -0,0 +1,29 @@
<?php
namespace LanguageServer\Protocol\TextDocument;
use LanguageServer\Protocol\Params;
class RangeFormattingParams extends Params
{
/**
* The document to format.
*
* @var LanguageServer\Protocol\TextDocumentIdentifier
*/
public $textDocument;
/**
* The range to format
*
* @var LanguageServer\Protocol\Range
*/
public $range;
/**
* The format options
*
* @var LanguageServer\Protocol\FormattingOptions
*/
public $options;
}

View File

@ -0,0 +1,16 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The document range formatting request is sent from the client to the server to format a given range in a document.
*/
class RangeFormattingRequest extends Request
{
/**
* @var RangeFormattingParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class RangeFormattingResponse extends Response
{
/**
* @var LanguageServer\Protocol\TextEdit[]
*/
public $result;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Params;
class ReferencesParams extends Params
{
/**
* @var LanguageServer\Protocol\ReferencesContext
*/
public $context;
}

View File

@ -0,0 +1,17 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The references request is sent from the client to the server to resolve project-wide references for the symbol
* denoted by the given text document position.
*/
class ReferencesRequest extends Request
{
/**
* @var ReferenceParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class ReferencesResponse extends Response
{
/**
* @var LanguageServer\Protocol\Location[]
*/
public $result;
}

View File

@ -0,0 +1,31 @@
<?php
namespace LanguageServer\Protocol\TextDocument;
use LanguageServer\Protocol\Params;
class RenameParams extends Params
{
/**
* The document to format.
*
* @var LanguageServer\Protocol\TextDocumentIdentifier
*/
public $textDocument;
/**
* The position at which this request was sent.
*
* @var LanguageServer\Protocol\Position
*/
public $position;
/**
* The new name of the symbol. If the given name is not valid the
* request must return a ResponseError with an
* appropriate message set.
*
* @var string
*/
public $newName;
}

View File

@ -0,0 +1,16 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
/**
* The rename request is sent from the client to the server to perform a workspace-wide rename of a symbol.
*/
class RenameRequest extends Request
{
/**
* @var RenameParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class RenameResponse extends Response
{
/**
* @var LanguageServer\Protocol\WorkspaceEdit
*/
public $result;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Request;
class SignatureHelpRequest extends Request
{
/**
* @var PositionParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\TextDocument;
use LanguageServer\Protocol\Response;
class SignatureHelpResponse extends Response
{
/**
* @var LanguageServer\Protocol\SignatureHelp
*/
public $result;
}

View File

@ -0,0 +1,17 @@
<?php
namespace LanguageServer\Protocol\Window;
use LanguageServer\Protocol\Notification;
/**
* The log message notification is sent from the server to the client to ask the
* client to log a particular message.
*/
class LogMessageNotification extends Notification
{
/**
* @var LogMessageParams
*/
public $params;
}

View File

@ -2,18 +2,14 @@
namespace LanguageServer\Protocol\Window; namespace LanguageServer\Protocol\Window;
use LanguageServer\Protocol\RequestParams; use LanguageServer\Protocol\Params;
/** class LogMessageParams extends Params
* The log message notification is sent from the server to the client to ask the
* client to log a particular message.
*/
class LogMessageParams extends RequestParams
{ {
/** /**
* The message type. See {@link MessageType} * The message type. See LanguageServer\Protocol\MessageType
* *
* @var number * @var int
*/ */
public $type; public $type;

View File

@ -0,0 +1,17 @@
<?php
namespace LanguageServer\Protocol\Methods\Windows;
use LanguageServer\Protocol\Notification;
/**
* The show message notification is sent from a server to a client to ask the client to display a particular message in
* the user interface.
*/
class ShowMessageNotification extends Notification
{
/**
* @var ShowMessageParams
*/
public $params;
}

View File

@ -2,10 +2,12 @@
namespace LanguageServer\Protocol\Window; namespace LanguageServer\Protocol\Window;
class ShowMessageParams use LanguageServer\Protocol\Params;
class ShowMessageParams extends Params
{ {
/** /**
* The message type. See {@link MessageType}. * The message type. See LanguageServer\Protocol\MessageType
* *
* @var int * @var int
*/ */

View File

@ -0,0 +1,18 @@
<?php
namespace LanguageServer\Protocol\Methods\Window;
use LanguageServer\Protocol\Request;
/**
* The show message request is sent from a server to a client to ask the client to display a particular message in the
* user interface. In addition to the show message notification the request allows to pass actions and to wait for an
* answer from the client.
*/
class ShowMessageRequest extends Request
{
/**
* @var ShowMessageRequestParams
*/
public $params;
}

View File

@ -21,7 +21,7 @@ class ShowMessageParams
/** /**
* The message action items to present. * The message action items to present.
* *
* @var MessageActionItem[]|null * @var LanguageServer\Protocol\MessageActionItem[]|null
*/ */
public $actions; public $actions;
} }

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\Workspace;
use LanguageServer\Protocol\Request;
class SymbolRequest extends Request
{
/**
* @var SymbolParams
*/
public $params;
}

View File

@ -0,0 +1,13 @@
<?php
namespace LanguageServer\Protocol\Methods\Workspace;
use LanguageServer\Protocol\Response;
class SymbolResponse extends Response
{
/**
* @var LanguageServer\Protocol\SymbolInformation[]
*/
public $result;
}

View File

@ -0,0 +1,26 @@
<?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;
}

View File

@ -2,7 +2,7 @@
namespace LanguageServer\Protocol; namespace LanguageServer\Protocol;
abstract class Params class Params
{ {
} }

23
src/Protocol/Position.php Normal file
View File

@ -0,0 +1,23 @@
<?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;
}

View File

@ -48,7 +48,7 @@ class ProtocolServer extends EventEmitter
break; break;
case ParsingMode::BODY: case ParsingMode::BODY:
if (strlen($buffer) === $contentLength) { if (strlen($buffer) === $contentLength) {
$req = Request::parse($body); $req = Message::parse($body, Request::class);
$this->emit($body->method, [$req]); $this->emit($body->method, [$req]);
$this->parsingMode = ParsingMode::HEADERS; $this->parsingMode = ParsingMode::HEADERS;
$this->buffer = ''; $this->buffer = '';

View File

@ -1,8 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\TextDocument; namespace LanguageServer\Protocol;
use LanguageServer\Protocol\RequestParams;
/** /**
* Diagnostics notification are sent from the server to the client to signal results * Diagnostics notification are sent from the server to the client to signal results

23
src/Protocol/Range.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace LanguageServer\Protocol;
/**
* 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;
}

View File

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

View File

@ -2,8 +2,10 @@
namespace LanguageServer\Protocol; namespace LanguageServer\Protocol;
use JsonMapper; /**
* A request message to describe a request between the client and the server. Every processed request must send a
* response back to the sender of the request.
*/
class Request extends Message class Request extends Message
{ {
/** /**
@ -17,27 +19,7 @@ class Request extends Message
public $method; public $method;
/** /**
* @var object * @var Params
*/ */
public $params; public $params;
public static function parse(string $body)
{
$mapper = new JsonMapper();
$request->id = $decoded->id;
$request->method = $decoded->method;
$pascalCasedMethod = ucfirst($decoded->method);
$namespace = __NAMESPACE__ . '\\' . str_replace('/', '\\', $pascalCasedMethod);
$className = end(explode('\\', $request->method)) . 'Params';
$fullyQualifiedName = $namespace . $className;
$mapper->classMap['RequestParams'] = $fullyQualifiedName;
$request = $mapper->map(json_decode($body), new self());
if (class_exists($fullyQualifiedName)) {
$request->params = new $fullyQualifiedName();
}
foreach ($request->params as $key => $value) {
$request->{$key} = $value;
}
return $request;
}
} }

View File

@ -1,5 +1,7 @@
<?php <?php
namespace LanguageServer\Protocol;
class ResponseError class ResponseError
{ {
/** /**

View File

@ -0,0 +1,32 @@
<?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;
}

View File

@ -1,6 +1,6 @@
<?php <?php
namespace LanguageServer\Protocol\Methods\Initialize\ServerCapabilities; namespace LanguageServer\Protocol;
/** /**
* Signature help options. * Signature help options.

View File

@ -0,0 +1,34 @@
<?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;
}

Some files were not shown because too many files have changed in this diff Show More