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

File extension specific settings #35350

Open
esprehn opened this issue Sep 29, 2017 · 62 comments
Open

File extension specific settings #35350

esprehn opened this issue Sep 29, 2017 · 62 comments
Assignees
Labels
config VS Code configuration, set up issues feature-request Request for new features or functionality
Milestone

Comments

@esprehn
Copy link

esprehn commented Sep 29, 2017

This was discussed here:
#1587

but instead what was implemented was language specific settings. That doesn't help us where we have the same language in files with different extensions but what to impose different settings on them.

(ex. I have a DSL like language that looks like JS, I want to make it syntax highlight as JS, but disable validation because some things aren't quit right. Having to fork the JS language bindings for that and maintain it is unfortunate.)

@sandy081
Copy link
Member

@esprehn You can associate file types with languages and associate settings to languages

Example:

"files.associations": {
	"*.idt": "markdown"
}
"[markdown]": {
          "editor.tabSize": 2
}

Is there a different use case that you need to associate settings to file associations?

@sandy081 sandy081 self-assigned this Sep 29, 2017
@sandy081 sandy081 added info-needed Issue requires more information from poster settings-editor VS Code settings editor issues labels Sep 29, 2017
@vscodebot vscodebot bot closed this as completed Oct 6, 2017
@vscodebot
Copy link

vscodebot bot commented Oct 6, 2017

This issue has been closed automatically because it needs more information and has not had recent activity. Please refer to our guidelines for filing issues. Thank you for your contributions.

@esprehn
Copy link
Author

esprehn commented Oct 9, 2017

I explained why I need this in the report example. I have a DSL that looks like JS, but isn't quite JS. I can map files with extension .foo to JS, but I can't say "syntax highlight .foo files, but don't show syntax errors". I would need to totally disable syntax errors for all JS language files. Similarly I may want other editor settings different for .foo files (ex gutter width), but I do want them syntax highlighted like JS.

I often do this in other editors like Sublime where I have various languages that have no language definition mapped to another language (ex. some obscure language I might map to Java since they have the same keywords.) That way I get nice syntax highlighted code which is easier to read. VSCode forces you to set things like the syntax error (red underline) reporting for a whole language, not on a per extension basis.

@sandy081
Copy link
Member

@esprehn I see. I agree with the editor settings example.

But for excluding files from linters, I think linters should have an option to exclude.

@sandy081 sandy081 reopened this Oct 10, 2017
@sandy081 sandy081 added feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster labels Oct 10, 2017
@sandy081 sandy081 added this to the Backlog milestone Oct 10, 2017
@esprehn
Copy link
Author

esprehn commented Oct 10, 2017

Having those settings be on a per linter setting seems unfortunate, there's tons of settings like php.validate.enable, each type has a {lang}.validate.enable flag. Instead of having every linter support .exclude it'd be much easier to just allow "[.foo]": { "php.validate.enable": false }

@sandy081 sandy081 added config VS Code configuration, set up issues and removed settings-editor VS Code settings editor issues labels Nov 17, 2017
@Kroc
Copy link

Kroc commented Feb 28, 2018

I don't like that unless the user has an extension installed to handle a file-type, I cannot specify the tab / ruler settings for arbitrary file-types in a portable, reliable way. For example, I have my own Markdown like system "ReMarkable" with a file-type of ".rem", it requires the use of tabs instead of spaces. I want to be able to specify this in the repositories I distribute, but with VSCode as it currently stands cannot do this.

".editorconfig" gets me almost there, but it's not a built in extension (it should be), and it doesn't support setting rulers.

Please reconsider this feature request.

@joemaffei
Copy link

I would like to see filename-specific settings. I happen to work in an environment that uses tabs, except for a few files like package.json that are indented with two spaces. I don't want an extension-specific or language-specific setting for json. "editor.detectIndentation": true does the trick if I edit an existing file, but obviously not when I create a new one. Being able to set indentation rules on a filename basis, as well as other settings like formatOnSave, etc, would be very helpful.

@aaronkahlhamer
Copy link

Here's my feeble attempt to stop it from formatting production files...

"editor.formatOnSave": true,
"files.associations": {
    "**/dist/**": "ignore"
  }

It works. Problem is, it converts it to Plain Text. I wish the following worked...

"[**/dist/]": {
   "editor.formatOnSave": false
}

@no-stack-dub-sack
Copy link

@mjbvz this discussion seems mostly central to file extension specific settings (except for @joemaffei's comment above), whereas #50888 & #52087 (closed as dupes) focus on individual files and directories - if this discussion is meant to encompass all three of these issues as one feature request now, can you consider renaming it so that others trying to open similar issues will be more easily able to identify this as a potential duplicate?

If this discussion will remain central to file extensions only, can one of the other issues be reconsidered as a separate feature request? Thank you!

@ma11hew28
Copy link

I want word wrap on for .txt files but not for .csv files.

@Srekel
Copy link

Srekel commented Sep 19, 2018

Just to add a use case: We format some of our our C++ headers manually but always use clang-format for source files, so I'd like to enable format-on-save just for "*.cpp" files.

@DanTup
Copy link
Contributor

DanTup commented Oct 2, 2018

I wish the following worked...

"[**/dist/]": {
   "editor.formatOnSave": false
}

I'd like this too - is there any way to make this work today?

@aster94
Copy link

aster94 commented May 8, 2019

if editorConfig was bundled with VSCode this would be so easy (for the users), hope to see this achieved soon

"files.insertFinalNewline": false,
[keywords.txt]{
    "files.insertFinalNewline": true,
}

@mikedpad
Copy link

mikedpad commented Jun 6, 2022

Another use case... Unity's UI Toolkit now uses XML and stylesheets to design user interfaces (.uxml and .uss files). Easy enough to add support for both files with a straight-forward option in settings.json:

  "files.associations": {
    "*.uss": "css",
    "*.uxml": "xml"
  },

The problem is some rules make use of their own vendor prefix: -unity- among several differences to CSS.

.bar-value-text {
    font-size: 30px;
    -unity-text-align: middle-center;
}

I'm not expecting support for .uss files without a VSCode extension. In the meantime, it would be nice to silence some of the warnings without interfering with my normal web dev workflow, outside of Unity. As others have suggested, I'd love to be able to make an exception to my settings.json file specifically for the .uss file extension.

Something like:

"[*.uss]": {
  "css.lint.vendorPrefix": "ignore",
  "css.lint.compatibleVendorPrefixes": "ignore",
  "css.lint.unknownVendorSpecificProperties": "ignore",
}

@kuzdogan
Copy link

kuzdogan commented Nov 18, 2022

I usually find myself jumping to types.d.ts file definitions when working on Typescript and fixing that file, only to compile and find out that nothing's changed and I didn't update the definition.

In my case I want to change the background of .d.ts pseudo extension to notice when I'm about to edit an already compiled file. Even better if I can set this setting to **/dist/*.d.ts or `**/build/*.d.ts/ etc.

For my use case I found this extension that does the job https://marketplace.visualstudio.com/items?itemName=rioj7.WhenFile but nice to have other VSCode settings per extension too

@mehulkar
Copy link

Another use case, I'm using Prysk to write tests. The file extension for test files is .t and I want to disable removing trailing white spaces on save for these files. I can assosicate these files with [plaintext], but that affects all plaintext files, which is not ideal.

In general, it should be possible to have settings for file extensions that are generally unknown to VSCode.

@KuSh
Copy link

KuSh commented Jan 14, 2023

Another use case, I'm using Prysk to write tests. The file extension for test files is .t and I want to disable removing trailing white spaces on save for these files. I can assosicate these files with [plaintext], but that affects all plaintext files, which is not ideal.

In general, it should be possible to have settings for file extensions that are generally unknown to VSCode.

You could use an editorconfig for that:

[*.t]
trim_trailing_whitespace = false

@mehulkar
Copy link

@KuSh I tried that, but it seems that VSCode settings are trumping editorconfig config.

@BillDenton
Copy link

For C/C++ files I'd like to enable format on save for some file paths. Some of the source files have been formatted (clang-format). I would like to keep those files formatted, but not touch other files.

@WillsterJohnson
Copy link

WillsterJohnson commented May 7, 2023

Is there any interest from the team to do anything about this?

It's been over three years since a member even commented on this #35350 (comment) and it's been over five years since a member made a comment actually about this issue #35350 (comment).

If you're not going to implement something, at least let us know with a wontfix or something rather than leaving the issue open for five and a half years with no word.

@shaneknysh
Copy link

I think it's pretty clear there is no interest from the team to address this. I'm not certain why it hasn't been closed other than so duplicates aren't created.

The options for a work around are not ideal either.

I also don't see this as the job of a plugin or a job a single plugin could do well.

@WillsterJohnson
Copy link

Honestly, I don't know why I keep being surprised at this sort of thing in Microsoft projects.
Someone suggests something cool, everyone who sees it loves it, permanent radio silence.

It's not all feature requests, not by a long shot, but enough requests are ignored that it's intensely uppsetting.

@shaneknysh
Copy link

It could be that the effort is too high and it benefits too few users.

@palapapa
Copy link

palapapa commented Sep 21, 2023

Still not supported after 6 years. Is it possible to make an extension that will allow applying arbitrary settings based on the current file extension instead of only the predefined "language-specific settings"?

@KieranP
Copy link

KieranP commented Oct 9, 2023

I too would find this useful. Our use case is as follows: We are redesigning our web application. In one folder we have all the old legacy CSS/JS, which doesn't conform to our new coding style/formatters. In another folder, we have all our new CSS/JS, which we want formatting to run on save for. We have turned on format on save for JS/CSS, but that means that now when we edit the old CSS/JS, it tries to format that, leading to lots of changes in the diff. Would be helpful to be able to turn off format on save for a path.

"[css][scss][javascript][typescript]": {
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true
},
"[app/assets/**/*]": {
   "editor.formatOnSave": false
}

@shaneknysh
Copy link

Given that this is 6 years old now and the only response from anyone close to being on the vs code team has been:
"no one wants this" and
"use an extention"
I think it is probably safe to move on with the assumption it is never going to happen.

Gretchen Wieners will make "Fetch" happen faster than this will be addressed.

@gmusante
Copy link

gmusante commented Dec 7, 2023

👍

@Keavon
Copy link

Keavon commented Jan 29, 2024

Just throwing in my support for this since it hasn't had any activity in a couple months.

My use case: I use Prettier to format my regular JSON files, but I have another file type that stores a whole bunch of data in JSON format and I have "files.associations": { "*.my-file-extension": "json" } set up for syntax highlighting. There's a bug in the Prettier formatter which breaks the JSON in these files, so I want to use the "vscode.json-language-features" formatter for my custom data type. Right now it seems to be one or the other, I can't set Prettier for regular JSON and JSON Language Features for my custom file extension JSON file.

@aradalvand
Copy link

aradalvand commented Apr 11, 2024

Almost 7 years since this issue was created and such a basic feature still hasn't been implemented. Why the hell are you not even reacting to an open issue with this many upvotes?!

Embarrassing. Absolutely shameful. You've proven yourselves to be outrageously irresponsible; congratulations.

@geekley
Copy link

geekley commented Apr 11, 2024

not even reacting to an open issue with this many upvotes

I'd assume that on a repo with 5000+ open issues (probably the # 1 most issues in github), most/all devs have notifications disabled so they won't be overwhelmed with comments every second; thus I think they're only notified when specifically @ pinged.

@shaneknysh
Copy link

After 7 years not having notifications on is not an excuse for not addressing g this issue.

6 years ago we got a "use an extension" answer and a "won't fix" resolution. there is still not an extension that handles many of these use cases elegantly.

I messaged the vscode TikTok account and asked them to feature this issue in a video.

@starball5
Copy link

Related on Stack Overflow: vscode setting for specific filename

@ascpixi
Copy link

ascpixi commented Jun 3, 2024

Joining in to show my support! This would be great for my build system, which uses Python-based build manifests. These files have some stuff pre-imported in, so it would be great if I could disable type checking just for those files.

I'm using "python.analysis.ignore": ["**/component.build"] for now, but it leaves a lot to be desired - it doesn't even highlight the most basic syntax errors. :(

@Frexuz
Copy link

Frexuz commented Jul 17, 2024

my use case that doesn't work, is to support chained file extensions:

  "[html.erb]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "aliariff.vscode-erb-beautify"
  },

it seems it doesn't match the saved file... (im guessing it's only matching against the file's last .erb extension?)

i only want to beautify html templates with this plugin, but not other template files that also uses the erb engine (like server provisioning config templates)

@gjsjohnmurray
Copy link
Contributor

@Frexuz this issue is asking for a new feature that doesn't yet exist even for simple (single dot) file extensions.

@CEbbinghaus
Copy link

Is this going to require another "[x, y, x]": treatment where someone just implements a naive version and the team steal it and make it work properly? I think that may be the fastest way to get it into main.

Haven't comprehensively checked all messages but I feel like the general want is for a globbing syntax to allow for overriding settings based on the file. Since a glob pattern might overlap with the language [markdown] syntax we may want to consider a different style. How about something like "(glob pattern)". And all it would require is a pure glob match against the currently open file within the editor and that should do it. Anybody got other considerations for the design or does that cover most use cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config VS Code configuration, set up issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests