@@ -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 );
0 commit comments