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

Support file-type-specific settings #1587

Closed
heaths opened this issue Dec 22, 2015 · 66 comments
Closed

Support file-type-specific settings #1587

heaths opened this issue Dec 22, 2015 · 66 comments
Assignees
Labels
config VS Code configuration, set up issues feature-request Request for new features or functionality plan-item VS Code - planned item for upcoming
Milestone

Comments

@heaths
Copy link
Member

heaths commented Dec 22, 2015

In our project we have a number of files where tabs are strictly required (a format we do not control). However, we want to normalize tabs to spaces throughout the rest of the project.

For now, I just ask that people don't edit those files in VSCode. I even considered adding them to the ignore list for VSCode itself. But it's not uncommon to have file-specific settings, so I thought it would be nice if VSCode allowed for more complex patterns - much like files.exclude, perhaps something like:

"editor.insertSpaces": true,
"diffEditor.ignoreTrimWhitespace": true,
"files.settings": {
  "**/*.idt": {
    "editor.insertSpaces": false,
    "diffEditor.ignoreTrimWhitespace": false
  }
}
@bpasero bpasero added feature-request Request for new features or functionality editor labels Dec 23, 2015
@bpasero bpasero added this to the Backlog milestone Dec 23, 2015
@bpasero
Copy link
Member

bpasero commented Dec 23, 2015

👍

@SamVerschueren
Copy link
Contributor

It's a nice idea but maybe It's a better idea to use an array instead of a map of globbing patterns. The order in which you specify the rules matter because what should be done in this case?

"files.settings": {
  "**/*.idt": {
    "editor.insertSpaces": false,
    "diffEditor.ignoreTrimWhitespace": false
  },
  "**/file.idt": {
    "editor.insertSpaces": true,
    "diffEditor.ignoreTrimWhitespace": true
  },
}

Maps don't keep their order so the result in this case is not known untill you test it. If **/*.idt is executed after **/file.idt, there is no way to specify other rules for file.idt.

When using an array, the order is kept and you know the outcome of the following settings.

"files.settings": [
  {
    "files": ["**/*.idt", "**/*.json"],
    "editor.insertSpaces": false,
    "diffEditor.ignoreTrimWhitespace": false
  },
  {
    "files": "**/index.idt",
    "editor.insertSpaces": true,
    "diffEditor.ignoreTrimWhitespace": true
  }
]

This way, you know for sure that index.idt will have the setting editor.insertSpaces: true.

We had a similar discussion in the XO linter for overridable configs. More information can be found here xojs/xo#58

@bpasero bpasero added workbench and removed editor labels Apr 7, 2016
@bpasero bpasero self-assigned this Apr 7, 2016
@bpasero bpasero changed the title More control over file-specific settings Support file-type-specific settings Jul 5, 2016
@siegebell
Copy link

adding to @SamVerschueren's idea, the pattern should conform to a DocumentSelector, and the entries should be ranked by languages.match

@jessicah
Copy link

