Skip to content

Commit 4539c3b

Browse files
should be green
1 parent dbf4bbe commit 4539c3b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

backend/core/src/main/java/org/sonarsource/sonarlint/core/analysis/AnalysisService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ private CompletableFuture<AnalysisResult> schedule(String configScopeId, Analyze
791791
})
792792
.thenApply(analysisResults -> {
793793
if (analysisResults == null) {
794-
throw new CancellationException("Analysis results should not be null");
794+
return null;
795795
}
796796
var languagePerFile = analysisResults.languagePerFile().entrySet().stream().collect(HashMap<URI, SonarLanguage>::new,
797797
(map, entry) -> map.put(entry.getKey().uri(), entry.getValue()), HashMap::putAll);

backend/rpc-impl/src/main/java/org/sonarsource/sonarlint/core/rpc/impl/AnalysisRpcServiceDelegate.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
*/
2020
package org.sonarsource.sonarlint.core.rpc.impl;
2121

22+
import java.util.List;
2223
import java.util.Map;
2324
import java.util.Set;
25+
import java.util.concurrent.CancellationException;
2426
import java.util.concurrent.CompletableFuture;
27+
import java.util.concurrent.CompletionException;
2528
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
2629
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
30+
import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode;
2731
import org.sonarsource.sonarlint.core.analysis.AnalysisResult;
2832
import org.sonarsource.sonarlint.core.analysis.AnalysisService;
2933
import org.sonarsource.sonarlint.core.analysis.NodeJsService;
@@ -141,7 +145,18 @@ public CompletableFuture<AnalyzeFilesResponse> analyzeFilesAndTrack(AnalyzeFiles
141145
return requestFutureAsync(cancelChecker -> getBean(AnalysisService.class)
142146
.scheduleAnalysis(params.getConfigurationScopeId(), params.getAnalysisId(), Set.copyOf(params.getFilesToAnalyze()),
143147
params.getExtraProperties(), params.isShouldFetchServerIssues(), TriggerType.FORCED_WITH_EXCLUSIONS, cancelChecker)
144-
.thenApply(AnalysisRpcServiceDelegate::generateAnalyzeFilesResponse), configurationScopeId);
148+
.exceptionally(exception -> {
149+
if (exception instanceof CompletionException || exception instanceof CancellationException) {
150+
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.RequestCancelled, "Analysis was cancelled", null));
151+
}
152+
return null;
153+
})
154+
.thenApply(analysisResults -> {
155+
if (analysisResults == null) {
156+
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.RequestCancelled, "Analysis was cancelled", null));
157+
}
158+
return generateAnalyzeFilesResponse(analysisResults);
159+
}), configurationScopeId);
145160
}
146161

147162
@Override

0 commit comments

Comments
 (0)