mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-09-11 16:07:00 +03:00
Refactor a little bit.
This commit is contained in:
parent
b17a77b8b8
commit
a106be94f1
@ -4,3 +4,7 @@ members = [
|
||||
"helix-term",
|
||||
"helix-syntax",
|
||||
]
|
||||
|
||||
# Build helix-syntax in release mode to make the code path faster in development.
|
||||
[profile.dev.package."helix-syntax"]
|
||||
opt-level = 3
|
||||
|
17
TODO.md
Normal file
17
TODO.md
Normal file
@ -0,0 +1,17 @@
|
||||
- Implement backspace/delete
|
||||
- Implement marks
|
||||
- Implement style configs, tab settings
|
||||
- Visual tab width
|
||||
- Refactor tree-sitter-highlight to work like the atom one, recomputing partial tree updates.
|
||||
- Only render highlights on screen
|
||||
- proper selection rendering
|
||||
- Undo tree
|
||||
- selection mode
|
||||
- key sequence shortcuts (gg etc)
|
||||
- syntax errors highlight query
|
||||
|
||||
- UI work: command line
|
||||
- UI work: tab popup on command line
|
||||
- UI work: completion popup
|
||||
- UI work: floating pane
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![allow(unused)]
|
||||
pub mod commands;
|
||||
pub mod graphemes;
|
||||
pub mod language_mode;
|
||||
pub mod syntax;
|
||||
mod selection;
|
||||
pub mod state;
|
||||
mod transaction;
|
||||
|
@ -65,6 +65,32 @@ impl LanguageLayer {
|
||||
// -- refactored from tree-sitter-highlight to be able to retain state
|
||||
// TODO: add seek() to iter
|
||||
|
||||
// problem: any time a layer is updated it must update it's injections on the parent (potentially
|
||||
// removing some from use)
|
||||
// can't modify to vec and exist in it at the same time since that would violate borrows
|
||||
// maybe we can do with an arena
|
||||
// maybe just caching on the top layer and nevermind the injections for now?
|
||||
//
|
||||
// Grammar {
|
||||
// layers: Vec<Box<Layer>> to prevent memory moves when vec is modified
|
||||
// }
|
||||
// injections tracked by marker:
|
||||
// if marker areas match it's fine and update
|
||||
// if not found add new layer
|
||||
// if length 0 then area got removed, clean up the layer
|
||||
//
|
||||
// layer update:
|
||||
// if range.len = 0 then remove the layer
|
||||
// for change in changes { tree.edit(change) }
|
||||
// tree = parser.parse(.., tree, ..)
|
||||
// calculate affected range and update injections
|
||||
// injection update:
|
||||
// look for existing injections
|
||||
// if present, range = (first injection start, last injection end)
|
||||
//
|
||||
// For now cheat and just throw out non-root layers if they exist. This should still improve
|
||||
// parsing in majority of cases.
|
||||
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::{iter, mem, ops, str, usize};
|
||||
use tree_sitter::{
|
||||
@ -73,8 +99,6 @@ impl LanguageLayer {
|
||||
};
|
||||
|
||||
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)]
|
||||
@ -207,7 +231,7 @@ pub fn highlight<'a>(
|
||||
cancellation_flag,
|
||||
highlighter: self,
|
||||
iter_count: 0,
|
||||
layers: layers,
|
||||
layers,
|
||||
next_event: None,
|
||||
last_highlight_range: None,
|
||||
};
|
||||
@ -405,7 +429,7 @@ fn new<F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a>(
|
||||
.parse(source, None)
|
||||
.ok_or(Error::Cancelled)?;
|
||||
unsafe { highlighter.parser.set_cancellation_flag(None) };
|
||||
let mut cursor = highlighter.cursors.pop().unwrap_or(QueryCursor::new());
|
||||
let mut cursor = highlighter.cursors.pop().unwrap_or_else(QueryCursor::new);
|
||||
|
||||
// Process combined injections.
|
||||
if let Some(combined_injections_query) = &config.combined_injections_query {
|
||||
@ -642,7 +666,7 @@ fn sort_layers(&mut self) {
|
||||
break;
|
||||
}
|
||||
if i > 0 {
|
||||
&self.layers[0..(i + 1)].rotate_left(1);
|
||||
self.layers[0..(i + 1)].rotate_left(1);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
@ -802,12 +826,9 @@ fn next(&mut self) -> Option<Self::Item> {
|
||||
local_defs: Vec::new(),
|
||||
};
|
||||
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 let "local.scope-inherits" = prop.key.as_ref() {
|
||||
scope.inherits =
|
||||
prop.value.as_ref().map_or(true, |r| r.as_ref() == "true");
|
||||
}
|
||||
}
|
||||
layer.scope_stack.push(scope);
|
@ -11,9 +11,6 @@ name = "hx"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
# termwiz = { git = "https://github.com/wez/wezterm", features = ["widgets"] }
|
||||
# termwiz = { path = "../../wezterm/termwiz", default-features = false, features = ["widgets"] }
|
||||
|
||||
helix-syntax = { path = "../helix-syntax" }
|
||||
|
||||
anyhow = "1"
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{keymap, theme::Theme, Args};
|
||||
use helix_core::{
|
||||
language_mode::{HighlightConfiguration, HighlightEvent, Highlighter},
|
||||
syntax::{HighlightConfiguration, HighlightEvent, Highlighter},
|
||||
state::coords_at_pos,
|
||||
state::Mode,
|
||||
State,
|
||||
@ -40,7 +40,6 @@ pub struct Editor {
|
||||
theme: Theme,
|
||||
highlighter: Highlighter,
|
||||
highlight_config: HighlightConfiguration,
|
||||
highlight_names: Vec<String>,
|
||||
}
|
||||
|
||||
impl Editor {
|
||||
@ -51,36 +50,7 @@ pub fn new(mut args: Args) -> Result<Self, Error> {
|
||||
let size = terminal::size().unwrap();
|
||||
let area = Rect::new(0, 0, size.0, size.1);
|
||||
|
||||
let highlight_names: Vec<String> = [
|
||||
"attribute",
|
||||
"constant.builtin",
|
||||
"constant",
|
||||
"function.builtin",
|
||||
"function.macro",
|
||||
"function",
|
||||
"keyword",
|
||||
"operator",
|
||||
"property",
|
||||
"punctuation",
|
||||
"comment",
|
||||
"escape",
|
||||
"label",
|
||||
// "punctuation.bracket",
|
||||
"punctuation.delimiter",
|
||||
"string",
|
||||
"string.special",
|
||||
"tag",
|
||||
"type",
|
||||
"type.builtin",
|
||||
"constructor",
|
||||
"variable",
|
||||
"variable.builtin",
|
||||
"variable.parameter",
|
||||
"path",
|
||||
]
|
||||
.iter()
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
let theme = Theme::default();
|
||||
|
||||
// let mut parser = tree_sitter::Parser::new();
|
||||
// parser.set_language(language).unwrap();
|
||||
@ -104,7 +74,7 @@ pub fn new(mut args: Args) -> Result<Self, Error> {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
highlight_config.configure(&highlight_names);
|
||||
highlight_config.configure(theme.scopes());
|
||||
|
||||
let mut editor = Editor {
|
||||
terminal,
|
||||
@ -112,11 +82,10 @@ pub fn new(mut args: Args) -> Result<Self, Error> {
|
||||
first_line: 0,
|
||||
size,
|
||||
surface: Surface::empty(area),
|
||||
theme: Theme::default(),
|
||||
theme,
|
||||
// TODO; move to state
|
||||
highlighter,
|
||||
highlight_config,
|
||||
highlight_names,
|
||||
};
|
||||
|
||||
if let Some(file) = args.files.pop() {
|
||||
@ -178,7 +147,7 @@ fn render(&mut self) {
|
||||
use tui::style::Color;
|
||||
|
||||
let style = match spans.first() {
|
||||
Some(span) => self.theme.get(self.highlight_names[span.0].as_str()),
|
||||
Some(span) => self.theme.get(self.theme.scopes()[span.0].as_str()),
|
||||
None => Style::default().fg(Color::Rgb(164, 160, 232)), // lavender
|
||||
};
|
||||
|
||||
|
@ -3,9 +3,38 @@
|
||||
|
||||
/// Color theme for syntax highlighting.
|
||||
pub struct Theme {
|
||||
scopes: Vec<String>,
|
||||
mapping: HashMap<&'static str, Style>,
|
||||
}
|
||||
|
||||
// let highlight_names: Vec<String> = [
|
||||
// "attribute",
|
||||
// "constant.builtin",
|
||||
// "constant",
|
||||
// "function.builtin",
|
||||
// "function.macro",
|
||||
// "function",
|
||||
// "keyword",
|
||||
// "operator",
|
||||
// "property",
|
||||
// "punctuation",
|
||||
// "comment",
|
||||
// "escape",
|
||||
// "label",
|
||||
// // "punctuation.bracket",
|
||||
// "punctuation.delimiter",
|
||||
// "string",
|
||||
// "string.special",
|
||||
// "tag",
|
||||
// "type",
|
||||
// "type.builtin",
|
||||
// "constructor",
|
||||
// "variable",
|
||||
// "variable.builtin",
|
||||
// "variable.parameter",
|
||||
// "path",
|
||||
// ];
|
||||
|
||||
impl Default for Theme {
|
||||
fn default() -> Self {
|
||||
let mapping = hashmap! {
|
||||
@ -45,7 +74,9 @@ fn default() -> Self {
|
||||
"function.builtin" => Style::default().fg(Color::Rgb(255, 0, 0)), // white
|
||||
};
|
||||
|
||||
Self { mapping }
|
||||
let scopes = mapping.keys().map(ToString::to_string).collect();
|
||||
|
||||
Self { mapping, scopes }
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,4 +87,8 @@ pub fn get(&self, scope: &str) -> Style {
|
||||
.copied()
|
||||
.unwrap_or_else(|| Style::default().fg(Color::Rgb(0, 0, 255)))
|
||||
}
|
||||
|
||||
pub fn scopes(&self) -> &[String] {
|
||||
&self.scopes
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
aaa
|
||||
bbb
|
||||
ccc
|
Loading…
Reference in New Issue
Block a user