Skip to content

Instantly share code, notes, and snippets.

@madskristensen
Created August 22, 2016 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madskristensen/06d435aad1542dab57949af106369b92 to your computer and use it in GitHub Desktop.
Save madskristensen/06d435aad1542dab57949af106369b92 to your computer and use it in GitHub Desktop.
How to set basic settings to any language in VS
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
namespace YamlSpacesFix
{
[Export(typeof(IWpfTextViewCreationListener))]
[ContentType(ContentType)]
[TextViewRole(PredefinedTextViewRoles.PrimaryDocument)]
public class YamlCreationListener : IWpfTextViewCreationListener
{
public const string ContentType = "YAML";
[Export(typeof(ContentTypeDefinition))]
[Name(ContentType), BaseDefinition("text")]
public ContentTypeDefinition MarkdownContentType { get; set; }
[Export(typeof(FileExtensionToContentTypeDefinition))]
[FileExtension(".yml"), ContentType(ContentType)]
public FileExtensionToContentTypeDefinition CsonFileExtension { get; set; }
public void TextViewCreated(IWpfTextView textView)
{
// Required. Forces spaces instead of tab when hitting the TAB key
textView.Options.SetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId, true);
// Optional. Makes indentation size 2. YAML should work with any indentation size
textView.Options.SetOptionValue(DefaultOptions.IndentSizeOptionId, 2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment