Support using ollama as an inline_completion_provider

This commit is contained in:
Oliver Azevedo Barnes 2025-06-29 13:29:45 -03:00
parent 047d515abf
commit 72d0b2402a
No known key found for this signature in database
9 changed files with 535 additions and 4 deletions

View file

@ -358,6 +358,41 @@ impl Render for InlineCompletionButton {
div().child(popover_menu.into_any_element())
}
EditPredictionProvider::Ollama => {
let enabled = self.editor_enabled.unwrap_or(false);
let icon = if enabled {
IconName::AiOllama
} else {
IconName::AiOllama // Could add disabled variant
};
let this = cx.entity().clone();
div().child(
PopoverMenu::new("ollama")
.menu(move |window, cx| {
Some(
this.update(cx, |this, cx| {
this.build_ollama_context_menu(window, cx)
}),
)
})
.trigger(
IconButton::new("ollama-completion", icon)
.icon_size(IconSize::Small)
.tooltip(|window, cx| {
Tooltip::for_action(
"Ollama Completion",
&ToggleMenu,
window,
cx,
)
}),
)
.with_handle(self.popover_menu_handle.clone()),
)
}
}
}
}
@ -805,6 +840,26 @@ impl InlineCompletionButton {
})
}
fn build_ollama_context_menu(
&self,
window: &mut Window,
cx: &mut Context<Self>,
) -> Entity<ContextMenu> {
let fs = self.fs.clone();
ContextMenu::build(window, cx, |menu, _window, _cx| {
menu.entry("Toggle Ollama Completions", None, {
let fs = fs.clone();
move |_window, cx| {
toggle_inline_completions_globally(fs.clone(), cx);
}
})
.entry("Ollama Settings...", None, |_window, cx| {
// TODO: Open Ollama-specific settings
cx.open_url("http://localhost:11434");
})
})
}
pub fn update_enabled(&mut self, editor: Entity<Editor>, cx: &mut Context<Self>) {
let editor = editor.read(cx);
let snapshot = editor.buffer().read(cx).snapshot(cx);