Skip to content

Commit fd2b607

Browse files
committed
Add action for toggling Auto FIM
Sometimes it's a bit annoying to get completions when moving though the source code. "llama.vim" has this by default, with auto fim enabled only in "insert mode". The default keyboard shortcut is "Ctrl+Shift+G".
1 parent 236cb41 commit fd2b607

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

llamaconstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace LlamaCpp::Internal::Constants {
66
const char LLAMACPP_USE_GLOBAL_SETTINGS[] = "LlamaCpp.UseGlobalSettings";
77

88
const char LLAMACPP_TOGGLE_ENABLE_DISABLE[] = "LlamaCpp.ToggleEnableDisable";
9+
const char LLAMACPP_TOGGLE_AUTOFIM[] = "LlamaCpp.ToggleAutoFIM";
910
const char LLAMACPP_REQUEST_SUGGESTION[] = "LlamaCpp.RequestSuggestion";
1011

1112
const char LLAMACPP_GENERAL_OPTIONS_ID[] = "LlamaCpp.General";

llamaplugin.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,34 @@ void LlamaPlugin::initialize()
123123
settings().apply();
124124
});
125125

126+
ActionBuilder toggleAutoFimAction(this, Constants::LLAMACPP_TOGGLE_AUTOFIM);
127+
toggleAutoFimAction.setText(Tr::tr("Toggle Auto FIM"));
128+
toggleAutoFimAction.setCheckable(true);
129+
toggleAutoFimAction.setChecked(settings().autoFim());
130+
toggleAutoFimAction.addOnTriggered(this, [this](bool checked) {
131+
qCInfo(llamaLog) << "Toggle Auto FIM" << checked;
132+
133+
settings().autoFim.setValue(checked);
134+
settings().apply();
135+
136+
if (checked) {
137+
// Show the llama.cpp text hint
138+
fim(-1, -1, false);
139+
} else {
140+
hideCompletionHint();
141+
}
142+
});
143+
toggleAutoFimAction.setDefaultKeySequence(Tr::tr("Ctrl+Shift+G"));
144+
126145
QAction *toggleAct = toggleAction.contextAction();
127146
QAction *requestAct = requestAction.contextAction();
128-
auto updateActions = [toggleAct, requestAct] {
147+
QAction *toogleAutoFimAct = toggleAutoFimAction.contextAction();
148+
auto updateActions = [toggleAct, requestAct, toogleAutoFimAct] {
129149
const bool enabled = settings().enableLlamaCpp();
130150
toggleAct->setToolTip(enabled ? Tr::tr("Disable llama.cpp.") : Tr::tr("Enable llama.cpp."));
131151
toggleAct->setChecked(enabled);
132152
requestAct->setEnabled(enabled);
153+
toogleAutoFimAct->setEnabled(enabled);
133154
};
134155

135156
settings().enableLlamaCpp.addOnChanged(this, updateActions);

0 commit comments

Comments
 (0)