@@ -36,6 +36,7 @@ import java.net.HttpURLConnection
3636import java.net.URL
3737import java.util.concurrent.atomic.AtomicBoolean
3838import java.util.concurrent.atomic.AtomicInteger
39+ import kotlin.time.Duration.Companion.minutes
3940
4041class ProjectContextProvider (val project : Project , private val encoderServer : EncoderServer , private val cs : CoroutineScope ) : Disposable {
4142 private val retryCount = AtomicInteger (0 )
@@ -218,9 +219,9 @@ class ProjectContextProvider(val project: Project, private val encoderServer: En
218219 )
219220 }
220221
221- private fun setConnectionTimeout (connection : HttpURLConnection ) {
222- connection.connectTimeout = 5000 // 5 seconds
223- connection.readTimeout = 5000 // 5 second
222+ private fun setConnectionTimeout (connection : HttpURLConnection , timeout : Int ) {
223+ connection.connectTimeout = timeout
224+ connection.readTimeout = timeout
224225 }
225226
226227 private fun setConnectionProperties (connection : HttpURLConnection ) {
@@ -311,10 +312,11 @@ class ProjectContextProvider(val project: Project, private val encoderServer: En
311312 private fun sendMsgToLsp (msgType : LspMessage , request : String? ): LspResponse {
312313 logger.info { " sending message: ${msgType.endpoint} to lsp on port ${encoderServer.port} " }
313314 val url = URL (" http://localhost:${encoderServer.port} /${msgType.endpoint} " )
314-
315+ // use 1h as timeout for index, 5 seconds for other APIs
316+ val timeoutMs = if (msgType is LspMessage .Index ) 60 .minutes.inWholeMilliseconds.toInt() else 5000
315317 return with (url.openConnection() as HttpURLConnection ) {
316318 setConnectionProperties(this )
317- setConnectionTimeout(this )
319+ setConnectionTimeout(this , timeoutMs )
318320 request?.let { r ->
319321 setConnectionRequest(this , r)
320322 }
0 commit comments