Skip to content

Commit 149e6af

Browse files
committed
Merge remote-tracking branch 'upstream/main' into lsp-client
2 parents cf4c29c + e3c47d7 commit 149e6af

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
@@ -40,18 +40,17 @@ class ProjectContextProvider(val project: Project, private val encoderServer: En
4040
private val retryCount = AtomicInteger(0)
4141
val isIndexComplete = AtomicBoolean(false)
4242
private val mapper = jacksonObjectMapper()
43+
4344
init {
4445
cs.launch {
45-
if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) {
46-
while (true) {
47-
if (encoderServer.isNodeProcessRunning()) {
48-
// TODO: need better solution for this
49-
delay(10000)
50-
initAndIndex()
51-
break
52-
} else {
53-
yield()
54-
}
46+
while (true) {
47+
if (encoderServer.isNodeProcessRunning()) {
48+
// TODO: need better solution for this
49+
delay(10000)
50+
initAndIndex()
51+
break
52+
} else {
53+
yield()
5554
}
5655
}
5756
}
@@ -109,9 +108,11 @@ class ProjectContextProvider(val project: Project, private val encoderServer: En
109108
if (isInitSuccess) {
110109
logger.info { "project context index starting" }
111110
delay(300)
112-
val isIndexSuccess = index()
113-
if (isIndexSuccess) isIndexComplete.set(true)
114-
return@launch
111+
if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) {
112+
val isIndexSuccess = index()
113+
if (isIndexSuccess) isIndexComplete.set(true)
114+
return@launch
115+
}
115116
}
116117
} catch (e: Exception) {
117118
if (e.stackTraceToString().contains("Connection refused")) {

0 commit comments

Comments
 (0)