mirror of https://github.com/helix-editor/helix
Complete words from open buffers
parent
22b184b570
commit
451a427162
|
@ -127,7 +127,8 @@ const MIN_WORD_GRAPHEMES: usize = 3;
|
||||||
/// Maximum word length allowed (in chars)
|
/// Maximum word length allowed (in chars)
|
||||||
const MAX_WORD_LEN: usize = 50;
|
const MAX_WORD_LEN: usize = 50;
|
||||||
|
|
||||||
type Word = kstring::KString;
|
// TODO: choose or create a suitable small string type.
|
||||||
|
type Word = String;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct WordIndexInner {
|
struct WordIndexInner {
|
||||||
|
@ -149,11 +150,7 @@ impl WordIndexInner {
|
||||||
if let Some(rc) = self.words.get_mut(word.as_ref()) {
|
if let Some(rc) = self.words.get_mut(word.as_ref()) {
|
||||||
*rc = rc.saturating_add(1);
|
*rc = rc.saturating_add(1);
|
||||||
} else {
|
} else {
|
||||||
let word = match word {
|
self.words.insert(word.into_owned(), 1);
|
||||||
Cow::Owned(s) => Word::from_string(s),
|
|
||||||
Cow::Borrowed(s) => Word::from_ref(s),
|
|
||||||
};
|
|
||||||
self.words.insert(word, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,10 +180,7 @@ impl WordIndex {
|
||||||
let inner = self.inner.read();
|
let inner = self.inner.read();
|
||||||
let mut matches = fuzzy_match(pattern, inner.words(), false);
|
let mut matches = fuzzy_match(pattern, inner.words(), false);
|
||||||
matches.sort_unstable_by_key(|(_, score)| *score);
|
matches.sort_unstable_by_key(|(_, score)| *score);
|
||||||
matches
|
matches.into_iter().map(|(word, _)| word.clone()).collect()
|
||||||
.into_iter()
|
|
||||||
.map(|(word, _)| word.to_string())
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_document(&self, text: &Rope) {
|
fn add_document(&self, text: &Rope) {
|
||||||
|
@ -443,7 +437,7 @@ mod tests {
|
||||||
impl WordIndex {
|
impl WordIndex {
|
||||||
fn words(&self) -> HashSet<String> {
|
fn words(&self) -> HashSet<String> {
|
||||||
let inner = self.inner.read();
|
let inner = self.inner.read();
|
||||||
inner.words().map(|w| w.to_string()).collect()
|
inner.words().cloned().collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue