-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add InlineValue objects to generated LSP (#19)
* Add protocol.inlineValue.d.ts, handle literal types. * Add Inline objects. * Improved class generation.
- Loading branch information
Showing
15 changed files
with
664 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php // Auto-generated from vscode-languageserver-protocol (typescript) | ||
|
||
namespace Phpactor\LanguageServerProtocol; | ||
|
||
use DTL\Invoke\Invoke; | ||
use Exception; | ||
use RuntimeException; | ||
|
||
class InlineValueEvaluatableExpression | ||
{ | ||
/** | ||
* The document range for which the inline value applies. | ||
* The range is used to extract the evaluatable expression from the underlying document. | ||
* | ||
* @var Range | ||
*/ | ||
public $range; | ||
|
||
/** | ||
* If specified the expression overrides the extracted expression. | ||
* | ||
* @var string|null | ||
*/ | ||
public $expression; | ||
|
||
/** | ||
* @param Range $range | ||
* @param string|null $expression | ||
*/ | ||
public function __construct(Range $range, ?string $expression = null) | ||
{ | ||
$this->range = $range; | ||
$this->expression = $expression; | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $array | ||
* @return self | ||
*/ | ||
public static function fromArray(array $array, bool $allowUnknownKeys = false) | ||
{ | ||
$map = [ | ||
'range' => ['names' => [Range::class], 'iterable' => false], | ||
'expression' => ['names' => [], 'iterable' => false], | ||
]; | ||
|
||
foreach ($array as $key => &$value) { | ||
if (!isset($map[$key])) { | ||
if ($allowUnknownKeys) { | ||
unset($array[$key]); | ||
continue; | ||
} | ||
|
||
throw new RuntimeException(sprintf( | ||
'Parameter "%s" on class "%s" not known, known parameters: "%s"', | ||
$key, | ||
self::class, | ||
implode('", "', array_keys($map)) | ||
)); | ||
} | ||
|
||
// from here we only care about arrays that can be transformed into | ||
// objects | ||
if (!is_array($value)) { | ||
continue; | ||
} | ||
|
||
if (empty($map[$key]['names'])) { | ||
continue; | ||
} | ||
|
||
if ($map[$key]['iterable']) { | ||
$value = array_map(function ($object) use ($map, $key, $allowUnknownKeys) { | ||
if (!is_array($object)) { | ||
return $object; | ||
} | ||
|
||
return self::invokeFromNames($map[$key]['names'], $object, $allowUnknownKeys) ?: $object; | ||
}, $value); | ||
continue; | ||
} | ||
|
||
$names = $map[$key]['names']; | ||
$value = self::invokeFromNames($names, $value, $allowUnknownKeys) ?: $value; | ||
} | ||
|
||
return Invoke::new(self::class, $array); | ||
} | ||
|
||
/** | ||
* @param array<string> $classNames | ||
* @param array<string,mixed> $object | ||
*/ | ||
private static function invokeFromNames(array $classNames, array $object, bool $allowUnknownKeys): ?object | ||
{ | ||
$lastException = null; | ||
foreach ($classNames as $className) { | ||
try { | ||
// @phpstan-ignore-next-line | ||
return call_user_func_array($className . '::fromArray', [$object, $allowUnknownKeys]); | ||
} catch (Exception $exception) { | ||
$lastException = $exception; | ||
continue; | ||
} | ||
} | ||
|
||
throw $lastException; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php // Auto-generated from vscode-languageserver-protocol (typescript) | ||
|
||
namespace Phpactor\LanguageServerProtocol; | ||
|
||
use DTL\Invoke\Invoke; | ||
use Exception; | ||
use RuntimeException; | ||
|
||
/** | ||
* Mixins (implemented TS interfaces): WorkDoneProgressParams | ||
*/ | ||
class InlineValueParams | ||
{ | ||
/** | ||
* The text document. | ||
* | ||
* @var TextDocumentIdentifier | ||
*/ | ||
public $textDocument; | ||
|
||
/** | ||
* The document range for which inline values should be computed. | ||
* | ||
* @var Range | ||
*/ | ||
public $range; | ||
|
||
/** | ||
* Additional information about the context in which inline values were | ||
* requested. | ||
* | ||
* @var array{frameId:int,stoppedLocation:Range} | ||
*/ | ||
public $context; | ||
|
||
/** | ||
* An optional token that a server can use to report work done progress. | ||
* | ||
* @var int|string|null | ||
*/ | ||
public $workDoneToken; | ||
|
||
/** | ||
* @param TextDocumentIdentifier $textDocument | ||
* @param Range $range | ||
* @param array{frameId:int,stoppedLocation:Range} $context | ||
* @param int|string|null $workDoneToken | ||
*/ | ||
public function __construct(TextDocumentIdentifier $textDocument, Range $range, array $context, $workDoneToken = null) | ||
{ | ||
$this->textDocument = $textDocument; | ||
$this->range = $range; | ||
$this->context = $context; | ||
$this->workDoneToken = $workDoneToken; | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $array | ||
* @return self | ||
*/ | ||
public static function fromArray(array $array, bool $allowUnknownKeys = false) | ||
{ | ||
$map = [ | ||
'textDocument' => ['names' => [TextDocumentIdentifier::class], 'iterable' => false], | ||
'range' => ['names' => [Range::class], 'iterable' => false], | ||
'context' => ['names' => [], 'iterable' => false], | ||
'workDoneToken' => ['names' => [], 'iterable' => false], | ||
]; | ||
|
||
foreach ($array as $key => &$value) { | ||
if (!isset($map[$key])) { | ||
if ($allowUnknownKeys) { | ||
unset($array[$key]); | ||
continue; | ||
} | ||
|
||
throw new RuntimeException(sprintf( | ||
'Parameter "%s" on class "%s" not known, known parameters: "%s"', | ||
$key, | ||
self::class, | ||
implode('", "', array_keys($map)) | ||
)); | ||
} | ||
|
||
// from here we only care about arrays that can be transformed into | ||
// objects | ||
if (!is_array($value)) { | ||
continue; | ||
} | ||
|
||
if (empty($map[$key]['names'])) { | ||
continue; | ||
} | ||
|
||
if ($map[$key]['iterable']) { | ||
$value = array_map(function ($object) use ($map, $key, $allowUnknownKeys) { | ||
if (!is_array($object)) { | ||
return $object; | ||
} | ||
|
||
return self::invokeFromNames($map[$key]['names'], $object, $allowUnknownKeys) ?: $object; | ||
}, $value); | ||
continue; | ||
} | ||
|
||
$names = $map[$key]['names']; | ||
$value = self::invokeFromNames($names, $value, $allowUnknownKeys) ?: $value; | ||
} | ||
|
||
return Invoke::new(self::class, $array); | ||
} | ||
|
||
/** | ||
* @param array<string> $classNames | ||
* @param array<string,mixed> $object | ||
*/ | ||
private static function invokeFromNames(array $classNames, array $object, bool $allowUnknownKeys): ?object | ||
{ | ||
$lastException = null; | ||
foreach ($classNames as $className) { | ||
try { | ||
// @phpstan-ignore-next-line | ||
return call_user_func_array($className . '::fromArray', [$object, $allowUnknownKeys]); | ||
} catch (Exception $exception) { | ||
$lastException = $exception; | ||
continue; | ||
} | ||
} | ||
|
||
throw $lastException; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php // Auto-generated from vscode-languageserver-protocol (typescript) | ||
|
||
namespace Phpactor\LanguageServerProtocol; | ||
|
||
interface InlineValueRefreshRequest | ||
{ | ||
public const METHOD = 'workspace/inlineValue/refresh'; | ||
} |
Oops, something went wrong.