Skip to content
Permalink
Browse files

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

  • Loading branch information...
iluuu1994 authored and muglug committed Jun 24, 2019
1 parent 766b1b0 commit 16768e363cbdfd2322fdf1b4ddc54552eeb0b211
Showing with 40 additions and 2 deletions.
  1. +1 −1 composer.json
  2. +2 −1 src/Psalm/Codebase.php
  3. +37 −0 tests/LanguageServer/CompletionTest.php
@@ -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",
@@ -1229,8 +1229,9 @@ public function getCompletionItemsForClassishThing(string $type_string, string $
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;
@@ -624,6 +624,43 @@ function baz(Collection $a) {
$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
*/

0 comments on commit 16768e3

Please sign in to comment.
You can’t perform that action at this time.