Skip to content

Commit 64cfc96

Browse files
SLVSCODE-756 handle replaced connections
1 parent 079d84b commit 64cfc96

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/main/java/org/sonarsource/sonarlint/ls/connected/ProjectBindingManager.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.net.URI;
2323
import java.nio.file.Path;
2424
import java.nio.file.Paths;
25+
import java.util.ArrayList;
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.Objects;
@@ -303,15 +304,25 @@ private void clearCaches(String connectionId) {
303304
fileBindingCache.entrySet().removeIf(e -> e.getValue().isPresent() && e.getValue().get().getConnectionId().equals(connectionId));
304305
}
305306

307+
private void handleDeletedConnections(@Nullable WorkspaceSettings oldValue, WorkspaceSettings newValue) {
308+
if (oldValue != null && !oldValue.getServerConnections().isEmpty()) {
309+
List<String> deletedConnectionIds = new ArrayList<>();
310+
// there used to be connections
311+
oldValue.getServerConnections().forEach((id, value) -> {
312+
if (!newValue.getServerConnections().containsKey(id)) {
313+
// connection was deleted
314+
deletedConnectionIds.add(id);
315+
}
316+
});
317+
if (!deletedConnectionIds.isEmpty()) {
318+
client.removeBindingsForDeletedConnections(deletedConnectionIds);
319+
}
320+
}
321+
}
322+
306323
@Override
307324
public void onChange(@CheckForNull WorkspaceSettings oldValue, WorkspaceSettings newValue) {
308-
if (oldValue != null && oldValue.getServerConnections().size() > newValue.getServerConnections().size()) {
309-
// connection(s) were deleted
310-
var deletedConnections = oldValue.getServerConnections().keySet().stream()
311-
.filter(id -> !newValue.getServerConnections().containsKey(id))
312-
.toList();
313-
client.removeBindingsForDeletedConnections(deletedConnections);
314-
}
325+
handleDeletedConnections(oldValue, newValue);
315326
newValue.getServerConnections().forEach((id, value) -> {
316327
if (oldValue == null) {
317328
// initial sync

0 commit comments

Comments
 (0)