override suspend fun execute()

in src/main/kotlin/org/jetbrains/qodana/requests.kt [40:94]


    override suspend fun execute(state: SarifLanguageServer.ServerState) {
        if (!File(path).exists()) {
            logger.error("sarif report doesn't exist at {$path}")
            return
        }
        val pathPrefix = state.pathPrefix
        if (pathPrefix == null) {
            logger.error("path prefix not set at the moment of reading the report")
            return
        }
        state.sarifLocation = path
        val diags = computeDiagnosticsAsIs(showBaselineIssues)
        val oldFiles = state.diagnostic?.keys ?: emptyList()
        state.diagnostic = diags.toMap(ConcurrentHashMap())
        state.repositoryFileCache = ConcurrentHashMap()
        state.sarifRevision = lazy { getRevisionId(path) }
        state.gitLocator?.value?.close()
        state.gitLocator = lazy {
            val revision = state.sarifRevision?.value
            if (revision != null && state.repoFolder != null) {
                GitLocator.create(state.repoFolder, revision)
            } else {
                null
            }
        }
        // check path prefix
        val exists = diags.keys.any { pathPrefix.resolve(it).exists() }
        if (!exists && diags.any()) {
           // we have a problem, since the suffix for the folder was wrong. let's try to recover
           val prefix = pathPrefix.toFile()
               .listFiles { f -> f.isDirectory }
               ?.map { d -> d.toPath() }
               ?.firstOrNull { p -> diags.keys.any { p.resolve(it).exists() } }
           if (prefix != null) {
               logger.warn("Prefix reassigned from ${state.pathPrefix} to $prefix")
               state.pathPrefix = prefix
           } else {
               logger.error("Supplied prefix doesn't match any files in the report.")
           }
        }

        // we need to invalidate old diagnostics if any
        for (file in oldFiles) {
            state.requestChannel.send(AnnounceDiagnostics(file, emptyList()))
        }

        for ((file, value) in diags) {
            state.requestChannel.send(AnnounceDiagnostics(file, value))
        }
        // we may have already some opened files at that moment. we need them to be remappable
        for (openFile in state.openFileCache.keys) {
            state.requestChannel.send(LoadRepoVersionForFile(openFile))
            state.requestChannel.send(RemapDiagnostics(openFile))
        }
    }