tags: Implement strip regex for docs processing

Co-Authored-By: Patrick Thomson <patrickt@users.noreply.github.com>
This commit is contained in:
Max Brunsfeld 2020-03-10 10:43:23 -07:00
parent 90cacca040
commit 157258d881
3 changed files with 64 additions and 16 deletions

View file

@ -81,6 +81,12 @@ impl<'a> From<tree_sitter_highlight::Error> for Error {
}
}
impl<'a> From<tree_sitter_tags::Error> for Error {
fn from(error: tree_sitter_tags::Error) -> Self {
Error::new(format!("{:?}", error))
}
}
impl From<serde_json::Error> for Error {
fn from(error: serde_json::Error) -> Self {
Error::new(error.to_string())

View file

@ -10,13 +10,13 @@ fn test_tags_javascript() {
((function_definition
name: (identifier) @name
body: (block . (expression_statement (string) @doc))) @function
(set! replace @doc "(^['\s]*)|(['\s]*$)"))
(set! strip @doc "(^['\s]*)|(['\s]*$)"))
(function_definition
name: (identifier) @name) @function
((class_definition
name: (identifier) @name
body: (block . (expression_statement (string) @doc))) @class
(set! replace @doc "(^['\s]*)|(['\s]*$)"))
(set! strip @doc "(^['\s]*)|(['\s]*$)"))
(class_definition
name: (identifier) @name) @class
(call
@ -31,14 +31,14 @@ fn test_tags_javascript() {
&tags_config,
br#"
class Customer:
"""
'''
Data about a customer
"""
'''
def age(self):
"""
'''
Get the customer's age
"""
'''
compute_age(self.id);
}
"#,
@ -53,6 +53,6 @@ fn test_tags_javascript() {
]
);
assert_eq!(tags[0].docs, Some("Data about a customer"));
assert_eq!(tags[1].docs, Some("Get the customer's age"));
assert_eq!(tags[0].docs.as_ref().unwrap(), "Data about a customer");
assert_eq!(tags[1].docs.as_ref().unwrap(), "Get the customer's age");
}