jcs090218 / flx-rs Goto Github PK
View Code? Open in Web Editor NEWRewrite emacs-flx in Rust for dynamic modules [maintainer=@jcs090218]
Home Page: https://crates.io/crates/flx-rs
License: MIT License
Rewrite emacs-flx in Rust for dynamic modules [maintainer=@jcs090218]
Home Page: https://crates.io/crates/flx-rs
License: MIT License
Original discussed in jcs-elpa/flx-rs#3
Here is another attempt to implement feature cache, see #3. I am not a rust expert, so I always look for improvement or better attempts.
(flx-score
"~/.emacs.d/straight/repos/orderless/orderless.el" "odrless")
(222 26 28 30 31 32 33 34)
(flx-score
"Code/Everyone/Xamarin/EMJavaBindings/EMJavaBindings/Additions/DrawableSoftReference.cs"
"odrless")
(138 1 62 63 68 69 70 85)
(flx-rs-score
"~/.emacs.d/straight/repos/orderless/orderless.el" "odrless")
(112 23 28 30 31 32 33 34)
(flx-rs-score
"Code/Everyone/Xamarin/EMJavaBindings/EMJavaBindings/Additions/DrawableSoftReference.cs"
"odrless")
(180 1 62 63 68 69 70 85)
A simple query like
#[test]
fn test() { score("Test", "d"); }
panics in find_best_match
when trying to find "d" in str_info
.
#[test]
fn test() { score("Testd", "d"); }
works since then str_info
built from the search string contains the query string char(s).
Seems like a pretty straight forward bug. But I didn't really dig enough into the code to know what the right fix would be.
We may want to expose a way somehow (maybe (Score( str: &str, query: &str, group-separator: &str))) so that the heatmap fn can boost the score of file/directory names.
pub fn get_heatmap_str(scores: &mut Vec<i32>, str: &str, group_separator: Option<char>) {
Original flx implements this through setting up the heatmap-fn on the file cache that's created.
https://github.com/lewang/flx/blob/e3b3f0533e44c5250ce73d728b59a7e96c692b5d/flx.el#L232
(defun flx-get-heatmap-file (filename)
"Return heatmap vector for filename."
(flx-get-heatmap-str filename ?/))
If we had the cache (and we're ok with not exposing the cache to elisp), we could add an extra param/boolean? to flx-rs-score like
(flx-rs-score x string USE-FILESYSTEM-HEATMAP-FN)
for it to autopick the right heatmap function in score.
If we have a cache and we are exposing that cache to elisp, it would probably suffice to have the elisp side pass the map over. I think this might be tricky though since the cache that's in elisp resembles more of an object than a true hashmap. (It's more like an object that contains a cache, a heatmap, and a heatmap-fn).
If we don't have the cache, it may make sense to allow the score function take in a group-separator string (or list of strings/not super sure if that makes sense).
e.g.
(flx-rs-score x string GROUP-SEPERATOR-CHAR)
Rust panics with
thread 'test_nok' panicked at 'attempt to multiply with overflow', src/search.rs:256:40
on longer strings. Maybe somewhat surprisingly, both the query as well as the search string seem to contribute to this panic.
#[test]
fn test_ok() {// base, works
let s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
score(s, "ABCDE");
}
#[test]
fn test_ok2() {// s increased by one, query reduced by one, still works
let s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890A";
score(s, "ABCD");
}
#[test]
fn test_panic() {// s increased by one, query left as is, panics
let s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890A";
score(s, "ABCDE");
}
I'm not sure whether only short strings are supported or this is a legit bug.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.