Skip to content

SLCORE-1427 Noisy analysis cancellation #1407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -779,17 +779,20 @@ private CompletableFuture<AnalysisResult> schedule(String configScopeId, Analyze
schedulerCache.getOrCreateAnalysisScheduler(configScopeId, command.getTrace()));
startChild(trace, "post", "schedule", () -> scheduler.post(command));
var result = command.getFutureResult();
result.exceptionally(exception -> {
eventPublisher.publishEvent(new AnalysisFailedEvent(analysisId));
if (exception instanceof CancellationException) {
LOG.debug("Analysis canceled");
} else {
LOG.error("Error during analysis", exception);
}
return null;
});
return result
.exceptionally(exception -> {
eventPublisher.publishEvent(new AnalysisFailedEvent(analysisId));
if (exception instanceof CancellationException) {
LOG.debug("Analysis canceled");
} else {
LOG.error("Error during analysis", exception);
}
return null;
})
.thenApply(analysisResults -> {
if (analysisResults == null) {
return null;
}
var languagePerFile = analysisResults.languagePerFile().entrySet().stream().collect(HashMap<URI, SonarLanguage>::new,
(map, entry) -> map.put(entry.getKey().uri(), entry.getValue()), HashMap::putAll);
logSummary(rawIssues, analysisResults.getDuration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode;
import org.sonarsource.sonarlint.core.analysis.AnalysisResult;
import org.sonarsource.sonarlint.core.analysis.AnalysisService;
import org.sonarsource.sonarlint.core.analysis.NodeJsService;
Expand Down Expand Up @@ -141,7 +142,12 @@ public CompletableFuture<AnalyzeFilesResponse> analyzeFilesAndTrack(AnalyzeFiles
return requestFutureAsync(cancelChecker -> getBean(AnalysisService.class)
.scheduleAnalysis(params.getConfigurationScopeId(), params.getAnalysisId(), Set.copyOf(params.getFilesToAnalyze()),
params.getExtraProperties(), params.isShouldFetchServerIssues(), TriggerType.FORCED_WITH_EXCLUSIONS, cancelChecker)
.thenApply(AnalysisRpcServiceDelegate::generateAnalyzeFilesResponse), configurationScopeId);
.thenApply(analysisResults -> {
if (analysisResults == null) {
throw new ResponseErrorException(new ResponseError(ResponseErrorCode.RequestCancelled, "Analysis was cancelled", null));
}
return generateAnalyzeFilesResponse(analysisResults);
}), configurationScopeId);
}

@Override
Expand Down
Loading