Skip to content

Commit 31fab63

Browse files
committed
patch
1 parent 30f3487 commit 31fab63

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,24 @@ class AmazonQStartupActivity : ProjectActivity {
4747
// Automatically start the project context LSP after some delay when average CPU load is below 30%.
4848
// The CPU load requirement is to avoid competing with native JetBrains indexing and other CPU expensive OS processes
4949
// In the future we will decouple LSP start and indexing start to let LSP perform other tasks.
50-
if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) {
51-
val startLspIndexingDuration = Duration.ofMinutes(30)
52-
project.waitForSmartMode()
53-
try {
54-
withTimeout(startLspIndexingDuration) {
55-
while (true) {
56-
val cpuUsage = ManagementFactory.getOperatingSystemMXBean().systemLoadAverage
57-
if (cpuUsage > 0 && cpuUsage < 30) {
58-
ProjectContextController.getInstance(project = project)
59-
break
60-
} else {
61-
delay(60_000) // Wait for 60 seconds
62-
}
50+
val startLspIndexingDuration = Duration.ofMinutes(30)
51+
project.waitForSmartMode()
52+
try {
53+
withTimeout(startLspIndexingDuration) {
54+
while (true) {
55+
val cpuUsage = ManagementFactory.getOperatingSystemMXBean().systemLoadAverage
56+
if (cpuUsage > 0 && cpuUsage < 30) {
57+
ProjectContextController.getInstance(project = project)
58+
break
59+
} else {
60+
delay(60_000) // Wait for 60 seconds
6361
}
6462
}
65-
} catch (e: TimeoutCancellationException) {
66-
LOG.warn { "Failed to start LSP server due to time out" }
67-
} catch (e: Exception) {
68-
LOG.warn { "Failed to start LSP server" }
6963
}
64+
} catch (e: TimeoutCancellationException) {
65+
LOG.warn { "Failed to start LSP server due to time out" }
66+
} catch (e: Exception) {
67+
LOG.warn { "Failed to start LSP server" }
7068
}
7169
}
7270

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import com.intellij.openapi.components.Service
88
import com.intellij.openapi.components.service
99
import com.intellij.openapi.project.Project
1010
import com.intellij.openapi.util.Disposer
11+
import com.intellij.openapi.vfs.VirtualFileManager
12+
import com.intellij.openapi.vfs.newvfs.BulkFileListener
13+
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
14+
import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent
15+
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
1116
import kotlinx.coroutines.CoroutineScope
1217
import kotlinx.coroutines.launch
1318
import software.aws.toolkits.core.utils.getLogger
@@ -24,6 +29,18 @@ class ProjectContextController(private val project: Project, private val cs: Cor
2429
encoderServer.downloadArtifactsAndStartServer()
2530
}
2631
}
32+
33+
project.messageBus.connect(this).subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener {
34+
override fun after(events: MutableList<out VFileEvent>) {
35+
events.forEach {
36+
if (it is VFileCreateEvent) {
37+
println("create")
38+
} else if (it is VFileDeleteEvent) {
39+
println("delete")
40+
}
41+
}
42+
}
43+
})
2744
}
2845

2946
enum class IndexUpdateMode(val value: String) {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
package software.aws.toolkits.jetbrains.services.amazonq.project
5-
import com.intellij.openapi.fileEditor.FileEditorManager
5+
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
66
import com.intellij.openapi.fileEditor.FileEditorManagerListener
7-
import com.intellij.openapi.vfs.VirtualFile
8-
import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings
97

108
class ProjectContextEditorListener : FileEditorManagerListener {
11-
override fun fileClosed(source: FileEditorManager, file: VirtualFile) {
12-
if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) {
13-
ProjectContextController.getInstance(source.project).updateIndex(file.path)
14-
}
9+
override fun selectionChanged(event: FileEditorManagerEvent) {
10+
val project = event.manager.project
11+
val oldFile = event.oldFile ?: return
12+
13+
// TODO: should run under BGT
14+
ProjectContextController.getInstance(project).updateIndex(listOf(oldFile.path), "update")
1515
}
1616
}

0 commit comments

Comments
 (0)