Skip to content

Commit 28688c7

Browse files
committed
refactor(language-completion): extract completion candidate creation to function
The change extracts the creation of command completion candidates into a separate private function `createCommandCompletionCandidate`. This refactoring improves code readability and reusability by reducing duplication within the `BuiltinCommandCompletion` provider. Additionally, it updates the `hasCompletion` flag for the "browse" command to `true`.
1 parent 3af06a2 commit 28688c7

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/dataprovider/BuiltinCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum class BuiltinCommand(
4545
"browse",
4646
"Get the content of a given URL",
4747
AllIcons.Toolwindows.WebToolWindow,
48-
false,
48+
true,
4949
true
5050
),
5151
Refactor(

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/provider/BuiltinCommandCompletion.kt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,28 @@ class BuiltinCommandCompletion : CompletionProvider<CompletionParameters>() {
1313
result: CompletionResultSet,
1414
) {
1515
BuiltinCommand.all().forEach {
16-
result.addElement(
17-
PrioritizedLookupElement.withPriority(
18-
LookupElementBuilder.create(it.commandName)
19-
.withIcon(it.icon)
20-
.withTypeText(it.description, true)
21-
.withInsertHandler { context, _ ->
22-
if (!it.hasCompletion) return@withInsertHandler
16+
val lookupElement = createCommandCompletionCandidate(it)
2317

24-
context.document.insertString(context.tailOffset, ":")
25-
context.editor.caretModel.moveCaretRelatively(1, 0, false, false, false)
26-
27-
val editor = context.editor
28-
AutoPopupController.getInstance(editor.project!!).scheduleAutoPopup(editor)
29-
},
30-
// before custom
31-
99.0
32-
)
33-
)
18+
result.addElement(lookupElement)
3419
}
3520
}
21+
22+
private fun createCommandCompletionCandidate(it: BuiltinCommand) =
23+
PrioritizedLookupElement.withPriority(
24+
LookupElementBuilder.create(it.commandName)
25+
.withIcon(it.icon)
26+
.withTypeText(it.description, true)
27+
.withInsertHandler { context, _ ->
28+
if (!it.hasCompletion) return@withInsertHandler
29+
30+
context.document.insertString(context.tailOffset, ":")
31+
context.editor.caretModel.moveCaretRelatively(1, 0, false, false, false)
32+
33+
val editor = context.editor
34+
AutoPopupController.getInstance(editor.project!!).scheduleAutoPopup(editor)
35+
},
36+
// before custom
37+
99.0
38+
)
3639
}
3740

0 commit comments

Comments
 (0)