Skip to content

Commit

Permalink
Highlight tabs present in indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaubry committed May 10, 2013
1 parent 81a62ed commit bdcd103
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions YamlDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencie
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{69EE9636-55BA-49C2-827E-D5684221C345}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
YamlDotNet.build = YamlDotNet.build
YamlDotNet.Converters.nuspec = YamlDotNet.Converters.nuspec
Expand Down
19 changes: 19 additions & 0 deletions YamlDotNetEditor/YamlDotNetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class YamlDotNetEditor : IClassifier
private readonly IClassificationType _tag;
private readonly IClassificationType _symbol;
private readonly IClassificationType _directive;
private readonly IClassificationType _tab;

internal YamlDotNetEditor(IClassificationTypeRegistryService registry)
{
Expand All @@ -83,6 +84,7 @@ internal YamlDotNetEditor(IClassificationTypeRegistryService registry)
_tag = registry.GetClassificationType("YamlTag");
_symbol = registry.GetClassificationType("YamlSymbol");
_directive = registry.GetClassificationType("YamlDirective");
_tab = registry.GetClassificationType("YamlTab");
}

/// <summary>
Expand Down Expand Up @@ -113,6 +115,23 @@ public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
text = text.Substring(0, commentIndex);
}

var match = Regex.Match(text, @"^( *(\t+))+");
if (match.Success)
{
foreach (Capture capture in match.Groups[2].Captures)
{
classifications.Add(
new ClassificationSpan(
new SnapshotSpan(
span.Snapshot,
new Span(span.Start + capture.Index, capture.Length)
),
_tab
)
);
}
}

try
{
var scanner = new Scanner(new StringReader(text));
Expand Down
14 changes: 14 additions & 0 deletions YamlDotNetEditor/YamlDotNetEditorFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,19 @@ public YamlDirectiveFormat()

}
}

[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = "YamlDotNetEditor")]
[Name("YamlTab")]
[UserVisible(true)] //this should be visible to the end user
[Order(Before = Priority.Default)] //set the priority to be after the default classifiers
internal sealed class YamlTabFormat : ClassificationFormatDefinition
{
public YamlTabFormat()
{
DisplayName = "YAML Tab"; //human readable version of the name
BackgroundColor = Color.FromRgb(182, 0, 0);
}
}
#endregion //Format definition
}
4 changes: 4 additions & 0 deletions YamlDotNetEditor/YamlDotNetEditorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ internal static class YamlDotNetEditorClassificationDefinition
[Export(typeof(ClassificationTypeDefinition))]
[Name("YamlDirective")]
internal static ClassificationTypeDefinition YamlDirectiveType = null;

[Export(typeof(ClassificationTypeDefinition))]
[Name("YamlTab")]
internal static ClassificationTypeDefinition YamlTabType = null;
}
}
2 changes: 1 addition & 1 deletion YamlDotNetEditor/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="YamlDotNetEditor..074a7b74-655b-409c-b5ac-a028f12d6e89" Version="1.0" Language="en-US" Publisher="Antoine Aubry" />
<Identity Id="YamlDotNetEditor..074a7b74-655b-409c-b5ac-a028f12d6e89" Version="1.1" Language="en-US" Publisher="Antoine Aubry" />
<DisplayName>YamlDotNetEditor</DisplayName>
<Description xml:space="preserve">This is a YAML editor classifier extension to the Visual Studio Editor.</Description>
<License>LICENSE</License>
Expand Down

0 comments on commit bdcd103

Please sign in to comment.