@@ -36,17 +36,17 @@ use xi_trace::{trace, trace_block};
36
36
use xi_plugin_lib:: { Cache , Plugin , StateCache , View , mainloop} ;
37
37
38
38
use syntect:: parsing:: { ParseState , ScopeStack , SyntaxSet , SCOPE_REPO ,
39
- SyntaxDefinition , ScopeRepository } ;
39
+ SyntaxReference , ScopeRepository } ;
40
40
use stackmap:: { StackMap , LookupResult } ;
41
41
42
42
const LINES_PER_RPC : usize = 10 ;
43
43
const INDENTATION_PRIORITY : u64 = 100 ;
44
44
45
45
/// The state for syntax highlighting of one file.
46
- struct PluginState {
46
+ struct PluginState < ' a > {
47
47
stack_idents : StackMap ,
48
48
offset : usize ,
49
- initial_state : LineState ,
49
+ initial_state : LineState < ' a > ,
50
50
spans_start : usize ,
51
51
// unflushed spans
52
52
spans : Vec < ScopeSpan > ,
@@ -60,15 +60,15 @@ type LockedRepo = MutexGuard<'static, ScopeRepository>;
60
60
// Note: this needs to be option because the caching layer relies on Default.
61
61
// We can't implement that because the actual initial state depends on the
62
62
// syntax. There are other ways to handle this, but this will do for now.
63
- type LineState = Option < ( ParseState , ScopeStack ) > ;
63
+ type LineState < ' a > = Option < ( ParseState < ' a > , ScopeStack ) > ;
64
64
65
65
/// The state of syntax highlighting for a collection of buffers.
66
66
struct Syntect < ' a > {
67
- view_state : HashMap < ViewId , PluginState > ,
67
+ view_state : HashMap < ViewId , PluginState < ' a > > ,
68
68
syntax_set : & ' a SyntaxSet ,
69
69
}
70
70
71
- impl PluginState {
71
+ impl < ' a > PluginState < ' a > {
72
72
fn new ( ) -> Self {
73
73
PluginState {
74
74
stack_idents : StackMap :: default ( ) ,
@@ -81,7 +81,7 @@ impl PluginState {
81
81
}
82
82
83
83
// compute syntax for one line, also accumulating the style spans
84
- fn compute_syntax ( & mut self , line : & str , state : LineState ) -> LineState {
84
+ fn compute_syntax ( & mut self , line : & str , state : LineState < ' a > ) -> LineState < ' a > {
85
85
let ( mut parse_state, mut scope_state) = state. or_else ( || self . initial_state . clone ( ) ) . unwrap ( ) ;
86
86
let ops = parse_state. parse_line ( & line) ;
87
87
@@ -127,7 +127,7 @@ impl PluginState {
127
127
128
128
#[ allow( unused) ]
129
129
// Return true if there's any more work to be done.
130
- fn highlight_one_line ( & mut self , ctx : & mut MyView ) -> bool {
130
+ fn highlight_one_line ( & mut self , ctx : & mut MyView < ' a > ) -> bool {
131
131
if let Some ( line_num) = ctx. get_frontier ( ) {
132
132
let ( line_num, offset, state) = ctx. get_prev ( line_num) ;
133
133
if offset != self . offset {
@@ -166,7 +166,7 @@ impl PluginState {
166
166
false
167
167
}
168
168
169
- fn flush_spans ( & mut self , ctx : & mut MyView ) {
169
+ fn flush_spans ( & mut self , ctx : & mut MyView < ' a > ) {
170
170
let _t = trace_block ( "PluginState::flush_spans" , & [ "syntect" ] ) ;
171
171
if !self . new_scopes . is_empty ( ) {
172
172
ctx. add_scopes ( & self . new_scopes ) ;
@@ -181,7 +181,7 @@ impl PluginState {
181
181
}
182
182
}
183
183
184
- type MyView = View < StateCache < LineState > > ;
184
+ type MyView < ' a > = View < StateCache < LineState < ' a > > > ;
185
185
186
186
impl < ' a > Syntect < ' a > {
187
187
fn new ( syntax_set : & ' a SyntaxSet ) -> Self {
@@ -192,10 +192,10 @@ impl<'a> Syntect<'a> {
192
192
}
193
193
194
194
/// Wipes any existing state and starts highlighting with `syntax`.
195
- fn do_highlighting ( & mut self , view : & mut MyView ) {
195
+ fn do_highlighting ( & mut self , view : & mut MyView < ' a > ) {
196
196
let initial_state = {
197
197
let syntax = self . guess_syntax ( view. get_path ( ) ) ;
198
- Some ( ( ParseState :: new ( syntax) , ScopeStack :: new ( ) ) )
198
+ Some ( ( ParseState :: new ( self . syntax_set , syntax) , ScopeStack :: new ( ) ) )
199
199
} ;
200
200
201
201
let state = self . view_state . get_mut ( & view. get_id ( ) ) . unwrap ( ) ;
@@ -208,7 +208,7 @@ impl<'a> Syntect<'a> {
208
208
view. schedule_idle ( ) ;
209
209
}
210
210
211
- fn guess_syntax ( & ' a self , path : Option < & Path > ) -> & ' a SyntaxDefinition {
211
+ fn guess_syntax ( & self , path : Option < & Path > ) -> & ' a SyntaxReference {
212
212
let _t = trace_block ( "Syntect::guess_syntax" , & [ "syntect" ] ) ;
213
213
match path {
214
214
Some ( path) => self . syntax_set . find_syntax_for_file ( path)
@@ -297,7 +297,7 @@ impl<'a> Syntect<'a> {
297
297
298
298
299
299
impl < ' a > Plugin for Syntect < ' a > {
300
- type Cache = StateCache < LineState > ;
300
+ type Cache = StateCache < LineState < ' a > > ;
301
301
302
302
fn new_view ( & mut self , view : & mut View < Self :: Cache > ) {
303
303
let _t = trace_block ( "Syntect::new_view" , & [ "syntect" ] ) ;
0 commit comments