diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 71bce2ddc..83f52651f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -sonarlint-core = "10.6.0.79033" +sonarlint-core = "10.7.0.79079" sonar-java = "8.1.0.36477" sonar-javascript = "10.15.0.27423" diff --git a/src/main/java/org/sonarlint/intellij/config/global/SonarLintGlobalOptionsPanel.java b/src/main/java/org/sonarlint/intellij/config/global/SonarLintGlobalOptionsPanel.java index 4209e8480..9afac99c4 100644 --- a/src/main/java/org/sonarlint/intellij/config/global/SonarLintGlobalOptionsPanel.java +++ b/src/main/java/org/sonarlint/intellij/config/global/SonarLintGlobalOptionsPanel.java @@ -33,6 +33,7 @@ import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.nio.file.Paths; import java.util.Objects; import javax.swing.BorderFactory; import javax.swing.JComponent; @@ -51,7 +52,8 @@ public class SonarLintGlobalOptionsPanel implements ConfigurationPanel { private static final String NODE_JS_TOOLTIP = "SonarLint requires Node.js to analyze some languages. You can provide an explicit path for the node executable here or leave " + - "this field blank to let SonarLint look for it using your PATH environment variable."; + "this field blank to let SonarLint look for it using your PATH environment variable." + + " Restarting your IDE is recommended."; private JPanel rootPane; private JBCheckBox autoTrigger; private JBTextField nodeJsPath; @@ -136,19 +138,31 @@ public void load(SonarLintGlobalSettings model) { autoTrigger.setSelected(model.isAutoTrigger()); nodeJsPath.setText(model.getNodejsPath()); focusOnNewCode.setSelected(model.isFocusOnNewCode()); - loadNodeJsSettings(); + loadNodeJsSettings(model); } - private void loadNodeJsSettings() { - getService(BackendService.class).getAutoDetectedNodeJs().thenAccept(settings -> { - if (settings == null) { - this.nodeJsPath.getEmptyText().setText("Node.js not found"); - this.nodeJsVersion.setText("N/A"); - } else { - this.nodeJsPath.getEmptyText().setText(settings.getPath().toString()); - this.nodeJsVersion.setText(settings.getVersion()); - } - }); + private void loadNodeJsSettings(SonarLintGlobalSettings model) { + if (model.getNodejsPath() == null || model.getNodejsPath().isBlank()) { + getService(BackendService.class).getAutoDetectedNodeJs().thenAccept(settings -> { + if (settings == null) { + this.nodeJsPath.getEmptyText().setText("Node.js not found"); + this.nodeJsVersion.setText("N/A"); + } else { + this.nodeJsPath.getEmptyText().setText(settings.getPath().toString()); + this.nodeJsVersion.setText(settings.getVersion()); + } + }); + } else { + var forcedNodeJsPath = Paths.get(model.getNodejsPath()); + getService(BackendService.class).changeClientNodeJsPath(forcedNodeJsPath).thenAccept(settings -> { + if (settings == null) { + this.nodeJsVersion.setText("N/A"); + } else { + this.nodeJsPath.setText(settings.getPath().toString()); + this.nodeJsVersion.setText(settings.getVersion()); + } + }); + } } @Override diff --git a/src/main/java/org/sonarlint/intellij/core/BackendService.kt b/src/main/java/org/sonarlint/intellij/core/BackendService.kt index b6a919402..7ace9bd28 100644 --- a/src/main/java/org/sonarlint/intellij/core/BackendService.kt +++ b/src/main/java/org/sonarlint/intellij/core/BackendService.kt @@ -88,6 +88,7 @@ import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcServer import org.sonarsource.sonarlint.core.rpc.protocol.backend.analysis.AnalyzeFilesAndTrackParams import org.sonarsource.sonarlint.core.rpc.protocol.backend.analysis.AnalyzeFilesResponse import org.sonarsource.sonarlint.core.rpc.protocol.backend.analysis.DidChangeAutomaticAnalysisSettingParams +import org.sonarsource.sonarlint.core.rpc.protocol.backend.analysis.DidChangeClientNodeJsPathParams import org.sonarsource.sonarlint.core.rpc.protocol.backend.binding.GetSharedConnectedModeConfigFileParams import org.sonarsource.sonarlint.core.rpc.protocol.backend.binding.GetSharedConnectedModeConfigFileResponse import org.sonarsource.sonarlint.core.rpc.protocol.backend.branch.DidVcsRepositoryChangeParams @@ -893,6 +894,13 @@ class BackendService : Disposable { } } + fun changeClientNodeJsPath(nodeJsPath: Path?): CompletableFuture { + return requestFromBackend { it.analysisService.didChangeClientNodeJsPath(DidChangeClientNodeJsPathParams(nodeJsPath)) } + .thenApplyAsync { response -> + response.details?.let { NodeJsSettings(it.path, it.version) } + } + } + fun updateFileSystem(filesByModule: Map>) { val deletedFileUris = filesByModule.values .flatMap { it.filter { event -> event.type == ModuleFileEvent.Type.DELETED } }