@@ -30,7 +30,8 @@ use file_controller::results::{
30
30
FileResult ,
31
31
LineResult ,
32
32
FindResult ,
33
- SymbolResult
33
+ SymbolResult ,
34
+ CONTEXT_SIZE ,
34
35
} ;
35
36
36
37
pub struct Cache {
@@ -131,15 +132,6 @@ impl Cache {
131
132
} ) )
132
133
}
133
134
134
- pub fn get_highlighted_line (
135
- & self ,
136
- file_name : & Path ,
137
- line : span:: Row < span:: ZeroIndexed > ,
138
- ) -> Result < String , String > {
139
- let lines = self . get_highlighted ( file_name) ?;
140
- Ok ( lines[ line. 0 as usize ] . clone ( ) )
141
- }
142
-
143
135
pub fn update_analysis ( & self ) {
144
136
println ! ( "Processing analysis..." ) ;
145
137
let workspace_root = self
@@ -275,11 +267,26 @@ impl Cache {
275
267
}
276
268
277
269
fn make_line_result ( & self , file_path : & Path , span : & Span ) -> Result < LineResult , String > {
278
- let text = match self . get_highlighted_line ( file_path, span. range . row_start ) {
279
- Ok ( t) => t,
270
+ let ( text, context) = match self . get_highlighted ( file_path) {
271
+ Ok ( lines) => {
272
+ let line = span. range . row_start . 0 as i32 ;
273
+ let text = lines[ line as usize ] . clone ( ) ;
274
+
275
+ let mut ctx_start = line - CONTEXT_SIZE ;
276
+ if ctx_start < 0 {
277
+ ctx_start = 0 ;
278
+ }
279
+ let mut ctx_end = line + CONTEXT_SIZE ;
280
+ if ctx_end >= lines. len ( ) as i32 {
281
+ ctx_end = lines. len ( ) as i32 - 1 ;
282
+ }
283
+ let context = lines[ ctx_start as usize ..=ctx_end as usize ] . join ( "\n " ) ;
284
+
285
+ ( text, context)
286
+ }
280
287
Err ( _) => return Err ( format ! ( "Error finding text for {:?}" , span) ) ,
281
288
} ;
282
- Ok ( LineResult :: new ( span, text) )
289
+ Ok ( LineResult :: new ( span, text, context ) )
283
290
}
284
291
285
292
// Sorts a set of search results into buckets by file.
0 commit comments