diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/startup/AmazonQStartupActivity.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/startup/AmazonQStartupActivity.kt index 0bafbd7279..c6aeccc39f 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/startup/AmazonQStartupActivity.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/startup/AmazonQStartupActivity.kt @@ -19,7 +19,6 @@ import software.aws.toolkits.jetbrains.services.amazonq.project.ProjectContextCo import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindow import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindowFactory import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager -import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings import java.lang.management.ManagementFactory import java.time.Duration import java.util.concurrent.atomic.AtomicBoolean @@ -50,26 +49,24 @@ class AmazonQStartupActivity : ProjectActivity { // Automatically start the project context LSP after some delay when average CPU load is below 30%. // The CPU load requirement is to avoid competing with native JetBrains indexing and other CPU expensive OS processes // In the future we will decouple LSP start and indexing start to let LSP perform other tasks. - if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) { - val startLspIndexingDuration = Duration.ofMinutes(30) - project.waitForSmartMode() - try { - withTimeout(startLspIndexingDuration) { - while (true) { - val cpuUsage = ManagementFactory.getOperatingSystemMXBean().systemLoadAverage - if (cpuUsage > 0 && cpuUsage < 30) { - ProjectContextController.getInstance(project = project) - break - } else { - delay(60_000) // Wait for 60 seconds - } + val startLspIndexingDuration = Duration.ofMinutes(30) + project.waitForSmartMode() + try { + withTimeout(startLspIndexingDuration) { + while (true) { + val cpuUsage = ManagementFactory.getOperatingSystemMXBean().systemLoadAverage + if (cpuUsage > 0 && cpuUsage < 30) { + ProjectContextController.getInstance(project = project) + break + } else { + delay(60_000) // Wait for 60 seconds } } - } catch (e: TimeoutCancellationException) { - LOG.warn { "Failed to start LSP server due to time out" } - } catch (e: Exception) { - LOG.warn { "Failed to start LSP server" } } + } catch (e: TimeoutCancellationException) { + LOG.warn { "Failed to start LSP server due to time out" } + } catch (e: Exception) { + LOG.warn { "Failed to start LSP server" } } } diff --git a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/project/ProjectContextProvider.kt b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/project/ProjectContextProvider.kt index ccfa4b7096..dcf29c19d7 100644 --- a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/project/ProjectContextProvider.kt +++ b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/project/ProjectContextProvider.kt @@ -38,18 +38,17 @@ class ProjectContextProvider(val project: Project, private val encoderServer: En private val retryCount = AtomicInteger(0) val isIndexComplete = AtomicBoolean(false) private val mapper = jacksonObjectMapper() + init { cs.launch { - if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) { - while (true) { - if (encoderServer.isNodeProcessRunning()) { - // TODO: need better solution for this - delay(10000) - initAndIndex() - break - } else { - yield() - } + while (true) { + if (encoderServer.isNodeProcessRunning()) { + // TODO: need better solution for this + delay(10000) + initAndIndex() + break + } else { + yield() } } } @@ -101,9 +100,11 @@ class ProjectContextProvider(val project: Project, private val encoderServer: En if (isInitSuccess) { logger.info { "project context index starting" } delay(300) - val isIndexSuccess = index() - if (isIndexSuccess) isIndexComplete.set(true) - return@launch + if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) { + val isIndexSuccess = index() + if (isIndexSuccess) isIndexComplete.set(true) + return@launch + } } } catch (e: Exception) { if (e.stackTraceToString().contains("Connection refused")) {