Skip to content

Commit

Permalink
Decouple LSP from vector index creation; start LSP by default (#4978)
Browse files Browse the repository at this point in the history
  • Loading branch information
Will-ShaoHua authored Oct 21, 2024
1 parent 13e5d8d commit e3c47d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down Expand Up @@ -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")) {
Expand Down

0 comments on commit e3c47d7

Please sign in to comment.