Remove CompletionItem.textEdit
parent
d8823bc7dc
commit
0e29092597
|
@ -6,8 +6,6 @@ namespace LanguageServer;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use LanguageServer\Index\ReadableIndex;
|
use LanguageServer\Index\ReadableIndex;
|
||||||
use LanguageServer\Protocol\{
|
use LanguageServer\Protocol\{
|
||||||
TextEdit,
|
|
||||||
Range,
|
|
||||||
Position,
|
Position,
|
||||||
CompletionList,
|
CompletionList,
|
||||||
CompletionItem,
|
CompletionItem,
|
||||||
|
@ -272,18 +270,10 @@ class CompletionProvider
|
||||||
$item->label = '$' . ($var instanceof Node\Expr\ClosureUse ? $var->var : $var->name);
|
$item->label = '$' . ($var instanceof Node\Expr\ClosureUse ? $var->var : $var->name);
|
||||||
$item->documentation = $this->definitionResolver->getDocumentationFromNode($var);
|
$item->documentation = $this->definitionResolver->getDocumentationFromNode($var);
|
||||||
$item->detail = (string)$this->definitionResolver->getTypeFromNode($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;
|
$list->items[] = $item;
|
||||||
}
|
}
|
||||||
} else if ($node instanceof Node\Stmt\InlineHTML || $pos == new Position(0, 0)) {
|
} else if ($node instanceof Node\Stmt\InlineHTML || $pos == new Position(0, 0)) {
|
||||||
$item = new CompletionItem('<?php', CompletionItemKind::KEYWORD);
|
$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;
|
$list->items[] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,13 +64,16 @@ class CompletionItem
|
||||||
public $insertText;
|
public $insertText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An edit which is applied to a document when selecting
|
* A range of text that should be replaced by this completion item.
|
||||||
* this completion. When an edit is provided the value of
|
|
||||||
* insertText is ignored.
|
|
||||||
*
|
*
|
||||||
* @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
|
* An optional array of additional text edits that are applied when
|
||||||
|
@ -106,7 +109,7 @@ class CompletionItem
|
||||||
* @param string|null $sortText
|
* @param string|null $sortText
|
||||||
* @param string|null $filterText
|
* @param string|null $filterText
|
||||||
* @param string|null $insertText
|
* @param string|null $insertText
|
||||||
* @param TextEdit|null $textEdit
|
* @param Range|null $range
|
||||||
* @param TextEdit[]|null $additionalTextEdits
|
* @param TextEdit[]|null $additionalTextEdits
|
||||||
* @param Command|null $command
|
* @param Command|null $command
|
||||||
* @param mixed|null $data
|
* @param mixed|null $data
|
||||||
|
@ -119,7 +122,7 @@ class CompletionItem
|
||||||
string $sortText = null,
|
string $sortText = null,
|
||||||
string $filterText = null,
|
string $filterText = null,
|
||||||
string $insertText = null,
|
string $insertText = null,
|
||||||
TextEdit $textEdit = null,
|
Range $range = null,
|
||||||
array $additionalTextEdits = null,
|
array $additionalTextEdits = null,
|
||||||
Command $command = null,
|
Command $command = null,
|
||||||
$data = null
|
$data = null
|
||||||
|
@ -131,7 +134,7 @@ class CompletionItem
|
||||||
$this->sortText = $sortText;
|
$this->sortText = $sortText;
|
||||||
$this->filterText = $filterText;
|
$this->filterText = $filterText;
|
||||||
$this->insertText = $insertText;
|
$this->insertText = $insertText;
|
||||||
$this->textEdit = $textEdit;
|
$this->range = $range;
|
||||||
$this->additionalTextEdits = $additionalTextEdits;
|
$this->additionalTextEdits = $additionalTextEdits;
|
||||||
$this->command = $command;
|
$this->command = $command;
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue