Support using ollama as an inline_completion_provider
This commit is contained in:
parent
047d515abf
commit
72d0b2402a
9 changed files with 535 additions and 4 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue