@@ -2,7 +2,7 @@ use crate::error::{OxError, Result};
22use crossterm:: style:: Color as CColor ;
33use mlua:: prelude:: * ;
44use std:: collections:: HashMap ;
5- use synoptic:: { from_extension , Highlighter } ;
5+ use synoptic:: Highlighter ;
66
77use super :: Color ;
88
@@ -27,14 +27,6 @@ impl SyntaxHighlighting {
2727 ) ) )
2828 }
2929 }
30-
31- /// Get a highlighter given a file extension
32- pub fn get_highlighter ( & self , ext : & str ) -> Highlighter {
33- self . user_rules . get ( ext) . map_or_else (
34- || from_extension ( ext, 4 ) . unwrap_or_else ( || Highlighter :: new ( 4 ) ) ,
35- std:: clone:: Clone :: clone,
36- )
37- }
3830}
3931
4032impl LuaUserData for SyntaxHighlighting {
@@ -84,40 +76,36 @@ impl LuaUserData for SyntaxHighlighting {
8476 ) ;
8577 methods. add_method_mut (
8678 "new" ,
87- |_, syntax_highlighting, ( extensions, rules) : ( LuaTable , LuaTable ) | {
88- // Make note of the highlighter
89- for ext_idx in 1 ..=( extensions. len ( ) ?) {
90- // Create highlighter
91- let mut highlighter = Highlighter :: new ( 4 ) ;
92- // Add rules one by one
93- for rule_idx in 1 ..=( rules. len ( ) ?) {
94- // Get rule
95- let rule = rules. get :: < i64 , HashMap < String , String > > ( rule_idx) ?;
96- // Find type of rule and attatch it to the highlighter
97- match rule[ "kind" ] . as_str ( ) {
98- "keyword" => {
99- highlighter. keyword ( rule[ "name" ] . clone ( ) , & rule[ "pattern" ] ) ;
100- }
101- "bounded" => highlighter. bounded (
102- rule[ "name" ] . clone ( ) ,
103- rule[ "start" ] . clone ( ) ,
104- rule[ "end" ] . clone ( ) ,
105- rule[ "escape" ] == "true" ,
106- ) ,
107- "bounded_interpolation" => highlighter. bounded_interp (
108- rule[ "name" ] . clone ( ) ,
109- rule[ "start" ] . clone ( ) ,
110- rule[ "end" ] . clone ( ) ,
111- rule[ "i_start" ] . clone ( ) ,
112- rule[ "i_end" ] . clone ( ) ,
113- rule[ "escape" ] == "true" ,
114- ) ,
115- _ => unreachable ! ( ) ,
79+ |_, syntax_highlighting, ( name, rules) : ( String , LuaTable ) | {
80+ // Create highlighter
81+ let mut highlighter = Highlighter :: new ( 4 ) ;
82+ // Add rules one by one
83+ for rule_idx in 1 ..=( rules. len ( ) ?) {
84+ // Get rule
85+ let rule = rules. get :: < i64 , HashMap < String , String > > ( rule_idx) ?;
86+ // Find type of rule and attatch it to the highlighter
87+ match rule[ "kind" ] . as_str ( ) {
88+ "keyword" => {
89+ highlighter. keyword ( rule[ "name" ] . clone ( ) , & rule[ "pattern" ] ) ;
11690 }
91+ "bounded" => highlighter. bounded (
92+ rule[ "name" ] . clone ( ) ,
93+ rule[ "start" ] . clone ( ) ,
94+ rule[ "end" ] . clone ( ) ,
95+ rule[ "escape" ] == "true" ,
96+ ) ,
97+ "bounded_interpolation" => highlighter. bounded_interp (
98+ rule[ "name" ] . clone ( ) ,
99+ rule[ "start" ] . clone ( ) ,
100+ rule[ "end" ] . clone ( ) ,
101+ rule[ "i_start" ] . clone ( ) ,
102+ rule[ "i_end" ] . clone ( ) ,
103+ rule[ "escape" ] == "true" ,
104+ ) ,
105+ _ => unreachable ! ( ) ,
117106 }
118- let ext = extensions. get :: < i64 , String > ( ext_idx) ?;
119- syntax_highlighting. user_rules . insert ( ext, highlighter) ;
120107 }
108+ syntax_highlighting. user_rules . insert ( name, highlighter) ;
121109 Ok ( ( ) )
122110 } ,
123111 ) ;
0 commit comments