@@ -131,9 +131,8 @@ impl Document {
131131 }
132132 }
133133
134− // TODO: passing scopes here is awkward
135134 // TODO: async fn?
136− pub fn load(path: PathBuf, scopes: &[String]) -> Result<Self, Error> {
135+ pub fn load(path: PathBuf) -> Result<Self, Error> {
137136 use std::{env, fs::File, io::BufReader};
138137 let _current_dir = env::current_dir()?;
139138
@@ -143,15 +142,8 @@ impl Document {
143142 // TODO: create if not found
144143
145144 let mut doc = Self::new(doc);
146−
147− let language_config = LOADER
148− .get()
149− .unwrap()
150− .language_config_for_file_name(path.as_path());
151− doc.set_language(language_config, scopes);
152−
153− // canonicalize path to absolute value
154− doc.path = Some(std::fs::canonicalize(path)?);
145+ // set the path and try detecting the language
146+ doc.set_path(&path)?;
155147
156148 Ok(doc)
157149 }
@@ -218,6 +210,15 @@ impl Document {
218210 }
219211 }
220212
213+ fn detect_language(&mut self) {
214+ if let Some(path) = self.path() {
215+ let loader = LOADER.get().unwrap();
216+ let language_config = loader.language_config_for_file_name(path);
217+ let scopes = loader.scopes();
218+ self.set_language(language_config, scopes);
219+ }
220+ }
221+
221222 pub fn set_path(&mut self, path: &Path) -> Result<(), std::io::Error> {
222223 // canonicalize path to absolute value
223224 let current_dir = std::env::current_dir()?;
@@ -229,6 +230,10 @@ impl Document {
229230 self.path = Some(path);
230231 }
231232 }
233+
234+ // try detecting the language based on filepath
235+ self.detect_language();
236+
232237 Ok(())
233238 }
234239
@@ -251,8 +256,10 @@ impl Document {
251256 };
252257 }
253258
254− pub fn set_language2(&mut self, scope: &str, scopes: &[String]) {
255− let language_config = LOADER.get().unwrap().language_config_for_scope(scope);
259+ pub fn set_language2(&mut self, scope: &str) {
260+ let loader = LOADER.get().unwrap();
261+ let language_config = loader.language_config_for_scope(scope);
262+ let scopes = loader.scopes();
256263
257264 self.set_language(language_config, scopes);
258265 }