Skip to content

Commit

Permalink
chore: add info/bundler_bin
Browse files Browse the repository at this point in the history
  • Loading branch information
ttak0422 committed Jan 14, 2024
1 parent cc8406f commit e1f4118
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 6 deletions.
10 changes: 9 additions & 1 deletion bundler/src/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod config;
mod export;
mod merge;
pub use crate::bundle::config::{AfterOption, Bundle, Component, LoadOption, PluginId, PluginPath};
pub use crate::bundle::config::{
AfterOption, Bundle, Component, Info, LoadOption, PluginId, PluginPath,
};
pub use crate::bundle::export::{ExportOption, Exporter};
use crate::bundle::merge::merge_vector;
use crate::content;
Expand Down Expand Up @@ -236,6 +238,9 @@ pub fn bundle<'a>(config: &'a content::Content) -> Bundle<'a> {
components,
load_option,
after_option: mk_after_option(&config.after_option),
info: Info {
bundler_bin: config.info.bundler_bin.as_str(),
},
}
}

Expand All @@ -251,5 +256,8 @@ pub fn export<'a>(bundle: Bundle<'a>, export_option: ExportOption<'a>) -> Result
// after options
bundle.after_option.export_file(&export_option)?;

// info
bundle.info.export_file(&export_option)?;

Ok(())
}
5 changes: 5 additions & 0 deletions bundler/src/bundle/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub struct AfterOption<'a> {
pub ftplugin: HashMap<&'a str, &'a str>,
}

pub struct Info<'a> {
pub bundler_bin: &'a str,
}

pub type PluginId<'a> = &'a str;

pub type PluginPath<'a> = &'a str;
Expand All @@ -36,4 +40,5 @@ pub struct Bundle<'a> {
pub components: Vec<Component<'a>>,
pub load_option: LoadOption<'a>,
pub after_option: AfterOption<'a>,
pub info: Info<'a>,
}
19 changes: 15 additions & 4 deletions bundler/src/bundle/export.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::bundle::{AfterOption, Component, LoadOption};
use crate::constant::dir::{AFTER, FTPLUGIN, MODULES};
use crate::bundle::{AfterOption, Component, Info, LoadOption};
use crate::constant::dir::{AFTER, FTPLUGIN, INFO, MODULES};
use crate::constant::file::{
COMMAND_KEYS, DENOPS_CLIENTS, EVENT_KEYS, FILETYPE_KEYS, MODULE_KEYS, STARTUP_KEYS,
TIMER_CLIENTS,
BUNDLER_BIN, COMMAND_KEYS, DENOPS_CLIENTS, EVENT_KEYS, FILETYPE_KEYS, MODULE_KEYS,
STARTUP_KEYS, TIMER_CLIENTS,
};
use crate::constant::{self, dir};
use crate::util::file::create_file_with_dirs;
Expand Down Expand Up @@ -195,3 +195,14 @@ impl<'a> Exporter for AfterOption<'a> {
Ok(())
}
}

impl<'a> Exporter for Info<'a> {
fn export_file(self, opt: &ExportOption) -> Result<()> {
// bundler bin
let mut bundler_bin_file =
create_file_with_dirs(String::from(opt.root_dir) + "/" + INFO + "/" + BUNDLER_BIN)?;
write!(bundler_bin_file, "return \"{}\"", self.bundler_bin)?;

Ok(())
}
}
2 changes: 2 additions & 0 deletions bundler/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod dir {
pub static RTP: &str = "rtp";
pub static AFTER: &str = "after";
pub static FTPLUGIN: &str = "ftplugin";
pub static INFO: &str = "info";
}

pub mod file {
Expand All @@ -23,4 +24,5 @@ pub mod file {
pub static COMMAND_KEYS: &str = "command_keys";
pub static TIMER_CLIENTS: &str = "timer_clients";
pub static DENOPS_CLIENTS: &str = "denops_clients";
pub static BUNDLER_BIN: &str = "bundler_bin";
}
7 changes: 6 additions & 1 deletion bundler/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod id_table;

use crate::content::common::Target;
pub use crate::content::config::{
AfterOption, Content, EagerPlugin, LazyGroup, LazyPlugin, Package,
AfterOption, Content, EagerPlugin, LazyGroup, LazyPlugin, Package, Info
};
use crate::content::from_target::FromTarget;
// TODO: capsule
Expand Down Expand Up @@ -39,9 +39,14 @@ pub fn unpack(payload: payload::Payload) -> Content {
let id_table = IdTable::from(payload.meta.id_map);
let after_option = AfterOption::from(payload.config.after);

let info = Info {
bundler_bin: payload.meta.bundler_bin,
};

Content {
packages,
id_table,
after_option,
info,
}
}
5 changes: 5 additions & 0 deletions bundler/src/content/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ pub struct AfterOption {
pub ftplugin: HashMap<String, String>,
}

pub struct Info {
pub bundler_bin: String,
}

pub struct Content {
pub packages: Vec<Package>,
pub id_table: IdTable,
pub after_option: AfterOption,
pub info: Info,
}

fn mk_args_code(args: serde_json::Value, language: &Language) -> String {
Expand Down
1 change: 1 addition & 0 deletions bundler/src/payload/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct IdMapElement {
pub struct Meta {
pub target: Target,
pub extra_packages: Vec<String>,
pub bundler_bin: String,
pub id_map: Vec<IdMapElement>,
}

Expand Down
2 changes: 2 additions & 0 deletions nix/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ in {
meta = {
inherit extraPackages;
inherit (cfg) target;
# hack to escape GC.
bundlerBin = bundler;
idMap = map (p: {
package = p;
pluginId = p.pname;
Expand Down

0 comments on commit e1f4118

Please sign in to comment.