private void processValueOrInsertedKey(@NotNull CompletionParameters params,
                                         @NotNull CompletionResultSet result,
                                         YamlMetaTypeProvider metaTypeProvider) {
    final YAMLScalar insertedScalar = (YAMLScalar)params.getPosition().getParent();

      /*
      trace("Position: " + getDebugInfo(position));
      trace("Position parent: " + getDebugInfo(insertedScalar));
      */

    if (insertedScalar.getTextRange().getStartOffset() < params.getOffset()) {
      // inserting scalar just after the end of `key:` transforms the key into scalar `key:IntelliJIdeaRulezzz`,
      // see valueMisplaced tree sample test
      int positionOffset = params.getOffset() - insertedScalar.getTextRange().getStartOffset();
      assert positionOffset > 0;
      String combinedText = insertedScalar.getText();
      if (positionOffset >= combinedText.length()) {
        //weird, just stop here since we don't understand how could it happen
        return;
      }
      if (combinedText.charAt(positionOffset - 1) == ':') {
        trace("Completion rejected: misplaced just after key position : " + YamlDebugUtil.getDebugInfo(params.getPosition()));
      }
    }

    YamlMetaTypeProvider.MetaTypeProxy meta = metaTypeProvider.getMetaTypeProxy(insertedScalar);
    trace("meta: " + meta);
    if (meta == null) {
      return;
    }
    YamlMetaType metaType = meta.getMetaType();

    if (insertedScalar.getParent() instanceof YAMLKeyValue) {
      PsiElement prevSibling = PsiTreeUtil.skipWhitespacesBackward(insertedScalar);
      if (isOfType(prevSibling, YAMLTokenTypes.COLON)) {
        prevSibling = PsiTreeUtil.skipWhitespacesBackward(prevSibling);
      }
      if (isOfType(prevSibling, YAMLTokenTypes.SCALAR_KEY)) {
        boolean hadScalarLookups = addValueCompletions(insertedScalar, metaType, result, Collections.emptyMap(), params);
        if (hadScalarLookups) {
          return;
        }
      }
    }

    if (insertedScalar.getParent() instanceof YAMLSequenceItem currentItem) {

      List<YAMLSequenceItem> siblingItems = Optional.ofNullable(currentItem.getParent())
        .filter(YAMLSequence.class::isInstance)
        .map(YAMLSequence.class::cast)
        .map(YAMLSequence::getItems)
        .orElse(Collections.emptyList());

      Map<String, YAMLScalar> siblingValues =
        siblingItems.stream()
          .filter(i -> i.getKeysValues().isEmpty()) // we only are interested in literal siblings
          .filter(i -> !currentItem.equals(i))
          .map(YAMLSequenceItem::getValue)
          .filter(Objects::nonNull)
          .filter(YAMLScalar.class::isInstance)
          .map(YAMLScalar.class::cast)
          .collect(Collectors.toMap(scalar -> scalar.getText().trim(), scalar -> scalar, (oldVal, newVal) -> newVal));

      boolean hadScalarInSequenceLookups = addValueCompletions(insertedScalar, metaType, result, siblingValues, params);
      if (hadScalarInSequenceLookups && !(metaType instanceof YamlAnyOfType)) {
        return;
      }
    }

    if (!(metaType instanceof YamlScalarType)) { // if it's certainly not a value
      addKeyCompletions(params, metaTypeProvider, meta, result, insertedScalar);
    }
  }
private void processValueOrInsertedKey(@NotNull CompletionParameters params,
                                         @NotNull CompletionResultSet result,
                                         YamlMetaTypeProvider metaTypeProvider)