Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zero-copy #79

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 59 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ name = "lemmy-help"
required-features = ["cli"]

[dependencies]
chumsky = { version = "0.8.0", default-features = false }
chumsky = { version = "1.0.0-alpha.3", default-features = false }
textwrap = { version = "0.16.0", default-features = false, optional = true }
comfy-table = { version = "6.1.2", default-features = false, optional = true }
lexopt = { version = "0.2.1", default-features = false, optional = true }
comfy-table = { version = "6.1.4", default-features = false, optional = true }
lexopt = { version = "0.3.0", default-features = false, optional = true }

[features]
vimdoc = ["dep:textwrap", "dep:comfy-table"]
Expand Down
5 changes: 5 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cargo rr -- -fact \
~/Code/Comment.nvim/lua/Comment/{init.lua,config.lua} ~/Code/Comment.nvim/plugin/Comment.lua \
~/Code/Comment.nvim/lua/Comment/{api.lua,ft.lua,utils.lua,opfunc.lua,extra.lua} > ~/Code/Comment.nvim/doc/Comment.txt
31 changes: 14 additions & 17 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use lemmy_help::{vimdoc::VimDoc, FromEmmy, Layout, LemmyHelp, Settings};
use lemmy_help::{parser, vimdoc::VimDoc, FromEmmy, Layout, Settings};

use lexopt::{
Arg::{Long, Short, Value},
Parser, ValueExt,
};
use std::{ffi::OsString, fs::read_to_string, path::PathBuf, str::FromStr};
use std::{fs::read_to_string, path::PathBuf, str::FromStr};

pub const NAME: &str = env!("CARGO_PKG_NAME");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -43,16 +43,11 @@ impl Cli {
std::process::exit(0);
}
Short('l') | Long("layout") => {
let layout = parser.value()?;
let Some(l) = layout.to_str() else {
return Err(lexopt::Error::MissingValue {
option: Some("layout".into()),
});
};
let layout = parser.value()?.string()?;
c.settings.layout =
Layout::from_str(l).map_err(|_| lexopt::Error::UnexpectedValue {
Layout::from_str(&layout).map_err(|_| lexopt::Error::UnexpectedValue {
option: "layout".into(),
value: l.into(),
value: layout.into(),
})?;
}
Short('i') | Long("indent") => {
Expand All @@ -67,10 +62,9 @@ impl Cli {
Value(val) => {
let file = PathBuf::from(&val);
if !file.is_file() {
return Err(lexopt::Error::UnexpectedArgument(OsString::from(format!(
"{} is not a file!",
file.display()
))));
return Err(lexopt::Error::UnexpectedArgument(
format!("{} is not a file!", file.display()).into(),
));
}
c.files.push(file)
}
Expand All @@ -82,14 +76,17 @@ impl Cli {
}

pub fn run(self) {
let mut lemmy = LemmyHelp::new();
let mut help_doc = String::new();

// FIXME: toc entries
for f in self.files {
let source = read_to_string(f).unwrap();
lemmy.for_help(&source, &self.settings).unwrap();
let ast = parser(&source);
let doc = VimDoc::from_emmy(&ast, &self.settings);
help_doc.push_str(&doc.to_string());
}

print!("{}", VimDoc::from_emmy(&lemmy, &self.settings));
print!("{help_doc}");

if self.modeline {
println!("vim:tw=78:ts=8:noet:ft=help:norl:");
Expand Down