Skip to content

Commit

Permalink
fix: add additional whitespace to match tokens that combining space a…
Browse files Browse the repository at this point in the history
…nd li… (TabbyML#270)

* fix: add additional whitespace to match tokens that combining space and line break

* fix lint
  • Loading branch information
wsxiaoys authored Jun 25, 2023
1 parent af517fb commit 9ca1f7e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
1 change: 0 additions & 1 deletion crates/tabby-scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub async fn scheduler(now: bool) -> Result<()> {
let ret = dataset::create_dataset(&config);
if let Err(err) = ret {
error!("Failed to build dataset, err: '{}'", err);
return;
}
};

Expand Down
39 changes: 35 additions & 4 deletions crates/tabby/src/serve/completions/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,37 @@ use std::collections::HashMap;
use lazy_static::lazy_static;

lazy_static! {
static ref DEFAULT: Vec<&'static str> = vec!("\n\n");
static ref DEFAULT: Vec<&'static str> = vec![
"\n\n",
"\n\n ",
"\n\n ",
"\n\n ",
"\n\n ",
"\n\n ",
"\n\n ",
"\n\n ",
"\n\n",
"\n\n\t",
"\n\n\t\t",
"\n\n\t\t\t",
"\n\n\t\t\t\t",
"\n\n\t\t\t\t\t",
"\n\n\t\t\t\t\t\t",
"\n\n\t\t\t\t\t\t\t",
];
static ref LANGUAGES: HashMap<&'static str, Vec<&'static str>> = {
let mut map = HashMap::new();
map.insert("python", vec!["\n\n", "\ndef", "\n#", "\nfrom", "\nclass"]);
map.insert(
"python",
vec!["\ndef", "\n#", "\nfrom", "\nclass"].with_default(),
);
map.insert(
"javascript",
vec!["\n\n", "\nfunction", "\n//", "\nimport", "\nclass"],
vec!["\nfunction", "\n//", "\nimport", "\nclass"],
);
map.insert(
"typescript",
vec![
"\n\n",
"\nfunction",
"\n//",
"\nimport",
Expand All @@ -27,6 +46,18 @@ lazy_static! {
};
}

trait WithDefault {
fn with_default(self) -> Self;
}

impl WithDefault for Vec<&'static str> {
fn with_default(mut self) -> Self {
let mut x = DEFAULT.clone();
self.append(&mut x);
self
}
}

pub fn get_stop_words(language: &str) -> &'static Vec<&'static str> {
LANGUAGES.get(language).unwrap_or(&DEFAULT)
}

0 comments on commit 9ca1f7e

Please sign in to comment.