Skip to content

Commit e3c47d7

Browse files
authored
Decouple LSP from vector index creation; start LSP by default (#4978)
1 parent 13e5d8d commit e3c47d7

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/startup/AmazonQStartupActivity.kt

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import software.aws.toolkits.jetbrains.services.amazonq.project.ProjectContextCo
1919
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindow
2020
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindowFactory
2121
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
22-
import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings
2322
import java.lang.management.ManagementFactory
2423
import java.time.Duration
2524
import java.util.concurrent.atomic.AtomicBoolean
@@ -50,26 +49,24 @@ class AmazonQStartupActivity : ProjectActivity {
5049
// Automatically start the project context LSP after some delay when average CPU load is below 30%.
5150
// The CPU load requirement is to avoid competing with native JetBrains indexing and other CPU expensive OS processes
5251
// In the future we will decouple LSP start and indexing start to let LSP perform other tasks.
53-
if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) {
54-
val startLspIndexingDuration = Duration.ofMinutes(30)
55-
project.waitForSmartMode()
56-
try {
57-
withTimeout(startLspIndexingDuration) {
58-
while (true) {
59-
val cpuUsage = ManagementFactory.getOperatingSystemMXBean().systemLoadAverage
60-
if (cpuUsage > 0 && cpuUsage < 30) {
61-
ProjectContextController.getInstance(project = project)
62-
break
63-
} else {
64-
delay(60_000) // Wait for 60 seconds
65-
}
52+
val startLspIndexingDuration = Duration.ofMinutes(30)
53+
project.waitForSmartMode()
54+
try {
55+
withTimeout(startLspIndexingDuration) {
56+
while (true) {
57+
val cpuUsage = ManagementFactory.getOperatingSystemMXBean().systemLoadAverage
58+
if (cpuUsage > 0 && cpuUsage < 30) {
59+
ProjectContextController.getInstance(project = project)
60+
break
61+
} else {
62+
delay(60_000) // Wait for 60 seconds
6663
}
6764
}
68-
} catch (e: TimeoutCancellationException) {
69-
LOG.warn { "Failed to start LSP server due to time out" }
70-
} catch (e: Exception) {
71-
LOG.warn { "Failed to start LSP server" }
7265
}
66+
} catch (e: TimeoutCancellationException) {
67+
LOG.warn { "Failed to start LSP server due to time out" }
68+
} catch (e: Exception) {
69+
LOG.warn { "Failed to start LSP server" }
7370
}
7471
}
7572

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/project/ProjectContextProvider.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,17 @@ class ProjectContextProvider(val project: Project, private val encoderServer: En
3838
private val retryCount = AtomicInteger(0)
3939
val isIndexComplete = AtomicBoolean(false)
4040
private val mapper = jacksonObjectMapper()
41+
4142
init {
4243
cs.launch {
43-
if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) {
44-
while (true) {
45-
if (encoderServer.isNodeProcessRunning()) {
46-
// TODO: need better solution for this
47-
delay(10000)
48-
initAndIndex()
49-
break
50-
} else {
51-
yield()
52-
}
44+
while (true) {
45+
if (encoderServer.isNodeProcessRunning()) {
46+
// TODO: need better solution for this
47+
delay(10000)
48+
initAndIndex()
49+
break
50+
} else {
51+
yield()
5352
}
5453
}
5554
}
@@ -101,9 +100,11 @@ class ProjectContextProvider(val project: Project, private val encoderServer: En
101100
if (isInitSuccess) {
102101
logger.info { "project context index starting" }
103102
delay(300)
104-
val isIndexSuccess = index()
105-
if (isIndexSuccess) isIndexComplete.set(true)
106-
return@launch
103+
if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) {
104+
val isIndexSuccess = index()
105+
if (isIndexSuccess) isIndexComplete.set(true)
106+
return@launch
107+
}
107108
}
108109
} catch (e: Exception) {
109110
if (e.stackTraceToString().contains("Connection refused")) {

0 commit comments

Comments
 (0)