Add a setting for custom associations between languages and files (#9290)

Closes #5178

Release Notes:

- Added a `file_types` setting that can be used to associate languages
with file names and file extensions. For example, to interpret all `.c`
files as C++, and files called `MyLockFile` as TOML, add the following
to `settings.json`:

    ```json
    {
      "file_types": {
        "C++": ["c"],
        "TOML": ["MyLockFile"]
      }
    }
    ```

As with most zed settings, this can be configured on a per-directory
basis by including a local `.zed/settings.json` file in that directory.

---------

Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
Max Brunsfeld
2024-03-13 10:23:30 -07:00
committed by GitHub
co-authored by Marshall
parent 77de5689a3
commit 724c19a223
30 changed files with 640 additions and 415 deletions
+3 -53
View File
@@ -1247,65 +1247,15 @@ fn path_for_file<'a>(
mod tests {
use super::*;
use gpui::AppContext;
use std::{
path::{Path, PathBuf},
sync::Arc,
time::SystemTime,
};
use language::TestFile;
use std::path::Path;
#[gpui::test]
fn test_path_for_file(cx: &mut AppContext) {
let file = TestFile {
path: Path::new("").into(),
full_path: PathBuf::from(""),
root_name: String::new(),
};
assert_eq!(path_for_file(&file, 0, false, cx), None);
}
struct TestFile {
path: Arc<Path>,
full_path: PathBuf,
}
impl language::File for TestFile {
fn path(&self) -> &Arc<Path> {
&self.path
}
fn full_path(&self, _: &gpui::AppContext) -> PathBuf {
self.full_path.clone()
}
fn as_local(&self) -> Option<&dyn language::LocalFile> {
unimplemented!()
}
fn mtime(&self) -> Option<SystemTime> {
unimplemented!()
}
fn file_name<'a>(&'a self, _: &'a gpui::AppContext) -> &'a std::ffi::OsStr {
unimplemented!()
}
fn worktree_id(&self) -> usize {
0
}
fn is_deleted(&self) -> bool {
unimplemented!()
}
fn as_any(&self) -> &dyn std::any::Any {
unimplemented!()
}
fn to_proto(&self) -> rpc::proto::File {
unimplemented!()
}
fn is_private(&self) -> bool {
false
}
}
}