1
0
Fork 0

remove createSignatureHelp and use constructors in data provider

pull/547/head
Philip Nelson 2017-12-05 12:26:39 +11:00
parent fa561f8481
commit afd7215624
1 changed files with 71 additions and 112 deletions

View File

@ -62,142 +62,101 @@ class SignatureHelpTest extends TestCase
return [ return [
'member call' => [ 'member call' => [
new Position(48, 9), new Position(48, 9),
$this->createSignatureHelp([ new SignatureHelp(
'label' => '(\\Foo\\SomethingElse $a, int|null $b = null)',
'documentation' => 'Function doc',
'parameters' => [
[ [
'label' => '\\Foo\\SomethingElse $a', new SignatureInformation(
'documentation' => 'A param with a different doc type', '(\\Foo\\SomethingElse $a, int|null $b = null)',
],
[ [
'label' => 'int|null $b = null', new ParameterInformation('\\Foo\\SomethingElse $a', 'A param with a different doc type'),
'documentation' => 'Param with default value', new ParameterInformation('int|null $b = null', 'Param with default value'),
], ],
'Function doc'
)
], ],
'activeSignature' => 0, 0,
'activeParameter' => 0, 0
]), ),
], ],
'member call 2nd param active' => [ 'member call 2nd param active' => [
new Position(49, 12), new Position(49, 12),
$this->createSignatureHelp([ new SignatureHelp(
'label' => '(\\Foo\\SomethingElse $a, int|null $b = null)',
'documentation' => 'Function doc',
'parameters' => [
[ [
'label' => '\\Foo\\SomethingElse $a', new SignatureInformation(
'documentation' => 'A param with a different doc type', '(\\Foo\\SomethingElse $a, int|null $b = null)',
],
[ [
'label' => 'int|null $b = null', new ParameterInformation('\\Foo\\SomethingElse $a', 'A param with a different doc type'),
'documentation' => 'Param with default value', new ParameterInformation('int|null $b = null', 'Param with default value'),
], ],
'Function doc'
)
], ],
'activeSignature' => 0, 0,
'activeParameter' => 1, 1
]), ),
], ],
'member call 2nd param active and closing )' => [ 'member call 2nd param active and closing )' => [
new Position(50, 11), new Position(50, 11),
$this->createSignatureHelp([ new SignatureHelp(
'label' => '(\\Foo\\SomethingElse $a, int|null $b = null)',
'documentation' => 'Function doc',
'parameters' => [
[ [
'label' => '\\Foo\\SomethingElse $a', new SignatureInformation(
'documentation' => 'A param with a different doc type', '(\\Foo\\SomethingElse $a, int|null $b = null)',
],
[ [
'label' => 'int|null $b = null', new ParameterInformation('\\Foo\\SomethingElse $a', 'A param with a different doc type'),
'documentation' => 'Param with default value', new ParameterInformation('int|null $b = null', 'Param with default value'),
], ],
'Function doc'
)
], ],
'activeSignature' => 0, 0,
'activeParameter' => 1, 1
]), ),
], ],
'method with no params' => [ 'method with no params' => [
new Position(51, 9), new Position(51, 9),
$this->createSignatureHelp([ new SignatureHelp([new SignatureInformation('()', [], 'Method with no params', 0, 0)]),
'label' => '()',
'documentation' => 'Method with no params',
'parameters' => [],
'activeSignature' => 0,
'activeParameter' => 0,
]),
], ],
'constructor' => [ 'constructor' => [
new Position(47, 14), new Position(47, 14),
$this->createSignatureHelp([ new SignatureHelp(
'label' => '(string $first, int $second, \Foo\Test $third)',
'documentation' => 'Constructor comment goes here',
'parameters' => [
[ [
'label' => 'string $first', new SignatureInformation(
'documentation' => 'First param', '(string $first, int $second, \Foo\Test $third)',
],
[ [
'label' => 'int $second', new ParameterInformation('string $first', 'First param'),
'documentation' => 'Second param', new ParameterInformation('int $second', 'Second param'),
new ParameterInformation('\Foo\Test $third', 'Third param with a longer description'),
], ],
[ 'Constructor comment goes here'
'label' => '\Foo\Test $third', )
'documentation' => 'Third param with a longer description',
], ],
], 0,
'activeSignature' => 0, 0
'activeParameter' => 0, ),
]),
], ],
'global function' => [ 'global function' => [
new Position(53, 4), new Position(53, 4),
$this->createSignatureHelp([ new SignatureHelp(
'label' => '(int $i, bool $b = false)',
'documentation' => null,
'parameters' => [
[ [
'label' => 'int $i', new SignatureInformation(
'documentation' => 'Global function param one', '(int $i, bool $b = false)',
],
[ [
'label' => 'bool $b = false', new ParameterInformation('int $i', 'Global function param one'),
'documentation' => 'Default false param', new ParameterInformation('bool $b = false', 'Default false param'),
]
),
], ],
], 0,
'activeSignature' => 0, 0
'activeParameter' => 0, )
]),
], ],
'static method' => [ 'static method' => [
new Position(55, 10), new Position(55, 10),
$this->createSignatureHelp([ new SignatureHelp(
'label' => '(mixed $a)', [new SignatureInformation('(mixed $a)', [new ParameterInformation('mixed $a')])],
'documentation' => null, 0,
'parameters' => [ 0
[ ),
'label' => 'mixed $a',
'documentation' => null,
],
],
'activeSignature' => 0,
'activeParameter' => 0,
]),
], ],
]; ];
} }
private function createSignatureHelp(array $info): SignatureHelp
{
$params = [];
foreach ($info['parameters'] as $param) {
$paramInfo = new ParameterInformation($param['label'], $param['documentation']);
$params[] = $paramInfo;
}
$signature = new SignatureInformation($info['label'], $params, $info['documentation']);
$help = new SignatureHelp([$signature], $info['activeSignature'], $info['activeParameter']);
return $help;
}
} }