mirror of https://github.com/lapce/lapce.git
clean up of old syntax code
This commit is contained in:
parent
fcac68412d
commit
955f99df11
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,8 @@
|
|||
use std::{collections::HashSet, path::Path};
|
||||
|
||||
use tree_sitter::{Parser, Query, TreeCursor};
|
||||
use tree_sitter::{Parser, TreeCursor};
|
||||
|
||||
use crate::style::{HighlightConfiguration, SCOPES};
|
||||
use crate::style::HighlightConfiguration;
|
||||
|
||||
const RUST_CODE_LENS_LIST: &[&str] =
|
||||
&["source_file", "impl_item", "trait_item", "declaration_list"];
|
||||
|
@ -59,9 +59,8 @@ pub(crate) fn new_highlight_config(&self) -> HighlightConfiguration {
|
|||
LapceLanguage::Rust => tree_sitter_rust::HIGHLIGHT_QUERY,
|
||||
LapceLanguage::Go => tree_sitter_go::HIGHLIGHT_QUERY,
|
||||
};
|
||||
let mut config =
|
||||
HighlightConfiguration::new(language, query, "", "").unwrap();
|
||||
config
|
||||
|
||||
HighlightConfiguration::new(language, query, "", "").unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn walk_tree(
|
||||
|
|
|
@ -32,7 +32,6 @@ pub struct LensLeaf {
|
|||
|
||||
pub struct LensIter<'a> {
|
||||
cursor: Cursor<'a, LensInfo>,
|
||||
ix: usize,
|
||||
end: usize,
|
||||
}
|
||||
|
||||
|
@ -64,7 +63,6 @@ pub fn height_of_line(&self, line: usize) -> usize {
|
|||
pub fn iter(&self) -> LensIter {
|
||||
LensIter {
|
||||
cursor: Cursor::new(&self.0, 0),
|
||||
ix: 0,
|
||||
end: self.len(),
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +72,6 @@ pub fn iter_chunks<I: IntervalBounds>(&self, range: I) -> LensIter {
|
|||
|
||||
LensIter {
|
||||
cursor: Cursor::new(&self.0, start),
|
||||
ix: 0,
|
||||
end,
|
||||
}
|
||||
}
|
||||
|
@ -199,11 +196,11 @@ fn from_base_units(l: &LensLeaf, in_base_units: usize) -> usize {
|
|||
accum
|
||||
}
|
||||
|
||||
fn is_boundary(l: &LensLeaf, offset: usize) -> bool {
|
||||
fn is_boundary(_l: &LensLeaf, _offset: usize) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn prev(l: &LensLeaf, offset: usize) -> Option<usize> {
|
||||
fn prev(_l: &LensLeaf, offset: usize) -> Option<usize> {
|
||||
if offset == 0 {
|
||||
None
|
||||
} else {
|
||||
|
|
|
@ -182,7 +182,6 @@ pub fn highlight<'a>(
|
|||
tree.clone(),
|
||||
source,
|
||||
self,
|
||||
cancellation_flag,
|
||||
&mut injection_callback,
|
||||
config,
|
||||
0,
|
||||
|
@ -387,7 +386,6 @@ fn new<F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a>(
|
|||
tree: Tree,
|
||||
source: &'a [u8],
|
||||
highlighter: &mut Highlighter,
|
||||
cancellation_flag: Option<&'a AtomicUsize>,
|
||||
injection_callback: &mut F,
|
||||
mut config: &'a HighlightConfiguration,
|
||||
mut depth: usize,
|
||||
|
@ -779,7 +777,6 @@ fn next(&mut self) -> Option<Self::Item> {
|
|||
self.tree.clone(),
|
||||
self.source,
|
||||
self.highlighter,
|
||||
self.cancellation_flag,
|
||||
&mut self.injection_callback,
|
||||
config,
|
||||
self.layers[0].depth + 1,
|
||||
|
@ -817,14 +814,11 @@ fn next(&mut self) -> Option<Self::Item> {
|
|||
for prop in
|
||||
layer.config.query.property_settings(match_.pattern_index)
|
||||
{
|
||||
match prop.key.as_ref() {
|
||||
"local.scope-inherits" => {
|
||||
scope.inherits = prop
|
||||
.value
|
||||
.as_ref()
|
||||
.map_or(true, |r| r.as_ref() == "true");
|
||||
}
|
||||
_ => {}
|
||||
if prop.key.as_ref() == "local.scope-inherits" {
|
||||
scope.inherits = prop
|
||||
.value
|
||||
.as_ref()
|
||||
.map_or(true, |r| r.as_ref() == "true");
|
||||
}
|
||||
}
|
||||
layer.scope_stack.push(scope);
|
||||
|
@ -1154,6 +1148,12 @@ fn add_text<'a, F>(
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for HtmlRenderer {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
fn injection_for_match<'a>(
|
||||
config: &HighlightConfiguration,
|
||||
query: &'a Query,
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
cell::RefCell,
|
||||
collections::{HashMap, HashSet},
|
||||
path::Path,
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use itertools::Itertools;
|
||||
use tree_sitter::{Parser, Point, Query, QueryCursor, Tree};
|
||||
use tree_sitter::{Node, Parser, Point, Tree};
|
||||
use xi_rope::{
|
||||
spans::{Spans, SpansBuilder},
|
||||
Interval, Rope, RopeDelta,
|
||||
|
@ -16,7 +15,7 @@
|
|||
use crate::{
|
||||
language::LapceLanguage,
|
||||
lens::{Lens, LensBuilder},
|
||||
style::{Highlight, HighlightEvent, Highlighter, LineStyle, Style, SCOPES},
|
||||
style::{Highlight, HighlightEvent, Highlighter, Style, SCOPES},
|
||||
};
|
||||
|
||||
thread_local! {
|
||||
|
@ -34,7 +33,7 @@ pub struct Syntax {
|
|||
pub normal_lines: Vec<usize>,
|
||||
pub line_height: usize,
|
||||
pub lens_height: usize,
|
||||
pub styles: Option<Spans<Style>>,
|
||||
pub styles: Option<Arc<Spans<Style>>>,
|
||||
}
|
||||
|
||||
impl Syntax {
|
||||
|
@ -188,7 +187,7 @@ fn traverse(point: Point, text: &str) -> Point {
|
|||
}
|
||||
highlights.build()
|
||||
});
|
||||
Some(styles)
|
||||
Some(Arc::new(styles))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -255,6 +254,99 @@ pub fn lens_from_normal_lines(
|
|||
}
|
||||
builder.build()
|
||||
}
|
||||
|
||||
pub fn find_matching_pair(&self, offset: usize) -> Option<usize> {
|
||||
let tree = self.tree.as_ref()?;
|
||||
let node = tree
|
||||
.root_node()
|
||||
.descendant_for_byte_range(offset, offset + 1)?;
|
||||
let mut chars = node.kind().chars();
|
||||
let char = chars.next()?;
|
||||
let char = matching_char(char)?;
|
||||
let tag = &char.to_string();
|
||||
|
||||
if let Some(offset) = self.find_tag_in_siblings(node, true, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
if let Some(offset) = self.find_tag_in_siblings(node, false, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn find_tag(
|
||||
&self,
|
||||
offset: usize,
|
||||
previous: bool,
|
||||
tag: &str,
|
||||
) -> Option<usize> {
|
||||
let tree = self.tree.as_ref()?;
|
||||
let node = tree
|
||||
.root_node()
|
||||
.descendant_for_byte_range(offset, offset + 1)?;
|
||||
|
||||
if let Some(offset) = self.find_tag_in_siblings(node, previous, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
|
||||
if let Some(offset) = self.find_tag_in_children(node, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
|
||||
let mut node = node;
|
||||
while let Some(parent) = node.parent() {
|
||||
if let Some(offset) = self.find_tag_in_siblings(parent, previous, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
node = parent;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn find_tag_in_siblings(
|
||||
&self,
|
||||
node: Node,
|
||||
previous: bool,
|
||||
tag: &str,
|
||||
) -> Option<usize> {
|
||||
let mut node = node;
|
||||
while let Some(sibling) = if previous {
|
||||
node.prev_sibling()
|
||||
} else {
|
||||
node.next_sibling()
|
||||
} {
|
||||
if sibling.kind() == tag {
|
||||
let offset = sibling.start_byte();
|
||||
return Some(offset);
|
||||
}
|
||||
node = sibling;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn find_tag_in_children(&self, node: Node, tag: &str) -> Option<usize> {
|
||||
for i in 0..node.child_count() {
|
||||
if let Some(child) = node.child(i) {
|
||||
if child.kind() == tag {
|
||||
let offset = child.start_byte();
|
||||
return Some(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn matching_char(c: char) -> Option<char> {
|
||||
Some(match c {
|
||||
'{' => '}',
|
||||
'}' => '{',
|
||||
'(' => ')',
|
||||
')' => '(',
|
||||
'[' => ']',
|
||||
']' => '[',
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -34,11 +34,6 @@ jsonrpc-lite = "0.5.0"
|
|||
bit-vec = "0.5.0"
|
||||
parking_lot = { version = "0.11.0", features = ["deadlock_detection"] }
|
||||
include_dir = "0.6.0"
|
||||
tree-sitter = "0.20.2"
|
||||
tree-sitter-highlight = "0.20.1"
|
||||
tree-sitter-rust = "0.20.0"
|
||||
tree-sitter-go = "0.19.1"
|
||||
tree-sitter-javascript = "0.20.0"
|
||||
anyhow = "1.0.32"
|
||||
strum = "0.19"
|
||||
strum_macros = "0.19"
|
||||
|
@ -48,7 +43,6 @@ serde_json = "1.0"
|
|||
notify = "5.0.0-pre.13"
|
||||
xi-rope = { git = "https://github.com/lapce/xi-editor", features = ["serde"] }
|
||||
xi-unicode = "0.3.0"
|
||||
fzyr = "0.1.2"
|
||||
fuzzy-matcher = "0.3.7"
|
||||
uuid = { version = "0.7.4", features = ["v4"] }
|
||||
lsp-types = { version = "0.89.2", features = ["proposed"] }
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
use crossbeam_channel::Sender;
|
||||
use druid::PaintCtx;
|
||||
use druid::{piet::PietTextLayout, Vec2};
|
||||
use druid::{
|
||||
piet::{PietText, Text, TextAttribute, TextLayoutBuilder},
|
||||
piet::{Text, TextAttribute, TextLayoutBuilder},
|
||||
Data, EventCtx, ExtEventSink, Target, WidgetId, WindowId,
|
||||
};
|
||||
use druid::{PaintCtx, Point};
|
||||
use language::{new_highlight_config, LapceLanguage};
|
||||
use lapce_core::style::{line_styles, LineStyle, LineStyles};
|
||||
use lapce_core::style::{line_styles, LineStyle, LineStyles, Style};
|
||||
use lapce_core::syntax::Syntax;
|
||||
use lapce_proxy::dispatch::{BufferHeadResponse, NewBufferResponse};
|
||||
use lsp_types::SemanticTokensLegend;
|
||||
use lsp_types::SemanticTokensServerCapabilities;
|
||||
use lsp_types::{CodeActionResponse, Position};
|
||||
use parking_lot::Mutex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cell::RefCell;
|
||||
use std::cmp::{self, Ordering};
|
||||
|
@ -22,29 +19,20 @@
|
|||
use std::str::FromStr;
|
||||
use std::sync::atomic::{self, AtomicU64};
|
||||
use std::{borrow::Cow, collections::BTreeSet, path::PathBuf, sync::Arc, thread};
|
||||
use tree_sitter::{Node, Tree};
|
||||
use tree_sitter_highlight::{
|
||||
Highlight, HighlightConfiguration, HighlightEvent, Highlighter,
|
||||
};
|
||||
use unicode_width::UnicodeWidthChar;
|
||||
use xi_rope::{
|
||||
interval::IntervalBounds,
|
||||
multiset::Subset,
|
||||
rope::Rope,
|
||||
spans::{Spans, SpansBuilder},
|
||||
Cursor, Delta, DeltaBuilder, Interval, RopeDelta, RopeInfo,
|
||||
multiset::Subset, rope::Rope, spans::Spans, Cursor, Delta, DeltaBuilder,
|
||||
Interval, RopeDelta, RopeInfo,
|
||||
};
|
||||
use xi_unicode::EmojiExt;
|
||||
|
||||
use crate::config::{Config, LapceTheme};
|
||||
use crate::editor::EditorLocationNew;
|
||||
use crate::find::FindProgress;
|
||||
use crate::language::SCOPES;
|
||||
use crate::{
|
||||
command::LapceUICommand,
|
||||
command::LAPCE_UI_COMMAND,
|
||||
find::Find,
|
||||
language,
|
||||
movement::{ColPosition, LinePosition, Movement, SelRegion, Selection},
|
||||
proxy::LapceProxy,
|
||||
state::{Counter, Mode},
|
||||
|
@ -120,26 +108,6 @@ pub struct HighlightTextLayout {
|
|||
pub highlights: Vec<(usize, usize, String)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Style {
|
||||
pub fg_color: Option<String>,
|
||||
}
|
||||
|
||||
pub enum UpdateEvent {
|
||||
Buffer(BufferUpdate),
|
||||
SemanticTokens(BufferUpdate, Vec<(usize, usize, String)>),
|
||||
}
|
||||
|
||||
pub struct BufferUpdate {
|
||||
pub id: BufferId,
|
||||
pub path: PathBuf,
|
||||
pub rope: Rope,
|
||||
pub rev: u64,
|
||||
pub language: LapceLanguage,
|
||||
pub highlights: Arc<Spans<Style>>,
|
||||
pub semantic_tokens: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum EditType {
|
||||
Other,
|
||||
|
@ -244,15 +212,9 @@ pub struct Buffer {
|
|||
pub id: BufferId,
|
||||
pub rope: Rope,
|
||||
pub content: BufferContent,
|
||||
pub line_styles: Rc<RefCell<Vec<Option<Arc<Vec<(usize, usize, Style)>>>>>>,
|
||||
pub styles: Arc<Spans<Style>>,
|
||||
pub semantic_tokens: bool,
|
||||
pub language: Option<LapceLanguage>,
|
||||
pub syntax: Option<Syntax>,
|
||||
pub new_line_styles: Rc<RefCell<LineStyles>>,
|
||||
pub semantic_styles: Option<Spans<lapce_core::style::Style>>,
|
||||
pub highlighter: Arc<Mutex<Highlighter>>,
|
||||
pub highlight: Option<Arc<Mutex<HighlightConfiguration>>>,
|
||||
pub semantic_styles: Option<Arc<Spans<Style>>>,
|
||||
pub max_len: usize,
|
||||
pub max_len_line: usize,
|
||||
pub num_lines: usize,
|
||||
|
@ -262,12 +224,9 @@ pub struct Buffer {
|
|||
pub loaded: bool,
|
||||
pub start_to_load: Rc<RefCell<bool>>,
|
||||
pub local: bool,
|
||||
update_sender: Arc<Sender<UpdateEvent>>,
|
||||
pub histories: im::HashMap<String, Rope>,
|
||||
pub history_styles: im::HashMap<String, Arc<Spans<Style>>>,
|
||||
pub history_line_styles: Rc<
|
||||
RefCell<HashMap<String, HashMap<usize, Arc<Vec<(usize, usize, Style)>>>>>,
|
||||
>,
|
||||
pub history_line_styles: Rc<RefCell<HashMap<String, LineStyles>>>,
|
||||
pub history_changes: im::HashMap<String, Arc<Vec<DiffLines>>>,
|
||||
|
||||
pub find: Rc<RefCell<Find>>,
|
||||
|
@ -289,7 +248,6 @@ pub struct Buffer {
|
|||
pub scroll_offset: Vec2,
|
||||
|
||||
pub code_actions: im::HashMap<usize, CodeActionResponse>,
|
||||
pub syntax_tree: Option<Arc<Tree>>,
|
||||
|
||||
tab_id: WidgetId,
|
||||
event_sink: ExtEventSink,
|
||||
|
@ -298,35 +256,24 @@ pub struct Buffer {
|
|||
impl Buffer {
|
||||
pub fn new(
|
||||
content: BufferContent,
|
||||
update_sender: Arc<Sender<UpdateEvent>>,
|
||||
tab_id: WidgetId,
|
||||
event_sink: ExtEventSink,
|
||||
) -> Self {
|
||||
let rope = Rope::from("");
|
||||
let language = match &content {
|
||||
BufferContent::File(path) => LapceLanguage::from_path(path),
|
||||
BufferContent::Local(_) => None,
|
||||
};
|
||||
let syntax = match &content {
|
||||
BufferContent::File(path) => Syntax::init(path),
|
||||
BufferContent::Local(_) => None,
|
||||
};
|
||||
let buffer = Self {
|
||||
|
||||
Self {
|
||||
id: BufferId::next(),
|
||||
rope,
|
||||
highlighter: Arc::new(Mutex::new(Highlighter::new())),
|
||||
highlight: language
|
||||
.map(|l| Arc::new(Mutex::new(new_highlight_config(l)))),
|
||||
language,
|
||||
syntax,
|
||||
new_line_styles: Rc::new(RefCell::new(HashMap::new())),
|
||||
semantic_styles: None,
|
||||
content,
|
||||
styles: Arc::new(SpansBuilder::new(0).build()),
|
||||
line_styles: Rc::new(RefCell::new(Vec::new())),
|
||||
find: Rc::new(RefCell::new(Find::new(0))),
|
||||
find_progress: Rc::new(RefCell::new(FindProgress::Ready)),
|
||||
semantic_tokens: false,
|
||||
max_len: 0,
|
||||
max_len_line: 0,
|
||||
num_lines: 0,
|
||||
|
@ -335,7 +282,6 @@ pub fn new(
|
|||
start_to_load: Rc::new(RefCell::new(false)),
|
||||
loaded: false,
|
||||
dirty: false,
|
||||
update_sender,
|
||||
local: false,
|
||||
histories: im::HashMap::new(),
|
||||
history_styles: im::HashMap::new(),
|
||||
|
@ -364,12 +310,9 @@ pub fn new(
|
|||
scroll_offset: Vec2::ZERO,
|
||||
|
||||
code_actions: im::HashMap::new(),
|
||||
syntax_tree: None,
|
||||
tab_id,
|
||||
event_sink,
|
||||
};
|
||||
*buffer.line_styles.borrow_mut() = vec![None; buffer.num_lines()];
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_local(mut self) -> Self {
|
||||
|
@ -392,7 +335,6 @@ pub fn reset_revs(&mut self) {
|
|||
self.deletes_from_union = Subset::new(0);
|
||||
self.undone_groups = BTreeSet::new();
|
||||
self.tombstones = Rope::default();
|
||||
self.syntax_tree = None;
|
||||
}
|
||||
|
||||
pub fn load_history(&mut self, version: &str, content: Rope) {
|
||||
|
@ -420,41 +362,35 @@ pub fn load_content(&mut self, content: &str) {
|
|||
self.max_len = max_len;
|
||||
self.max_len_line = max_len_line;
|
||||
self.num_lines = self.num_lines();
|
||||
*self.line_styles.borrow_mut() = vec![None; self.num_lines()];
|
||||
self.loaded = true;
|
||||
self.notify_update(None);
|
||||
}
|
||||
|
||||
fn retrieve_history_styles(&self, version: &str, content: Rope) {
|
||||
if let BufferContent::File(path) = &self.content {
|
||||
if let Some(highlight_config) = self.highlight.clone() {
|
||||
let highlighter = self.highlighter.clone();
|
||||
let id = self.id;
|
||||
let path = path.clone();
|
||||
let event_sink = self.event_sink.clone();
|
||||
let tab_id = self.tab_id;
|
||||
let version = version.to_string();
|
||||
rayon::spawn(move || {
|
||||
let mut highlight_config = highlight_config.lock();
|
||||
let mut highlighter = highlighter.lock();
|
||||
let highlights = rope_styles(
|
||||
content,
|
||||
&mut highlighter,
|
||||
&mut highlight_config,
|
||||
);
|
||||
|
||||
let _ = event_sink.submit_command(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::UpdateHistoryStyle {
|
||||
id,
|
||||
path,
|
||||
history: version,
|
||||
highlights,
|
||||
},
|
||||
Target::Widget(tab_id),
|
||||
);
|
||||
});
|
||||
}
|
||||
let id = self.id;
|
||||
let path = path.clone();
|
||||
let tab_id = self.tab_id;
|
||||
let version = version.to_string();
|
||||
let event_sink = self.event_sink.clone();
|
||||
rayon::spawn(move || {
|
||||
if let Some(syntax) =
|
||||
Syntax::init(&path).map(|s| s.parse(0, content, None))
|
||||
{
|
||||
if let Some(styles) = syntax.styles {
|
||||
let _ = event_sink.submit_command(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::UpdateHistoryStyle {
|
||||
id,
|
||||
path,
|
||||
history: version,
|
||||
highlights: styles,
|
||||
},
|
||||
Target::Widget(tab_id),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -500,19 +436,6 @@ fn trigger_history_change(&self) {
|
|||
}
|
||||
|
||||
pub fn notify_update(&self, delta: Option<&RopeDelta>) {
|
||||
if let Some(language) = self.language {
|
||||
if let BufferContent::File(path) = &self.content {
|
||||
let _ = self.update_sender.send(UpdateEvent::Buffer(BufferUpdate {
|
||||
id: self.id,
|
||||
path: path.clone(),
|
||||
rope: self.rope.clone(),
|
||||
rev: self.rev,
|
||||
language,
|
||||
highlights: self.styles.clone(),
|
||||
semantic_tokens: self.semantic_tokens,
|
||||
}));
|
||||
}
|
||||
}
|
||||
self.trigger_syntax_change(delta);
|
||||
self.trigger_history_change();
|
||||
}
|
||||
|
@ -810,7 +733,7 @@ fn get_hisotry_line_styles(
|
|||
&self,
|
||||
history: &str,
|
||||
line: usize,
|
||||
) -> Option<Arc<Vec<(usize, usize, Style)>>> {
|
||||
) -> Option<Arc<Vec<LineStyle>>> {
|
||||
let rope = self.histories.get(history)?;
|
||||
let styles = self.history_styles.get(history)?;
|
||||
let mut cached_line_styles = self.history_line_styles.borrow_mut();
|
||||
|
@ -822,7 +745,7 @@ fn get_hisotry_line_styles(
|
|||
let start_offset = rope.offset_of_line(line);
|
||||
let end_offset = rope.offset_of_line(line + 1);
|
||||
|
||||
let line_styles: Vec<(usize, usize, Style)> = styles
|
||||
let line_styles: Vec<LineStyle> = styles
|
||||
.iter_chunks(start_offset..end_offset)
|
||||
.filter_map(|(iv, style)| {
|
||||
let start = iv.start();
|
||||
|
@ -830,15 +753,15 @@ fn get_hisotry_line_styles(
|
|||
if start > end_offset || end < start_offset {
|
||||
None
|
||||
} else {
|
||||
Some((
|
||||
if start > start_offset {
|
||||
Some(LineStyle {
|
||||
start: if start > start_offset {
|
||||
start - start_offset
|
||||
} else {
|
||||
0
|
||||
},
|
||||
end - start_offset,
|
||||
style.clone(),
|
||||
))
|
||||
end: end - start_offset,
|
||||
style: style.clone(),
|
||||
})
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
@ -847,6 +770,14 @@ fn get_hisotry_line_styles(
|
|||
Some(line_styles)
|
||||
}
|
||||
|
||||
pub fn styles(&self) -> Option<&Arc<Spans<Style>>> {
|
||||
let styles = self
|
||||
.semantic_styles
|
||||
.as_ref()
|
||||
.or_else(|| self.syntax.as_ref().and_then(|s| s.styles.as_ref()));
|
||||
styles
|
||||
}
|
||||
|
||||
fn line_style(&self, line: usize) -> Arc<Vec<LineStyle>> {
|
||||
if self.new_line_styles.borrow().get(&line).is_none() {
|
||||
let styles = self
|
||||
|
@ -864,42 +795,6 @@ fn line_style(&self, line: usize) -> Arc<Vec<LineStyle>> {
|
|||
self.new_line_styles.borrow().get(&line).cloned().unwrap()
|
||||
}
|
||||
|
||||
fn get_line_styles(&self, line: usize) -> Arc<Vec<(usize, usize, Style)>> {
|
||||
if let Some(line_styles) =
|
||||
self.line_styles.borrow().get(line).and_then(|s| s.as_ref())
|
||||
{
|
||||
return line_styles.clone();
|
||||
}
|
||||
let start_offset = self.offset_of_line(line);
|
||||
let end_offset = self.offset_of_line(line + 1);
|
||||
let line_styles: Vec<(usize, usize, Style)> = self
|
||||
.styles
|
||||
.iter_chunks(start_offset..end_offset)
|
||||
.filter_map(|(iv, style)| {
|
||||
let start = iv.start();
|
||||
let end = iv.end();
|
||||
if start > end_offset || end < start_offset {
|
||||
None
|
||||
} else {
|
||||
Some((
|
||||
if start > start_offset {
|
||||
start - start_offset
|
||||
} else {
|
||||
0
|
||||
},
|
||||
end - start_offset,
|
||||
style.clone(),
|
||||
))
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let line_styles = Arc::new(line_styles);
|
||||
if let Some(style) = self.line_styles.borrow_mut().get_mut(line) {
|
||||
*style = Some(line_styles.clone());
|
||||
}
|
||||
line_styles
|
||||
}
|
||||
|
||||
pub fn history_text_layout(
|
||||
&self,
|
||||
ctx: &mut PaintCtx,
|
||||
|
@ -927,13 +822,13 @@ pub fn history_text_layout(
|
|||
);
|
||||
|
||||
if let Some(styles) = self.get_hisotry_line_styles(history, line) {
|
||||
for (start, end, style) in styles.iter() {
|
||||
if let Some(fg_color) = style.fg_color.as_ref() {
|
||||
for line_style in styles.iter() {
|
||||
if let Some(fg_color) = line_style.style.fg_color.as_ref() {
|
||||
if let Some(fg_color) =
|
||||
config.get_color(&("style.".to_string() + fg_color))
|
||||
{
|
||||
layout_builder = layout_builder.range_attribute(
|
||||
start..end,
|
||||
line_style.start..line_style.end,
|
||||
TextAttribute::TextColor(fg_color.clone()),
|
||||
);
|
||||
}
|
||||
|
@ -1621,8 +1516,8 @@ pub fn move_offset(
|
|||
(new_offset, ColPosition::Col(col))
|
||||
}
|
||||
Movement::NextUnmatched(c) => {
|
||||
if self.syntax_tree.is_some() {
|
||||
let new_offset = self
|
||||
if let Some(syntax) = self.syntax.as_ref() {
|
||||
let new_offset = syntax
|
||||
.find_tag(offset, false, &c.to_string())
|
||||
.unwrap_or(offset);
|
||||
let (_, col) =
|
||||
|
@ -1641,8 +1536,8 @@ pub fn move_offset(
|
|||
}
|
||||
}
|
||||
Movement::PreviousUnmatched(c) => {
|
||||
if self.syntax_tree.is_some() {
|
||||
let new_offset = self
|
||||
if let Some(syntax) = self.syntax.as_ref() {
|
||||
let new_offset = syntax
|
||||
.find_tag(offset, true, &c.to_string())
|
||||
.unwrap_or(offset);
|
||||
let (_, col) =
|
||||
|
@ -1658,9 +1553,9 @@ pub fn move_offset(
|
|||
}
|
||||
}
|
||||
Movement::MatchPairs => {
|
||||
if self.syntax_tree.is_some() {
|
||||
if let Some(syntax) = self.syntax.as_ref() {
|
||||
let new_offset =
|
||||
self.find_matching_pair(offset).unwrap_or(offset);
|
||||
syntax.find_matching_pair(offset).unwrap_or(offset);
|
||||
let (_, col) =
|
||||
self.offset_to_line_col(new_offset, config.editor.tab_width);
|
||||
(new_offset, ColPosition::Col(col))
|
||||
|
@ -1677,89 +1572,13 @@ pub fn move_offset(
|
|||
}
|
||||
|
||||
pub fn previous_unmatched(&self, c: char, offset: usize) -> Option<usize> {
|
||||
if self.syntax_tree.is_some() {
|
||||
self.find_tag(offset, true, &c.to_string())
|
||||
if let Some(syntax) = self.syntax.as_ref() {
|
||||
syntax.find_tag(offset, true, &c.to_string())
|
||||
} else {
|
||||
WordCursor::new(&self.rope, offset).previous_unmatched(c)
|
||||
}
|
||||
}
|
||||
|
||||
fn find_matching_pair(&self, offset: usize) -> Option<usize> {
|
||||
let tree = self.syntax_tree.as_ref()?;
|
||||
let node = tree
|
||||
.root_node()
|
||||
.descendant_for_byte_range(offset, offset + 1)?;
|
||||
let mut chars = node.kind().chars();
|
||||
let char = chars.next()?;
|
||||
let char = matching_char(char)?;
|
||||
let tag = &char.to_string();
|
||||
|
||||
if let Some(offset) = self.find_tag_in_siblings(node, true, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
if let Some(offset) = self.find_tag_in_siblings(node, false, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn find_tag(&self, offset: usize, previous: bool, tag: &str) -> Option<usize> {
|
||||
let tree = self.syntax_tree.as_ref()?;
|
||||
let node = tree
|
||||
.root_node()
|
||||
.descendant_for_byte_range(offset, offset + 1)?;
|
||||
|
||||
if let Some(offset) = self.find_tag_in_siblings(node, previous, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
|
||||
if let Some(offset) = self.find_tag_in_children(node, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
|
||||
let mut node = node;
|
||||
while let Some(parent) = node.parent() {
|
||||
if let Some(offset) = self.find_tag_in_siblings(parent, previous, tag) {
|
||||
return Some(offset);
|
||||
}
|
||||
node = parent;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn find_tag_in_siblings(
|
||||
&self,
|
||||
node: Node,
|
||||
previous: bool,
|
||||
tag: &str,
|
||||
) -> Option<usize> {
|
||||
let mut node = node;
|
||||
while let Some(sibling) = if previous {
|
||||
node.prev_sibling()
|
||||
} else {
|
||||
node.next_sibling()
|
||||
} {
|
||||
if sibling.kind() == tag {
|
||||
let offset = sibling.start_byte();
|
||||
return Some(offset);
|
||||
}
|
||||
node = sibling;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn find_tag_in_children(&self, node: Node, tag: &str) -> Option<usize> {
|
||||
for i in 0..node.child_count() {
|
||||
if let Some(child) = node.child(i) {
|
||||
if child.kind() == tag {
|
||||
let offset = child.start_byte();
|
||||
return Some(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn prev_code_boundary(&self, offset: usize) -> usize {
|
||||
WordCursor::new(&self.rope, offset).prev_code_boundary()
|
||||
}
|
||||
|
@ -1768,13 +1587,6 @@ pub fn next_code_boundary(&self, offset: usize) -> usize {
|
|||
WordCursor::new(&self.rope, offset).next_code_boundary()
|
||||
}
|
||||
|
||||
pub fn update_syntax_tree(&mut self, rev: u64, tree: Tree) {
|
||||
if rev != self.rev {
|
||||
return;
|
||||
}
|
||||
self.syntax_tree = Some(Arc::new(tree));
|
||||
}
|
||||
|
||||
pub fn update_history_changes(
|
||||
&mut self,
|
||||
rev: u64,
|
||||
|
@ -1787,22 +1599,6 @@ pub fn update_history_changes(
|
|||
self.history_changes.insert(history.to_string(), changes);
|
||||
}
|
||||
|
||||
pub fn update_styles(
|
||||
&mut self,
|
||||
rev: u64,
|
||||
highlights: Spans<Style>,
|
||||
semantic_tokens: bool,
|
||||
) {
|
||||
if rev != self.rev {
|
||||
return;
|
||||
}
|
||||
if semantic_tokens {
|
||||
self.semantic_tokens = true;
|
||||
}
|
||||
self.styles = Arc::new(highlights);
|
||||
*self.line_styles.borrow_mut() = vec![None; self.num_lines];
|
||||
}
|
||||
|
||||
fn update_size(&mut self, inval_lines: &InvalLines) {
|
||||
if inval_lines.inval_count != inval_lines.new_count {
|
||||
self.num_lines = self.num_lines();
|
||||
|
@ -1835,23 +1631,15 @@ fn update_size(&mut self, inval_lines: &InvalLines) {
|
|||
}
|
||||
}
|
||||
|
||||
fn update_line_styles(&mut self, delta: &RopeDelta, inval_lines: &InvalLines) {
|
||||
fn update_styles(&mut self, delta: &RopeDelta) {
|
||||
if let Some(styles) = self.semantic_styles.as_mut() {
|
||||
styles.apply_shape(delta);
|
||||
Arc::make_mut(styles).apply_shape(delta);
|
||||
} else if let Some(syntax) = self.syntax.as_mut() {
|
||||
if let Some(styles) = syntax.styles.as_mut() {
|
||||
styles.apply_shape(delta);
|
||||
Arc::make_mut(styles).apply_shape(delta);
|
||||
}
|
||||
}
|
||||
self.new_line_styles.borrow_mut().clear();
|
||||
|
||||
Arc::make_mut(&mut self.styles).apply_shape(delta);
|
||||
let mut line_styles = self.line_styles.borrow_mut();
|
||||
let right = line_styles.split_off(inval_lines.start_line);
|
||||
let right = &right[inval_lines.inval_count..];
|
||||
let mut new = vec![None; inval_lines.new_count];
|
||||
line_styles.append(&mut new);
|
||||
line_styles.extend_from_slice(right);
|
||||
}
|
||||
|
||||
fn mk_new_rev(
|
||||
|
@ -1951,7 +1739,6 @@ fn apply_edit(
|
|||
self.tombstones = new_tombstones;
|
||||
self.deletes_from_union = new_deletes_from_union;
|
||||
self.code_actions.clear();
|
||||
self.syntax_tree = None;
|
||||
|
||||
let logical_start_line = self.rope.line_of_offset(iv.start);
|
||||
let new_logical_end_line = self.rope.line_of_offset(iv.start + newlen) + 1;
|
||||
|
@ -1964,7 +1751,7 @@ fn apply_edit(
|
|||
new_count: new_hard_count,
|
||||
};
|
||||
self.update_size(&inval_lines);
|
||||
self.update_line_styles(delta, &inval_lines);
|
||||
self.update_styles(delta);
|
||||
self.find.borrow_mut().unset();
|
||||
*self.find_progress.borrow_mut() = FindProgress::Started;
|
||||
self.notify_update(Some(delta));
|
||||
|
@ -2851,47 +2638,6 @@ pub fn str_col(s: &str, tab_width: usize) -> usize {
|
|||
total_width
|
||||
}
|
||||
|
||||
fn rope_styles(
|
||||
rope: Rope,
|
||||
highlighter: &mut Highlighter,
|
||||
highlight_config: &mut HighlightConfiguration,
|
||||
) -> Spans<Style> {
|
||||
let mut current_hl: Option<Highlight> = None;
|
||||
let mut highlights = SpansBuilder::new(rope.len());
|
||||
for hightlight in highlighter
|
||||
.highlight(
|
||||
highlight_config,
|
||||
rope.slice_to_cow(0..rope.len()).as_bytes(),
|
||||
None,
|
||||
|_| None,
|
||||
)
|
||||
.unwrap()
|
||||
{
|
||||
if let Ok(highlight) = hightlight {
|
||||
match highlight {
|
||||
HighlightEvent::Source { start, end } => {
|
||||
if let Some(hl) = current_hl {
|
||||
if let Some(hl) = SCOPES.get(hl.0) {
|
||||
highlights.add_span(
|
||||
Interval::new(start, end),
|
||||
Style {
|
||||
fg_color: Some(hl.to_string()),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
HighlightEvent::HighlightStart(hl) => {
|
||||
current_hl = Some(hl);
|
||||
}
|
||||
HighlightEvent::HighlightEnd => current_hl = None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
highlights.build()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn buffer_diff(
|
||||
left_rope: Rope,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use anyhow::Result;
|
||||
use druid::{Point, Rect, Selector, Size, WidgetId, WindowId};
|
||||
use indexmap::IndexMap;
|
||||
use lapce_core::{style::LineStyle, syntax::Syntax};
|
||||
use lapce_core::{style::Style, syntax::Syntax};
|
||||
use lapce_proxy::{
|
||||
dispatch::{DiffInfo, FileNodeItem},
|
||||
plugin::PluginDescription,
|
||||
|
@ -16,13 +16,11 @@
|
|||
use serde_json::Value;
|
||||
use strum::{self, EnumMessage, IntoEnumIterator};
|
||||
use strum_macros::{Display, EnumIter, EnumMessage, EnumString};
|
||||
use tree_sitter::Tree;
|
||||
use tree_sitter_highlight::Highlight;
|
||||
use xi_rope::{spans::Spans, Rope};
|
||||
|
||||
use crate::{
|
||||
buffer::BufferId,
|
||||
buffer::{DiffLines, Style},
|
||||
buffer::DiffLines,
|
||||
data::{EditorTabChild, SplitContent},
|
||||
editor::EditorLocationNew,
|
||||
keypress::{KeyMap, KeyPress},
|
||||
|
@ -553,28 +551,13 @@ pub enum LapceUICommand {
|
|||
DocumentFormat(PathBuf, u64, Result<Value>),
|
||||
DocumentFormatAndSave(PathBuf, u64, Result<Value>),
|
||||
BufferSave(PathBuf, u64),
|
||||
UpdateSemanticStyles(BufferId, PathBuf, u64, Spans<lapce_core::style::Style>),
|
||||
UpdateSemanticTokens(BufferId, PathBuf, u64, Vec<(usize, usize, String)>),
|
||||
UpdateHighlights(BufferId, u64, Vec<(usize, usize, Highlight)>),
|
||||
UpdateSemanticStyles(BufferId, PathBuf, u64, Arc<Spans<Style>>),
|
||||
UpdateTerminalTitle(TermId, String),
|
||||
UpdateStyle {
|
||||
id: BufferId,
|
||||
path: PathBuf,
|
||||
rev: u64,
|
||||
highlights: Spans<Style>,
|
||||
semantic_tokens: bool,
|
||||
},
|
||||
UpdateHistoryStyle {
|
||||
id: BufferId,
|
||||
path: PathBuf,
|
||||
history: String,
|
||||
highlights: Spans<Style>,
|
||||
},
|
||||
UpdateSyntaxTree {
|
||||
id: BufferId,
|
||||
path: PathBuf,
|
||||
rev: u64,
|
||||
tree: Tree,
|
||||
highlights: Arc<Spans<Style>>,
|
||||
},
|
||||
UpdateSyntax {
|
||||
path: PathBuf,
|
||||
|
|
|
@ -28,16 +28,12 @@
|
|||
use notify::Watcher;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use tree_sitter::Parser;
|
||||
use tree_sitter_highlight::{
|
||||
Highlight, HighlightConfiguration, HighlightEvent, Highlighter,
|
||||
};
|
||||
use xi_rope::{spans::SpansBuilder, Interval, RopeDelta, Transformer};
|
||||
use xi_rope::{RopeDelta, Transformer};
|
||||
|
||||
use crate::{
|
||||
buffer::{
|
||||
has_unmatched_pair, matching_char, matching_pair_direction, Buffer,
|
||||
BufferContent, BufferUpdate, EditType, LocalBufferKind, Style, UpdateEvent,
|
||||
BufferContent, EditType, LocalBufferKind,
|
||||
},
|
||||
command::{
|
||||
CommandTarget, EnsureVisiblePosition, LapceCommandNew, LapceUICommand,
|
||||
|
@ -53,7 +49,6 @@
|
|||
explorer::FileExplorerData,
|
||||
find::Find,
|
||||
keypress::KeyPressData,
|
||||
language::{new_highlight_config, new_parser, LapceLanguage, SCOPES},
|
||||
menu::MenuData,
|
||||
movement::{Cursor, CursorMode, InsertDrift, Movement, SelRegion, Selection},
|
||||
palette::{PaletteData, PaletteType, PaletteViewData},
|
||||
|
@ -402,10 +397,8 @@ pub struct LapceTabData {
|
|||
pub proxy_status: Arc<ProxyStatus>,
|
||||
pub keypress: Arc<KeyPressData>,
|
||||
pub settings: Arc<LapceSettingsPanelData>,
|
||||
pub update_receiver: Option<Receiver<UpdateEvent>>,
|
||||
pub term_tx: Arc<Sender<(TermId, TermEvent)>>,
|
||||
pub term_rx: Option<Receiver<(TermId, TermEvent)>>,
|
||||
pub update_sender: Arc<Sender<UpdateEvent>>,
|
||||
pub window_origin: Point,
|
||||
pub panels: im::HashMap<PanelPosition, Arc<PanelData>>,
|
||||
pub panel_active: PanelPosition,
|
||||
|
@ -471,8 +464,6 @@ pub fn new(
|
|||
None
|
||||
};
|
||||
|
||||
let (update_sender, update_receiver) = unbounded();
|
||||
let update_sender = Arc::new(update_sender);
|
||||
let (term_sender, term_receiver) = unbounded();
|
||||
let proxy = Arc::new(LapceProxy::new(
|
||||
tab_id,
|
||||
|
@ -498,7 +489,6 @@ pub fn new(
|
|||
tab_id,
|
||||
workspace_info.as_ref(),
|
||||
palette.preview_editor,
|
||||
update_sender.clone(),
|
||||
proxy.clone(),
|
||||
&config,
|
||||
event_sink.clone(),
|
||||
|
@ -596,8 +586,6 @@ pub fn new(
|
|||
settings,
|
||||
proxy_status: Arc::new(ProxyStatus::Connecting),
|
||||
keypress,
|
||||
update_sender,
|
||||
update_receiver: Some(update_receiver),
|
||||
window_origin: Point::ZERO,
|
||||
panels,
|
||||
panel_size: PanelSize {
|
||||
|
@ -631,18 +619,6 @@ pub fn workspace_info(&self) -> WorkspaceInfo {
|
|||
}
|
||||
|
||||
pub fn start_update_process(&mut self, event_sink: ExtEventSink) {
|
||||
if let Some(receiver) = self.update_receiver.take() {
|
||||
let tab_id = self.id;
|
||||
let local_event_sink = event_sink.clone();
|
||||
thread::spawn(move || {
|
||||
LapceTabData::buffer_update_process(
|
||||
tab_id,
|
||||
receiver,
|
||||
local_event_sink,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(receiver) = self.term_rx.take() {
|
||||
let tab_id = self.id;
|
||||
let local_event_sink = event_sink.clone();
|
||||
|
@ -914,7 +890,7 @@ pub fn run_workbench_command(
|
|||
.as_secs(),
|
||||
};
|
||||
|
||||
event_sink.submit_command(
|
||||
let _ = event_sink.submit_command(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::SetWorkspace(workspace),
|
||||
Target::Auto,
|
||||
|
@ -1384,59 +1360,6 @@ fn toggle_panel(&mut self, ctx: &mut EventCtx, kind: PanelKind) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn buffer_update_process(
|
||||
tab_id: WidgetId,
|
||||
receiver: Receiver<UpdateEvent>,
|
||||
event_sink: ExtEventSink,
|
||||
) {
|
||||
let mut parsers = HashMap::new();
|
||||
let mut highlighter = Highlighter::new();
|
||||
let mut highlight_configs = HashMap::new();
|
||||
loop {
|
||||
match receiver.recv() {
|
||||
Err(_) => return,
|
||||
Ok(event) => {
|
||||
match event {
|
||||
UpdateEvent::Buffer(update) => {
|
||||
buffer_receive_update(
|
||||
update,
|
||||
&mut parsers,
|
||||
&mut highlighter,
|
||||
&mut highlight_configs,
|
||||
&event_sink,
|
||||
tab_id,
|
||||
);
|
||||
}
|
||||
UpdateEvent::SemanticTokens(update, tokens) => {
|
||||
let mut highlights =
|
||||
SpansBuilder::new(update.rope.len());
|
||||
for (start, end, hl) in tokens {
|
||||
highlights.add_span(
|
||||
Interval::new(start, end),
|
||||
Style {
|
||||
fg_color: Some(hl.to_string()),
|
||||
},
|
||||
);
|
||||
}
|
||||
let highlights = highlights.build();
|
||||
let _ = event_sink.submit_command(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::UpdateStyle {
|
||||
id: update.id,
|
||||
path: update.path,
|
||||
rev: update.rev,
|
||||
highlights,
|
||||
semantic_tokens: true,
|
||||
},
|
||||
Target::Widget(tab_id),
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_picker_pwd(&mut self, ctx: &mut EventCtx) {
|
||||
let path = self.picker.pwd.clone();
|
||||
let event_sink = ctx.get_external_handle();
|
||||
|
@ -1699,7 +1622,6 @@ pub struct LapceMainSplitData {
|
|||
pub open_files: im::HashMap<PathBuf, Arc<Buffer>>,
|
||||
pub splits: im::HashMap<WidgetId, Arc<SplitData>>,
|
||||
pub local_buffers: im::HashMap<LocalBufferKind, Arc<Buffer>>,
|
||||
pub update_sender: Arc<Sender<UpdateEvent>>,
|
||||
pub register: Arc<Register>,
|
||||
pub proxy: Arc<LapceProxy>,
|
||||
pub palette_preview_editor: Arc<WidgetId>,
|
||||
|
@ -2192,7 +2114,6 @@ pub fn go_to_location(
|
|||
if !buffer_exists {
|
||||
let mut buffer = Buffer::new(
|
||||
BufferContent::File(path.clone()),
|
||||
self.update_sender.clone(),
|
||||
*self.tab_id,
|
||||
ctx.get_external_handle(),
|
||||
);
|
||||
|
@ -2302,7 +2223,6 @@ pub fn new(
|
|||
tab_id: WidgetId,
|
||||
workspace_info: Option<&WorkspaceInfo>,
|
||||
palette_preview_editor: WidgetId,
|
||||
update_sender: Arc<Sender<UpdateEvent>>,
|
||||
proxy: Arc<LapceProxy>,
|
||||
config: &Config,
|
||||
event_sink: ExtEventSink,
|
||||
|
@ -2326,7 +2246,6 @@ pub fn new(
|
|||
editors.insert(editor.view_id, Arc::new(editor));
|
||||
let mut buffer = Buffer::new(
|
||||
BufferContent::File(path.clone()),
|
||||
update_sender.clone(),
|
||||
tab_id,
|
||||
event_sink.clone(),
|
||||
);
|
||||
|
@ -2338,7 +2257,6 @@ pub fn new(
|
|||
LocalBufferKind::Empty,
|
||||
Arc::new(Buffer::new(
|
||||
BufferContent::Local(LocalBufferKind::Empty),
|
||||
update_sender.clone(),
|
||||
tab_id,
|
||||
event_sink.clone(),
|
||||
)),
|
||||
|
@ -2354,7 +2272,6 @@ pub fn new(
|
|||
local_buffers,
|
||||
active: Arc::new(None),
|
||||
active_tab: Arc::new(None),
|
||||
update_sender: update_sender.clone(),
|
||||
register: Arc::new(Register::default()),
|
||||
proxy: proxy.clone(),
|
||||
palette_preview_editor: Arc::new(palette_preview_editor),
|
||||
|
@ -2374,7 +2291,6 @@ pub fn new(
|
|||
None,
|
||||
&mut positions,
|
||||
tab_id,
|
||||
update_sender,
|
||||
config,
|
||||
event_sink.clone(),
|
||||
);
|
||||
|
@ -2416,7 +2332,6 @@ pub fn add_editor(
|
|||
) {
|
||||
let mut buffer = Buffer::new(
|
||||
BufferContent::Local(buffer_kind.clone()),
|
||||
self.update_sender.clone(),
|
||||
*self.tab_id,
|
||||
event_sink,
|
||||
)
|
||||
|
@ -3859,92 +3774,6 @@ pub fn hex_to_color(hex: &str) -> Result<Color> {
|
|||
))
|
||||
}
|
||||
|
||||
fn buffer_receive_update(
|
||||
update: BufferUpdate,
|
||||
parsers: &mut HashMap<LapceLanguage, Parser>,
|
||||
highlighter: &mut Highlighter,
|
||||
highlight_configs: &mut HashMap<LapceLanguage, HighlightConfiguration>,
|
||||
event_sink: &ExtEventSink,
|
||||
tab_id: WidgetId,
|
||||
) {
|
||||
if let std::collections::hash_map::Entry::Vacant(e) =
|
||||
parsers.entry(update.language)
|
||||
{
|
||||
let parser = new_parser(update.language);
|
||||
e.insert(parser);
|
||||
}
|
||||
let parser = parsers.get_mut(&update.language).unwrap();
|
||||
if let Some(tree) = parser.parse(
|
||||
update.rope.slice_to_cow(0..update.rope.len()).as_bytes(),
|
||||
None,
|
||||
) {
|
||||
let _ = event_sink.submit_command(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::UpdateSyntaxTree {
|
||||
id: update.id,
|
||||
path: update.path.clone(),
|
||||
rev: update.rev,
|
||||
tree,
|
||||
},
|
||||
Target::Widget(tab_id),
|
||||
);
|
||||
}
|
||||
|
||||
if !update.semantic_tokens {
|
||||
if let std::collections::hash_map::Entry::Vacant(e) =
|
||||
highlight_configs.entry(update.language)
|
||||
{
|
||||
let highlight_config = new_highlight_config(update.language);
|
||||
e.insert(highlight_config);
|
||||
}
|
||||
let highlight_config = highlight_configs.get(&update.language).unwrap();
|
||||
let mut current_hl: Option<Highlight> = None;
|
||||
let mut highlights = SpansBuilder::new(update.rope.len());
|
||||
for hightlight in highlighter
|
||||
.highlight(
|
||||
highlight_config,
|
||||
update.rope.slice_to_cow(0..update.rope.len()).as_bytes(),
|
||||
None,
|
||||
|_| None,
|
||||
)
|
||||
.unwrap()
|
||||
{
|
||||
if let Ok(highlight) = hightlight {
|
||||
match highlight {
|
||||
HighlightEvent::Source { start, end } => {
|
||||
if let Some(hl) = current_hl {
|
||||
if let Some(hl) = SCOPES.get(hl.0) {
|
||||
highlights.add_span(
|
||||
Interval::new(start, end),
|
||||
Style {
|
||||
fg_color: Some(hl.to_string()),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
HighlightEvent::HighlightStart(hl) => {
|
||||
current_hl = Some(hl);
|
||||
}
|
||||
HighlightEvent::HighlightEnd => current_hl = None,
|
||||
}
|
||||
}
|
||||
}
|
||||
let highlights = highlights.build();
|
||||
let _ = event_sink.submit_command(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::UpdateStyle {
|
||||
id: update.id,
|
||||
path: update.path,
|
||||
rev: update.rev,
|
||||
highlights,
|
||||
semantic_tokens: false,
|
||||
},
|
||||
Target::Widget(tab_id),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn str_is_pair_left(c: &str) -> bool {
|
||||
if c.chars().count() == 1 {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
buffer::{Buffer, BufferContent, UpdateEvent},
|
||||
buffer::{Buffer, BufferContent},
|
||||
config::Config,
|
||||
data::{
|
||||
EditorTabChild, LapceData, LapceEditorData, LapceEditorTabData,
|
||||
|
@ -50,7 +50,6 @@ pub fn to_data(
|
|||
parent_split: Option<WidgetId>,
|
||||
editor_positions: &mut HashMap<PathBuf, Vec<(WidgetId, EditorLocationNew)>>,
|
||||
tab_id: WidgetId,
|
||||
update_sender: Arc<Sender<UpdateEvent>>,
|
||||
config: &Config,
|
||||
event_sink: ExtEventSink,
|
||||
) -> SplitContent {
|
||||
|
@ -61,7 +60,6 @@ pub fn to_data(
|
|||
parent_split.unwrap(),
|
||||
editor_positions,
|
||||
tab_id,
|
||||
update_sender,
|
||||
config,
|
||||
event_sink,
|
||||
);
|
||||
|
@ -73,7 +71,6 @@ pub fn to_data(
|
|||
parent_split,
|
||||
editor_positions,
|
||||
tab_id,
|
||||
update_sender,
|
||||
config,
|
||||
event_sink,
|
||||
);
|
||||
|
@ -97,7 +94,6 @@ pub fn to_data(
|
|||
split: WidgetId,
|
||||
editor_positions: &mut HashMap<PathBuf, Vec<(WidgetId, EditorLocationNew)>>,
|
||||
tab_id: WidgetId,
|
||||
update_sender: Arc<Sender<UpdateEvent>>,
|
||||
config: &Config,
|
||||
event_sink: ExtEventSink,
|
||||
) -> LapceEditorTabData {
|
||||
|
@ -115,7 +111,6 @@ pub fn to_data(
|
|||
editor_tab_id,
|
||||
editor_positions,
|
||||
tab_id,
|
||||
update_sender.clone(),
|
||||
config,
|
||||
event_sink.clone(),
|
||||
)
|
||||
|
@ -148,7 +143,6 @@ pub fn to_data(
|
|||
editor_tab_id: WidgetId,
|
||||
editor_positions: &mut HashMap<PathBuf, Vec<(WidgetId, EditorLocationNew)>>,
|
||||
tab_id: WidgetId,
|
||||
update_sender: Arc<Sender<UpdateEvent>>,
|
||||
config: &Config,
|
||||
event_sink: ExtEventSink,
|
||||
) -> EditorTabChild {
|
||||
|
@ -159,7 +153,6 @@ pub fn to_data(
|
|||
editor_tab_id,
|
||||
editor_positions,
|
||||
tab_id,
|
||||
update_sender,
|
||||
config,
|
||||
event_sink,
|
||||
);
|
||||
|
@ -182,7 +175,6 @@ pub fn to_data(
|
|||
parent_split: Option<WidgetId>,
|
||||
editor_positions: &mut HashMap<PathBuf, Vec<(WidgetId, EditorLocationNew)>>,
|
||||
tab_id: WidgetId,
|
||||
update_sender: Arc<Sender<UpdateEvent>>,
|
||||
config: &Config,
|
||||
event_sink: ExtEventSink,
|
||||
) -> SplitData {
|
||||
|
@ -200,7 +192,6 @@ pub fn to_data(
|
|||
Some(split_id),
|
||||
editor_positions,
|
||||
tab_id,
|
||||
update_sender.clone(),
|
||||
config,
|
||||
event_sink.clone(),
|
||||
)
|
||||
|
@ -258,7 +249,6 @@ pub fn to_data(
|
|||
editor_tab_id: WidgetId,
|
||||
editor_positions: &mut HashMap<PathBuf, Vec<(WidgetId, EditorLocationNew)>>,
|
||||
tab_id: WidgetId,
|
||||
update_sender: Arc<Sender<UpdateEvent>>,
|
||||
config: &Config,
|
||||
event_sink: ExtEventSink,
|
||||
) -> LapceEditorData {
|
||||
|
@ -290,7 +280,6 @@ pub fn to_data(
|
|||
if !data.open_files.contains_key(path) {
|
||||
let buffer = Arc::new(Buffer::new(
|
||||
BufferContent::File(path.clone()),
|
||||
update_sender,
|
||||
tab_id,
|
||||
event_sink,
|
||||
));
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
use crate::{
|
||||
buffer::BufferId,
|
||||
command::{LapceCommand, LapceUICommand, LAPCE_UI_COMMAND},
|
||||
movement::{ColPosition, LinePosition, Movement, SelRegion, Selection},
|
||||
movement::{ColPosition, Movement, SelRegion, Selection},
|
||||
split::SplitMoveDirection,
|
||||
state::Mode,
|
||||
state::VisualMode,
|
||||
|
@ -37,15 +37,14 @@
|
|||
use druid::Modifiers;
|
||||
use druid::{
|
||||
kurbo::Line, piet::PietText, Color, Command, Env, EventCtx, FontFamily,
|
||||
PaintCtx, Point, Rect, RenderContext, Size, Target, TextLayout, Vec2, WidgetId,
|
||||
PaintCtx, Point, Rect, RenderContext, Size, Target, Vec2, WidgetId,
|
||||
};
|
||||
use druid::{Application, ExtEventSink, MouseEvent};
|
||||
use lapce_core::lens::Lens;
|
||||
use lapce_core::syntax::Syntax;
|
||||
use lsp_types::CompletionTextEdit;
|
||||
use lsp_types::{
|
||||
CodeActionResponse, CompletionItem, DiagnosticSeverity, DocumentChanges,
|
||||
GotoDefinitionResponse, Location, Position, TextEdit, Url, WorkspaceEdit,
|
||||
CodeActionResponse, CompletionItem, DiagnosticSeverity, GotoDefinitionResponse,
|
||||
Location, Position,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashSet;
|
||||
|
@ -1669,7 +1668,7 @@ fn paint_gutter_inline_diff(
|
|||
}
|
||||
}
|
||||
|
||||
fn paint_gutter_code_lens(&self, ctx: &mut PaintCtx, gutter_width: f64) {
|
||||
fn paint_gutter_code_lens(&self, ctx: &mut PaintCtx, _gutter_width: f64) {
|
||||
let rect = ctx.size().to_rect();
|
||||
let scroll_offset = self.editor.scroll_offset;
|
||||
let empty_lens = Syntax::lens_from_normal_lines(
|
||||
|
@ -1933,92 +1932,6 @@ fn paint_code_actions_hint(&self, ctx: &mut PaintCtx, gutter_width: f64) {
|
|||
}
|
||||
}
|
||||
|
||||
fn paint_code_lens_line(
|
||||
&self,
|
||||
ctx: &mut PaintCtx,
|
||||
line: usize,
|
||||
is_focused: bool,
|
||||
cursor_line: usize,
|
||||
y: f64,
|
||||
y_shift: f64,
|
||||
bounds: [f64; 2],
|
||||
code_lens: bool,
|
||||
char_width: f64,
|
||||
code_lens_char_width: f64,
|
||||
config: &Config,
|
||||
) {
|
||||
if line > self.buffer.last_line() {
|
||||
return;
|
||||
}
|
||||
|
||||
let line_content = if let Some(syntax) = self.buffer.syntax.as_ref() {
|
||||
let rope = &syntax.text;
|
||||
let last_line = rope.line_of_offset(rope.len());
|
||||
if line > last_line {
|
||||
return;
|
||||
}
|
||||
let start = rope.offset_of_line(line);
|
||||
let end = rope.offset_of_line(line + 1);
|
||||
rope.slice_to_cow(start..end)
|
||||
} else {
|
||||
self.buffer.line_content(line)
|
||||
};
|
||||
|
||||
let mut x = 0.0;
|
||||
let mut x_shift = 0.0;
|
||||
let mut start_char = 0;
|
||||
if code_lens {
|
||||
for ch in line_content.chars() {
|
||||
if ch == ' ' {
|
||||
x += char_width;
|
||||
start_char += 1;
|
||||
} else if ch == '\t' {
|
||||
x += char_width * config.editor.tab_width as f64;
|
||||
start_char += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
x_shift = x - start_char as f64 * code_lens_char_width;
|
||||
}
|
||||
|
||||
let line_height = if code_lens {
|
||||
config.editor.code_lens_font_size as f64
|
||||
} else {
|
||||
config.editor.line_height as f64
|
||||
};
|
||||
|
||||
self.paint_cursor_on_line(
|
||||
ctx,
|
||||
is_focused,
|
||||
cursor_line,
|
||||
line,
|
||||
x_shift,
|
||||
y,
|
||||
if code_lens {
|
||||
code_lens_char_width
|
||||
} else {
|
||||
char_width
|
||||
},
|
||||
line_height,
|
||||
config,
|
||||
);
|
||||
let text_layout = self.buffer.new_text_layout(
|
||||
ctx,
|
||||
line,
|
||||
&line_content[start_char..],
|
||||
None,
|
||||
12,
|
||||
bounds,
|
||||
config,
|
||||
);
|
||||
ctx.draw_text(
|
||||
&text_layout,
|
||||
Point::new(x, if code_lens { y } else { y + y_shift }),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn paint_code_lens_content(
|
||||
&self,
|
||||
ctx: &mut PaintCtx,
|
||||
|
@ -4243,7 +4156,6 @@ fn run_command(
|
|||
}
|
||||
}
|
||||
}
|
||||
LapceCommand::MoveLineUp => {}
|
||||
LapceCommand::NextError => {
|
||||
self.next_error(ctx, env);
|
||||
}
|
||||
|
@ -4838,40 +4750,6 @@ pub struct HighlightTextLayout {
|
|||
pub highlights: Vec<(usize, usize, String)>,
|
||||
}
|
||||
|
||||
fn get_workspace_edit_changes_edits<'a>(
|
||||
url: &Url,
|
||||
workspace_edit: &'a WorkspaceEdit,
|
||||
) -> Option<Vec<&'a TextEdit>> {
|
||||
let changes = workspace_edit.changes.as_ref()?;
|
||||
changes.get(url).map(|c| c.iter().collect())
|
||||
}
|
||||
|
||||
fn get_workspace_edit_document_changes_edits<'a>(
|
||||
url: &Url,
|
||||
workspace_edit: &'a WorkspaceEdit,
|
||||
) -> Option<Vec<&'a TextEdit>> {
|
||||
let changes = workspace_edit.document_changes.as_ref()?;
|
||||
match changes {
|
||||
DocumentChanges::Edits(edits) => {
|
||||
for edit in edits {
|
||||
if &edit.text_document.uri == url {
|
||||
let e = edit
|
||||
.edits
|
||||
.iter()
|
||||
.filter_map(|e| match e {
|
||||
lsp_types::OneOf::Left(edit) => Some(edit),
|
||||
lsp_types::OneOf::Right(_) => None,
|
||||
})
|
||||
.collect();
|
||||
return Some(e);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
DocumentChanges::Operations(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn next_in_file_diff_offset(
|
||||
position: Position,
|
||||
path: &Path,
|
||||
|
|
|
@ -465,7 +465,7 @@ pub fn key_down<T: KeyPressFocus>(
|
|||
self.match_keymap(&[keypress], focus)
|
||||
{
|
||||
if let Ok(cmd) = LapceCommand::from_str(&command) {
|
||||
if let Some(_) = cmd.move_command(None) {
|
||||
if cmd.move_command(None).is_some() {
|
||||
focus.run_command(ctx, &cmd, None, mods, env);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
use lazy_static::lazy_static;
|
||||
use std::path::Path;
|
||||
use tree_sitter::Parser;
|
||||
use tree_sitter_highlight::HighlightConfiguration;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref SCOPES: Vec<String> = vec![
|
||||
"constant".to_string(),
|
||||
"constant.builtin".to_string(),
|
||||
"type".to_string(),
|
||||
"type.builtin".to_string(),
|
||||
"property".to_string(),
|
||||
"comment".to_string(),
|
||||
"constructor".to_string(),
|
||||
"function".to_string(),
|
||||
"function.method".to_string(),
|
||||
"function.macro".to_string(),
|
||||
"punctuation.bracket".to_string(),
|
||||
"punctuation.delimiter".to_string(),
|
||||
"label".to_string(),
|
||||
"keyword".to_string(),
|
||||
"string".to_string(),
|
||||
"variable.parameter".to_string(),
|
||||
"variable.builtin".to_string(),
|
||||
"variable.other.member".to_string(),
|
||||
"operator".to_string(),
|
||||
"attribute".to_string(),
|
||||
"escape".to_string(),
|
||||
];
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Copy, Clone)]
|
||||
pub enum LapceLanguage {
|
||||
Rust,
|
||||
Javascript,
|
||||
Go,
|
||||
}
|
||||
|
||||
impl LapceLanguage {
|
||||
pub fn from_path(path: &Path) -> Option<LapceLanguage> {
|
||||
let extension = path.extension()?.to_str()?;
|
||||
Some(match extension {
|
||||
"rs" => LapceLanguage::Rust,
|
||||
"js" => LapceLanguage::Javascript,
|
||||
"jsx" => LapceLanguage::Javascript,
|
||||
"go" => LapceLanguage::Go,
|
||||
// "toml" => LapceLanguage::Toml,
|
||||
// "yaml" => LapceLanguage::Yaml,
|
||||
// "yml" => LapceLanguage::Yaml,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_highlight_config(language: LapceLanguage) -> HighlightConfiguration {
|
||||
match language {
|
||||
LapceLanguage::Rust => {
|
||||
let mut configuration = HighlightConfiguration::new(
|
||||
tree_sitter_rust::language(),
|
||||
tree_sitter_rust::HIGHLIGHT_QUERY,
|
||||
"",
|
||||
"",
|
||||
)
|
||||
.unwrap();
|
||||
configuration.configure(&SCOPES);
|
||||
configuration
|
||||
}
|
||||
LapceLanguage::Javascript => {
|
||||
let mut configuration = HighlightConfiguration::new(
|
||||
tree_sitter_javascript::language(),
|
||||
tree_sitter_javascript::HIGHLIGHT_QUERY,
|
||||
"",
|
||||
"",
|
||||
)
|
||||
.unwrap();
|
||||
configuration.configure(&SCOPES);
|
||||
configuration
|
||||
}
|
||||
LapceLanguage::Go => {
|
||||
let mut configuration = HighlightConfiguration::new(
|
||||
tree_sitter_go::language(),
|
||||
tree_sitter_go::HIGHLIGHT_QUERY,
|
||||
"",
|
||||
"",
|
||||
)
|
||||
.unwrap();
|
||||
configuration.configure(&SCOPES);
|
||||
configuration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_parser(language: LapceLanguage) -> Parser {
|
||||
let language = match language {
|
||||
LapceLanguage::Rust => tree_sitter_rust::language(),
|
||||
LapceLanguage::Javascript => tree_sitter_javascript::language(),
|
||||
LapceLanguage::Go => tree_sitter_go::language(),
|
||||
};
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(language).unwrap();
|
||||
parser
|
||||
}
|
|
@ -10,7 +10,6 @@
|
|||
pub mod explorer;
|
||||
pub mod find;
|
||||
pub mod keypress;
|
||||
pub mod language;
|
||||
pub mod lsp;
|
||||
pub mod menu;
|
||||
pub mod movement;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use druid::piet::PietText;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use xi_rope::{RopeDelta, Transformer};
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use alacritty_terminal::{grid::Dimensions, term::cell::Flags};
|
||||
use anyhow::Result;
|
||||
use bit_vec::BitVec;
|
||||
use crossbeam_channel::{unbounded, Receiver, Sender, TryRecvError};
|
||||
use druid::{
|
||||
piet::{Svg, TextAttribute},
|
||||
Command, ExtEventSink, FontFamily, FontWeight, Lens, Modifiers, Target,
|
||||
WidgetId, WindowId,
|
||||
WidgetId,
|
||||
};
|
||||
use druid::{
|
||||
piet::{Text, TextLayout as PietTextLayout, TextLayoutBuilder},
|
||||
|
@ -13,9 +12,8 @@
|
|||
};
|
||||
use fuzzy_matcher::skim::SkimMatcherV2;
|
||||
use fuzzy_matcher::FuzzyMatcher;
|
||||
use fzyr::Score;
|
||||
use itertools::Itertools;
|
||||
use lsp_types::{DocumentSymbolResponse, Location, Position, Range, SymbolKind};
|
||||
use lsp_types::{DocumentSymbolResponse, Range, SymbolKind};
|
||||
use serde_json;
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
|
@ -1175,51 +1173,6 @@ fn filter_items(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PaletteItem {
|
||||
#[allow(dead_code)]
|
||||
window_id: WindowId,
|
||||
|
||||
#[allow(dead_code)]
|
||||
tab_id: WidgetId,
|
||||
|
||||
#[allow(dead_code)]
|
||||
icon: PaletteIcon,
|
||||
|
||||
#[allow(dead_code)]
|
||||
kind: PaletteType,
|
||||
|
||||
#[allow(dead_code)]
|
||||
text: String,
|
||||
|
||||
#[allow(dead_code)]
|
||||
hint: Option<String>,
|
||||
|
||||
#[allow(dead_code)]
|
||||
score: Score,
|
||||
|
||||
#[allow(dead_code)]
|
||||
index: usize,
|
||||
|
||||
#[allow(dead_code)]
|
||||
match_mask: BitVec,
|
||||
|
||||
#[allow(dead_code)]
|
||||
position: Option<Position>,
|
||||
|
||||
#[allow(dead_code)]
|
||||
location: Option<Location>,
|
||||
|
||||
#[allow(dead_code)]
|
||||
path: Option<PathBuf>,
|
||||
|
||||
#[allow(dead_code)]
|
||||
workspace: Option<LapceWorkspace>,
|
||||
|
||||
#[allow(dead_code)]
|
||||
command: Option<LapceCommand>,
|
||||
}
|
||||
|
||||
fn file_paint_items(
|
||||
path: &Path,
|
||||
indices: &[usize],
|
||||
|
|
|
@ -87,7 +87,7 @@ fn handle_notification(&mut self, rpc: Self::Notification) -> ControlFlow {
|
|||
style.style,
|
||||
);
|
||||
}
|
||||
let styles_span = styles_span.build();
|
||||
let styles_span = Arc::new(styles_span.build());
|
||||
let _ = event_sink.submit_command(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::UpdateSemanticStyles(
|
||||
|
@ -100,20 +100,6 @@ fn handle_notification(&mut self, rpc: Self::Notification) -> ControlFlow {
|
|||
);
|
||||
});
|
||||
}
|
||||
Notification::SemanticTokens {
|
||||
rev,
|
||||
buffer_id,
|
||||
path,
|
||||
tokens,
|
||||
} => {
|
||||
let _ = self.event_sink.submit_command(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::UpdateSemanticTokens(
|
||||
buffer_id, path, rev, tokens,
|
||||
),
|
||||
Target::Widget(self.tab_id),
|
||||
);
|
||||
}
|
||||
Notification::ReloadBuffer {
|
||||
buffer_id,
|
||||
new_content,
|
||||
|
@ -643,12 +629,6 @@ pub enum CursorShape {
|
|||
#[serde(tag = "method", content = "params")]
|
||||
pub enum Notification {
|
||||
ProxyConnected {},
|
||||
SemanticTokens {
|
||||
rev: u64,
|
||||
buffer_id: BufferId,
|
||||
path: PathBuf,
|
||||
tokens: Vec<(usize, usize, String)>,
|
||||
},
|
||||
SemanticStyles {
|
||||
rev: u64,
|
||||
buffer_id: BufferId,
|
||||
|
|
|
@ -134,11 +134,9 @@ pub fn get_semantic_tokens(&self, buffer: &Buffer) {
|
|||
.as_ref()
|
||||
.unwrap()
|
||||
.semantic_tokens_provider;
|
||||
if let Some(styles) = format_semantic_styles(
|
||||
buffer,
|
||||
semantic_tokens_provider,
|
||||
res.clone(),
|
||||
) {
|
||||
if let Some(styles) =
|
||||
format_semantic_styles(buffer, semantic_tokens_provider, res)
|
||||
{
|
||||
local_dispatcher.send_notification(
|
||||
"semantic_styles",
|
||||
json!({
|
||||
|
@ -150,19 +148,6 @@ pub fn get_semantic_tokens(&self, buffer: &Buffer) {
|
|||
}),
|
||||
)
|
||||
}
|
||||
if let Some(tokens) =
|
||||
format_semantic_tokens(buffer, semantic_tokens_provider, res)
|
||||
{
|
||||
local_dispatcher.send_notification(
|
||||
"semantic_tokens",
|
||||
json!({
|
||||
"rev": rev,
|
||||
"buffer_id": buffer_id,
|
||||
"path": path,
|
||||
"tokens": tokens,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1044,39 +1029,6 @@ fn format_semantic_styles(
|
|||
Some(highlights)
|
||||
}
|
||||
|
||||
fn format_semantic_tokens(
|
||||
buffer: &Buffer,
|
||||
semantic_tokens_provider: &Option<SemanticTokensServerCapabilities>,
|
||||
value: Value,
|
||||
) -> Option<Vec<(usize, usize, String)>> {
|
||||
let semantic_tokens: SemanticTokens = serde_json::from_value(value).ok()?;
|
||||
let semantic_tokens_provider = semantic_tokens_provider.as_ref()?;
|
||||
let semantic_lengends = semantic_tokens_lengend(semantic_tokens_provider);
|
||||
|
||||
let mut highlights = Vec::new();
|
||||
let mut line = 0;
|
||||
let mut start = 0;
|
||||
let mut last_start = 0;
|
||||
for semantic_token in &semantic_tokens.data {
|
||||
if semantic_token.delta_line > 0 {
|
||||
line += semantic_token.delta_line as usize;
|
||||
start = buffer.offset_of_line(line);
|
||||
}
|
||||
start += semantic_token.delta_start as usize;
|
||||
let end = start + semantic_token.length as usize;
|
||||
let kind = semantic_lengends.token_types[semantic_token.token_type as usize]
|
||||
.as_str()
|
||||
.to_string();
|
||||
if start < last_start {
|
||||
continue;
|
||||
}
|
||||
last_start = start;
|
||||
highlights.push((start, end, kind));
|
||||
}
|
||||
|
||||
Some(highlights)
|
||||
}
|
||||
|
||||
fn semantic_tokens_lengend(
|
||||
semantic_tokens_provider: &SemanticTokensServerCapabilities,
|
||||
) -> SemanticTokensLegend {
|
||||
|
|
|
@ -34,11 +34,6 @@ jsonrpc-lite = "0.5.0"
|
|||
bit-vec = "0.5.0"
|
||||
parking_lot = { version = "0.11.0", features = ["deadlock_detection"] }
|
||||
include_dir = "0.6.0"
|
||||
tree-sitter = "0.20.2"
|
||||
tree-sitter-highlight = "0.20.1"
|
||||
tree-sitter-rust = "0.20.0"
|
||||
tree-sitter-go = "0.19.1"
|
||||
tree-sitter-javascript = "0.20.0"
|
||||
anyhow = "1.0.32"
|
||||
strum = "0.19"
|
||||
strum_macros = "0.19"
|
||||
|
@ -48,7 +43,6 @@ serde_json = "1.0"
|
|||
notify = "5.0.0-pre.13"
|
||||
xi-rope = { git = "https://github.com/lapce/xi-editor", features = ["serde"] }
|
||||
xi-unicode = "0.3.0"
|
||||
fzyr = "0.1.2"
|
||||
fuzzy-matcher = "0.3.7"
|
||||
uuid = { version = "0.7.4", features = ["v4"] }
|
||||
lsp-types = { version = "0.89.2", features = ["proposed"] }
|
||||
|
|
|
@ -1767,8 +1767,16 @@ fn update(
|
|||
ctx.request_layout();
|
||||
}
|
||||
|
||||
if !buffer.styles.same(&old_buffer.styles) {
|
||||
ctx.request_paint();
|
||||
match (buffer.styles(), old_buffer.styles()) {
|
||||
(None, None) => {}
|
||||
(None, Some(_)) | (Some(_), None) => {
|
||||
ctx.request_paint();
|
||||
}
|
||||
(Some(new), Some(old)) => {
|
||||
if !new.same(old) {
|
||||
ctx.request_paint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if buffer.rev != old_buffer.rev {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
};
|
||||
use itertools::Itertools;
|
||||
use lapce_data::{
|
||||
buffer::{BufferContent, BufferUpdate, LocalBufferKind, UpdateEvent},
|
||||
buffer::LocalBufferKind,
|
||||
command::{LapceUICommand, LAPCE_NEW_COMMAND, LAPCE_UI_COMMAND},
|
||||
completion::CompletionStatus,
|
||||
config::{Config, LapceTheme},
|
||||
|
@ -770,31 +770,6 @@ fn event(
|
|||
}
|
||||
ctx.set_handled();
|
||||
}
|
||||
LapceUICommand::UpdateSemanticTokens(_id, path, rev, tokens) => {
|
||||
let buffer =
|
||||
data.main_split.open_files.get_mut(path).unwrap();
|
||||
if buffer.rev == *rev {
|
||||
if let Some(language) = buffer.language.as_ref() {
|
||||
if let BufferContent::File(path) = &buffer.content {
|
||||
let _ = data.update_sender.send(
|
||||
UpdateEvent::SemanticTokens(
|
||||
BufferUpdate {
|
||||
id: buffer.id,
|
||||
path: path.clone(),
|
||||
rope: buffer.rope.clone(),
|
||||
rev: *rev,
|
||||
language: *language,
|
||||
highlights: buffer.styles.clone(),
|
||||
semantic_tokens: true,
|
||||
},
|
||||
tokens.to_owned(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.set_handled();
|
||||
}
|
||||
LapceUICommand::ShowCodeActions
|
||||
| LapceUICommand::CancelCodeActions => {
|
||||
self.code_action.event(ctx, event, data, env);
|
||||
|
@ -823,23 +798,6 @@ fn event(
|
|||
));
|
||||
ctx.set_handled();
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
LapceUICommand::UpdateStyle {
|
||||
id,
|
||||
path,
|
||||
rev,
|
||||
highlights,
|
||||
semantic_tokens,
|
||||
} => {
|
||||
let buffer =
|
||||
data.main_split.open_files.get_mut(path).unwrap();
|
||||
Arc::make_mut(buffer).update_styles(
|
||||
*rev,
|
||||
highlights.to_owned(),
|
||||
*semantic_tokens,
|
||||
);
|
||||
ctx.set_handled();
|
||||
}
|
||||
LapceUICommand::FocusSourceControl => {
|
||||
for (_, panel) in data.panels.iter_mut() {
|
||||
for kind in panel.widgets.clone() {
|
||||
|
@ -867,19 +825,6 @@ fn event(
|
|||
}
|
||||
ctx.set_handled();
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
LapceUICommand::UpdateSyntaxTree {
|
||||
id,
|
||||
path,
|
||||
rev,
|
||||
tree,
|
||||
} => {
|
||||
let buffer =
|
||||
data.main_split.open_files.get_mut(path).unwrap();
|
||||
Arc::make_mut(buffer)
|
||||
.update_syntax_tree(*rev, tree.to_owned());
|
||||
ctx.set_handled();
|
||||
}
|
||||
LapceUICommand::UpdateSyntax { path, rev, syntax } => {
|
||||
ctx.set_handled();
|
||||
let buffer =
|
||||
|
@ -919,10 +864,9 @@ fn event(
|
|||
ctx.set_handled();
|
||||
let buffer =
|
||||
data.main_split.open_files.get_mut(path).unwrap();
|
||||
Arc::make_mut(buffer).history_styles.insert(
|
||||
history.to_string(),
|
||||
Arc::new(highlights.to_owned()),
|
||||
);
|
||||
Arc::make_mut(buffer)
|
||||
.history_styles
|
||||
.insert(history.to_string(), highlights.to_owned());
|
||||
buffer
|
||||
.history_line_styles
|
||||
.borrow_mut()
|
||||
|
|
|
@ -304,7 +304,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceWindowData, _env: &Env) {
|
|||
let line = Line::new(Point::new(x, 0.0), Point::new(x, size.height));
|
||||
ctx.stroke(line, line_color, 1.0);
|
||||
|
||||
if tab.source_control.branch != "" {
|
||||
if !tab.source_control.branch.is_empty() {
|
||||
let command_rect = Size::ZERO.to_rect().with_origin(Point::new(x, 0.0));
|
||||
|
||||
x += 5.0;
|
||||
|
|
Loading…
Reference in New Issue