Skip to content

Commit 0ab9ace

Browse files
rawagnergeetikabatra
authored andcommitted
Remove LSP markers when LSP server is disabled. Fixes #82
Signed-off-by: Rastislav Wagner <[email protected]>
1 parent 2092ca9 commit 0ab9ace

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

plugins/com.redhat.fabric8analytics.lsp.eclipse.ui/src/com/redhat/fabric8analytics/lsp/eclipse/ui/Fabric8AnalyticsStreamConnectionProvider.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@
1919
import java.io.OutputStream;
2020
import java.nio.file.Files;
2121
import java.nio.file.Paths;
22+
import java.util.ArrayList;
2223
import java.util.Arrays;
2324
import java.util.List;
2425

2526
import org.apache.commons.io.IOUtils;
27+
import org.eclipse.core.resources.IMarker;
28+
import org.eclipse.core.resources.IProject;
29+
import org.eclipse.core.resources.IResource;
30+
import org.eclipse.core.resources.IWorkspaceRoot;
31+
import org.eclipse.core.resources.ResourcesPlugin;
32+
import org.eclipse.core.runtime.CoreException;
2633
import org.eclipse.core.runtime.FileLocator;
2734
import org.eclipse.core.runtime.NullProgressMonitor;
2835
import org.eclipse.core.runtime.Platform;
@@ -43,6 +50,10 @@
4350
public class Fabric8AnalyticsStreamConnectionProvider extends ProcessStreamConnectionProvider
4451
implements StreamConnectionProvider {
4552

53+
public static final String SERVER_ID = "com.redhat.fabric8analytics.lsp.eclipse.server";
54+
55+
private static final String LSP_SERVER_ID_ATTRIBUTE = "languageServerId";
56+
4657
public static final String RECOMMENDER_API_TOKEN = "RECOMMENDER_API_TOKEN";
4758

4859
public static final String RECOMMENDER_API_URL = "RECOMMENDER_API_URL";
@@ -104,8 +115,32 @@ public void start() throws IOException {
104115
@Override
105116
public void stop() {
106117
super.stop();
118+
removeMarkers();
107119
Fabric8AnalysisLSUIActivator.getDefault().logInfo("The Fabric8 analyses server is stopped");
108120
}
121+
122+
private void removeMarkers() {
123+
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
124+
IProject[] projects = workspaceRoot.getProjects();
125+
for (IProject project : projects) {
126+
try {
127+
List<IMarker> markersToDelete = new ArrayList<>();
128+
IMarker[] markers = project.findMarkers(null, true, IResource.DEPTH_INFINITE);
129+
for (IMarker marker : markers) {
130+
if (marker.exists()) {
131+
Object serverId = marker.getAttribute(LSP_SERVER_ID_ATTRIBUTE);
132+
if (SERVER_ID.equals(serverId)) {
133+
markersToDelete.add(marker);
134+
}
135+
}
136+
}
137+
ResourcesPlugin.getWorkspace()
138+
.deleteMarkers(markersToDelete.toArray(new IMarker[markersToDelete.size()]));
139+
} catch (CoreException e) {
140+
Fabric8AnalysisLSUIActivator.getDefault().logError("Error occured while removing LSP markers", e);
141+
}
142+
}
143+
}
109144

110145
@Override
111146
protected ProcessBuilder createProcessBuilder() {

0 commit comments

Comments
 (0)