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
parent 77de5689a3
commit 724c19a223
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 640 additions and 415 deletions

View file

@ -583,7 +583,7 @@ impl SemanticIndex {
}
if let Ok(language) = language_registry
.language_for_file(&absolute_path, None)
.language_for_file_path(&absolute_path)
.await
{
// Test if file is valid parseable file
@ -1144,7 +1144,7 @@ impl SemanticIndex {
for mut pending_file in pending_files {
if let Ok(language) = language_registry
.language_for_file(&pending_file.relative_path, None)
.language_for_file_path(&pending_file.relative_path)
.await
{
if !PARSEABLE_ENTIRE_FILE_TYPES.contains(&language.name().as_ref())

View file

@ -5,8 +5,7 @@ use crate::{
FileToEmbed, JobHandle, SearchResult, SemanticIndex, EMBEDDING_QUEUE_FLUSH_TIMEOUT,
};
use ai::test::FakeEmbeddingProvider;
use gpui::{Task, TestAppContext};
use gpui::TestAppContext;
use language::{Language, LanguageConfig, LanguageMatcher, LanguageRegistry, ToOffset};
use parking_lot::Mutex;
use pretty_assertions::assert_eq;
@ -57,7 +56,7 @@ async fn test_semantic_index(cx: &mut TestAppContext) {
)
.await;
let languages = Arc::new(LanguageRegistry::new(Task::ready(())));
let languages = Arc::new(LanguageRegistry::test(cx.executor().clone()));
let rust_language = rust_lang();
let toml_language = toml_lang();
languages.add(rust_language);
@ -1720,6 +1719,7 @@ fn init_test(cx: &mut TestAppContext) {
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);
SemanticIndexSettings::register(cx);
language::init(cx);
Project::init_settings(cx);
});
}