in src/main/kotlin/rules_intellij/indexing/IndexingService.kt [112:162]
fun index(request: IndexRequest): IndexResponse {
ConsoleLog.info("Indexing Server: IndexRequest: $request")
val project = synchronized(this) {
projectsByIds[request.projectId]
} ?: throw StatusException(Status.NOT_FOUND)
ConsoleLog.info("Collecting files to index...")
val chunk = ProjectPartialIndexChunk(request)
val outputDir = Paths.get(PathManager.getTempPath())
.resolve(java.lang.Long.toHexString(request.projectId))
.resolve(java.lang.Long.toHexString(StringHash.calc(request.indexId)))
if (!outputDir.exists() && !outputDir.toFile().mkdirs()) {
throw StatusException(Status.INTERNAL)
}
val exportedRequest = IndexesExporterRequest(
chunk = chunk,
//additionalMetadata = SharedIndexMetadataInfo(),
compression = SharedIndexCompression.PLAIN,
outputDir = outputDir,
excludeFilesWithHashCollision = false,
)
ConsoleLog.info("Indexing $chunk...")
val indicator = DummyIndicator()
try {
val result = IndexesExporter.exportIndexesChunk(
project = project,
indicator = indicator,
request = exportedRequest
)
return IndexResponse.newBuilder()
.setIjxPath(result.files.indexPath.toString())
.setIjxMetadataPath(result.files.metadataPath.toString())
.setIjxSha256Path(result.files.sha256Path.toString())
.build()
} catch (e: Exception) {
if (e.message?.contains("shared index is empty") == true) {
return IndexResponse.newBuilder()
.setIjxPath(createTempFile().toString())
.setIjxMetadataPath(createTempFile().toString())
.setIjxSha256Path(createTempFile().toString())
.build()
}
throw e
}
}