From 2e7aef08eda044dc95fd970218c852ac3c7e6eb9 Mon Sep 17 00:00:00 2001 From: Temnyakov Nikolay Date: Tue, 16 Jan 2024 20:09:34 +0300 Subject: [PATCH 1/2] fix error stackoverflow --- gradle.properties | 2 +- .../idea/arch/indexing/CacheBuilder.java | 84 ++++++++++++++----- .../idea/arch/indexing/DocHubIndexData.java | 3 +- .../dochub/idea/arch/tools/Navigation.java | 9 +- src/main/resources/META-INF/plugin.xml | 2 - 5 files changed, 74 insertions(+), 26 deletions(-) diff --git a/gradle.properties b/gradle.properties index 74ffc66..07db86d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project Properties group=org.dochub.idea -version=3.11.0 +version=3.12.0 # Supported build number ranges and IntelliJ Platform versions pluginSinceBuild=231 diff --git a/src/main/java/org/dochub/idea/arch/indexing/CacheBuilder.java b/src/main/java/org/dochub/idea/arch/indexing/CacheBuilder.java index ed8ab9c..64bb591 100644 --- a/src/main/java/org/dochub/idea/arch/indexing/CacheBuilder.java +++ b/src/main/java/org/dochub/idea/arch/indexing/CacheBuilder.java @@ -13,8 +13,19 @@ import org.dochub.idea.arch.utils.VirtualFileSystemUtils; import org.jetbrains.annotations.Nullable; -import java.io.*; -import java.util.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Queue; public class CacheBuilder { private static boolean isFileExists(Project project, String filename) { @@ -23,9 +34,9 @@ private static boolean isFileExists(Project project, String filename) { private static Map parseEnvFile(String filename) { Map result = new HashMap<>(); - try( BufferedReader br = new BufferedReader( new FileReader( filename))) { + try (BufferedReader br = new BufferedReader(new FileReader(filename))) { String line; - while(( line = br.readLine()) != null ) { + while ((line = br.readLine()) != null) { String[] lineStruct = line.split("\\="); result.put(lineStruct[0], lineStruct.length > 1 ? lineStruct[1] : null); } @@ -42,7 +53,7 @@ public static class SectionData { public Map ids = new HashMap(); } - private static void manifestMerge(Map context, DocHubIndexData data, VirtualFile source) { + private static void manifestMerge(Map context, DocHubIndexData data, VirtualFile source) { for (String sectionKey : data.keySet()) { if (sectionKey.equals("imports")) continue; @@ -75,29 +86,63 @@ private static void manifestMerge(Map context, DocHubIndexD } } + private static Optional getPsiFile(VirtualFile vFile, Project project) { + + return Optional.ofNullable(vFile) + .map(e -> PsiManager + .getInstance(project) + .findFile(e)); + } + + private static Map getFileData(PsiFile psi, Project project, Map context) { + + return FileBasedIndex + .getInstance() + .getFileData(DocHubIndex.INDEX_ID, psi.getVirtualFile(), project); + } + + private static void parseYamlManifest(Project project, String path, Map context) { + VirtualFile vFile = VirtualFileSystemUtils.findFile(path, project); - if (vFile != null) { - PsiFile targetFile = PsiManager.getInstance(project).findFile(vFile); - if (targetFile != null) { - Map index = FileBasedIndex.getInstance().getFileData(DocHubIndex.INDEX_ID, vFile, project); + Queue queue = new LinkedList<>(); + List done = new ArrayList<>(); + + while (vFile != null) { + + Optional psiFile = getPsiFile(vFile, project); - for (Object key : index.keySet()) { - DocHubIndexData data = (DocHubIndexData) index.get(key); + if (psiFile.isPresent()) { + + Map index = getFileData(psiFile.get(), project, context); + + for (Integer key : index.keySet()) { + DocHubIndexData data = index.get(key); DocHubIndexData.Section imports = data.get("imports"); + if (imports != null) { - for (int i = 0; i < imports.imports.size(); i ++) { - String importPath = - (vFile.getParent().getPath() + "/" + imports.imports.get(i)) - .substring(project.getBasePath().length()); - parseYamlManifest(project, importPath, context); - } + + VirtualFile finalVFile = vFile; + List list = imports.imports + .stream() + .map(anImport -> (finalVFile.getParent().getPath() + "/" + anImport).substring(Objects.requireNonNull(project.getBasePath()).length())) + .toList(); + + list.forEach(queue::offer); } manifestMerge(context, data, vFile); } + + String importPath = queue.poll(); + + while (done.contains(importPath)) { + importPath = queue.poll(); + } + done.add(importPath); + vFile = importPath != null ? VirtualFileSystemUtils.findFile(importPath, project) : null; } } } @@ -107,8 +152,9 @@ private static String getFromEnv(Project project) { for (String name : names) { if (isFileExists(project, name)) { Map env = parseEnvFile(project.getBasePath() + "/" + name); - return "public/" + env.get("VUE_APP_DOCHUB_ROOT_MANIFEST"); - }; + return "public/" + env.get("VUE_APP_DOCHUB_ROOT_MANIFEST"); + } + ; } return null; } diff --git a/src/main/java/org/dochub/idea/arch/indexing/DocHubIndexData.java b/src/main/java/org/dochub/idea/arch/indexing/DocHubIndexData.java index 96de2fd..73968e9 100644 --- a/src/main/java/org/dochub/idea/arch/indexing/DocHubIndexData.java +++ b/src/main/java/org/dochub/idea/arch/indexing/DocHubIndexData.java @@ -9,6 +9,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -17,7 +18,7 @@ public final class DocHubIndexData extends HashMap locations = new ArrayList(); public ArrayList ids = new ArrayList(); - public ArrayList imports = new ArrayList<>(); + public List imports = new ArrayList<>(); public boolean isEmpty() { return (locations.size() + ids.size() + imports.size()) == 0; } diff --git a/src/main/java/org/dochub/idea/arch/tools/Navigation.java b/src/main/java/org/dochub/idea/arch/tools/Navigation.java index 7dd369f..6351465 100644 --- a/src/main/java/org/dochub/idea/arch/tools/Navigation.java +++ b/src/main/java/org/dochub/idea/arch/tools/Navigation.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Map; +import java.util.Objects; import static org.dochub.idea.arch.tools.Consts.ROOT_SOURCE_PATH; import static org.dochub.idea.arch.tools.Consts.ROOT_SOURCE_URI; @@ -50,7 +51,7 @@ public VirtualFile getVFile(String uri) { source = CacheBuilder.getRootManifestName(project); } else if (uri.startsWith(ROOT_SOURCE_PATH)) { source = uri.substring(ROOT_SOURCE_PATH.length()); - } else if (uri.startsWith(project.getBasePath())) { + } else if (uri.startsWith(Objects.requireNonNull(project.getBasePath()))) { source = uri.substring(project.getBasePath().length()); }else source = uri; @@ -97,14 +98,16 @@ private void gotoByID(String uri, String entity, String id) { private void gotoBySource(String uri) { VirtualFile vFile = getVFile(uri); if (vFile != null) - gotoPsiElement(PsiManager.getInstance(project).findFile(vFile)); + gotoPsiElement(Objects.requireNonNull(PsiManager.getInstance(project).findFile(vFile))); } private void gotoByPosition(String uri, int start) { VirtualFile vFile = getVFile(uri); if (vFile != null) { PsiFile targetFile = PsiManager.getInstance(project).findFile(vFile); - gotoPsiElement(targetFile.findElementAt(start)); + if(targetFile != null) { + gotoPsiElement(Objects.requireNonNull(targetFile.findElementAt(start))); + } } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 8184b6e..d5381e3 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -102,8 +102,6 @@ - - From a32dabcc66a924b77bc5037eff387b81ade4d447 Mon Sep 17 00:00:00 2001 From: rpiontik Date: Wed, 17 Jan 2024 15:22:13 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 07db86d..501b5d0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # Project Properties group=org.dochub.idea -version=3.12.0 +version=3.12.1 # Supported build number ranges and IntelliJ Platform versions pluginSinceBuild=231