From 004ac86f2a0e557599bf14440035e0e107cf5184 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Mon, 21 Feb 2022 10:45:27 +0100 Subject: Make compatible with older IntelliJ's --- .../src/main/java/ai/vespa/intellij/schema/utils/Files.java | 5 ++--- .../src/main/java/ai/vespa/intellij/schema/utils/Path.java | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'integration/intellij/src') diff --git a/integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Files.java b/integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Files.java index 0f1fece1439..3f6d6b2d8d8 100644 --- a/integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Files.java +++ b/integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Files.java @@ -24,10 +24,9 @@ public class Files { * @return the file or empty if not found */ public static Optional open(Path file, Project project) { - // Apparently there s no API for getting a file by path. + // Apparently there's no API for getting a file by path. // This method returns all files having a particular name. - for (VirtualFile candidate : FilenameIndex.getVirtualFilesByName(file.last(), - GlobalSearchScope.allScope(project))) { + for (VirtualFile candidate : FilenameIndex.getAllFilesByExt(project, file.extension())) { // Not safe, but (at least in tests) there doesn't appear to be a way to get the workspace root (/src) if (candidate.getPath().endsWith(file.getRelative())) return Optional.of(PsiManager.getInstance(project).findFile(candidate)); diff --git a/integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Path.java b/integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Path.java index 07b2e7f3adf..ce889c24fea 100644 --- a/integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Path.java +++ b/integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Path.java @@ -154,6 +154,13 @@ public final class Path { /** Returns an immutable list of the elements of this path in order */ public List elements() { return elements; } + /** Returns the extension of this file name, or an empty string if none. */ + public String extension() { + int dotIndex = last().lastIndexOf('.'); + if (dotIndex < 0) return ""; + return last().substring(dotIndex + 1); + } + /** Returns this as a string */ @Override public String toString() { -- cgit v1.2.3