Added dictionary plugin and switched from a Mutex
to an RwLock
in the anyrun_plugin
crate
This change means that `get_matches` no longer has access to a mutable version of the state of the plugin. A redesign is needed to allow for this if needed.
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
use abi_stable::std_types::{ROption, RString, RVec};
|
||||
use anyrun_plugin::{anyrun_interface::HandleResult, plugin, Match, PluginInfo};
|
||||
use rink_core::{ast, date, gnu_units, CURRENCY_FILE};
|
||||
|
||||
fn init(_config_dir: RString) -> rink_core::Context {
|
||||
let mut ctx = rink_core::Context::new();
|
||||
fn init(_config_dir: RString) {
|
||||
// Currently broken due to limitations with the declarative macro anyrun_plugin crate.
|
||||
// For any plugin that does something relatively time intensive like fetching something
|
||||
// from the internet, the internal Mutex would block making requests way too long when typed rapidly.
|
||||
|
||||
// TODO: Redesign the anyrun_plugin crate to allow for both mutable and non mutable borrows of the
|
||||
// shared data for functions
|
||||
|
||||
/*let mut ctx = rink_core::Context::new();
|
||||
|
||||
let units = gnu_units::parse_str(rink_core::DEFAULT_FILE.unwrap());
|
||||
let dates = date::parse_datefile(rink_core::DATES_FILE);
|
||||
@@ -28,7 +34,7 @@ fn init(_config_dir: RString) -> rink_core::Context {
|
||||
});
|
||||
ctx.load_dates(dates);
|
||||
|
||||
ctx
|
||||
ctx*/
|
||||
}
|
||||
|
||||
fn info() -> PluginInfo {
|
||||
@@ -38,8 +44,11 @@ fn info() -> PluginInfo {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_matches(input: RString, ctx: &mut rink_core::Context) -> RVec<Match> {
|
||||
match rink_core::one_line(ctx, &input) {
|
||||
fn get_matches(input: RString, _: &()) -> RVec<Match> {
|
||||
match rink_core::one_line(
|
||||
&mut rink_core::simple_context().expect("Failed to create rink context"),
|
||||
&input,
|
||||
) {
|
||||
Ok(result) => vec![Match {
|
||||
title: result.into(),
|
||||
description: ROption::RNone,
|
||||
@@ -52,8 +61,8 @@ fn get_matches(input: RString, ctx: &mut rink_core::Context) -> RVec<Match> {
|
||||
}
|
||||
}
|
||||
|
||||
fn handler(selection: Match, _: &mut rink_core::Context) -> HandleResult {
|
||||
fn handler(selection: Match, _: &mut ()) -> HandleResult {
|
||||
HandleResult::Copy(selection.title.into_bytes())
|
||||
}
|
||||
|
||||
plugin!(init, info, get_matches, handler, rink_core::Context);
|
||||
plugin!(init, info, get_matches, handler, ());
|
||||
|
Reference in New Issue
Block a user