@@ -14,8 +14,6 @@ use std::{
1414 cell::RefCell,
1515 collections::{HashMap, HashSet},
1616 fmt,
17− fs::File,
18− io::Read,
1917 path::Path,
2018 sync::Arc,
2119};
@@ -308,15 +306,12 @@ impl Loader {
308306 // TODO: content_regex handling conflict resolution
309307 }
310308
311− pub fn language_config_for_shebang(&self, path: &Path) -> Option<Arc<LanguageConfiguration>> {
312− // Read the first 128 bytes of the file. If its a shebang line, try to find the language
313− let file = File::open(path).ok()?;
314− let mut buf = String::with_capacity(128);
315− file.take(128).read_to_string(&mut buf).ok()?;
309+ pub fn language_config_for_shebang(&self, source: &Rope) -> Option<Arc<LanguageConfiguration>> {
310+ let line = Cow::from(source.line(0));
316311 static SHEBANG_REGEX: Lazy<Regex> =
317312 Lazy::new(|| Regex::new(r"^#!\s*(?:\S*[/\\](?:env\s+)?)?([^\s\.\d]+)").unwrap());
318313 let configuration_id = SHEBANG_REGEX
319− .captures(&buf)
314+ .captures(&line)
320315 .and_then(|cap| self.language_config_ids_by_shebang.get(&cap[1]));
321316
322317 configuration_id.and_then(|&id| self.language_configs.get(id).cloned())