This would also help with editing patch files. Gets tiring accidentally bricking them because of the trailing space on empty lines :(

@calebmer
Copy link

Also nice for word wrapping in markdown or HTML files, but not code. A great improvement for developers who write a lot.

@sandy081 sandy081 self-assigned this Jan 4, 2017
@sandy081 sandy081 modified the milestones: January 2017, Backlog Jan 4, 2017
@sandy081 sandy081 added plan-item VS Code - planned item for upcoming config VS Code configuration, set up issues labels Jan 4, 2017
@egamma egamma mentioned this issue Jan 4, 2017
56 tasks
@sandy081
Copy link
Member

Following is the proposal for introducing file (glob pattern) / language based editor settings.

Defining a new setting called workbench.editor.overrideSettings or workbench.overrideEditorSettings and its schema is as follows:

{
   "workbench.editor.showTabs": true
    "workbench.editor.overrideSettings": [
		{
			"files": [
				"**/*.idt",
				"**/*.json"
			],
			"editor.insertSpaces": false,
			"diffEditor.ignoreTrimWhitespace": false
		},
		{
			"files": "**/index.idt",
			"editor.insertSpaces": true,
			"diffEditor.ignoreTrimWhitespace": true
		},
		{
			"language": "markdown",
			"editor.wordWrap": 0
		}
	]
}

@Microsoft/vscode Please provide your feedback and suggestions.

Thanks

@SamVerschueren
Copy link
Contributor

Looks good to me.

As a sidenote to everyone reading this topic, much of this already can be done with the EditorConfig plugin which in my opinion is a better alternative when working in teams. I agree, not everything is possible with EditorConfig, but if it's possible, then I suggest using that instead.

@bpasero
Copy link
Member

bpasero commented Jan 11, 2017

Here is a little bit different suggestion (variant of yours):

{
   "workbench.editor.showTabs": true,
   "editor.overrides": [
   		{
   			"files": [
				"**/*.idt",
				"**/*.json"
			],
			"settings": {
				"editor.insertSpaces": false,
				"diffEditor.ignoreTrimWhitespace": false
			}
   		}
		{
			"files": "**/index.idt",
			"settings": {
				"editor.insertSpaces": true,
				"diffEditor.ignoreTrimWhitespace": true
			}
		},
		{
			"language": "markdown",
			"settings": {
				"editor.wordWrap": 0
			}
		}
	]
}

Difference:

  • I call it editor.overrides because in most situations the settings would only apply when you open an editor with a specific file or language mode set and would not apply in other contexts
  • I introduce an extra settings node to be able to distinguish the actual context the setting applies to (files or language) from the actual settings.

@rajinder-yadav
Copy link

rajinder-yadav commented Jan 23, 2017

With respect to configurable tab size and being able to specify filetype extension. I would suggest the following, it's pretty compact and flexible.

   // Don't need to specify the '.' before extension name.
   // Specify multiple extensions with '|' or separator.
   tabFileExtensions: {
    "cpp": "h|hpp|c|cpp|cc",
    "web": "js|html|css|ts"
   }

  "editor.tabSize": {
     "default": 4,
     "web": 2,
     "cpp": 3
   }

@wopian
Copy link

wopian commented Jan 24, 2017

The current implementation looks more compact and doesn't sacrifice readability & ease of use. Users can simply copy & paste syntax settings straight into their settings.json.

"editor.tabSize": 4,
"[js,html,css,ts]": {
      "editor.tabSize": "2"
},
"[h,hpp,c,cpp,cc]": {
      "editor.tabSize": 3
}

Your implementation would require users to add the syntax settings into multiple areas of their settings.json

@sandy081
Copy link
Member

Just to make sure that, as beginning and to be simple, we only support one language per entry. Multiple languages as a single key is not supported. So, one can write only as follows

"[js]": {
    "editor.tabSize": "2"
},
"[html]": {
   "editor.tabSize": "2"
}

@egamma
Copy link
Member

egamma commented Jan 26, 2017

Closing - the plan item is done.

@egamma egamma closed this as completed Jan 26, 2017
@IgorNovozhilov
Copy link

@egamma, in which version this functionality available?
image
2017-01-27_15h43_13
2017-01-27_15h45_36

@sandy081
Copy link
Member

@IgorNovozhilov Language based settings are available in current insiders. With respect to the issue you mentioned, I will take a look

@wopian
Copy link

wopian commented Jan 27, 2017

@sandy081 any idea when the 1.9 insider might hit stable?

@fredrikaverpil
Copy link

fredrikaverpil commented Jan 27, 2017

@wopian here are the iteration plans: https://github.com/Microsoft/vscode/wiki/Iteration-Plans

It says early February.

@sandy081
Copy link
Member

@IgorNovozhilov There is a bug in the feature that following settings are not respected by language

editor.tabSize
editor.insertSpaces
editor.detectIndentation
editor.trimAutoWhitespace

Thanks for catching this scenario and reporting. I will be filing a separate issue to track this - #19511

@jonhoo
Copy link

jonhoo commented May 15, 2017

@sandy081 it looks like it is not possible to set extension properties within a language-specific configuration block? For example, the following does not work:

    "[rust]": {
        "vim.textwidth": 100
    },

I also get the green underlining, with a warning saying "Unknown Identifier. Use language identifiers". I suspect this might be related to #19511, and perhaps also #4891?

@mjbvz
Copy link
Collaborator

mjbvz commented May 16, 2017

@jonhoo I don't think extensions can contribute language specific settings at the moment. I've opened #26707 to track this

@sandy081
Copy link
Member

@jonhoo Yes only core editor settings are supported in language-specific configuration block. Regarding warning, it is shown if there is no such language defined (in this case rust).

@cossio
Copy link

cossio commented May 22, 2017

So how does this work in the end? I want to set word-wrapping for some filetypes. What do I do? Is this documented?

@cossio
Copy link

cossio commented May 22, 2017

https://code.visualstudio.com/docs/getstarted/settings#_language-specific-editor-settings

@myfairsyer
Copy link

as beginning and to be simple, we only support one language per entry. Multiple languages as a single key is not supported.

So is later support of multiple langauges per key/entry something planned for the future?
Is there a seperate issue to track that?

@sandy081
Copy link
Member

@myfairsyer Its not yet planned.. Feel free to file an issue for that. Thanks.

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

No branches or pull requests