Skip to content

Commit

Permalink
#12, revert newlines, disable VS warnings (for uppercase fields)
Browse files Browse the repository at this point in the history
  • Loading branch information
Art-Stea1th committed May 17, 2018
1 parent 2afd904 commit ff9715c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
13 changes: 10 additions & 3 deletions Extension/ASD.ESH/Classification/Classifier.SpansConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
using VB = Microsoft.CodeAnalysis.VisualBasic;

namespace ASD.ESH.Classification {

internal sealed partial class Classifier {

internal sealed class SpansConverter {
private readonly SemanticModel model;
private readonly SyntaxNode root;
private readonly ITextSnapshot snapshot;

private SemanticModel model;
private SyntaxNode root;
private ITextSnapshot snapshot;

public SpansConverter(SemanticModel model, SyntaxNode root, ITextSnapshot snapshot) {
this.model = model; this.root = root; this.snapshot = snapshot;
Expand All @@ -34,6 +37,7 @@ public IEnumerable<ClassificationSpan> ConvertAll(IEnumerable<ClassifiedSpan> sp
}

private ClassificationSpan Convert(ClassifiedSpan span) {

var symbol = GetSymbol(span.TextSpan);
if (symbol == null) { return null; }

Expand All @@ -44,13 +48,15 @@ private ClassificationSpan Convert(ClassifiedSpan span) {
}

private ISymbol GetSymbol(TextSpan textSpan) {

var expressionSyntaxNode = GetExpression(root.FindNode(textSpan));

return model.GetSymbolInfo(expressionSyntaxNode).Symbol
?? model.GetDeclaredSymbol(expressionSyntaxNode);
}

private SyntaxNode GetExpression(SyntaxNode node) {

switch (node) {
case CS.Syntax.ArgumentSyntax s:
return s.Expression;
Expand All @@ -65,6 +71,7 @@ private SyntaxNode GetExpression(SyntaxNode node) {

private ClassificationSpan CreateSpan(TextSpan span, IClassificationType type)
=> new ClassificationSpan(new SnapshotSpan(snapshot, new Span(span.Start, span.Length)), type);

}
}
}
4 changes: 4 additions & 0 deletions Extension/ASD.ESH/Classification/Classifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
using Microsoft.VisualStudio.Text.Classification;

namespace ASD.ESH.Classification {

using Helpers;

internal sealed partial class Classifier : IClassifier {

#pragma warning disable CS0067
public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged;
#pragma warning restore CS0067
Expand All @@ -27,6 +29,7 @@ internal sealed partial class Classifier : IClassifier {
private IList<ClassificationSpan> lastSpans = emptyList;

public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span) {

var snapshot = span.Snapshot;
var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();

Expand All @@ -44,6 +47,7 @@ public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span) {
}

private async Task<IList<ClassificationSpan>> GetSpansAync(Document document, ITextSnapshot snapshot) {

var model = await document.GetSemanticModelAsync().ConfigureAwait(false);
var root = await document.GetSyntaxRootAsync().ConfigureAwait(false);
var spans = await document.GetClassifiedSpansAsync(new TextSpan(0, snapshot.Length)).ConfigureAwait(false);
Expand Down
3 changes: 3 additions & 0 deletions Extension/ASD.ESH/Classification/ClassifierProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
using Microsoft.VisualStudio.Utilities;

namespace ASD.ESH.Classification {

[Export(typeof(IClassifierProvider))]
[ContentType("CSharp"), ContentType("Basic")]
internal sealed class ClassifierProvider : IClassifierProvider {

#pragma warning disable CS0649
[Import] private IClassificationTypeRegistryService registryService; // set via MEF
#pragma warning restore CS0649

IClassifier IClassifierProvider.GetClassifier(ITextBuffer textBuffer) {

return textBuffer.Properties.GetOrCreateSingletonProperty(
creator: () => {
TypesRegistry.InitializeIfNeeded(registryService);
Expand Down
9 changes: 6 additions & 3 deletions Extension/ASD.ESH/Classification/TypesRegistry.Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
using Microsoft.VisualStudio.Utilities;

namespace ASD.ESH.Classification {

internal static partial class TypesRegistry {

private sealed class Definitions {

private static class DefaultColor {
public const string Blue = "#9CDCFE";
public const string Yellow = "#DCDCAA";
Expand All @@ -20,7 +23,7 @@ private static class DefaultColor {

private const string priority = PredefinedClassificationTypeNames.Identifier;

#pragma warning disable CS0649
#pragma warning disable CS0649, IDE1006

[Export(typeof(ClassificationTypeDefinition)), Name(pT + UserTagName.Event)]
internal static ClassificationTypeDefinition EventType;
Expand Down Expand Up @@ -55,7 +58,7 @@ private static class DefaultColor {
[Export(typeof(ClassificationTypeDefinition)), Name(pT + UserTagName.Property)]
internal static ClassificationTypeDefinition PropertyType;

#pragma warning restore CS0649
#pragma warning restore CS0649, IDE1006

[Export(typeof(EditorFormatDefinition)), Name(pF + UserTagName.Event), UserVisible(true)]
[ClassificationType(ClassificationTypeNames = pT + UserTagName.Event), Order(After = priority)]
Expand Down Expand Up @@ -135,11 +138,11 @@ public PropertyFormatDefinition()
}

private abstract class FormatDefinition : ClassificationFormatDefinition {

public FormatDefinition(string displayName, string defaultForegroundColor) : this(displayName) {
ForegroundColor = (Color)ColorConverter
.ConvertFromString(defaultForegroundColor);
}

public FormatDefinition(string displayName) {
DisplayName = $"User Tags - {displayName}";
}
Expand Down
6 changes: 6 additions & 0 deletions Extension/ASD.ESH/Classification/TypesRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
using Microsoft.VisualStudio.Text.Classification;

namespace ASD.ESH.Classification {

internal static partial class TypesRegistry {

private const string pT = "ASD-ESH."; // prefix type-name
private const string pF = pT + "Definition."; // prefix format-name

private static readonly object token = new object();
private static IClassificationTypeRegistryService registryService;

public static void InitializeIfNeeded(IClassificationTypeRegistryService service) {

if (service == null) {
throw new System.ArgumentNullException(nameof(service));
}
Expand All @@ -29,10 +32,12 @@ public static void InitializeIfNeeded(IClassificationTypeRegistryService service
}

public static IClassificationType ResolveType(ISymbol symbol) {

var userTagName = default(string);
var modifier = DeclarationModifiers.From(symbol);

switch (symbol.Kind) {

case SymbolKind.Event:
userTagName
= UserTagName.Event; break;
Expand Down Expand Up @@ -76,6 +81,7 @@ public static IClassificationType ResolveType(ISymbol symbol) {
}

private static class UserTagName {

public const string Event = nameof(SymbolKind.Event);
public const string Field = nameof(SymbolKind.Field);
public const string FieldConstant = nameof(SymbolKind.Field) + "Constant";
Expand Down
3 changes: 3 additions & 0 deletions Extension/ASD.ESH/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
using Microsoft.CodeAnalysis.Text;

namespace ASD.ESH.Helpers {

internal static class Extensions {

public static Task<IEnumerable<ClassifiedSpan>> GetClassifiedSpansAsync(
this Document document, TextSpan textSpan, CancellationToken cancellationToken = default(CancellationToken))
=> Classifier.GetClassifiedSpansAsync(document, textSpan, cancellationToken);

}
}

0 comments on commit ff9715c

Please sign in to comment.