|
44 | 44 | import org.eclipse.lsp4j.Command;
|
45 | 45 | import org.eclipse.lsp4j.Diagnostic;
|
46 | 46 | import org.eclipse.lsp4j.DiagnosticSeverity;
|
| 47 | +import org.eclipse.lsp4j.DidChangeWatchedFilesParams; |
47 | 48 | import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams;
|
| 49 | +import org.eclipse.lsp4j.FileChangeType; |
| 50 | +import org.eclipse.lsp4j.FileEvent; |
48 | 51 | import org.eclipse.lsp4j.MessageParams;
|
49 | 52 | import org.eclipse.lsp4j.MessageType;
|
50 | 53 | import org.eclipse.lsp4j.TextDocumentIdentifier;
|
|
66 | 69 | import org.sonarsource.sonarlint.core.rpc.protocol.backend.binding.GetBindingSuggestionParams;
|
67 | 70 | import org.sonarsource.sonarlint.core.rpc.protocol.backend.binding.GetSharedConnectedModeConfigFileParams;
|
68 | 71 | import org.sonarsource.sonarlint.core.rpc.protocol.backend.hotspot.HotspotStatus;
|
| 72 | +import org.sonarsource.sonarlint.core.rpc.protocol.client.connection.GetConnectionSuggestionsParams; |
69 | 73 | import org.sonarsource.sonarlint.core.serverapi.proto.sonarqube.ws.Common;
|
70 | 74 | import org.sonarsource.sonarlint.core.serverapi.proto.sonarqube.ws.Components;
|
71 | 75 | import org.sonarsource.sonarlint.core.serverapi.proto.sonarqube.ws.Hotspots;
|
@@ -106,6 +110,7 @@ class ConnectedModeMediumTests extends AbstractLanguageServerMediumTests {
|
106 | 110 | private static final String PROJECT_NAME1 = "Project One";
|
107 | 111 | private static final String PROJECT_KEY2 = "project:key2";
|
108 | 112 | private static final String PROJECT_NAME2 = "Project Two";
|
| 113 | + private static final String ORGANIZATION_KEY = "myOrganization"; |
109 | 114 | private static final long CURRENT_TIME = System.currentTimeMillis();
|
110 | 115 | private static Path omnisharpDir;
|
111 | 116 | private static Path folder1BaseDir;
|
@@ -1476,4 +1481,41 @@ void should_allow_client_to_explicitly_ask_for_binding_suggestions() {
|
1476 | 1481 | assertThat(result.getSuggestions()).hasSize(1);
|
1477 | 1482 | });
|
1478 | 1483 | }
|
| 1484 | + |
| 1485 | + @Test |
| 1486 | + void should_allow_client_to_explicitly_ask_for_connection_suggestions() { |
| 1487 | + // add config scope |
| 1488 | + var workspaceUri = folder1BaseDir.resolve("foo-bar").toUri().toString(); |
| 1489 | + var workspaceFolder = new WorkspaceFolder(workspaceUri, "foo-bar"); |
| 1490 | + client.folderSettings = new HashMap<>(); |
| 1491 | + client.folderSettings.put(workspaceUri, new HashMap<>()); |
| 1492 | + lsProxy.getWorkspaceService().didChangeWorkspaceFolders(new DidChangeWorkspaceFoldersParams( |
| 1493 | + new WorkspaceFoldersChangeEvent(List.of(workspaceFolder), Collections.emptyList()))); |
| 1494 | + |
| 1495 | + foldersToRemove.add(workspaceUri); |
| 1496 | + |
| 1497 | + // create clue file inside |
| 1498 | + var clueFileName = "connectedMode.json"; |
| 1499 | + var clueFileContent = String.format(""" |
| 1500 | + { |
| 1501 | + "sonarCloudOrganization": "%s", |
| 1502 | + "projectKey": "%s", |
| 1503 | + "region": "EU" |
| 1504 | + }""", ORGANIZATION_KEY, PROJECT_KEY); |
| 1505 | + |
| 1506 | + // Create file for SLCORE |
| 1507 | + lsProxy.getWorkspaceService().didChangeWatchedFiles(new DidChangeWatchedFilesParams(List.of(new FileEvent(folder1BaseDir.resolve("foo-bar").resolve(".sonarlint").resolve(clueFileName).toFile().toURI().toString(), FileChangeType.Created)))); |
| 1508 | + // send updated file content to SLCORE |
| 1509 | + didOpen(folder1BaseDir.resolve("foo-bar").resolve(".sonarlint").resolve(clueFileName).toFile().toURI().toString(), clueFileName, clueFileContent); |
| 1510 | + |
| 1511 | + awaitUntilAsserted(() -> { |
| 1512 | + var result = lsProxy.getConnectionSuggestions(new GetConnectionSuggestionsParams(workspaceUri)).get(); |
| 1513 | + var connectionSuggestions = result.getConnectionSuggestions(); |
| 1514 | + assertThat(connectionSuggestions).isNotNull(); |
| 1515 | + assertThat(connectionSuggestions).isNotEmpty(); |
| 1516 | + assertTrue(connectionSuggestions.get(0).getConnectionSuggestion().isRight()); |
| 1517 | + assertThat(connectionSuggestions.get(0).getConnectionSuggestion().getRight().getOrganization()).isEqualTo(ORGANIZATION_KEY); |
| 1518 | + assertThat(connectionSuggestions.get(0).getConnectionSuggestion().getRight().getProjectKey()).isEqualTo(PROJECT_KEY); |
| 1519 | + }); |
| 1520 | + } |
1479 | 1521 | }
|
0 commit comments