@@ -177,14 +177,13 @@ impl HighlightingAssets {
177177 & self ,
178178 language : Option < & str > ,
179179 file : InputFile ,
180- file_name : Option < & str > ,
181180 reader : & mut InputFileReader ,
182181 mapping : & SyntaxMapping ,
183182 ) -> & SyntaxReference {
184- let syntax = match ( language, file, file_name ) {
185- ( Some ( language) , _, _ ) => self . syntax_set . find_syntax_by_token ( language) ,
186- ( None , InputFile :: Ordinary ( file ) , _ ) => {
187- let path = Path :: new ( file ) ;
183+ let syntax = match ( language, file) {
184+ ( Some ( language) , _) => self . syntax_set . find_syntax_by_token ( language) ,
185+ ( None , InputFile :: Ordinary ( ofile ) ) => {
186+ let path = Path :: new ( ofile . filename ( ) ) ;
188187
189188 let file_name = path. file_name ( ) . and_then ( |n| n. to_str ( ) ) . unwrap_or ( "" ) ;
190189 let extension = path. extension ( ) . and_then ( |x| x. to_str ( ) ) . unwrap_or ( "" ) ;
@@ -208,12 +207,12 @@ impl HighlightingAssets {
208207 None => ext_syntax. or ( line_syntax) ,
209208 }
210209 }
211- ( None , InputFile :: StdIn , None ) => String :: from_utf8 ( reader. first_line . clone ( ) )
210+ ( None , InputFile :: StdIn ( None ) ) => String :: from_utf8 ( reader. first_line . clone ( ) )
212211 . ok ( )
213212 . and_then ( |l| self . syntax_set . find_syntax_by_first_line ( & l) ) ,
214- ( None , InputFile :: StdIn , Some ( file_name) ) => self
213+ ( None , InputFile :: StdIn ( Some ( file_name) ) ) => self
215214 . syntax_set
216- . find_syntax_by_extension ( & file_name)
215+ . find_syntax_by_extension ( file_name. to_str ( ) . unwrap ( ) )
217216 . or_else ( || {
218217 self . syntax_set . find_syntax_by_extension (
219218 Path :: new ( file_name)
@@ -225,7 +224,7 @@ impl HighlightingAssets {
225224 . or ( String :: from_utf8 ( reader. first_line . clone ( ) )
226225 . ok ( )
227226 . and_then ( |l| self . syntax_set . find_syntax_by_first_line ( & l) ) ) ,
228- ( _, InputFile :: ThemePreviewFile , _ ) => self . syntax_set . find_syntax_by_name ( "Rust" ) ,
227+ ( _, InputFile :: ThemePreviewFile ) => self . syntax_set . find_syntax_by_name ( "Rust" ) ,
229228 } ;
230229
231230 syntax. unwrap_or_else ( || self . syntax_set . find_syntax_plain_text ( ) )
@@ -242,7 +241,7 @@ mod tests {
242241 use tempdir:: TempDir ;
243242
244243 use crate :: assets:: HighlightingAssets ;
245- use crate :: inputfile:: InputFile ;
244+ use crate :: inputfile:: { InputFile , OrdinaryFile } ;
246245 use crate :: syntax_mapping:: { MappingTarget , SyntaxMapping } ;
247246
248247 struct SyntaxDetectionTest < ' a > {
@@ -261,28 +260,17 @@ mod tests {
261260 }
262261 }
263262
264- fn syntax_for_file_with_content (
265- & self ,
266- file_name : & str ,
267- first_line : & str ,
268- as_stdin : bool ,
269- ) -> String {
263+ fn syntax_for_file_with_content ( & self , file_name : & str , first_line : & str ) -> String {
270264 let file_path = self . temp_dir . path ( ) . join ( file_name) ;
271265 {
272266 let mut temp_file = File :: create ( & file_path) . unwrap ( ) ;
273267 writeln ! ( temp_file, "{}" , first_line) . unwrap ( ) ;
274268 }
275269
276- let input_file = InputFile :: Ordinary ( OsStr :: new ( & file_path) ) ;
277- let ( file, file_name) = if as_stdin {
278- ( InputFile :: StdIn , Some ( file_name) )
279- } else {
280- ( input_file, None )
281- } ;
270+ let input_file = InputFile :: Ordinary ( OrdinaryFile :: new ( OsStr :: new ( & file_path) , None ) ) ;
282271 let syntax = self . assets . get_syntax (
283272 None ,
284- file,
285- file_name,
273+ input_file,
286274 & mut input_file. get_reader ( & io:: stdin ( ) ) . unwrap ( ) ,
287275 & self . syntax_mapping ,
288276 ) ;
@@ -291,7 +279,7 @@ mod tests {
291279 }
292280
293281 fn syntax_for_file ( & self , file_name : & str ) -> String {
294- self . syntax_for_file_with_content ( file_name, "" , false )
282+ self . syntax_for_file_with_content ( file_name, "" )
295283 }
296284 }
297285
@@ -325,15 +313,15 @@ mod tests {
325313 let test = SyntaxDetectionTest :: new ( ) ;
326314
327315 assert_eq ! (
328- test. syntax_for_file_with_content( "my_script" , "#!/bin/bash" , false ) ,
316+ test. syntax_for_file_with_content( "my_script" , "#!/bin/bash" ) ,
329317 "Bourne Again Shell (bash)"
330318 ) ;
331319 assert_eq ! (
332- test. syntax_for_file_with_content( "build" , "#!/bin/bash" , false ) ,
320+ test. syntax_for_file_with_content( "build" , "#!/bin/bash" ) ,
333321 "Bourne Again Shell (bash)"
334322 ) ;
335323 assert_eq ! (
336- test. syntax_for_file_with_content( "my_script" , "<?php" , false ) ,
324+ test. syntax_for_file_with_content( "my_script" , "<?php" ) ,
337325 "PHP"
338326 ) ;
339327 }
@@ -365,13 +353,10 @@ mod tests {
365353 let test = SyntaxDetectionTest :: new ( ) ;
366354
367355 // from file extension
368- assert_eq ! (
369- test. syntax_for_file_with_content( "test.cpp" , "" , true ) ,
370- "C++"
371- ) ;
356+ assert_eq ! ( test. syntax_for_file_with_content( "test.cpp" , "" ) , "C++" ) ;
372357 // from first line (fallback)
373358 assert_eq ! (
374- test. syntax_for_file_with_content( "my_script" , "#!/bin/bash" , true ) ,
359+ test. syntax_for_file_with_content( "my_script" , "#!/bin/bash" ) ,
375360 "Bourne Again Shell (bash)"
376361 ) ;
377362 }
0 commit comments