Skip to content

Commit ce20d91

Browse files
committed
refactor(rename): handle exceptions and improve logging for rename suggestions #129
This commit enhances the RenameLookupManagerListener by adding exception handling and refactoring the code to extract a method for clearer and more maintainable code. The new method `doExecuteNameSuggest` is introduced to encapsulate the logic for adding rename suggestions to the lookup, ensuring that the suggestions are only added if the lookup is not disposed. This commit also improves logging by catching and logging exceptions that occur during the rename suggestion process, providing better visibility into potential issues.
1 parent 0d1ac46 commit ce20d91

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/kotlin/cc/unitmesh/devti/practise/RenameLookupManagerListener.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ class RenameLookupManagerListener(val project: Project) : LookupManagerListener
4444
"$originName is a badname. Please provide 5 better options name for follow code: \n```${element.language.displayName}\n${element.text}\n```\n\n1."
4545

4646

47+
try {
48+
doExecuteNameSuggest(promptText, lookupImpl)
49+
} catch (e: Exception) {
50+
logger.warn("Error in RenameLookupManagerListener", e)
51+
}
52+
}
53+
54+
private fun doExecuteNameSuggest(promptText: String, lookupImpl: LookupImpl) {
4755
val stringJob = LLMCoroutineScope.scope(project).launch {
4856
AutoDevStatusService.notifyApplication(AutoDevStatus.InProgress)
4957

@@ -56,12 +64,12 @@ class RenameLookupManagerListener(val project: Project) : LookupManagerListener
5664
val result = sb.toString()
5765
logger.info("result: $result")
5866
extractSuggestionsFromString(result).filter { it.isNotBlank() }.map {
59-
runReadAction {
60-
if (!lookupImpl.isLookupDisposed) {
61-
lookupImpl.addItem(CustomRenameLookupElement(it), PrefixMatcher.ALWAYS_TRUE)
62-
}
67+
runReadAction {
68+
if (!lookupImpl.isLookupDisposed) {
69+
lookupImpl.addItem(CustomRenameLookupElement(it), PrefixMatcher.ALWAYS_TRUE)
6370
}
6471
}
72+
}
6573

6674
runInEdt {
6775
lookupImpl.isCalculating = false

0 commit comments

Comments
 (0)