diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-02-21 10:45:27 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-02-21 10:45:27 +0100 |
commit | 004ac86f2a0e557599bf14440035e0e107cf5184 (patch) | |
tree | 0a04880729fbaa9435fa0810d7bce76f9e242f3d /integration/intellij/src | |
parent | 1dfb1a1d626d5a9474b9db95cec061ada4b626a4 (diff) |
Make compatible with older IntelliJ's
Diffstat (limited to 'integration/intellij/src')
-rw-r--r-- | integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Files.java | 5 | ||||
-rw-r--r-- | integration/intellij/src/main/java/ai/vespa/intellij/schema/utils/Path.java | 7 |
2 files changed, 9 insertions, 3 deletions
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<PsiFile> 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<String> 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() { |