@@ -131,9 +131,8 @@ impl Document {
134− // TODO: passing scopes here is awkward
135 // TODO: async fn?
134 // TODO: async fn?
136− pub fn load(path: PathBuf, scopes: &[String]) -> Result<Self, Error> {
135+ pub fn load(path: PathBuf) -> Result<Self, Error> {
137 use std::{env, fs::File, io::BufReader};
136 use std::{env, fs::File, io::BufReader};
138 let _current_dir = env::current_dir()?;
137 let _current_dir = env::current_dir()?;
@@ -143,15 +142,8 @@ impl Document {
143 // TODO: create if not found
142 // TODO: create if not found
145 let mut doc = Self::new(doc);
144 let mut doc = Self::new(doc);
146−
145+ // set the path and try detecting the language
147− let language_config = LOADER
146+ doc.set_path(&path)?;
150− .language_config_for_file_name(path.as_path());
151− doc.set_language(language_config, scopes);
153− // canonicalize path to absolute value
154− doc.path = Some(std::fs::canonicalize(path)?);
@@ -218,6 +210,15 @@ impl Document {
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);
221 pub fn set_path(&mut self, path: &Path) -> Result<(), std::io::Error> {
222 pub fn set_path(&mut self, path: &Path) -> Result<(), std::io::Error> {
222 // canonicalize path to absolute value
223 // canonicalize path to absolute value
223 let current_dir = std::env::current_dir()?;
224 let current_dir = std::env::current_dir()?;
@@ -229,6 +230,10 @@ impl Document {
229 self.path = Some(path);
230 self.path = Some(path);
234+ // try detecting the language based on filepath
235+ self.detect_language();
@@ -251,8 +256,10 @@ impl Document {
254− pub fn set_language2(&mut self, scope: &str, scopes: &[String]) {
259+ pub fn set_language2(&mut self, scope: &str) {
260+ let loader = LOADER.get().unwrap();
255− let language_config = LOADER.get().unwrap().language_config_for_scope(scope);
261+ let language_config = loader.language_config_for_scope(scope);
262+ let scopes = loader.scopes();
257 self.set_language(language_config, scopes);
264 self.set_language(language_config, scopes);