@@ -255,57 +255,56 @@ impl HighlightingAssets {
255 ) -> Result<SyntaxReferenceInSet> {
255 ) -> Result<SyntaxReferenceInSet> {
256 if let Some(language) = language {
256 if let Some(language) = language {
257 let syntax_set = self.get_syntax_set_by_name(language)?;
257 let syntax_set = self.get_syntax_set_by_name(language)?;
258− syntax_set
258+ return syntax_set
259 .find_syntax_by_token(language)
259 .find_syntax_by_token(language)
260 .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set })
260 .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set })
261− .ok_or_else(|| Error::UnknownSyntax(language.to_owned()))
261+ .ok_or_else(|| Error::UnknownSyntax(language.to_owned()));
263− let line_syntax = self.get_first_line_syntax(&mut input.reader)?;
264+ let line_syntax = self.get_first_line_syntax(&mut input.reader)?;
265− // Get the path of the file:
266+ // Get the path of the file:
266− // If this was set by the metadata, that will take priority.
267+ // 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+ // If it wasn't, it will use the real file path (if available).
268− let path_str =
269+ let path_str = input
270− .metadata
270+ .metadata
271− .user_provided_name
271+ .user_provided_name
272− .as_ref()
272+ .as_ref()
273− .or_else(|| match input.kind {
273+ .or_else(|| match input.kind {
274− OpenedInputKind::OrdinaryFile(ref path) => Some(path),
274+ OpenedInputKind::OrdinaryFile(ref path) => Some(path),
275− _ => None,
275+ _ => None,
278− if let Some(path_str) = path_str {
278+ if let Some(path_str) = path_str {
279− // If a path was provided, we try and detect the syntax based on extension mappings.
279+ // If a path was provided, we try and detect the syntax based on extension mappings.
280− let path = Path::new(path_str);
280+ let path = Path::new(path_str);
281− let absolute_path = PathAbs::new(path)
281+ let absolute_path = PathAbs::new(path)
283− .map(|p| p.as_path().to_path_buf())
283+ .map(|p| p.as_path().to_path_buf())
284− .unwrap_or_else(|| path.to_owned());
284+ .unwrap_or_else(|| path.to_owned());
286− match mapping.get_syntax_for(absolute_path) {
286+ match mapping.get_syntax_for(absolute_path) {
287− Some(MappingTarget::MapToUnknown) => line_syntax
287+ Some(MappingTarget::MapToUnknown) => line_syntax
288− .ok_or_else(|| Error::UndetectedSyntax(path.to_string_lossy().into())),
288+ .ok_or_else(|| Error::UndetectedSyntax(path.to_string_lossy().into())),
290− Some(MappingTarget::MapTo(syntax_name)) => {
290+ Some(MappingTarget::MapTo(syntax_name)) => {
291− let syntax_set = self.get_syntax_set()?;
291+ let syntax_set = self.get_syntax_set()?;
292− syntax_set
292+ syntax_set
293− .find_syntax_by_name(syntax_name)
293+ .find_syntax_by_name(syntax_name)
294− .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set })
294+ .map(|syntax| SyntaxReferenceInSet { syntax, syntax_set })
295− .ok_or_else(|| Error::UnknownSyntax(syntax_name.to_owned()))
295+ .ok_or_else(|| Error::UnknownSyntax(syntax_name.to_owned()))
298− None => {
298+ None => {
299− let file_name = path.file_name().unwrap_or_default();
299+ let file_name = path.file_name().unwrap_or_default();
300− self.get_extension_syntax(file_name)?
300+ self.get_extension_syntax(file_name)?
301− .or(line_syntax)
301+ .or(line_syntax)
302− .ok_or_else(|| Error::UndetectedSyntax(path.to_string_lossy().into()))
302+ .ok_or_else(|| Error::UndetectedSyntax(path.to_string_lossy().into()))
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()))
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()))