Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 727a3f0

Browse files
fix highlighting of method invocations and primitive types; close #247
1 parent 3f99934 commit 727a3f0

1 file changed

Lines changed: 31 additions & 12 deletions

File tree

src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ protected override void Colorize(AstNode node, HighlightingColor color)
407407
var resolverNode = node;
408408
while (CSharpAstResolver.IsUnresolvableNode(resolverNode) && resolverNode.Parent != null)
409409
resolverNode = resolverNode.Parent;
410+
if (resolverNode.Role == Roles.TargetExpression && resolverNode.Parent is InvocationExpression)
411+
resolverNode = resolverNode.Parent;
412+
413+
if (node is Identifier)
414+
resolverNode.AddAnnotation(node);
415+
if (color != null)
416+
resolverNode.AddAnnotation(color);
410417
currentNavigator.Resolved(resolverNode, resolver.Resolve(resolverNode));
411418
}
412419
base.Colorize(node, color);
@@ -423,6 +430,12 @@ protected override void Colorize(Identifier identifier, ResolveResult rr)
423430
base.Colorize(identifier, rr);
424431
}
425432

433+
public override void VisitPrimitiveType(PrimitiveType primitiveType)
434+
{
435+
// highlight usages of primitive types as well.
436+
Colorize(primitiveType, null);
437+
}
438+
426439
public readonly Color DefaultFillColor = Color.FromArgb(22, 30, 130, 255);
427440

428441
public void SetCurrentSymbol(ISymbol symbol)
@@ -454,7 +467,7 @@ IResolveVisitorNavigator InitNavigator()
454467
return null;
455468
var navigators = new IResolveVisitorNavigator[searchScopes.Count];
456469
for (int i = 0; i < navigators.Length; i++) {
457-
navigators[i] = searchScopes[i].GetNavigator(compilation, Colorize);
470+
navigators[i] = searchScopes[i].GetNavigator(compilation, ColorizeMatch);
458471
}
459472
IResolveVisitorNavigator combinedNavigator;
460473
if (searchScopes.Count == 1) {
@@ -466,18 +479,24 @@ IResolveVisitorNavigator InitNavigator()
466479
return combinedNavigator;
467480
}
468481

469-
void Colorize(AstNode node, ResolveResult result)
482+
void ColorizeMatch(AstNode node, ResolveResult result)
470483
{
471-
Identifier identifier = node.GetChildByRole(Roles.Identifier);
472-
if (!identifier.IsNull)
473-
AddMarker(identifier.StartLocation, identifier.EndLocation);
474-
else
475-
AddMarker(node.StartLocation, node.EndLocation);
476-
}
477-
478-
void AddMarker(TextLocation start, TextLocation end)
479-
{
480-
Colorize(start, end, symbolReferenceColor);
484+
Identifier identifier = node.Annotation<Identifier>() ?? node.GetChildByRole(Roles.Identifier);
485+
TextLocation start, end;
486+
if (!identifier.IsNull) {
487+
start = identifier.StartLocation;
488+
end = identifier.EndLocation;
489+
} else {
490+
start = node.StartLocation;
491+
end = node.EndLocation;
492+
}
493+
var complementary = node.Annotation<HighlightingColor>();
494+
HighlightingColor newColor = symbolReferenceColor;
495+
if (complementary != null) {
496+
newColor = newColor.Clone();
497+
newColor.MergeWith(complementary);
498+
}
499+
Colorize(start, end, newColor);
481500
}
482501
#endregion
483502
}

0 commit comments

Comments
 (0)