Skip to content

Commit 6b5e5d5

Browse files
committed
make enrichDocumentInfo private and add a clear comment
1 parent 81d01e1 commit 6b5e5d5

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

java/src/main/java/org/digma/intellij/plugin/idea/psi/java/JavaCodeObjectDiscovery.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public class JavaCodeObjectDiscovery {
3737
if (documentInfo == null){
3838
documentInfo = buildDocumentInfoImpl(project,psiJavaFile);
3939
}
40+
/*
41+
why do we need a separate enrichDocumentInfo stage?
42+
when building the DocumentInfo index there is no guarantee that reference resolving will work, it depends on the
43+
state of intellij index. so span discovery may not work during indexing.
44+
JavaDocumentInfoIndex does not even try to run span discovery, it only does method discovery.
45+
so when we take the DocumentInfo from the index we assume that it doesn't contain span discovery and endpoint discovery.
46+
enrichDocumentInfo will run span discovery and endpoint discovery and add it to the methods of DocumentInfo.
47+
buildDocumentInfo is always called in smart mode and so span discovery and endpoint discovery should work.
48+
49+
*/
4050
enrichDocumentInfo(project,documentInfo,psiJavaFile,micronautFramework,jaxrsFramework,grpcFramework);
4151
return documentInfo;
4252

@@ -96,13 +106,18 @@ private static void collectMethods(@NotNull String fileUri, @NotNull PsiClass[]
96106
}
97107

98108

99-
static void enrichDocumentInfo(Project project, @NotNull DocumentInfo documentInfo, @NotNull PsiFile psiFile, @NotNull MicronautFramework micronautFramework, @NotNull JaxrsFramework jaxrsFramework, @NotNull GrpcFramework grpcFramework) {
100-
/*
101-
This method is called after loading the DocumentInfo from DocumentInfoIndex, and it is meant to
102-
enrich the DocumentInfo with discovery that can not be done in file based index or dumb mode.
103-
for example span discovery does not work in dumb mode, it must be done in smart mode.
104-
This method must be called in smart mode inside s ReadAction or UI thread.
109+
private static void enrichDocumentInfo(Project project, @NotNull DocumentInfo documentInfo, @NotNull PsiFile psiFile, @NotNull MicronautFramework micronautFramework, @NotNull JaxrsFramework jaxrsFramework, @NotNull GrpcFramework grpcFramework) {
110+
/*
111+
need to make sure that spans and endpoints are cleared here.
112+
why?
113+
This DocumentInfo may have already been enriched before,when it was enriched it may already contain span and endpoints.
114+
todo: not sure its necessary to remove because it seems that the index returns a copy, so when adding span and endpoint discovery
115+
it is not saved to the index and the next time we take a DocumentInfo from the index it will not contain span and endpoint discovery.
105116
*/
117+
documentInfo.getMethods().forEach((id, methodInfo) -> {
118+
methodInfo.getSpans().clear();
119+
methodInfo.getEndpoints().clear();
120+
});
106121

107122
spanDiscovery(project, psiFile, documentInfo);
108123
endpointDiscovery(psiFile, documentInfo, micronautFramework, jaxrsFramework, grpcFramework);

model/src/main/kotlin/org/digma/intellij/plugin/model/discovery/MethodInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data class MethodInfo(
1313
val spans: List<SpanInfo>,
1414
) : CodeObjectInfo {
1515

16-
private val endpoints: MutableList<EndpointInfo> = mutableListOf()
16+
val endpoints: MutableList<EndpointInfo> = mutableListOf()
1717

1818

1919
/*

0 commit comments

Comments
 (0)