27
27
import org .eclipse .jdt .ls .core .internal .JavaClientConnection ;
28
28
import org .eclipse .jdt .ls .core .internal .JavaLanguageServerPlugin ;
29
29
import org .eclipse .jdt .ls .core .internal .SharedASTProvider ;
30
+ import org .eclipse .jdt .ls .core .internal .managers .ProjectsManager ;
31
+ import org .eclipse .jdt .ls .core .internal .managers .ProjectsManager .CHANGE_TYPE ;
30
32
import org .eclipse .jdt .ls .core .internal .preferences .PreferenceManager ;
31
33
import org .eclipse .jdt .ls .core .internal .preferences .Preferences ;
32
34
import org .eclipse .jdt .ls .core .internal .preferences .Preferences .Severity ;
@@ -49,6 +51,7 @@ public class DocumentLifeCycleHandler {
49
51
50
52
private JavaClientConnection connection ;
51
53
private PreferenceManager preferenceManager ;
54
+ private ProjectsManager projectsManager ;
52
55
53
56
54
57
void didClose (DidCloseTextDocumentParams params ){
@@ -91,11 +94,22 @@ public void run(IProgressMonitor monitor) throws CoreException {
91
94
}
92
95
93
96
void didSave (DidSaveTextDocumentParams params ){
97
+ try {
98
+ ResourcesPlugin .getWorkspace ().run (new IWorkspaceRunnable () {
99
+ @ Override
100
+ public void run (IProgressMonitor monitor ) throws CoreException {
101
+ handleSaved (params );
102
+ }
103
+ }, new NullProgressMonitor ());
104
+ } catch (CoreException e ) {
105
+ JavaLanguageServerPlugin .logException ("Handle document save " , e );
106
+ }
94
107
}
95
108
96
- public DocumentLifeCycleHandler (JavaClientConnection connection , PreferenceManager preferenceManager ) {
109
+ public DocumentLifeCycleHandler (JavaClientConnection connection , PreferenceManager preferenceManager , ProjectsManager projectsManager ) {
97
110
this .connection = connection ;
98
111
this .preferenceManager = preferenceManager ;
112
+ this .projectsManager = projectsManager ;
99
113
}
100
114
101
115
private void handleOpen (DidOpenTextDocumentParams params ) {
@@ -192,4 +206,14 @@ private void handleClosed(DidCloseTextDocumentParams params) {
192
206
} catch (CoreException e ) {
193
207
}
194
208
}
209
+
210
+ private void handleSaved (DidSaveTextDocumentParams params ) {
211
+ JavaLanguageServerPlugin .logInfo ("DocumentLifeCycleHandler.handleSaved" );
212
+ String uri = params .getTextDocument ().getUri ();
213
+ ICompilationUnit unit = JDTUtils .resolveCompilationUnit (uri );
214
+ if (unit != null && unit .isWorkingCopy ()) {
215
+ projectsManager .fileChanged (uri , CHANGE_TYPE .CHANGED );
216
+ }
217
+ }
218
+
195
219
}
0 commit comments