first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -1,38 +1,34 @@
|
||||
mod queries;
|
||||
use languages::Language;
|
||||
pub use queries::highlight_query::{ColorMap, TextSlice};
|
||||
|
||||
use std::{
|
||||
cell::{Ref, RefCell},
|
||||
collections::{HashMap, HashSet},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
|
||||
use arborium::tree_sitter::{InputEdit, Parser, Tree};
|
||||
use futures::stream::AbortHandle;
|
||||
use galaxyui::{color::ColorU, AppContext, Entity, ModelContext, WeakModelHandle};
|
||||
use queries::{
|
||||
highlight_query::HighlightQuery,
|
||||
indent_query::{indentation_delta, IndentDelta},
|
||||
};
|
||||
use languages::Language;
|
||||
use parking_lot::Mutex;
|
||||
use queries::highlight_query::HighlightQuery;
|
||||
pub use queries::highlight_query::{ColorMap, TextSlice};
|
||||
use queries::indent_query::{indentation_delta, IndentDelta};
|
||||
use rangemap::{RangeMap, RangeSet};
|
||||
use string_offset::{ByteOffset, CharOffset};
|
||||
|
||||
use galaxy_editor::{
|
||||
content::{
|
||||
buffer::{Buffer, BufferSnapshot},
|
||||
edit::PreciseDelta,
|
||||
text::IndentUnit,
|
||||
version::BufferVersion,
|
||||
},
|
||||
decoration::DecorationLayer,
|
||||
};
|
||||
use galaxyui::text::point::Point;
|
||||
use galaxy_editor::content::buffer::{Buffer, BufferSnapshot};
|
||||
use galaxy_editor::content::edit::PreciseDelta;
|
||||
use galaxy_editor::content::text::IndentUnit;
|
||||
use galaxy_editor::content::version::BufferVersion;
|
||||
use galaxy_editor::decoration::DecorationLayer;
|
||||
use galaxyui_core::color::ColorU;
|
||||
use galaxyui_core::text::point::Point;
|
||||
use galaxyui_core::{AppContext, Entity, ModelContext, WeakModelHandle};
|
||||
|
||||
const MAX_SYNTAX_TREES: usize = 3;
|
||||
|
||||
/// Maximum buffer size in bytes for which we attempt to parse a syntax tree.
|
||||
/// Files larger than this are skipped to avoid tree-sitter's super-linear
|
||||
/// memory growth on large inputs. See this tree-sitter issue:
|
||||
/// https://github.com/tree-sitter/tree-sitter/issues/222#issuecomment-435987441
|
||||
const MAX_PARSE_BYTES: usize = 2 * 1024 * 1024; // 2 MB
|
||||
|
||||
thread_local! {
|
||||
static PARSER: RefCell<Parser> = RefCell::new(Parser::new());
|
||||
}
|
||||
@@ -225,12 +221,17 @@ impl SyntaxTreeState {
|
||||
}
|
||||
|
||||
/// Re-parse the tree based on the updated tree and source content.
|
||||
///
|
||||
/// Returns `None` if the buffer exceeds [`MAX_PARSE_BYTES`].
|
||||
async fn parse_text(
|
||||
content: BufferSnapshot,
|
||||
old_tree: Option<Tree>,
|
||||
language: &Language,
|
||||
) -> Tree {
|
||||
PARSER.with(|parser| {
|
||||
) -> Option<Tree> {
|
||||
if content.byte_len() > MAX_PARSE_BYTES {
|
||||
return None;
|
||||
}
|
||||
Some(PARSER.with(|parser| {
|
||||
let mut parser = parser.borrow_mut();
|
||||
parser
|
||||
.set_language(&language.grammar)
|
||||
@@ -244,7 +245,7 @@ impl SyntaxTreeState {
|
||||
parser
|
||||
.parse_with_options(&mut callback, old_tree.as_ref(), None)
|
||||
.expect("Should succeed")
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
/// Translate an incoming edit delta into an InputEdit for incrementally updating the syntax
|
||||
@@ -355,6 +356,17 @@ impl DecorationLayer for SyntaxTreeState {
|
||||
new_tree
|
||||
},
|
||||
move |model, new_tree, ctx| {
|
||||
let Some(new_tree) = new_tree else {
|
||||
// Buffer exceeded MAX_PARSE_BYTES; skip updating the syntax tree, but
|
||||
// still emit DecorationUpdated so any delayed rendering is flushed
|
||||
let mut syntax_tree_lock = model.syntax_tree.lock();
|
||||
syntax_tree_lock.remove(&version);
|
||||
drop(syntax_tree_lock);
|
||||
model.invalidate_highlight_cache_for_version(version);
|
||||
// (the editor delays showing content until this event fires).
|
||||
ctx.emit(DecorationStateEvent::DecorationUpdated { version });
|
||||
return;
|
||||
};
|
||||
let mut syntax_tree_lock = model.syntax_tree.lock();
|
||||
model.invalidate_highlight_cache_for_version(version);
|
||||
if let Some(old_tree) = syntax_tree_lock.get_mut(&version) {
|
||||
|
||||
Reference in New Issue
Block a user