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

Completion rewrite #120

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ed9eb1c
refactored structure and high level implementation
Feel-ix-343 Jun 1, 2024
7a6dac0
refactor into crates
Feel-ix-343 Jun 1, 2024
f58a699
refactored shell with high level implementation
Feel-ix-343 Jun 8, 2024
0dc82d7
refactor into crates
Feel-ix-343 Jun 10, 2024
a9bd6b5
rewrite again; this time work incrementally
Feel-ix-343 Jun 11, 2024
d395f66
support headings and indexed blocks
Feel-ix-343 Jun 13, 2024
e239d7d
take 50
Feel-ix-343 Jun 13, 2024
5a64d7e
support markdown links and some goodies
Feel-ix-343 Jun 14, 2024
faffada
documentation
Feel-ix-343 Jun 15, 2024
aba0ac4
documentation
Feel-ix-343 Jun 15, 2024
7b21c8f
Refactor into generic entity
Feel-ix-343 Jun 19, 2024
5181f8d
initial implementation of unnamed
Feel-ix-343 Jun 19, 2024
faf2cf3
inital impl of block compeltiosn
Feel-ix-343 Jun 20, 2024
aeebf41
Simplify the API
Feel-ix-343 Jun 21, 2024
055f6de
Refactored Querier
Feel-ix-343 Jun 21, 2024
e2a21f3
Refactored structure
Feel-ix-343 Jul 1, 2024
6899e62
implementing the commands api for simple named section links
Feel-ix-343 Jul 2, 2024
8bad053
Remove comments
Feel-ix-343 Jul 2, 2024
cadc4b8
Support aliases
Feel-ix-343 Jul 3, 2024
77f861f
Support aliases
Feel-ix-343 Jul 3, 2024
d7c82e0
remove allow
Feel-ix-343 Jul 3, 2024
0b45eb6
add allow map_flatten (because it's correct)
Feel-ix-343 Jul 3, 2024
f4283c5
refactor APIs and add support for block completions
Feel-ix-343 Jul 4, 2024
7f1ce7b
Don't give block completions for current line
Feel-ix-343 Jul 4, 2024
9eb8c0d
give documentation for block completions
Feel-ix-343 Jul 4, 2024
f1dfb72
clean up a little:
Feel-ix-343 Jul 4, 2024
f807e3c
settings for display text block links
Feel-ix-343 Jul 4, 2024
ac7bf9c
change mock setting value
Feel-ix-343 Jul 4, 2024
aea3500
support daily notes
Feel-ix-343 Jul 5, 2024
53d41e2
preselect
Feel-ix-343 Jul 6, 2024
8168c7e
some performance improvements
Feel-ix-343 Jul 6, 2024
900fdb5
Improve block completions performance
Feel-ix-343 Jul 7, 2024
9a0ec2f
support escaping brakets in block queries
Feel-ix-343 Jul 7, 2024
2f129cf
Don't match blocks twice
Feel-ix-343 Jul 7, 2024
a5a0f2b
settings for num block completions
Feel-ix-343 Jul 7, 2024
03c8a98
other stuff
Feel-ix-343 Jul 7, 2024
de89d08
Proper unresolved referenceable filter
Feel-ix-343 Jul 9, 2024
64438d2
Initial alias implementation
Feel-ix-343 Jul 9, 2024
f944b75
Optimize aliases
Feel-ix-343 Jul 9, 2024
bd18124
remove unstable feature uses
Feel-ix-343 Jul 9, 2024
6bf0c4d
update mock settings
Feel-ix-343 Jul 10, 2024
5029656
update flake to main
Feel-ix-343 Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions '
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use std::path::Path;

use nucleo_matcher::{pattern::{self, Normalization}, Matcher};
use vault::Vault;
use rayon::prelude::*;

pub(crate) struct Querier<'a> {
vault: &'a Vault
}

impl<'a> Querier<'a> {
fn new(vault: &'a Vault) -> Self {
Self { vault }
}
}

impl<'a> Querier<'a> {
fn query(&self, file_ref: FileRef) -> Vec<&'a Path> {
let paths = self.vault.md_files
.keys()
.map(|key| (key.file_name().unwrap().to_str().unwrap().to_string(), key))
.collect::<Vec<_>>();

let matched = fuzzy_match(&file_ref, paths);
matched.into_par_iter()
.map(|((_, path), _)| path as &Path)
.collect()
}
}

impl<'a> Matchable for (String, &'a PathBuf) {
fn match_string(&self) -> &str {
self.0.as_str()
}
}


pub trait Matchable {
fn match_string(&self) -> &str;
}


struct NucleoMatchable<T: Matchable>(T);
impl<T: Matchable> Deref for NucleoMatchable<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<T: Matchable> AsRef<str> for NucleoMatchable<T> {
fn as_ref(&self) -> &str {
self.match_string()
}
}



use crate::parser::{FileRef, Parser};
pub fn fuzzy_match<'a, T: Matchable>(
filter_text: &str,
items: impl IntoIterator<Item = T>,
) -> Vec<(T, u32)> {
let items = items.into_iter().map(NucleoMatchable);

let mut matcher = Matcher::new(nucleo_matcher::Config::DEFAULT);
let matches = pattern::Pattern::parse(
filter_text,
pattern::CaseMatching::Smart,
Normalization::Smart,
)
.match_list(items, &mut matcher);

matches
.into_iter()
.map(|(item, score)| (item.0, score))
.collect()
}
Loading