Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import software.aws.toolkits.jetbrains.core.gettingstarted.emitUserState
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.services.codewhisperer.settings.CodeWhispererSettings
import software.aws.toolkits.jetbrains.services.cwc.editor.context.project.ProjectContextController
import java.lang.management.ManagementFactory
import java.time.Duration
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 @@ -37,22 +37,22 @@ 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()
}
}
}
}

data class IndexRequestPayload(
val filePaths: List<String>,
val projectRoot: String,
Expand Down Expand Up @@ -113,9 +113,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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you need to call index() regardless of whether projectContext is enabled or not. If enabled, call it with config 'all' otherwise config 'default'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah this one doesn't have the latest lsp API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's still the old one which only does chat vector

if (isIndexSuccess) isIndexComplete.set(true)
return@launch
}
}
} catch (e: Exception) {
if (e.stackTraceToString().contains("Connection refused")) {
Expand Down
Loading