1
0

sources.rs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. use std::path::PathBuf;
  2. use crate::fs::File;
  3. impl<'a> File<'a> {
  4. /// For this file, return a vector of alternate file paths that, if any of
  5. /// them exist, mean that *this* file should be coloured as “compiled”.
  6. ///
  7. /// The point of this is to highlight compiled files such as `foo.js` when
  8. /// their source file `foo.coffee` exists in the same directory.
  9. /// For example, `foo.js` is perfectly valid without `foo.coffee`, so we
  10. /// don’t want to always blindly highlight `*.js` as compiled.
  11. /// (See also `FileExtensions#is_compiled`)
  12. pub fn get_source_files(&self) -> Vec<PathBuf> {
  13. if let Some(ext) = &self.ext {
  14. match &ext[..] {
  15. "css" => vec![self.path.with_extension("sass"), self.path.with_extension("scss"), // SASS, SCSS
  16. self.path.with_extension("styl"), self.path.with_extension("less")], // Stylus, Less
  17. "mjs" => vec![self.path.with_extension("mts")], // JavaScript ES Modules source
  18. "cjs" => vec![self.path.with_extension("cts")], // JavaScript Commonjs Modules source
  19. "js" => vec![self.path.with_extension("coffee"), self.path.with_extension("ts")], // CoffeeScript, TypeScript
  20. "aux" | // TeX: auxiliary file
  21. "bbl" | // BibTeX bibliography file
  22. "bcf" | // biblatex control file
  23. "blg" | // BibTeX log file
  24. "fdb_latexmk" | // TeX latexmk file
  25. "fls" | // TeX -recorder file
  26. "headfootlength" | // TeX package autofancyhdr file
  27. "lof" | // TeX list of figures
  28. "log" | // TeX log file
  29. "lot" | // TeX list of tables
  30. "toc" | // TeX table of contents
  31. "xdv" => vec![self.path.with_extension("tex")], // XeTeX dvi
  32. _ => vec![], // No source files if none of the above
  33. }
  34. }
  35. else {
  36. vec![] // No source files if there’s no extension, either!
  37. }
  38. }
  39. }