1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Jump between parens when autocompleting method with parameters (#1839)

This commit is contained in:
Ilija Tovilo 2019-06-24 13:51:12 +02:00 committed by Matthew Brown
parent 766b1b0384
commit 16768e363c
3 changed files with 40 additions and 2 deletions

View File

@ -15,7 +15,7 @@
"openlss/lib-array2xml": "^1.0",
"ocramius/package-versions": "^1.2",
"composer/xdebug-handler": "^1.1",
"felixfbecker/language-server-protocol": "^1.2",
"felixfbecker/language-server-protocol": "^1.3",
"felixfbecker/advanced-json-rpc": "^3.0.3",
"netresearch/jsonmapper": "^1.0",
"webmozart/glob": "^4.1",

View File

@ -1229,8 +1229,9 @@ class Codebase
null,
(string)$method_storage->visibility,
$method_storage->cased_name,
$method_storage->cased_name . '()'
$method_storage->cased_name . (count($method_storage->params) !== 0 ? '($0)' : '()')
);
$completion_item->insertTextFormat = \LanguageServerProtocol\InsertTextFormat::SNIPPET;
if ($method_storage->is_static) {
$static_completion_items[] = $completion_item;

View File

@ -624,6 +624,43 @@ class CompletionTest extends \Psalm\Tests\TestCase
$this->assertSame(['B\Collection', '->', []], $codebase->getCompletionDataAtPosition('somefile.php', new Position(10, 61)));
}
public function testCursorPositionOnMethodCompletion(): void
{
$codebase = $this->project_analyzer->getCodebase();
$config = $codebase->config;
$config->throw_exception = false;
$this->addFile(
'somefile.php',
'<?php
namespace B;
class A {
public function bar(string $a) {
$this->
}
public function baz() {}
}'
);
$codebase->file_provider->openFile('somefile.php');
$codebase->scanFiles();
$this->analyzeFile('somefile.php', new Context());
$completion_data = $codebase->getCompletionDataAtPosition('somefile.php', new Position(5, 31));
$this->assertSame(['B\A', '->', []], $completion_data);
$completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1]);
$this->assertCount(2, $completion_items);
$this->assertEquals('bar($0)', $completion_items[0]->insertText);
$this->assertEquals('baz()', $completion_items[1]->insertText);
}
/**
* @return void
*/