1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Improve internal typing for sabre/event promises

This commit is contained in:
Matthew Brown 2018-12-10 23:18:53 -05:00
parent d9945a0ced
commit b052e211a0
5 changed files with 34 additions and 9 deletions

View File

@ -23,6 +23,10 @@
<class name="LogicException"/> <class name="LogicException"/>
</ignoreExceptions> </ignoreExceptions>
<stubs>
<file name="src/Psalm/Internal/Stubs/SabreEvent.php"/>
</stubs>
<issueHandlers> <issueHandlers>
<MisplacedRequiredParam errorLevel="suppress"/> <MisplacedRequiredParam errorLevel="suppress"/>
<PossiblyNullOperand errorLevel="suppress"/> <PossiblyNullOperand errorLevel="suppress"/>

View File

@ -173,7 +173,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
* @param int|null $processId The process Id of the parent process that started the server. * @param int|null $processId The process Id of the parent process that started the server.
* Is null if the process has not been started by another process. If the parent process is * Is null if the process has not been started by another process. If the parent process is
* not alive then the server should exit (see exit notification) its process. * not alive then the server should exit (see exit notification) its process.
* @return Promise <InitializeResult> * @return Promise<InitializeResult>
* @psalm-suppress PossiblyUnusedMethod * @psalm-suppress PossiblyUnusedMethod
*/ */
public function initialize( public function initialize(

View File

@ -171,7 +171,7 @@ class TextDocument
* *
* @param TextDocumentIdentifier $textDocument The text document * @param TextDocumentIdentifier $textDocument The text document
* @param Position $position The position inside the text document * @param Position $position The position inside the text document
* @return Promise <Location|Location[]> * @return Promise<Location|Hover>
*/ */
public function definition(TextDocumentIdentifier $textDocument, Position $position): Promise public function definition(TextDocumentIdentifier $textDocument, Position $position): Promise
{ {
@ -223,7 +223,7 @@ class TextDocument
* *
* @param TextDocumentIdentifier $textDocument The text document * @param TextDocumentIdentifier $textDocument The text document
* @param Position $position The position inside the text document * @param Position $position The position inside the text document
* @return Promise <Hover> * @return Promise<Hover>
*/ */
public function hover(TextDocumentIdentifier $textDocument, Position $position): Promise public function hover(TextDocumentIdentifier $textDocument, Position $position): Promise
{ {
@ -275,7 +275,7 @@ class TextDocument
* *
* @param TextDocumentIdentifier The text document * @param TextDocumentIdentifier The text document
* @param Position $position The position * @param Position $position The position
* @return Promise <CompletionItem[]|CompletionList> * @return Promise<CompletionItem[]|CompletionList>
*/ */
public function completion(TextDocumentIdentifier $textDocument, Position $position): Promise public function completion(TextDocumentIdentifier $textDocument, Position $position): Promise
{ {

View File

@ -0,0 +1,20 @@
<?php
namespace Sabre\Event;
/**
* @template TReturn
* @param callable():\Generator<mixed, mixed, mixed, TReturn> $gen
* @return Promise<TReturn>
*/
function coroutine(callable $gen) : Promise {}
/**
* @template TReturn
*/
class Promise {
/**
* @return TReturn
*/
function wait() {}
}

View File

@ -57,9 +57,6 @@ class TNamedObject extends Atomic
*/ */
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format) public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{ {
$class_parts = explode('\\', $this->value);
$class_name = array_pop($class_parts);
$intersection_types = $this->getNamespacedIntersectionTypes( $intersection_types = $this->getNamespacedIntersectionTypes(
$namespace, $namespace,
$aliased_classes, $aliased_classes,
@ -71,8 +68,12 @@ class TNamedObject extends Atomic
return 'self' . $intersection_types; return 'self' . $intersection_types;
} }
if ($namespace && preg_match('/^' . preg_quote($namespace) . '\\\\' . $class_name . '$/i', $this->value)) { if ($namespace && stripos($this->value, $namespace . '\\') === 0) {
return $class_name . $intersection_types; return preg_replace(
'/^' . preg_quote($namespace . '\\') . '/i',
'',
$this->value
) . $intersection_types;
} }
if (!$namespace && stripos($this->value, '\\') === false) { if (!$namespace && stripos($this->value, '\\') === false) {