@@ -140,29 +140,38 @@ impl HighlightingAssets {
140140 }
141141 }
142142
143− /// Use [Self::get_syntax_for_file_name] instead
143+ /// Use [Self::get_syntax_for_path] instead
144144 #[deprecated]
145145 pub fn syntax_for_file_name(
146146 &self,
147147 file_name: impl AsRef<Path>,
148148 mapping: &SyntaxMapping,
149149 ) -> Option<&SyntaxReference> {
150− self.get_syntax_for_file_name(file_name, mapping)
151− .expect(
152− ".syntax_for_file_name() is deprecated, use .get_syntax_for_file_name() instead",
153− )
150+ self.get_syntax_for_path(file_name, mapping)
151+ .ok()
154152 .map(|syntax_in_set| syntax_in_set.syntax)
155153 }
156154
157− pub fn get_syntax_for_file_name(
158− &self,
159− file_name: impl AsRef<Path>,
160− mapping: &SyntaxMapping,
161− ) -> Result<Option<SyntaxReferenceInSet>> {
162− Ok(self.get_syntax_for_path(file_name.as_ref(), mapping).ok())
163− }
164−
165− fn get_syntax_for_path(
155+ /// Detect the syntax based on, in order:
156+ /// 1. Syntax mappings (e.g. `/etc/profile` -> `Bourne Again Shell (bash)`)
157+ /// 2. The file name (e.g. `Dockerfile`)
158+ /// 3. The file name extension (e.g. `.rs`)
159+ ///
160+ /// When detecting syntax based on syntax mappings, the full path is taken
161+ /// into account. When detecting syntax based on file name, no regard is
162+ /// taken to the path of the file. Only the file name itself matters. When
163+ /// detecting syntax based on file name extension, only the file name
164+ /// extension itself matters.
165+ ///
166+ /// Returns [Error::UndetectedSyntax] if it was not possible detect syntax
167+ /// based on path/file name/extension (or if the path was mapped to
168+ /// [MappingTarget::MapToUnknown]). In this case it is appropriate to fall
169+ /// back to other methods to detect syntax. Such as using the contents of
170+ /// the first line of the file.
171+ ///
172+ /// Returns [Error::UnknownSyntax] if a syntax mapping exist, but the mapped
173+ /// syntax does not exist.
174+ pub fn get_syntax_for_path(
166175 &self,
167176 path: impl AsRef<Path>,
168177 mapping: &SyntaxMapping,
@@ -218,7 +227,6 @@ impl HighlightingAssets {
218227
219228 let path = input.path();
220229 let path_syntax = if let Some(path) = path {
221− // If a path was provided, we try and detect the syntax based on extension mappings.
222230 self.get_syntax_for_path(
223231 PathAbs::new(path).map_or_else(|_| path.to_owned(), |p| p.as_path().to_path_buf()),
224232 mapping,