microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.22k stars 28.55k forks source link

File extension specific settings #35350

Open esprehn opened 6 years ago

esprehn commented 6 years ago

This was discussed here: https://github.com/Microsoft/vscode/issues/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 commented 6 years ago

@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?

vscodebot[bot] commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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.

esprehn commented 6 years ago

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 }

Kroc commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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

Srekel commented 5 years ago

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 commented 5 years ago

I wish the following worked...

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

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

aster94 commented 5 years ago

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,
}
shaneknysh commented 5 years ago

editorConfig would only solve this for behaviors supported by editorConfig.

FormatonSave is not a supported behavior of editorConfig

"[**/dist/]": {
   "editor.formatOnSave": false
}
aster94 commented 5 years ago

editorConfig would only solve this for behaviors supported by editorConfig.

Right, but i guess that after they implement the code that recognize the file type using per file settings should be feasible

pokemane commented 5 years ago

The "by language" instead of "by filetype" also isn't useful when you're dealing with a proprietary language and extension that doesn't have an existing vscode extension and isn't recognized by vscode already.

arsdever commented 4 years ago

Hello. I'm facing a similar problem.

I try to enable editor rulers for only a single file or files matching the pattern but it seems there's no way to do such a thing.

I've tried the following ways. No one worked for me

    "[./myfile]": {
        "editor.rulers": [20]
    },
...
    "[{workspaceFolder}/myfile]": {
        "editor.rulers": [20]
    },
...
    "[/absolute/path/to/my/file]": {
        "editor.rulers": [20]
    },
gusbemacbe commented 4 years ago

@sandy081, @bpasero and @Tyriar

I have been searched issues, but I did not find similar issues. In spite of this issue being unrelated, I decide to leave it here.

I am referring to the issue from another repository https://github.com/PKief/vscode-material-icon-theme/issues/241#issuecomment-504582281.

Will there be support for file name which contains space for catching icon association?

sandy081 commented 4 years ago

@gusbemacbe Looks related to themes and not related to this issue. I would recommend to file a separate issue so that your issue can be discussed and tracked separately.

gusbemacbe commented 4 years ago

@sandy081, in this repo or @Pkief's repo?

sandy081 commented 4 years ago

I would start with extension's repo which is Pkief's

tracker1 commented 4 years ago

From my own issue... I think it would be nice to support multiple extensions and/or globs in a setting via comma separated list (whitespace trimmed out), using parens as a block instead of square braces for easier detection.

For Example:

{
  "(.txt, .ans, .asc, .msg, .rip)": {
    "editor.renderControlCharacters": true,
    "files.encoding": "cp437",
  },
}
muuvmuuv commented 4 years ago

Adding my use case here:

I am programming schematics for our Angular project and would love to have ejs syntax highlighting for the .template files (Angular is not using ejs but Angular template syntax is quite the same). What I do not want is auto formatting for those files since they are treated as HTML and get formatted pretty ugly.

  "[*.template]": {
    "editor.formatOnSave": false
  },
zawys commented 3 years ago

That could even replace the "files.associations" setting:

"[file:*.template]": {
  "language": "html",
  "editor.formatOnSave": false
},
uloco commented 3 years ago

This feature would also be really helpful for ignoring files when having project wide organize-imports on save. If you have global imports in some files (maybe because the library you are using is forcing you to do so), you will have to disable auto organize for the whole project. Otherwise your code will break, due to reordering of the imports.

Like so:

"editor.codeActionsOnSave": {
  "source.organizeImports": true
},
[!file/with/global/import]: {
  "editor.codeActionsOnSave": {
    "source.organizeImports": false
  },
}
infacto commented 3 years ago

Another good case is to set different settings for *.spec.ts / *.test.ts files. Means: A pseudo extension. For example like:

{
  "editor.rulers": [120],
  "*.(spec|test).ts": {
    "editor.rulers": [80],
  }
}

