feat: add rust prompt rewrite support (#296)
parent
4388fd0050
commit
be5fe0d737
|
|
@ -2851,6 +2851,7 @@ dependencies = [
|
||||||
"tracing-test",
|
"tracing-test",
|
||||||
"tree-sitter-javascript",
|
"tree-sitter-javascript",
|
||||||
"tree-sitter-python",
|
"tree-sitter-python",
|
||||||
|
"tree-sitter-rust",
|
||||||
"tree-sitter-tags",
|
"tree-sitter-tags",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
@ -3528,6 +3529,16 @@ dependencies = [
|
||||||
"tree-sitter",
|
"tree-sitter",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tree-sitter-rust"
|
||||||
|
version = "0.20.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "797842733e252dc11ae5d403a18060bf337b822fc2ae5ddfaa6ff4d9cc20bda6"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"tree-sitter",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-sitter-tags"
|
name = "tree-sitter-tags"
|
||||||
version = "0.20.2"
|
version = "0.20.2"
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ serde = { workspace = true }
|
||||||
serde-jsonlines = { workspace = true }
|
serde-jsonlines = { workspace = true }
|
||||||
file-rotate = "0.7.5"
|
file-rotate = "0.7.5"
|
||||||
tree-sitter-python = "0.20.2"
|
tree-sitter-python = "0.20.2"
|
||||||
|
tree-sitter-rust = "0.20.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
temp_testdir = "0.2"
|
temp_testdir = "0.2"
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,8 @@ lazy_static! {
|
||||||
map
|
map
|
||||||
};
|
};
|
||||||
static ref LANGUAGE_TAGS: HashMap<&'static str, TagsConfigurationSync> = {
|
static ref LANGUAGE_TAGS: HashMap<&'static str, TagsConfigurationSync> = {
|
||||||
HashMap::from([(
|
HashMap::from([
|
||||||
|
(
|
||||||
"python",
|
"python",
|
||||||
TagsConfigurationSync(
|
TagsConfigurationSync(
|
||||||
TagsConfiguration::new(
|
TagsConfiguration::new(
|
||||||
|
|
@ -234,6 +235,18 @@ lazy_static! {
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
),
|
),
|
||||||
)])
|
),
|
||||||
|
(
|
||||||
|
"rust",
|
||||||
|
TagsConfigurationSync(
|
||||||
|
TagsConfiguration::new(
|
||||||
|
tree_sitter_rust::language(),
|
||||||
|
tree_sitter_rust::TAGGING_QUERY,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,8 +155,12 @@ fn collect_snippets(index: &IndexState, language: &str, text: &str) -> Vec<Strin
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sanitize_text(text: &str) -> String {
|
fn sanitize_text(text: &str) -> String {
|
||||||
let x = text.replace(|c: char| !c.is_ascii_digit() && !c.is_alphabetic(), " ");
|
// Only keep [a-zA-Z0-9-_]
|
||||||
let tokens: Vec<&str> = x.split(' ').collect();
|
let x = text.replace(
|
||||||
|
|c: char| !c.is_ascii_digit() && !c.is_alphabetic() && c != '_' && c != '-',
|
||||||
|
" ",
|
||||||
|
);
|
||||||
|
let tokens: Vec<&str> = x.split(' ').filter(|x| x.len() > 5).collect();
|
||||||
tokens.join(" ")
|
tokens.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -182,7 +186,7 @@ impl IndexState {
|
||||||
.schema()
|
.schema()
|
||||||
.get_field("body")
|
.get_field("body")
|
||||||
.ok_or(anyhow!("Index doesn't have required field"))?;
|
.ok_or(anyhow!("Index doesn't have required field"))?;
|
||||||
let query_parser = QueryParser::for_index(&index, vec![field_name]);
|
let query_parser = QueryParser::for_index(&index, vec![field_body]);
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
searcher: reader.searcher(),
|
searcher: reader.searcher(),
|
||||||
query_parser,
|
query_parser,
|
||||||
|
|
@ -194,5 +198,5 @@ impl IndexState {
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref LANGUAGE_LINE_COMMENT_CHAR: HashMap<&'static str, &'static str> =
|
static ref LANGUAGE_LINE_COMMENT_CHAR: HashMap<&'static str, &'static str> =
|
||||||
HashMap::from([("python", "#")]);
|
HashMap::from([("python", "#"), ("rust", "//"),]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue