diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java b/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java
index 4cee4a85b66c..ebe812819b61 100644
--- a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java
+++ b/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java
@@ -116,6 +116,20 @@ public class VfsUtilCore {
return FileUtil.isAncestor(ancestor, file, strict);
}
+ /**
+ * Gets relative path of file to root when it's possible
+ * This method is designed to be used for file descriptions (in trees, lists etc.)
+ * @param file the file
+ * @param root candidate to be parent file (Project base dir, any content roots etc.)
+ * @return relative path of {@code file} or full path if {@code root} is not actual ancestor of {@code file}
+ */
+ @Nullable
+ public static String getRelativeLocation(@Nullable VirtualFile file, @NotNull VirtualFile root) {
+ if (file == null) return null;
+ String path = getRelativePath(file, root);
+ return path != null ? path : file.getPresentableUrl();
+ }
+
@Nullable
public static String getRelativePath(@NotNull VirtualFile file, @NotNull VirtualFile ancestor) {
return getRelativePath(file, ancestor, VFS_SEPARATOR_CHAR);
diff --git a/platform/lang-impl/src/com/intellij/ide/bookmarks/BookmarkItem.java b/platform/lang-impl/src/com/intellij/ide/bookmarks/BookmarkItem.java
index fc493f7593d7..bec428739074 100644
--- a/platform/lang-impl/src/com/intellij/ide/bookmarks/BookmarkItem.java
+++ b/platform/lang-impl/src/com/intellij/ide/bookmarks/BookmarkItem.java
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.openapi.vcs.FileStatusManager;
+import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -76,6 +77,7 @@ public class BookmarkItem extends ItemWrapper implements Comparable