@@ -255,57 +255,56 @@ impl HighlightingAssets {
255255 ) -> Result<SyntaxReferenceInSet> {
256256 if let Some(language) = language {
257257 let syntax_set = self.get_syntax_set_by_name(language)?;
258− syntax_set
258+ return syntax_set
259259 .find_syntax_by_token(language)
260260 .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set })
261− .ok_or_else(|| Error::UnknownSyntax(language.to_owned()))
262− } else {
263− let line_syntax = self.get_first_line_syntax(&mut input.reader)?;
264−
265− // Get the path of the file:
266− // If this was set by the metadata, that will take priority.
267− // If it wasn't, it will use the real file path (if available).
268− let path_str =
269− input
270− .metadata
271− .user_provided_name
272− .as_ref()
273− .or_else(|| match input.kind {
274− OpenedInputKind::OrdinaryFile(ref path) => Some(path),
275− _ => None,
276− });
277−
278− if let Some(path_str) = path_str {
279− // If a path was provided, we try and detect the syntax based on extension mappings.
280− let path = Path::new(path_str);
281− let absolute_path = PathAbs::new(path)
282− .ok()
283− .map(|p| p.as_path().to_path_buf())
284− .unwrap_or_else(|| path.to_owned());
285−
286− match mapping.get_syntax_for(absolute_path) {
287− Some(MappingTarget::MapToUnknown) => line_syntax
288− .ok_or_else(|| Error::UndetectedSyntax(path.to_string_lossy().into())),
289−
290− Some(MappingTarget::MapTo(syntax_name)) => {
291− let syntax_set = self.get_syntax_set()?;
292− syntax_set
293− .find_syntax_by_name(syntax_name)
294− .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set })
295− .ok_or_else(|| Error::UnknownSyntax(syntax_name.to_owned()))
296− }
297−
298− None => {
299− let file_name = path.file_name().unwrap_or_default();
300− self.get_extension_syntax(file_name)?
301− .or(line_syntax)
302− .ok_or_else(|| Error::UndetectedSyntax(path.to_string_lossy().into()))
303− }
261+ .ok_or_else(|| Error::UnknownSyntax(language.to_owned()));
262+ }
263+
264+ let line_syntax = self.get_first_line_syntax(&mut input.reader)?;
265+
266+ // Get the path of the file:
267+ // If this was set by the metadata, that will take priority.
268+ // If it wasn't, it will use the real file path (if available).
269+ let path_str = input
270+ .metadata
271+ .user_provided_name
272+ .as_ref()
273+ .or_else(|| match input.kind {
274+ OpenedInputKind::OrdinaryFile(ref path) => Some(path),
275+ _ => None,
276+ });
277+
278+ if let Some(path_str) = path_str {
279+ // If a path was provided, we try and detect the syntax based on extension mappings.
280+ let path = Path::new(path_str);
281+ let absolute_path = PathAbs::new(path)
282+ .ok()
283+ .map(|p| p.as_path().to_path_buf())
284+ .unwrap_or_else(|| path.to_owned());
285+
286+ match mapping.get_syntax_for(absolute_path) {
287+ Some(MappingTarget::MapToUnknown) => line_syntax
288+ .ok_or_else(|| Error::UndetectedSyntax(path.to_string_lossy().into())),
289+
290+ Some(MappingTarget::MapTo(syntax_name)) => {
291+ let syntax_set = self.get_syntax_set()?;
292+ syntax_set
293+ .find_syntax_by_name(syntax_name)
294+ .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set })
295+ .ok_or_else(|| Error::UnknownSyntax(syntax_name.to_owned()))
296+ }
297+
298+ None => {
299+ let file_name = path.file_name().unwrap_or_default();
300+ self.get_extension_syntax(file_name)?
301+ .or(line_syntax)
302+ .ok_or_else(|| Error::UndetectedSyntax(path.to_string_lossy().into()))
304303 }
305− } else {
306− // If a path wasn't provided, we fall back to the detect first-line syntax.
307− line_syntax.ok_or_else(|| Error::UndetectedSyntax("[unknown]".into()))
308304 }
305+ } else {
306+ // If a path wasn't provided, we fall back to the detect first-line syntax.
307+ line_syntax.ok_or_else(|| Error::UndetectedSyntax("[unknown]".into()))
309308 }
310309 }
311310