Merge remote-tracking branch 'origin/master' into add-tagger-error-detection
This commit is contained in:
commit
49be94f069
2 changed files with 22 additions and 6 deletions
|
|
@ -10,6 +10,8 @@ use tree_sitter::{
|
|||
};
|
||||
|
||||
const CANCELLATION_CHECK_INTERVAL: usize = 100;
|
||||
const BUFFER_HTML_RESERVE_CAPACITY: usize = 10 * 1024;
|
||||
const BUFFER_LINES_RESERVE_CAPACITY: usize = 1000;
|
||||
|
||||
/// Indicates which highlight should be applied to a region of source code.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
|
|
@ -884,11 +886,13 @@ where
|
|||
|
||||
impl HtmlRenderer {
|
||||
pub fn new() -> Self {
|
||||
HtmlRenderer {
|
||||
html: Vec::new(),
|
||||
line_offsets: vec![0],
|
||||
let mut result = HtmlRenderer {
|
||||
html: Vec::with_capacity(BUFFER_HTML_RESERVE_CAPACITY),
|
||||
line_offsets: Vec::with_capacity(BUFFER_LINES_RESERVE_CAPACITY),
|
||||
carriage_return_highlight: None,
|
||||
}
|
||||
};
|
||||
result.line_offsets.push(0);
|
||||
result
|
||||
}
|
||||
|
||||
pub fn set_carriage_return_highlight(&mut self, highlight: Option<Highlight>) {
|
||||
|
|
@ -896,6 +900,10 @@ impl HtmlRenderer {
|
|||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
self.html.truncate(BUFFER_HTML_RESERVE_CAPACITY);
|
||||
self.line_offsets.truncate(BUFFER_LINES_RESERVE_CAPACITY);
|
||||
self.html.shrink_to_fit();
|
||||
self.line_offsets.shrink_to_fit();
|
||||
self.html.clear();
|
||||
self.line_offsets.clear();
|
||||
self.line_offsets.push(0);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ use std::sync::atomic::AtomicUsize;
|
|||
use std::{fmt, slice, str};
|
||||
use tree_sitter::Language;
|
||||
|
||||
const BUFFER_TAGS_RESERVE_CAPACITY: usize = 100;
|
||||
const BUFFER_DOCS_RESERVE_CAPACITY: usize = 1024;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum TSTagsError {
|
||||
|
|
@ -117,8 +120,13 @@ pub extern "C" fn ts_tagger_tag(
|
|||
let scope_name = unsafe { unwrap(CStr::from_ptr(scope_name).to_str()) };
|
||||
|
||||
if let Some(config) = tagger.languages.get(scope_name) {
|
||||
buffer.tags.truncate(BUFFER_TAGS_RESERVE_CAPACITY);
|
||||
buffer.docs.truncate(BUFFER_DOCS_RESERVE_CAPACITY);
|
||||
buffer.tags.shrink_to_fit();
|
||||
buffer.docs.shrink_to_fit();
|
||||
buffer.tags.clear();
|
||||
buffer.docs.clear();
|
||||
|
||||
let source_code = unsafe { slice::from_raw_parts(source_code, source_code_len as usize) };
|
||||
let cancellation_flag = unsafe { cancellation_flag.as_ref() };
|
||||
|
||||
|
|
@ -186,8 +194,8 @@ pub extern "C" fn ts_tagger_tag(
|
|||
pub extern "C" fn ts_tags_buffer_new() -> *mut TSTagsBuffer {
|
||||
Box::into_raw(Box::new(TSTagsBuffer {
|
||||
context: TagsContext::new(),
|
||||
tags: Vec::with_capacity(64),
|
||||
docs: Vec::with_capacity(64),
|
||||
tags: Vec::with_capacity(BUFFER_TAGS_RESERVE_CAPACITY),
|
||||
docs: Vec::with_capacity(BUFFER_DOCS_RESERVE_CAPACITY),
|
||||
errors_present: false,
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue