@@ -14,8 +14,6 @@ use std::{
14 cell::RefCell,
14 cell::RefCell,
15 collections::{HashMap, HashSet},
15 collections::{HashMap, HashSet},
19 path::Path,
17 path::Path,
20 sync::Arc,
18 sync::Arc,
@@ -308,15 +306,12 @@ impl Loader {
308 // TODO: content_regex handling conflict resolution
306 // TODO: content_regex handling conflict resolution
311− pub fn language_config_for_shebang(&self, path: &Path) -> Option<Arc<LanguageConfiguration>> {
309+ pub fn language_config_for_shebang(&self, source: &Rope) -> Option<Arc<LanguageConfiguration>> {
312− // Read the first 128 bytes of the file. If its a shebang line, try to find the language
310+ let line = Cow::from(source.line(0));
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()?;
316 static SHEBANG_REGEX: Lazy<Regex> =
311 static SHEBANG_REGEX: Lazy<Regex> =
317 Lazy::new(|| Regex::new(r"^#!\s*(?:\S*[/\\](?:env\s+)?)?([^\s\.\d]+)").unwrap());
312 Lazy::new(|| Regex::new(r"^#!\s*(?:\S*[/\\](?:env\s+)?)?([^\s\.\d]+)").unwrap());
318 let configuration_id = SHEBANG_REGEX
313 let configuration_id = SHEBANG_REGEX
319− .captures(&buf)
314+ .captures(&line)
320 .and_then(|cap| self.language_config_ids_by_shebang.get(&cap[1]));
315 .and_then(|cap| self.language_config_ids_by_shebang.get(&cap[1]));
322 configuration_id.and_then(|&id| self.language_configs.get(id).cloned())
317 configuration_id.and_then(|&id| self.language_configs.get(id).cloned())