PsiReference[] (@NotNull PsiElement element, String value, final String acceptedExtension) { final PsiDirectory directory = element.getContainingFile().getOriginalFile().getParent(); if (directory == null) return PsiReference.EMPTY_ARRAY; final boolean startsWithSlash = value.startsWith("/"); final FileReferenceSet fileReferenceSet = new FileReferenceSet(value, element, 1, null, directory.getVirtualFile().isCaseSensitive()) { @Override public @NotNull Collection<PsiFileSystemItem> getDefaultContexts() { if (startsWithSlash || !directory.isValid()) { return super.getDefaultContexts(); } return Collections.singletonList(directory); } @Override protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() { return item -> { if (item instanceof PsiDirectory) return true; final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(item); return virtualFile != null && acceptedExtension.equals(virtualFile.getExtension()); }; } }; if (startsWithSlash) { fileReferenceSet.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL); } return fileReferenceSet.getAllReferences(); }