Skip to content

Commit

Permalink
feat(rename-suggestion): improve rename suggestion logic and add logg…
Browse files Browse the repository at this point in the history
…ing #132

This commit enhances the rename suggestion feature by introducing a more robust logic and adds logging capabilities. The changes include:

- Implementing `AutoDevStatusService` to notify the application status.
- Adding try-catch blocks to handle exceptions gracefully.
- Modifying the string flow collection and suggestion parsing logic.
- Updating the `LookupListener` to handle lookup cancellation.

These improvements ensure a smoother and more reliable rename suggestion experience, with better error handling and status updates.
  • Loading branch information
phodal committed Apr 3, 2024
1 parent c70fea8 commit 3324a79
Showing 1 changed file with 27 additions and 16 deletions.
Expand Up @@ -3,6 +3,8 @@ package cc.unitmesh.devti.practise
import cc.unitmesh.devti.AutoDevIcons
import cc.unitmesh.devti.llms.LlmFactory
import cc.unitmesh.devti.settings.coder.coderSetting
import cc.unitmesh.devti.statusbar.AutoDevStatus
import cc.unitmesh.devti.statusbar.AutoDevStatusService
import cc.unitmesh.devti.util.LLMCoroutineScope
import com.intellij.codeInsight.completion.InsertionContext
import com.intellij.codeInsight.completion.PrefixMatcher
Expand Down Expand Up @@ -58,30 +60,39 @@ class RenameLookupManagerListener(val project: Project) : LookupManagerListener


val stringJob = LLMCoroutineScope.scope(project).launch {
val stringFlow: Flow<String> = llm.stream(promptText, "", false)
val sb = StringBuilder()
stringFlow.collect {
sb.append(it)
}
AutoDevStatusService.notifyApplication(AutoDevStatus.InProgress)

val result = sb.toString()
logger.info("result: $result")
parseSuggestions(result)
.filter { it.isNotBlank() }
.map {
runReadAction {
lookupImpl.addItem(RenameLookupElement(it), PrefixMatcher.ALWAYS_TRUE)
}
try {
val stringFlow: Flow<String> = llm.stream(promptText, "", false)
val sb = StringBuilder()
stringFlow.collect {
sb.append(it)
}
val result = sb.toString()
logger.info("result: $result")
parseSuggestions(result)
.filter { it.isNotBlank() }
.map {
runReadAction {
lookupImpl.addItem(RenameLookupElement(it), PrefixMatcher.ALWAYS_TRUE)
}
}

runInEdt {
lookupImpl.isCalculating = false
lookupImpl.refreshUi(true, false)
runInEdt {
lookupImpl.isCalculating = false
lookupImpl.refreshUi(true, false)
}
} catch (e: Exception) {
AutoDevStatusService.notifyApplication(AutoDevStatus.Error)
logger.error("Error in RenameLookupManagerListener", e)
}

AutoDevStatusService.notifyApplication(AutoDevStatus.Ready)
}

lookupImpl.addLookupListener(object : LookupListener {
override fun lookupCanceled(event: LookupEvent) {
AutoDevStatusService.notifyApplication(AutoDevStatus.Ready)
stringJob.cancel()
}
})
Expand Down

0 comments on commit 3324a79

Please sign in to comment.