Skip to content

fix(amazonq): Automatic start workspace indexing for new project open #4858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d718646
fix index cache not loaded
leigaol Jul 18, 2024
84a2810
upgrade lsp to 0.1.5
leigaol Aug 29, 2024
63d08b3
rm extra change
leigaol Aug 29, 2024
bf9570c
Merge branch 'main' of github.com:leigaol/aws-toolkit-jetbrains into …
leigaol Aug 29, 2024
4db7c3c
Merge branch 'main' into lsp015
leigaol Aug 30, 2024
2efd9ee
add lsp log file
leigaol Aug 30, 2024
2e6fa7e
Merge branch 'main' of github.com:leigaol/aws-toolkit-jetbrains into …
leigaol Sep 3, 2024
e6572ce
start lsp early
leigaol Sep 3, 2024
94e4edd
auto start indexing
leigaol Sep 3, 2024
185e3b4
rm changes
leigaol Sep 3, 2024
8673ae8
minimize changes
leigaol Sep 3, 2024
c8c6c7c
Merge branch 'main' into lsp_log
leigaol Sep 3, 2024
ada4764
use with timeout
leigaol Sep 3, 2024
9c91aa0
Merge branch 'lsp_log' of github.com:leigaol/aws-toolkit-jetbrains in…
leigaol Sep 3, 2024
e0c7a33
Merge branch 'main' into lsp_log
leigaol Sep 4, 2024
2813e6f
update based on feedback
leigaol Sep 4, 2024
04c8d1b
update scope
leigaol Sep 4, 2024
bde9fcb
rm unused imports
leigaol Sep 4, 2024
1000c1d
detect
leigaol Sep 5, 2024
c5f5195
Merge branch 'main' into lsp_log
leigaol Sep 5, 2024
d6a2f19
Merge branch 'main' into lsp_log
leigaol Sep 6, 2024
3daa33e
Merge branch 'main' into lsp_log
leigaol Sep 9, 2024
61fbc3f
Merge branch 'main' into lsp_log
leigaol Sep 10, 2024
986918f
resolve comments
leigaol Sep 10, 2024
1a87a52
Merge branch 'lsp_log' of github.com:leigaol/aws-toolkit-jetbrains in…
leigaol Sep 10, 2024
af30b33
move to start up activity
leigaol Sep 10, 2024
b3682c9
Merge branch 'main' into lsp_log
leigaol Sep 10, 2024
b3e605d
Merge branch 'main' into lsp_log
leigaol Sep 11, 2024
dd8a71f
add suspend
leigaol Sep 11, 2024
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
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Automatically start workspace indexing when new project is opened"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.options.ShowSettingsUtil
import com.intellij.psi.PsiDocumentManager
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.filter
Expand All @@ -29,19 +30,26 @@
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.delay
import kotlinx.coroutines.withTimeout

Check warning on line 36 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/ChatController.kt

View workflow job for this annotation

GitHub Actions / qodana

Unused import directive

Unused import directive
import migration.software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererModelConfigurator
import software.amazon.awssdk.services.codewhispererstreaming.model.UserIntent
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.info
import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.jetbrains.core.coroutines.EDT
import software.aws.toolkits.jetbrains.core.coroutines.disposableCoroutineScope

Check warning on line 43 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/ChatController.kt

View workflow job for this annotation

GitHub Actions / qodana

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.core.coroutines.projectCoroutineScope
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
import software.aws.toolkits.jetbrains.services.amazonq.auth.AuthController
import software.aws.toolkits.jetbrains.services.amazonq.auth.AuthNeededState
import software.aws.toolkits.jetbrains.services.amazonq.messages.MessagePublisher
import software.aws.toolkits.jetbrains.services.amazonq.onboarding.OnboardingPageInteraction
import software.aws.toolkits.jetbrains.services.amazonq.onboarding.OnboardingPageInteractionType
import software.aws.toolkits.jetbrains.services.amazonq.webview.FqnWebviewAdapter

Check warning on line 51 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/ChatController.kt

View workflow job for this annotation

GitHub Actions / qodana

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.amazonq.webview.FqnWebviewAdapter.Companion

Check warning on line 52 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/controller/ChatController.kt

View workflow job for this annotation

GitHub Actions / qodana

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererFeatureConfigService
import software.aws.toolkits.jetbrains.services.codewhisperer.settings.CodeWhispererConfigurable
import software.aws.toolkits.jetbrains.services.codewhisperer.settings.CodeWhispererSettings
Expand Down Expand Up @@ -82,6 +90,8 @@
import software.aws.toolkits.telemetry.CwsprChatCommandType
import java.time.Instant
import java.util.UUID
import java.time.Duration
import java.lang.management.ManagementFactory

class ChatController private constructor(
private val context: AmazonQAppInitContext,
Expand All @@ -103,6 +113,32 @@
authController = AuthController(),
)

init {
// 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
if (CodeWhispererSettings.getInstance().isProjectContextEnabled()) {
val scope = projectCoroutineScope(context.project)
scope.launch {
delay(60_000) // Wait for 60 seconds to get accurate CPU load for 1 min
try {
kotlinx.coroutines.time.withTimeout(Duration.ofMinutes(30)) {
while (true) {
val cpuUsage = ManagementFactory.getOperatingSystemMXBean().systemLoadAverage
if (cpuUsage > 0 && cpuUsage < 30) {
ProjectContextController.getInstance(project = context.project)
break
} else {
delay(60_000) // Wait for 60 seconds
}
}
}
} catch (e: TimeoutCancellationException) {
logger.warn(e) { "Failed to start LSP server" }
}
}
}
}

override suspend fun processClearQuickAction(message: IncomingCwcMessage.ClearChat) {
chatSessionStorage.deleteSession(message.tabId)
TelemetryHelper.recordTelemetryChatRunCommand(CwsprChatCommandType.Clear, startUrl = getStartUrl(context.project))
Expand Down
Loading