Return an iterator-bool tuple instead of just an iterator.

This commit is contained in:
Patrick Thomson 2020-08-05 11:18:59 -04:00
parent 1a571ae208
commit 5a52dc2cd7
3 changed files with 9 additions and 5 deletions

View file

@ -53,7 +53,8 @@ pub fn generate_tags(
let source = fs::read(path)?;
let t0 = Instant::now();
for tag in context.generate_tags(tags_config, &source, Some(&cancellation_flag))? {
let (tagged, _) = context.generate_tags(tags_config, &source, Some(&cancellation_flag))?;
for tag in tagged {
let tag = tag?;
if !quiet {
write!(

View file

@ -126,7 +126,10 @@ pub extern "C" fn ts_tagger_tag(
.context
.generate_tags(config, source_code, cancellation_flag)
{
Ok(tags) => tags,
Ok((tags, found_error)) => {
buffer.errors_present = found_error;
tags
}
Err(e) => {
return match e {
Error::InvalidLanguage => TSTagsError::InvalidLanguage,

View file

@ -255,7 +255,7 @@ impl TagsContext {
config: &'a TagsConfiguration,
source: &'a [u8],
cancellation_flag: Option<&'a AtomicUsize>,
) -> Result<impl Iterator<Item = Result<Tag, Error>> + 'a, Error> {
) -> Result<(impl Iterator<Item = Result<Tag, Error>> + 'a, bool), Error> {
self.parser
.set_language(config.language)
.map_err(|_| Error::InvalidLanguage)?;
@ -271,7 +271,7 @@ impl TagsContext {
.matches(&config.query, tree_ref.root_node(), move |node| {
&source[node.byte_range()]
});
Ok(TagsIter {
Ok((TagsIter {
_tree: tree,
matches,
source,
@ -285,7 +285,7 @@ impl TagsContext {
inherits: false,
local_defs: Vec::new(),
}],
})
}, tree_ref.root_node().has_error()))
}
}