Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A settings to allow mapping file types to known languages in Zed #5178

Closed
1 task done
daxartio opened this issue Oct 15, 2022 · 12 comments · Fixed by #9290
Closed
1 task done

A settings to allow mapping file types to known languages in Zed #5178

daxartio opened this issue Oct 15, 2022 · 12 comments · Fixed by #9290
Assignees
Labels
enhancement [core label] language An umbrella label for all programming languages syntax behaviors setting Feedback for preferences, configuration, etc

Comments

@daxartio
Copy link

daxartio commented Oct 15, 2022

Check for existing issues

  • Completed

Is your feature request related to a problem?

I want to see Cargo.lock content with highlights syntax’s.

Describe the solution you'd like

Add a setting to settings.json

If applicable, add mockups / screenshots to help present your vision of the feature

settings.json

{
    "files": {
        "associations": {
            "*.avsc": "json",
            "Cargo.lock": "toml"
        }
    }
}
@daxartio daxartio added enhancement [core label] triage Maintainer needs to classify the issue labels Oct 15, 2022
@DarkArc
Copy link

DarkArc commented Nov 12, 2022

I'm not sure if this qualifies as the same issue; however, I work on a project which for historic reasons is C++ code with .c file extensions. It would be nice if I could say "hey in this project (or even globally) treat .c as .cc/cpp"

@JosephTLyons JosephTLyons added setting Feedback for preferences, configuration, etc and removed triage Maintainer needs to classify the issue labels Nov 14, 2022
@JosephTLyons
Copy link
Contributor

I'm wondering if the suggested structure should be flipped so that a list could be used. The structure would be saying "apply this language's syntax highlighting to the following languages":

{
    "files": {
        "associations": {
            "json": ["*.avsc"],
            "toml": ["Cargo.lock"],
        }
    }
}

I'm not sure. This would reduce duplication, but maybe it feels a bit backwards?

@aewing
Copy link

aewing commented Mar 15, 2023

This would be a great stop-gap for Svelte support, as Svelte users could associate their .svelte files with HTML

@BryanSchuetz
Copy link

A million times, yes.

@maddanio
Copy link

since there are already many many requests for language support it would make sense to allow custom languages and also to easily install language defs from others. really you would only need file extensions and lsps

@JarWarren
Copy link

I'm wondering if the suggested structure should be flipped so that a list could be used. The structure would be saying "apply this language's syntax highlighting to the following languages":

{
    "files": {
        "associations": {
            "json": ["*.avsc"],
            "toml": ["Cargo.lock"],
        }
    }
}

I'm not sure. This would reduce duplication, but maybe it feels a bit backwards?

+1 This seems easier and more practical. Simply list all associated filetypes per language.

@JosephTLyons JosephTLyons changed the title Custom extensions A settings to allow mapping file types to known languages in Zed Jul 9, 2023
@JosephTLyons
Copy link
Contributor

In addition to adding this type of configuration, we should also populate some defaults, such as those suggested in:

@JosephTLyons JosephTLyons added the language An umbrella label for all programming languages syntax behaviors label Dec 18, 2023
@vyckes
Copy link

vyckes commented Jan 15, 2024

This would be a huge step forward for Zed already. Currently, Zed becomes not useable for most of my projects, just because it lacks some languages (e.g. SCSS). But if I am able to map SCSS to the CSS engine (syntax highlighting, basic formatting/completion) it would be a huge step forward.

@ljwljwljwljw
Copy link

Has anyone started working on this?

@JosephTLyons
Copy link
Contributor

Has anyone started working on this?

Not that I'm aware of. Feel free to open a PR if it's something you're interested in. :)

@ljwljwljwljw
Copy link

Has anyone started working on this?

Not that I'm aware of. Feel free to open a PR if it's something you're interested in. :)

I'm trying to implement this, but I found that the current architecture assumes LanguageConfig is static and will not be updated by any Settings, the path_suffixes in LanguageConfig for each language is loaded by languages::init(languages.clone(), node_runtime.clone(), cx) before user's local settings and project settings are loaded. Are there any APIs or callbacks, like onLocalSettingsLoaded, that we can use to update the language configs after local settings are loaded?

@ljwljwljwljw
Copy link

ljwljwljwljw commented Feb 3, 2024

Has anyone started working on this?

Not that I'm aware of. Feel free to open a PR if it's something you're interested in. :)

I'm trying to implement this, but I found that the current architecture assumes LanguageConfig is static and will not be updated by any Settings, the path_suffixes in LanguageConfig for each language is loaded by languages::init(languages.clone(), node_runtime.clone(), cx) before user's local settings and project settings are loaded. Are there any APIs or callbacks, like onLocalSettingsLoaded, that we can use to update the language configs after local settings are loaded?

Another solution may be to pass AppContext as an argument to language_for_file, language_for_name_or_extension in order to load the user's custom path suffixes settings, however, it requires a lot of changes.

maxbrunsfeld added a commit that referenced this issue Mar 13, 2024
)

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [core label] language An umbrella label for all programming languages syntax behaviors setting Feedback for preferences, configuration, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants