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 27 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 @@ -5,12 +5,25 @@

import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.waitForSmartMode
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.wm.ToolWindowManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.time.withTimeout
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.warn
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
import java.util.concurrent.atomic.AtomicBoolean

class AmazonQStartupActivity : ProjectActivity {
Expand All @@ -27,9 +40,43 @@
CodeWhispererExplorerActionManager.getInstance().setIsFirstRestartAfterQInstall(false)
}
}

startLsp(project)
if (runOnce.get()) return
emitUserState(project)
runOnce.set(true)
}

private fun startLsp(project: Project) {
// 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 scope = CoroutineScope(SupervisorJob())
val startLspIndexingDuration = Duration.ofMinutes(30)
scope.launch {
project.waitForSmartMode()

Check warning on line 57 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/startup/AmazonQStartupActivity.kt

View workflow job for this annotation

GitHub Actions / qodana

Unstable API Usage

'waitForSmartMode(com.intellij.openapi.project.Project, kotlin.coroutines.Continuation)' is marked unstable with @ApiStatus.Internal
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(e) { "Failed to start LSP server due to time out" }
} catch (e: Error) {
LOG.warn(e) { "Failed to start LSP server" }
}
}
}
}

companion object {

Check warning on line 79 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/startup/AmazonQStartupActivity.kt

View workflow job for this annotation

GitHub Actions / qodana

Companion object in extensions

Companion objects in IDE extension implementations may only contain a logger and constants
private val LOG = getLogger<AmazonQStartupActivity>()
}
}
Loading