Skip to content

Commit

Permalink
SLLS-276 update labels for SonarQube for VS Code
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Nov 19, 2024
1 parent 64ba9cb commit 8837e9a
Show file tree
Hide file tree
Showing 18 changed files with 323 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public class CommandManager {
// Client side
static final String SONARLINT_DEACTIVATE_RULE_COMMAND = "SonarLint.DeactivateRule";
static final String RESOLVE_ISSUE = "SonarLint.ResolveIssue";
static final String SONARLINT_ACTION_PREFIX = "SonarLint: ";
static final String SONARLINT_ACTION_PREFIX = "SonarQube: ";

private final SonarLintExtendedLanguageClient client;
private final SettingsManager settingsManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class DiagnosticPublisher {

static final String SONARLINT_SOURCE = "sonarlint";
static final String SONARLINT_SOURCE = "sonarqube";
static final String REMOTE_SOURCE = "remote";

public static final String ITEM_LOCATION = "location";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public SkippedPluginsNotifier(SonarLintExtendedLanguageClient client, LanguageCl
}

public void notifyOnceForSkippedPlugins(Language language, DidSkipLoadingPluginParams.SkipReason reason, String minVersion, @Nullable String currentVersion) {
final var title = String.format("SonarLint failed to analyze %s code", LSLanguage.valueOf(language.name()).getLabel());
final var title = String.format("SonarQube for VS Code failed to analyze %s code", LSLanguage.valueOf(language.name()).getLabel());
if (reason == DidSkipLoadingPluginParams.SkipReason.UNSATISFIED_JRE) {
handleMissingJRERequirement(minVersion, Objects.requireNonNull(currentVersion), title);
} else if (reason == DidSkipLoadingPluginParams.SkipReason.UNSATISFIED_NODE_JS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public class SonarLintLanguageServer implements SonarLintExtendedLanguageServer,
private final ExecutorService branchChangeEventExecutor;

SonarLintLanguageServer(InputStream inputStream, OutputStream outputStream, Collection<Path> analyzers) {
this.lspThreadPool = Executors.newCachedThreadPool(Utils.threadFactory("SonarLint LSP message processor", false));
this.lspThreadPool = Executors.newCachedThreadPool(Utils.threadFactory("SonarQube for VS Code LSP message processor", false));

var input = new ExitingInputStream(inputStream, this);
var launcher = new Launcher.Builder<SonarLintExtendedLanguageClient>()
Expand All @@ -206,7 +206,7 @@ public class SonarLintLanguageServer implements SonarLintExtendedLanguageServer,
.setOutput(outputStream)
.setExecutorService(lspThreadPool)
.create();
this.branchChangeEventExecutor = Executors.newSingleThreadExecutor(Utils.threadFactory("SonarLint branch change event handler", false));
this.branchChangeEventExecutor = Executors.newSingleThreadExecutor(Utils.threadFactory("SonarQube for VS Code branch change event handler", false));

this.analyzers = analyzers;
this.client = launcher.getRemoteProxy();
Expand Down Expand Up @@ -864,7 +864,7 @@ public CompletableFuture<Void> changeIssueStatus(ChangeIssueStatusParams params)
client.showMessage(new MessageParams(MessageType.Info, "Issue status was changed"));
}).exceptionally(t -> {
lsLogOutput.errorWithStackTrace("Error changing issue status", t);
client.showMessage(new MessageParams(MessageType.Error, "Could not change status for the issue. Look at the SonarLint output for details."));
client.showMessage(new MessageParams(MessageType.Error, "Could not change status for the issue. Look at the SonarQube for IDE output for details."));
return null;
}).thenAccept(unused -> {
if (!StringUtils.isEmpty(params.getComment())) {
Expand Down Expand Up @@ -910,7 +910,7 @@ public CompletableFuture<Void> changeHotspotStatus(ChangeHotspotStatusParams par
client.showMessage(new MessageParams(MessageType.Info, "Hotspot status was changed"));
}).exceptionally(t -> {
lsLogOutput.errorWithStackTrace("Error changing hotspot status", t);
client.showMessage(new MessageParams(MessageType.Error, "Could not change status for the hotspot. Look at the SonarLint output for details."));
client.showMessage(new MessageParams(MessageType.Error, "Could not change status for the hotspot. Look at the SonarQube for IDE output for details."));
return null;
});
}
Expand All @@ -936,7 +936,7 @@ public CompletableFuture<GetAllowedHotspotStatusesResponse> getAllowedHotspotSta
statuses);
}).exceptionally(t -> {
lsLogOutput.errorWithStackTrace("Error changing hotspot status", t);
client.showMessage(new MessageParams(MessageType.Error, "Could not change status for the hotspot. Look at the SonarLint output for details."));
client.showMessage(new MessageParams(MessageType.Error, "Could not change status for the hotspot. Look at the SonarQube for IDE output for details."));
return null;
});
}
Expand All @@ -957,7 +957,7 @@ public void reopenResolvedLocalIssues(ReopenAllIssuesForFileParams params) {
return r;
}).exceptionally(e -> {
lsLogOutput.errorWithStackTrace("Error while reopening resolved local issues", e);
client.showMessage(new MessageParams(MessageType.Error, "Could not reopen resolved local issues. Look at the SonarLint output for details."));
client.showMessage(new MessageParams(MessageType.Error, "Could not reopen resolved local issues. Look at the SonarQube for IDE output for details."));
return null;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void didChangeClientNodeJsPath(DidChangeClientNodeJsPathParams params) {
.exceptionally(t -> {
logOutput.errorWithStackTrace("Error getting issue status change permissions", t);
client.logMessage(new MessageParams(MessageType.Error, "Could not get issue status change for issue \""
+ issueKey + "\". Look at the SonarLint output for details."));
+ issueKey + "\". Look at the SonarQube for IDE output for details."));
return null;
});
}
Expand All @@ -278,7 +278,7 @@ public CompletableFuture<Void> addIssueComment(AddIssueCommentParams params) {
return initializedBackend().getIssueService().addComment(params)
.exceptionally(t -> {
logOutput.errorWithStackTrace("Error adding issue comment", t);
client.showMessage(new MessageParams(MessageType.Error, "Could not add a new issue comment. Look at the SonarLint output for " +
client.showMessage(new MessageParams(MessageType.Error, "Could not add a new issue comment. Look at the SonarQube for IDE output for " +
"details."));
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@

public class SonarLintVSCodeClient implements SonarLintRpcClientDelegate {

public static final String SONARLINT_SOURCE = "sonarlint";
public static final String SONARLINT_SOURCE = "sonarqube";
private final SonarLintExtendedLanguageClient client;
private SettingsManager settingsManager;
private SmartNotifications smartNotifications;
Expand Down Expand Up @@ -296,7 +296,7 @@ public AssistBindingResponse assistBinding(AssistBindingParams params, SonarLint
@Override
public void noBindingSuggestionFound(NoBindingSuggestionFoundParams params) {
var messageRequestParams = new ShowMessageRequestParams();
messageRequestParams.setMessage("SonarLint couldn't match the server project '" + params.getProjectKey() + "' to any of the currently " +
messageRequestParams.setMessage("SonarQube for VS Code couldn't match the server project '" + params.getProjectKey() + "' to any of the currently " +
"open workspace folders. Please make sure the project is open in the workspace, or try configuring the binding manually.");
messageRequestParams.setType(MessageType.Error);
var learnMoreAction = new MessageActionItem("Learn more");
Expand Down
46 changes: 23 additions & 23 deletions src/test/java/org/sonarsource/sonarlint/ls/CommandManagerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ void noDisableRuleForBoundProject() {
var codeActions = underTest.computeCodeActions(new CodeActionParams(FAKE_TEXT_DOCUMENT, FAKE_RANGE,
new CodeActionContext(List.of(new Diagnostic(FAKE_RANGE, "Foo", DiagnosticSeverity.Error, SONARLINT_SOURCE, "XYZ")))), NOP_CANCEL_TOKEN);

assertThat(codeActions).extracting(c -> c.getRight().getTitle()).containsOnly("SonarLint: Show issue details for 'XYZ'",
"SonarLint: Resolve issue violating rule 'XYZ' as...");
assertThat(codeActions).extracting(c -> c.getRight().getTitle()).containsOnly("SonarQube: Show issue details for 'XYZ'",
"SonarQube: Resolve issue violating rule 'XYZ' as...");
}

@Test
Expand All @@ -210,8 +210,8 @@ void suggestDisableRuleForUnboundProject() {

assertThat(codeActions).extracting(c -> c.getRight().getTitle())
.containsOnly(
"SonarLint: Show issue details for 'XYZ'",
"SonarLint: Deactivate rule 'XYZ'");
"SonarQube: Show issue details for 'XYZ'",
"SonarQube: Deactivate rule 'XYZ'");
}

@Test
Expand Down Expand Up @@ -241,9 +241,9 @@ void showQuickFixFromAnalyzer() {

assertThat(codeActions).extracting(c -> c.getRight().getTitle())
.containsExactly(
"SonarLint: Fix the issue!",
"SonarLint: Show issue details for 'XYZ'",
"SonarLint: Deactivate rule 'XYZ'");
"SonarQube: Fix the issue!",
"SonarQube: Show issue details for 'XYZ'",
"SonarQube: Deactivate rule 'XYZ'");
}

@Test
Expand Down Expand Up @@ -280,9 +280,9 @@ void showQuickFixFromAnalyzerForNotebook() {

assertThat(codeActions).extracting(c -> c.getRight().getTitle())
.containsExactly(
"SonarLint: Fix the issue!",
"SonarLint: Show issue details for 'XYZ'",
"SonarLint: Deactivate rule 'XYZ'");
"SonarQube: Fix the issue!",
"SonarQube: Show issue details for 'XYZ'",
"SonarQube: Deactivate rule 'XYZ'");
}

@ParameterizedTest
Expand Down Expand Up @@ -320,10 +320,10 @@ void codeActionsForTaintWithContext(String taintSource) {
new CodeActionContext(List.of(d))), NOP_CANCEL_TOKEN);

assertThat(codeActions).extracting(c -> c.getRight().getTitle()).containsOnly(
"SonarLint: Show issue details for 'ruleKey'",
"SonarLint: Show all locations for taint vulnerability 'ruleKey'",
"SonarLint: Open taint vulnerability 'ruleKey' on 'connectionId'",
"SonarLint: Resolve issue violating rule 'ruleKey' as...");
"SonarQube: Show issue details for 'ruleKey'",
"SonarQube: Show all locations for taint vulnerability 'ruleKey'",
"SonarQube: Open taint vulnerability 'ruleKey' on 'connectionId'",
"SonarQube: Resolve issue violating rule 'ruleKey' as...");

assertThat(codeActions.get(0).getRight().getCommand().getArguments()).containsOnly(
issueId,
Expand Down Expand Up @@ -358,9 +358,9 @@ void codeActionsForTaintNoContext() {
new CodeActionContext(List.of(d))), NOP_CANCEL_TOKEN);

assertThat(codeActions).extracting(c -> c.getRight().getTitle()).containsOnly(
"SonarLint: Show issue details for 'ruleKey'",
"SonarLint: Open taint vulnerability 'ruleKey' on 'connectionId'",
"SonarLint: Resolve issue violating rule 'ruleKey' as...");
"SonarQube: Show issue details for 'ruleKey'",
"SonarQube: Open taint vulnerability 'ruleKey' on 'connectionId'",
"SonarQube: Resolve issue violating rule 'ruleKey' as...");

assertThat(codeActions.get(0).getRight().getCommand().getArguments()).containsOnly(
taintId,
Expand Down Expand Up @@ -388,9 +388,9 @@ void suggestShowAllLocationsForIssueWithFlows() {

assertThat(codeActions).extracting(c -> c.getRight().getTitle())
.containsOnly(
"SonarLint: Show issue details for 'XYZ'",
"SonarLint: Deactivate rule 'XYZ'",
"SonarLint: Show all locations for issue 'XYZ'");
"SonarQube: Show issue details for 'XYZ'",
"SonarQube: Deactivate rule 'XYZ'",
"SonarQube: Show all locations for issue 'XYZ'");
}

@Test
Expand Down Expand Up @@ -723,8 +723,8 @@ void hasResolveIssueActionForBoundProject() {

assertThat(codeActions).extracting(c -> c.getRight().getTitle())
.containsExactly(
"SonarLint: Resolve issue violating rule 'XYZ' as...",
"SonarLint: Show issue details for 'XYZ'");
"SonarQube: Resolve issue violating rule 'XYZ' as...",
"SonarQube: Show issue details for 'XYZ'");
}

@Test
Expand Down Expand Up @@ -759,7 +759,7 @@ void doesNotHaveResolveIssueActionWhenIssueStatusChangeNotPermitted() {

assertThat(codeActions).extracting(c -> c.getRight().getTitle())
.containsExactly(
"SonarLint: Show issue details for 'XYZ'");
"SonarQube: Show issue details for 'XYZ'");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void send_notification_once_for_jre() {
verify(languageClient, times(1)).openJavaHomeSettings();

var message = messageCaptor.getValue();
assertThat(message.getMessage()).contains("SonarLint failed to analyze Java code")
assertThat(message.getMessage()).contains("SonarQube for VS Code failed to analyze Java code")
.contains("Java runtime version 17 or later is required. Current version is 11.");
assertThat(message.getActions()).containsExactly(SkippedPluginsNotifier.ACTION_OPEN_SETTINGS);
}
Expand All @@ -89,7 +89,7 @@ void send_notification_for_jre_and_close_notification() {
verify(languageClient, times(1)).showMessageRequest(messageCaptor.capture());

var message = messageCaptor.getValue();
assertThat(message.getMessage()).contains("SonarLint failed to analyze Java code")
assertThat(message.getMessage()).contains("SonarQube for VS Code failed to analyze Java code")
.contains("Java runtime version 17 or later is required. Current version is 11.");
assertThat(message.getActions()).containsExactly(SkippedPluginsNotifier.ACTION_OPEN_SETTINGS);
}
Expand All @@ -105,7 +105,7 @@ void send_notification_for_node_when_found() {
verify(languageClient, times(1)).openPathToNodeSettings();

var message = messageCaptor.getValue();
assertThat(message.getMessage()).contains("SonarLint failed to analyze JavaScript code")
assertThat(message.getMessage()).contains("SonarQube for VS Code failed to analyze JavaScript code")
.contains("Node.js runtime version minNodeJsVersion or later is required. Current version is currentNodeJsVersion.");
assertThat(message.getActions()).containsExactly(SkippedPluginsNotifier.ACTION_OPEN_SETTINGS, SkippedPluginsNotifier.ACTION_DONT_SHOW_AGAIN);
}
Expand All @@ -120,7 +120,7 @@ void send_notification_for_node_when_not_found() {
verify(languageClient, times(1)).showMessageRequest(messageCaptor.capture());

var message = messageCaptor.getValue();
assertThat(message.getMessage()).contains("SonarLint failed to analyze JavaScript code")
assertThat(message.getMessage()).contains("SonarQube for VS Code failed to analyze JavaScript code")
.contains("Node.js runtime version minNodeJsVersion or later is required.")
.doesNotContain("Current version is");
assertThat(message.getActions()).containsExactly(SkippedPluginsNotifier.ACTION_OPEN_SETTINGS, SkippedPluginsNotifier.ACTION_DONT_SHOW_AGAIN);
Expand All @@ -138,7 +138,7 @@ void should_turn_off_notifications_when_user_opts_out() {
verify(languageClient, never()).openPathToNodeSettings();

var message = messageCaptor.getValue();
assertThat(message.getMessage()).contains("SonarLint failed to analyze JavaScript code")
assertThat(message.getMessage()).contains("SonarQube for VS Code failed to analyze JavaScript code")
.contains("Node.js runtime version minNodeJsVersion or later is required. Current version is currentNodeJsVersion.");
assertThat(message.getActions()).containsExactly(SkippedPluginsNotifier.ACTION_OPEN_SETTINGS, SkippedPluginsNotifier.ACTION_DONT_SHOW_AGAIN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
package org.sonarsource.sonarlint.ls.backend;

import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.MessageType;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.sonarsource.sonarlint.core.issue.IssueNotFoundException;
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcServer;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.binding.BindingRpcService;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.binding.GetSharedConnectedModeConfigFileParams;
Expand All @@ -35,6 +39,8 @@
import org.sonarsource.sonarlint.core.rpc.protocol.backend.connection.org.ListUserOrganizationsParams;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.hotspot.HotspotRpcService;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.hotspot.OpenHotspotInBrowserParams;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.issue.AddIssueCommentParams;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.issue.IssueRpcService;
import org.sonarsource.sonarlint.ls.SonarLintExtendedLanguageClient;
import org.sonarsource.sonarlint.ls.connected.ProjectBinding;
import org.sonarsource.sonarlint.ls.log.LanguageClientLogger;
Expand All @@ -52,6 +58,7 @@ class BackendServiceTests {
ConfigurationRpcService configurationService = mock(ConfigurationRpcService.class);
BindingRpcService bindingRpcService = mock(BindingRpcService.class);
ConnectionRpcService connectionRpcService = mock(ConnectionRpcService.class);
IssueRpcService issueService = mock(IssueRpcService.class);
static LanguageClientLogger lsLogOutput = mock(LanguageClientLogger.class);
static SonarLintExtendedLanguageClient client = mock(SonarLintExtendedLanguageClient.class);
static BackendService underTest = new BackendService(backend, lsLogOutput, client);
Expand All @@ -68,6 +75,7 @@ void init() {
when(backend.getConfigurationService()).thenReturn(configurationService);
when(backend.getBindingService()).thenReturn(bindingRpcService);
when(backend.getConnectionService()).thenReturn(connectionRpcService);
when(backend.getIssueService()).thenReturn(issueService);
}

@Test
Expand Down Expand Up @@ -131,4 +139,17 @@ void shouldListUserOrganizations() {
assertThat(argumentCaptor.getValue().getCredentials().getLeft().getToken()).isEqualTo(token);
}

@Test
void shouldAddIssueComment() {
var issueId = UUID.randomUUID();
when(issueService.addComment(any())).thenReturn(CompletableFuture.failedFuture(new IssueNotFoundException("Could not find issue", issueId)));

underTest.addIssueComment(new AddIssueCommentParams("configScope", issueId.toString(), "comment"));

var messageParamsCaptor = ArgumentCaptor.forClass(MessageParams.class);

verify(client).showMessage(messageParamsCaptor.capture());
assertThat(messageParamsCaptor.getValue().getMessage()).contains("Could not add a new issue comment. Look at the SonarQube for IDE output for details.");
assertThat(messageParamsCaptor.getValue().getType()).isEqualTo(MessageType.Error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ void testNoBindingSuggestionFound() {

var projectKey = "projectKey";
var messageRequestParams = new ShowMessageRequestParams();
messageRequestParams.setMessage("SonarLint couldn't match the server project '" + projectKey + "' to any of the currently open workspace folders. Please make sure the project is open in the workspace, or try configuring the binding manually.");
messageRequestParams.setMessage("SonarQube for VS Code couldn't match the server project '" + projectKey + "' to any of the currently open workspace folders. Please make sure the project is open in the workspace, or try configuring the binding manually.");
messageRequestParams.setType(MessageType.Error);
var learnMoreAction = new MessageActionItem("Learn more");
messageRequestParams.setActions(List.of(learnMoreAction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void shouldShowSonarCloudNotificationToUserAndNotClickOnNotification() {
var link = "http://some.link";
var showNotificationParams = new ShowSmartNotificationParams(message, link, Set.of(), category, "testConnection");

var browseAction = new MessageActionItem("Show on SonarCloud");
var browseAction = new MessageActionItem("Show on SonarQube Cloud");
when(client.showMessageRequest(any())).thenReturn(CompletableFuture.completedFuture(null));
var settingsAction = new MessageActionItem("Open Settings");

Expand Down
Loading

0 comments on commit 8837e9a

Please sign in to comment.