completer = $completer; } /** * {@inheritdoc} */ public function getSuggestion(string $buffer, int $cursorPosition): ?SuggestionResult { $completions = $this->completer->getCompletions( new CompletionRequest($buffer, $cursorPosition, CompletionRequest::MODE_SUGGESTION) ); if (empty($completions)) { return null; } $completion = $completions[0]; $currentWord = CurrentWord::extract($buffer, $cursorPosition); if ($currentWord !== '' && \stripos($completion, $currentWord) === 0) { $suffix = \substr($completion, \strlen($currentWord)); } else { $suffix = $completion; } return SuggestionResult::forAppend( $suffix, SuggestionResult::SOURCE_CONTEXT_AWARE, $cursorPosition ); } /** * {@inheritdoc} */ public function getPriority(): int { // High priority, but lower than history (which should be 100) // We want context-aware to kick in when history doesn't match return 90; } }