Skip to content

Commit 4b978a3

Browse files
SLCORE-1427 Noisy analysis cancellation
1 parent 2b36a82 commit 4b978a3

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -779,17 +779,20 @@ private CompletableFuture<AnalysisResult> schedule(String configScopeId, Analyze
779779
schedulerCache.getOrCreateAnalysisScheduler(configScopeId, command.getTrace()));
780780
startChild(trace, "post", "schedule", () -> scheduler.post(command));
781781
var result = command.getFutureResult();
782-
result.exceptionally(exception -> {
783-
eventPublisher.publishEvent(new AnalysisFailedEvent(analysisId));
784-
if (exception instanceof CancellationException) {
785-
LOG.debug("Analysis canceled");
786-
} else {
787-
LOG.error("Error during analysis", exception);
788-
}
789-
return null;
790-
});
791782
return result
783+
.exceptionally(exception -> {
784+
eventPublisher.publishEvent(new AnalysisFailedEvent(analysisId));
785+
if (exception instanceof CancellationException) {
786+
LOG.debug("Analysis canceled");
787+
} else {
788+
LOG.error("Error during analysis", exception);
789+
}
790+
return null;
791+
})
792792
.thenApply(analysisResults -> {
793+
if (analysisResults == null) {
794+
return null;
795+
}
793796
var languagePerFile = analysisResults.languagePerFile().entrySet().stream().collect(HashMap<URI, SonarLanguage>::new,
794797
(map, entry) -> map.put(entry.getKey().uri(), entry.getValue()), HashMap::putAll);
795798
logSummary(rawIssues, analysisResults.getDuration());

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.concurrent.CompletableFuture;
2525
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
2626
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
27+
import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode;
2728
import org.sonarsource.sonarlint.core.analysis.AnalysisResult;
2829
import org.sonarsource.sonarlint.core.analysis.AnalysisService;
2930
import org.sonarsource.sonarlint.core.analysis.NodeJsService;
@@ -141,7 +142,12 @@ public CompletableFuture<AnalyzeFilesResponse> analyzeFilesAndTrack(AnalyzeFiles
141142
return requestFutureAsync(cancelChecker -> getBean(AnalysisService.class)
142143
.scheduleAnalysis(params.getConfigurationScopeId(), params.getAnalysisId(), Set.copyOf(params.getFilesToAnalyze()),
143144
params.getExtraProperties(), params.isShouldFetchServerIssues(), TriggerType.FORCED_WITH_EXCLUSIONS, cancelChecker)
144-
.thenApply(AnalysisRpcServiceDelegate::generateAnalyzeFilesResponse), configurationScopeId);
145+
.thenApply(analysisResults -> {
146+
if (analysisResults == null) {
147+
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.RequestCancelled, "Analysis was cancelled", null));
148+
}
149+
return generateAnalyzeFilesResponse(analysisResults);
150+
}), configurationScopeId);
145151
}
146152

147153
@Override

0 commit comments

Comments
 (0)