If we want a more stronger typed key, we could use "file:*.(spec|test).ts". But I'm sure, you have a better idea for that. :) Not sure if regex will work. Alternatives e.g. *.{spec,test}.ts or [*.spec.ts, *.test.ts]. It would be greate if I could specify multiple names.

{
  "[*.spec.ts, *.test.ts]": {
    "editor.rulers": [80],
  }
}
graeme-verticalscope commented 3 years ago

This feature would also be helpful for adjusting test configuration when running an integration tests vs a unit test. I'd like to be able to adjust go.testTags when running integration tests, for example:

{
  "[*_int_test.go]": {
    "go.testTags": "integration",
  }
}
yumetodo commented 3 years ago

In my case, a.csv is encoded by cp932, b.csv is encoded by UTF-8. In this case, when I want to customise files.encoding, file specific, not file extension specific, config is required.

Neonit commented 3 years ago

Another use case: tabSize: 4 for .php files, tabSize: 2 for .phtml files. I'd use the latter for HTML with some PHP parts inside and the former for PHP code only files.

deiga commented 3 years ago

@Neonit For your use-case I can recommend https://editorconfig.org/

Neonit commented 3 years ago

@deiga Went with modelines for now, but maybe an editorconfig would be even more convenient. Thanks for your suggestion.

tmcguire commented 3 years ago

Another usecase is to disable removing trailing whitespace in .unity files, which Unity would add back. The following does not work, because no "unity" language exists, and it doesn't seem to be possible to define your own languages in settings.json:

    "[unity]": {
        "files.trimTrailingWhitespace": false
    },
    "files.associations": {
        "*.unity": "unity"
    },
yajo commented 3 years ago

https://github.com/microsoft/vscode/issues/35350#issuecomment-895211215 is also solved with editorconfig.

tracker1 commented 2 years ago

While editorconfig is possible, it would be nice to have an in-the-box solution as well.

stephancasas commented 2 years ago

My use case is for overriding wordWrapColumn on a per-file/directory basis — especially in JS/PHP config files relating to APIs. When wrapped, the long endpoint urls become disorderly very quickly, and it'd be nice to make these a bit more readable.

Definitely hope to see this implemented, but I'm also going to take a look at extending what's already been accomplished in modelines.

adam-grant-hendry commented 2 years ago

Python Use Case: Sorting imports on save can break code in setup.py. e.g. setuptools must be imported before Cython when creating Extension modules, but alphabetically Cython comes ahead of it. black now alphabetizes imports (not just isort), so this is a headache when saving and checking in code.

adam-grant-hendry commented 2 years ago

#35350 (comment) is also solved with editorconfig.

Again, not for formatOnSave or codeActionsOnSave. editorconfig does not handle things like excluding specific files from having their imports sorted.

adam-grant-hendry commented 2 years ago

Python Use Case: Sorting imports on save can break code in setup.py. e.g. setuptools must be imported before Cython when creating Extension modules, but alphabetically Cython comes ahead of it. black now alphabetizes imports (not just isort), so this is a headache when saving and checking in code.

Looks like I'm late to the party. @muuvmuuv @zawys @uloco already mentioned the python import sorting use case, so I gave them all a +1. Looks like the end user needs are for languages, file extensions, and specific files (paths), so customizability is key here.

adam-grant-hendry commented 2 years ago

FWIW, for Python, adding # isort: skip after import works

# These do not get sorted
from setuptools import find_packages, setup  # isort: skip
from Cython.Build import cythonize  # isort: skip

My settings.json has the following:

"[python]": {
    "editor.codeActionsOnSave": {
        "source.organizeImports": true
    },
    "editor.formatOnSave": true
}

I am on Windows 10 and my Visual Studio Code is version 1.66.1

mikedpad commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

BillDenton commented 1 year ago

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 commented 1 year ago

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 https://github.com/microsoft/vscode/issues/35350#issuecomment-578640866 and it's been over five years since a member made a comment actually about this issue https://github.com/microsoft/vscode/issues/35350#issuecomment-335399238.

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

palapapa commented 11 months ago

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"?