1
0
Fork 0

Remove CompletionItem.textEdit

pull/266/head
Felix Becker 2017-02-01 16:32:24 +01:00
parent d8823bc7dc
commit 0e29092597
3 changed files with 11 additions and 40 deletions

View File

@ -6,8 +6,6 @@ namespace LanguageServer;
use PhpParser\Node;
use LanguageServer\Index\ReadableIndex;
use LanguageServer\Protocol\{
TextEdit,
Range,
Position,
CompletionList,
CompletionItem,
@ -272,18 +270,10 @@ class CompletionProvider
$item->label = '$' . ($var instanceof Node\Expr\ClosureUse ? $var->var : $var->name);
$item->documentation = $this->definitionResolver->getDocumentationFromNode($var);
$item->detail = (string)$this->definitionResolver->getTypeFromNode($var);
$item->textEdit = new TextEdit(
new Range($pos, $pos),
stripStringOverlap($doc->getRange(new Range(new Position(0, 0), $pos)), $item->label)
);
$list->items[] = $item;
}
} else if ($node instanceof Node\Stmt\InlineHTML || $pos == new Position(0, 0)) {
$item = new CompletionItem('<?php', CompletionItemKind::KEYWORD);
$item->textEdit = new TextEdit(
new Range($pos, $pos),
stripStringOverlap($doc->getRange(new Range(new Position(0, 0), $pos)), '<?php')
);
$list->items[] = $item;
}

View File

@ -64,13 +64,16 @@ class CompletionItem
public $insertText;
/**
* An edit which is applied to a document when selecting
* this completion. When an edit is provided the value of
* insertText is ignored.
* A range of text that should be replaced by this completion item.
*
* @var TextEdit|null
* Defaults to a range from the start of the current word to the current position.
*
* *Note:* The range must be a single line range and it must contain the position at which completion
* has been requested.
*
* @var Range|null
*/
public $textEdit;
public $range;
/**
* An optional array of additional text edits that are applied when
@ -106,7 +109,7 @@ class CompletionItem
* @param string|null $sortText
* @param string|null $filterText
* @param string|null $insertText
* @param TextEdit|null $textEdit
* @param Range|null $range
* @param TextEdit[]|null $additionalTextEdits
* @param Command|null $command
* @param mixed|null $data
@ -119,7 +122,7 @@ class CompletionItem
string $sortText = null,
string $filterText = null,
string $insertText = null,
TextEdit $textEdit = null,
Range $range = null,
array $additionalTextEdits = null,
Command $command = null,
$data = null
@ -131,7 +134,7 @@ class CompletionItem
$this->sortText = $sortText;
$this->filterText = $filterText;
$this->insertText = $insertText;
$this->textEdit = $textEdit;
$this->range = $range;
$this->additionalTextEdits = $additionalTextEdits;
$this->command = $command;
$this->data = $data;

View File

@ -109,25 +109,3 @@ function getClosestNode(Node $node, string $type)
}
}
}
/**
* Returns the part of $b that is not overlapped by $a
* Example:
*
* stripStringOverlap('whatever<?', '<?php') === 'php'
*
* @param string $a
* @param string $b
* @return string
*/
function stripStringOverlap(string $a, string $b): string
{
$aLen = strlen($a);
$bLen = strlen($b);
for ($i = 1; $i <= $bLen; $i++) {
if (substr($b, 0, $i) === substr($a, $aLen - $i)) {
return substr($b, $i);
}
}
return $b;
}