Skip to content

Commit

Permalink
Merge pull request #67 from RabotaRu/v3.12.1
Browse files Browse the repository at this point in the history
v3.12.1
  • Loading branch information
rpiontik authored Feb 14, 2024
2 parents a217472 + a32dabc commit 1d6ed57
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 26 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
84 changes: 65 additions & 19 deletions src/main/java/org/dochub/idea/arch/indexing/CacheBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -23,9 +34,9 @@ private static boolean isFileExists(Project project, String filename) {

private static Map<String, String> parseEnvFile(String filename) {
Map<String, String> 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);
}
Expand All @@ -42,7 +53,7 @@ public static class SectionData {
public Map<String, ArrayList> ids = new HashMap();
}

private static void manifestMerge(Map<String, SectionData> context, DocHubIndexData data, VirtualFile source) {
private static void manifestMerge(Map<String, SectionData> context, DocHubIndexData data, VirtualFile source) {
for (String sectionKey : data.keySet()) {

if (sectionKey.equals("imports")) continue;
Expand Down Expand Up @@ -75,29 +86,63 @@ private static void manifestMerge(Map<String, SectionData> context, DocHubIndexD
}
}

private static Optional<PsiFile> getPsiFile(VirtualFile vFile, Project project) {

return Optional.ofNullable(vFile)
.map(e -> PsiManager
.getInstance(project)
.findFile(e));
}

private static Map<Integer, DocHubIndexData> getFileData(PsiFile psi, Project project, Map<String, SectionData> context) {

return FileBasedIndex
.getInstance()
.getFileData(DocHubIndex.INDEX_ID, psi.getVirtualFile(), project);
}


private static void parseYamlManifest(Project project, String path, Map<String, SectionData> 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<String> queue = new LinkedList<>();
List<String> done = new ArrayList<>();

while (vFile != null) {

Optional<PsiFile> psiFile = getPsiFile(vFile, project);

for (Object key : index.keySet()) {
DocHubIndexData data = (DocHubIndexData) index.get(key);
if (psiFile.isPresent()) {

Map<Integer, DocHubIndexData> 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<String> 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;
}
}
}
Expand All @@ -107,8 +152,9 @@ private static String getFromEnv(Project project) {
for (String name : names) {
if (isFileExists(project, name)) {
Map<String, String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -17,7 +18,7 @@ public final class DocHubIndexData extends HashMap<String, DocHubIndexData.Secti
public class Section {
public ArrayList<String> locations = new ArrayList();
public ArrayList<String> ids = new ArrayList();
public ArrayList<String> imports = new ArrayList<>();
public List<String> imports = new ArrayList<>();
public boolean isEmpty() {
return (locations.size() + ids.size() + imports.size()) == 0;
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/dochub/idea/arch/tools/Navigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@

<fileBasedIndex implementation="org.dochub.idea.arch.indexing.DocHubIndex"/>

<!-- <stubIndex implementation=" index.stubs.org.dochub.idea.arch.JSONataMethodNameIndex"/>-->

</extensions>

<extensions defaultExtensionNs="JavaScript">
Expand Down

0 comments on commit 1d6ed57

Please sign in to comment.