44import com .intellij .openapi .diagnostic .Logger ;
55import com .intellij .openapi .project .Project ;
66import org .apache .commons .lang3 .time .StopWatch ;
7- import org .digma .intellij .plugin .analytics .AnalyticsService ;
8- import org .digma .intellij .plugin .analytics .BackendConnectionMonitor ;
7+ import org .digma .intellij .plugin .analytics .BackendConnectionUtil ;
98import org .digma .intellij .plugin .common .Backgroundable ;
109import org .digma .intellij .plugin .document .DocumentInfoContainer ;
1110import org .digma .intellij .plugin .document .DocumentInfoService ;
1211import org .digma .intellij .plugin .log .Log ;
1312import org .digma .intellij .plugin .model .discovery .MethodInfo ;
1413import org .digma .intellij .plugin .model .discovery .MethodUnderCaret ;
1514import org .digma .intellij .plugin .ui .CaretContextService ;
16- import org .digma .intellij .plugin .ui .model .environment .EnvironmentsSupplier ;
1715import org .digma .intellij .plugin .ui .service .ErrorsViewService ;
1816import org .digma .intellij .plugin .ui .service .InsightsViewService ;
19- import org .digma .intellij .plugin .ui .service .SummaryViewService ;
2017
2118import java .util .ArrayList ;
2219
@@ -32,10 +29,8 @@ public class EditorInteractionService implements CaretContextService, Disposable
3229
3330 private final InsightsViewService insightsViewService ;
3431 private final ErrorsViewService errorsViewService ;
35- private final SummaryViewService summaryViewService ;
3632 private final DocumentInfoService documentInfoService ;
37- private final EnvironmentsSupplier environmentsSupplier ;
38- private final BackendConnectionMonitor backendConnectionMonitor ;
33+ private final BackendConnectionUtil backendConnectionUtil ;
3934
4035
4136 /*
@@ -47,61 +42,28 @@ public EditorInteractionService(Project project) {
4742 this .project = project ;
4843 insightsViewService = project .getService (InsightsViewService .class );
4944 errorsViewService = project .getService (ErrorsViewService .class );
50- summaryViewService = project .getService (SummaryViewService .class );
5145 documentInfoService = project .getService (DocumentInfoService .class );
52- backendConnectionMonitor = project .getService (BackendConnectionMonitor .class );
53- var analyticsService = project .getService (AnalyticsService .class );
54- environmentsSupplier = analyticsService .getEnvironment ();
46+ backendConnectionUtil = project .getService (BackendConnectionUtil .class );
5547 }
5648
5749 public static CaretContextService getInstance (Project project ) {
5850 return project .getService (CaretContextService .class );
5951 }
6052
61-
62- boolean hadConnectionError = false ;
63-
64- private boolean testConnectionToBackend () {
65-
66- //refresh will run in the background.
67- //if there is currently no connection, but connection will recover during this refresh call then
68- //not sure backendConnectionMonitor will catch it so the contextChange flow may still block.
69- //the next contextChange will pass.
70- //but anyway if the connection will recover an environmentChanged event will fire and that should have some kind
71- //of hook to intentionally cause a contextChange event.
72- environmentsSupplier .refresh ();
73-
74- //hadConnectionError helps to call contextEmptyNoConnection() only once on the first time that a connection error is discovered.
75- //and there is no need to empty again or change the models and ui until the connection is back.
76- if (backendConnectionMonitor .isConnectionError ()) {
77- if (hadConnectionError ) {
78- Log .log (logger ::debug , "Not Executing contextChanged because there is no connection to backend service" );
79- return false ;
80- }
81- contextEmptyNoConnection ();
82- hadConnectionError = true ;
83- return false ;
84- } else {
85- hadConnectionError = false ;
86- return true ;
87- }
88- }
89-
90-
9153 @ Override
9254 public void contextChanged (MethodUnderCaret methodUnderCaret ) {
9355
9456 Log .log (logger ::debug , "contextChanged called for '{}'" , methodUnderCaret );
9557
96- if (project .isDisposed ()){
58+ if (project .isDisposed ()) {
9759 Log .log (logger ::debug , "project is disposed in contextChanged for '{}'" , methodUnderCaret .getId ());
9860 return ;
9961 }
10062
10163 //There is no need to execute the contextChanged flow if there is no connection to the backend.
10264 // so testConnectionToBackend will detect a backend connection error , call contextEmptyNoConnection once
10365 // to clean the views, and will return. and will keep blocking until the connection is regained.
104- if (!testConnectionToBackend ()) {
66+ if (!backendConnectionUtil . testConnectionToBackend ()) {
10567 Log .log (logger ::debug , "No connection to backend, not executing contextChanged for '{}'" , methodUnderCaret .getId ());
10668 return ;
10769 }
@@ -120,7 +82,6 @@ public void contextChanged(MethodUnderCaret methodUnderCaret) {
12082 }
12183
12284
123-
12485 private void contextChangedImpl (MethodUnderCaret methodUnderCaret ) {
12586
12687 /*
@@ -130,28 +91,28 @@ private void contextChangedImpl(MethodUnderCaret methodUnderCaret) {
13091
13192 Log .log (logger ::debug , "contextChangedImpl invoked for '{}'" , methodUnderCaret );
13293
133- if (!methodUnderCaret .isSupportedFile ()){
94+ if (!methodUnderCaret .isSupportedFile ()) {
13495 Log .log (logger ::debug , "methodUnderCaret is non supported file {}. " , methodUnderCaret );
13596 contextEmptyNonSupportedFile (methodUnderCaret .getFileUri ());
136- }else if (methodUnderCaret .getId ().isBlank ()) {
97+ } else if (methodUnderCaret .getId ().isBlank ()) {
13798 Log .log (logger ::debug , "No id in methodUnderCaret,trying fileUri {}. " , methodUnderCaret );
13899 //if no id then try to show a preview for the document
139- if (methodUnderCaret .getFileUri ().isBlank ()){
100+ if (methodUnderCaret .getFileUri ().isBlank ()) {
140101 Log .log (logger ::debug , "No id and no fileUri in methodUnderCaret,clearing context {}. " , methodUnderCaret );
141102 contextEmpty ();
142- }else {
103+ } else {
143104 Log .log (logger ::debug , "Showing document preview for {}. " , methodUnderCaret );
144- DocumentInfoContainer documentInfoContainer = documentInfoService .getDocumentInfo (methodUnderCaret );
145- if (documentInfoContainer == null ){
105+ DocumentInfoContainer documentInfoContainer = documentInfoService .getDocumentInfo (methodUnderCaret );
106+ if (documentInfoContainer == null ) {
146107 Log .log (logger ::debug , "Could not find document info for {}, Showing empty preview." , methodUnderCaret );
147- }else {
148- Log .log (logger ::debug , "Found document info for {}. document: {}" , methodUnderCaret ,documentInfoContainer .getPsiFile ());
108+ } else {
109+ Log .log (logger ::debug , "Found document info for {}. document: {}" , methodUnderCaret , documentInfoContainer .getPsiFile ());
149110 }
150111
151- insightsViewService .showDocumentPreviewList (documentInfoContainer ,methodUnderCaret .getFileUri ());
152- errorsViewService .showDocumentPreviewList (documentInfoContainer ,methodUnderCaret .getFileUri ());
112+ insightsViewService .showDocumentPreviewList (documentInfoContainer , methodUnderCaret .getFileUri ());
113+ errorsViewService .showDocumentPreviewList (documentInfoContainer , methodUnderCaret .getFileUri ());
153114 }
154- }else {
115+ } else {
155116 MethodInfo methodInfo = documentInfoService .getMethodInfo (methodUnderCaret );
156117 if (methodInfo == null ) {
157118 Log .log (logger ::warn , "Could not find MethodInfo for MethodUnderCaret {}. " , methodUnderCaret );
@@ -186,13 +147,6 @@ public void contextEmpty() {
186147 errorsViewService .empty ();
187148 }
188149
189- private void contextEmptyNoConnection () {
190- Log .log (logger ::debug , "contextEmptyNoConnection called" );
191- insightsViewService .empty ();
192- errorsViewService .empty ();
193- summaryViewService .empty ();
194- }
195-
196150 @ Override
197151 public void dispose () {
198152 Log .log (logger ::debug , "disposing.." );
0 commit comments