From 1db03ebecdccc00bf16b0aa0ebca08b512801c1d Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Sun, 22 Jun 2025 21:07:51 +0200 Subject: [PATCH] wip --- .vscode/launch.json | 6 +++--- src/buffer/highlighter.rs | 38 ++++++++++++++++++++++++++++---------- src/buffer/mod.rs | 4 ++-- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d11a903..bbc204e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "program": "${workspaceFolder}/target/debug/edit", "cwd": "${workspaceFolder}", "args": [ - "${workspaceFolder}/src/bin/edit/main.rs" + "C:/Users/lhecker/projects/posh-git/src/GitPrompt.ps1" ], }, { @@ -21,7 +21,7 @@ "program": "${workspaceFolder}/target/debug/edit", "cwd": "${workspaceFolder}", "args": [ - "${workspaceFolder}/src/bin/edit/main.rs" + "C:/Users/lhecker/projects/posh-git/src/GitPrompt.ps1" ], }, { @@ -32,7 +32,7 @@ "program": "${workspaceFolder}/target/debug/edit", "cwd": "${workspaceFolder}", "args": [ - "${workspaceFolder}/src/bin/edit/main.rs" + "C:/Users/lhecker/projects/posh-git/src/GitPrompt.ps1" ], } ] diff --git a/src/buffer/highlighter.rs b/src/buffer/highlighter.rs index b03009c..2bcafa3 100644 --- a/src/buffer/highlighter.rs +++ b/src/buffer/highlighter.rs @@ -1,7 +1,7 @@ #![allow(dead_code, unused_variables, unused_mut)] use std::fmt::Debug; -use std::ops::{Range, RangeInclusive}; +use std::ops::Range; use crate::arena::{Arena, scratch_arena}; use crate::document::ReadableDocument; @@ -51,7 +51,7 @@ enum Test { } struct Language { - word_chars: &'static [RangeInclusive], + word_chars: &'static [u16; 6], states: &'static [&'static [Transition]], } @@ -91,7 +91,20 @@ const POWERSHELL: Language = { const METHOD: u8 = 11; Language { - word_chars: &[b'0'..=b'9', b'A'..=b'Z', b'a'..=b'z', b'?'..=b'?', b'_'..=b'_'], + word_chars: &[ + // /.-,+*)('&%$#"! + 0b_1110110000101010, + // ?>=<;:9876543210 + 0b_1111011111111111, + // ONMLKJIHGFEDCBA@ + 0b_1111111111111110, + // _^]\[ZYXWVUTSRQP + 0b_1111111111111111, + // onmlkjihgfedcba` + 0b_1111111111111111, + // ~}|{zyxwvutsrqp + 0b_0100011111111111, + ], states: &[ // GROUND &[ @@ -228,9 +241,14 @@ impl<'doc> Highlighter<'doc> { } } - fn fill_word_chars(dst: &mut [bool; 256], src: &[RangeInclusive]) { - for r in src { - dst[*r.start() as usize..=*r.end() as usize].fill(true); + fn fill_word_chars(dst: &mut [bool; 256], src: &[u16; 6]) { + for y in 0..src.len() { + let mut r = src[y]; + while r != 0 { + let bit = r.trailing_zeros() as usize; + r &= !(1 << bit); + dst[32 + y * 16 + bit] = true; + } } dst[0x80..].fill(true); } @@ -245,6 +263,10 @@ impl<'doc> Highlighter<'doc> { let mut line_buf = Vec::new_in(&*scratch); let mut res = Vec::new_in(arena); + if self.offset != 0 { + self.logical_pos_y += 1; + } + // Accumulate a line of text into `line_buf`. { let mut chunk = self.doc.read_forward(self.offset); @@ -254,10 +276,6 @@ impl<'doc> Highlighter<'doc> { return res; } - if self.offset != 0 { - self.logical_pos_y += 1; - } - loop { let (off, line) = simd::lines_fwd(chunk, 0, 0, 1); self.offset += off; diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index ee0e22a..fd9d204 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -1961,7 +1961,7 @@ impl TextBuffer { global_off += chunk.len(); } - while highlighter.logical_pos_y() < cursor.logical_pos.y { + while highlighter.logical_pos_y() < cursor_beg.logical_pos.y - 1 { let scratch_alt = scratch_arena(Some(&scratch)); _ = highlighter.parse_next_line(&scratch_alt); } @@ -1973,7 +1973,7 @@ impl TextBuffer { HighlightKind::Comment => IndexedColor::Green, HighlightKind::Number => IndexedColor::BrightGreen, HighlightKind::String => IndexedColor::BrightRed, - HighlightKind::Variable => IndexedColor::BrightCyan, + HighlightKind::Variable => IndexedColor::BrightBlue, HighlightKind::Operator => IndexedColor::White, HighlightKind::Keyword => IndexedColor::BrightMagenta, HighlightKind::Method => IndexedColor::BrightYellow,