private void visitJsonPathLiteralsInFile(@NotNull InjectedLanguageManager injectedLanguageManager,
                                             @NotNull PsiFile hostFile,
                                             @Nullable PsiLanguageInjectionHost fromHost,
                                             @NotNull Consumer<String> pathNameConsumer) {
      PsiManager psiManager = hostFile.getManager();

      hostFile.accept(new PsiRecursiveElementVisitor() {
        @Override
        public void visitElement(@NotNull PsiElement element) {
          super.visitElement(element);

          if (element instanceof PsiLanguageInjectionHost
              && !psiManager.areElementsEquivalent(element, fromHost)) { // ignore file where we are asking for completion
            List<Pair<PsiElement, TextRange>> files = injectedLanguageManager.getInjectedPsiFiles(element);
            if (files == null) return;

            for (Pair<PsiElement, TextRange> rangePair : files) {
              if (rangePair.getFirst() instanceof JsonPathFile jsonPathFile) {
                visitJsonPathLiterals(jsonPathFile);
              }
            }
          }
        }

        private void visitJsonPathLiterals(JsonPathFile jsonPathFile) {
          jsonPathFile.accept(new JsonPathRecursiveElementVisitor() {
            @Override
            public void visitIdSegment(@NotNull JsonPathIdSegment o) {
              super.visitIdSegment(o);

              JsonPathId id = o.getId();
              if (!id.getTextRange().isEmpty()) {
                String literalText = getElementTextWithoutHostEscaping(id);
                if (!StringUtil.isEmptyOrSpaces(literalText)) {
                  pathNameConsumer.accept(literalText);
                }
              }
            }

            @Override
            public void visitExpressionSegment(@NotNull JsonPathExpressionSegment o) {
              super.visitExpressionSegment(o);

              JsonPathQuotedPathsList quotedPathsList = o.getQuotedPathsList();
              if (quotedPathsList == null) return;

              for (JsonPathStringLiteral stringLiteral : quotedPathsList.getStringLiteralList()) {
                String literalText = getElementTextWithoutHostEscaping(stringLiteral);
                if (literalText != null) {
                  String literalValue = StringUtil.unquoteString(literalText);
                  if (!StringUtil.isEmptyOrSpaces(literalValue)) {
                    pathNameConsumer.accept(literalValue);
                  }
                }
              }
            }

            private String getElementTextWithoutHostEscaping(@NotNull PsiElement element) {
              if (injectedLanguageManager.isInjectedFragment(element.getContainingFile())) {
                return injectedLanguageManager.getUnescapedText(element);
              }
              else {
                return element.getText();
              }
            }
          });
        }
      });
    }
private void visitJsonPathLiteralsInFile(@NotNull InjectedLanguageManager injectedLanguageManager,
                                             @NotNull PsiFile hostFile,
                                             @Nullable PsiLanguageInjectionHost fromHost,
                                             @NotNull Consumer<String> pathNameConsumer)