18 changed files with 835 additions and 110 deletions
@ -0,0 +1,291 @@ |
|||||||
|
<?xml version="1.0"?> |
||||||
|
<SyntaxDefinition name="C#" extensions=".cs" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008"> |
||||||
|
<!-- This is a variant of the AvalonEdit C# highlighting that has several constructs disabled. |
||||||
|
The disabled constructs (e.g. contextual keywords) are highlighted using the CSharpSemanticHighlighter instead. |
||||||
|
--> |
||||||
|
|
||||||
|
<!-- The named colors 'Comment' and 'String' are used in SharpDevelop to detect if a line is inside a multiline string/comment --> |
||||||
|
<Color name="Comment" foreground="Green" exampleText="// comment" /> |
||||||
|
<Color name="String" foreground="Blue" exampleText="string text = "Hello, World!""/> |
||||||
|
<Color name="Char" foreground="Magenta" exampleText="char linefeed = '\n';"/> |
||||||
|
<Color name="Preprocessor" foreground="Green" exampleText="#region Title" /> |
||||||
|
<Color name="Punctuation" exampleText="a(b.c);" /> |
||||||
|
<Color name="ValueTypes" fontWeight="bold" foreground="Red" exampleText="bool b = true;" /> |
||||||
|
<Color name="ReferenceTypes" foreground="Red" exampleText="object o;" /> |
||||||
|
<Color name="NumberLiteral" foreground="DarkBlue" exampleText="3.1415f"/> |
||||||
|
<Color name="ThisOrBaseReference" fontWeight="bold" exampleText="this.Do(); base.Do();"/> |
||||||
|
<Color name="NullOrValueKeywords" fontWeight="bold" exampleText="if (value == null)"/> |
||||||
|
<Color name="Keywords" fontWeight="bold" foreground="Blue" exampleText="if (a) {} else {}"/> |
||||||
|
<Color name="GotoKeywords" foreground="Navy" exampleText="continue; return null;"/> |
||||||
|
<Color name="ContextKeywords" foreground="Navy" exampleText="var a = from x in y select z;"/> |
||||||
|
<Color name="ExceptionKeywords" fontWeight="bold" foreground="Teal" exampleText="try {} catch {} finally {}"/> |
||||||
|
<Color name="CheckedKeyword" fontWeight="bold" foreground="DarkGray" exampleText="checked {}"/> |
||||||
|
<Color name="UnsafeKeywords" foreground="Olive" exampleText="unsafe { fixed (..) {} }"/> |
||||||
|
<Color name="OperatorKeywords" fontWeight="bold" foreground="Pink" exampleText="public static implicit operator..."/> |
||||||
|
<Color name="ParameterModifiers" fontWeight="bold" foreground="DeepPink" exampleText="(ref int a, params int[] b)"/> |
||||||
|
<Color name="Modifiers" foreground="Brown" exampleText="static readonly int a;"/> |
||||||
|
<Color name="Visibility" fontWeight="bold" foreground="Blue" exampleText="public override void ToString();"/> |
||||||
|
<Color name="NamespaceKeywords" fontWeight="bold" foreground="Green" exampleText="namespace A.B { using System; }"/> |
||||||
|
<Color name="GetSetAddRemove" foreground="SaddleBrown" exampleText="int Prop { get; set; }"/> |
||||||
|
<Color name="TrueFalse" fontWeight="bold" foreground="DarkCyan" exampleText="b = false; a = true;" /> |
||||||
|
<Color name="TypeKeywords" fontWeight="bold" foreground="DarkCyan" exampleText="if (x is int) { a = x as int; type = typeof(int); size = sizeof(int); c = new object(); }"/> |
||||||
|
|
||||||
|
<!-- Colors used for semantic highlighting --> |
||||||
|
<Color name="TypeReferences" foreground="DarkCyan" exampleText="System.Uri uri;"/> |
||||||
|
<Color name="MethodCall" foreground="MidnightBlue" fontWeight="bold" exampleText="o.ToString();"/> |
||||||
|
<Color name="FieldAccess" fontStyle="italic" exampleText="return this.name;"/> |
||||||
|
|
||||||
|
<RuleSet name="CommentMarkerSet"> |
||||||
|
<Keywords fontWeight="bold" foreground="Red"> |
||||||
|
<Word>TODO</Word> |
||||||
|
<Word>FIXME</Word> |
||||||
|
</Keywords> |
||||||
|
<Keywords fontWeight="bold" foreground="#E0E000"> |
||||||
|
<Word>HACK</Word> |
||||||
|
<Word>UNDONE</Word> |
||||||
|
</Keywords> |
||||||
|
</RuleSet> |
||||||
|
|
||||||
|
<!-- This is the main ruleset. --> |
||||||
|
<RuleSet> |
||||||
|
<Span color="Preprocessor"> |
||||||
|
<Begin>\#</Begin> |
||||||
|
<RuleSet name="PreprocessorSet"> |
||||||
|
<Span> <!-- preprocessor directives that allow comments --> |
||||||
|
<Begin fontWeight="bold"> |
||||||
|
(define|undef|if|elif|else|endif|line)\b |
||||||
|
</Begin> |
||||||
|
<RuleSet> |
||||||
|
<Span color="Comment" ruleSet="CommentMarkerSet"> |
||||||
|
<Begin>//</Begin> |
||||||
|
</Span> |
||||||
|
</RuleSet> |
||||||
|
</Span> |
||||||
|
<Span> <!-- preprocessor directives that don't allow comments --> |
||||||
|
<Begin fontWeight="bold"> |
||||||
|
(region|endregion|error|warning|pragma)\b |
||||||
|
</Begin> |
||||||
|
</Span> |
||||||
|
</RuleSet> |
||||||
|
</Span> |
||||||
|
|
||||||
|
<Span color="Comment"> |
||||||
|
<Begin color="XmlDoc/DocComment">///</Begin> |
||||||
|
<RuleSet> |
||||||
|
<Import ruleSet="XmlDoc/DocCommentSet"/> |
||||||
|
<Import ruleSet="CommentMarkerSet"/> |
||||||
|
</RuleSet> |
||||||
|
</Span> |
||||||
|
|
||||||
|
<Span color="Comment" ruleSet="CommentMarkerSet"> |
||||||
|
<Begin>//</Begin> |
||||||
|
</Span> |
||||||
|
|
||||||
|
<Span color="Comment" ruleSet="CommentMarkerSet" multiline="true"> |
||||||
|
<Begin>/\*</Begin> |
||||||
|
<End>\*/</End> |
||||||
|
</Span> |
||||||
|
|
||||||
|
<Span color="String"> |
||||||
|
<Begin>"</Begin> |
||||||
|
<End>"</End> |
||||||
|
<RuleSet> |
||||||
|
<!-- span for escape sequences --> |
||||||
|
<Span begin="\\" end="."/> |
||||||
|
</RuleSet> |
||||||
|
</Span> |
||||||
|
|
||||||
|
<Span color="Char"> |
||||||
|
<Begin>'</Begin> |
||||||
|
<End>'</End> |
||||||
|
<RuleSet> |
||||||
|
<!-- span for escape sequences --> |
||||||
|
<Span begin="\\" end="."/> |
||||||
|
</RuleSet> |
||||||
|
</Span> |
||||||
|
|
||||||
|
<Span color="String" multiline="true"> |
||||||
|
<Begin color="String">@"</Begin> |
||||||
|
<End>"</End> |
||||||
|
<RuleSet> |
||||||
|
<!-- span for escape sequences --> |
||||||
|
<Span begin='""' end=""/> |
||||||
|
</RuleSet> |
||||||
|
</Span> |
||||||
|
|
||||||
|
<!-- don't highlight "@int" as keyword --> |
||||||
|
<Rule> |
||||||
|
@[\w\d_]+ |
||||||
|
</Rule> |
||||||
|
|
||||||
|
<Keywords color="ThisOrBaseReference"> |
||||||
|
<Word>this</Word> |
||||||
|
<Word>base</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="TypeKeywords"> |
||||||
|
<Word>as</Word> |
||||||
|
<Word>is</Word> |
||||||
|
<Word>new</Word> |
||||||
|
<Word>sizeof</Word> |
||||||
|
<Word>typeof</Word> |
||||||
|
<Word>stackalloc</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="TrueFalse"> |
||||||
|
<Word>true</Word> |
||||||
|
<Word>false</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="Keywords"> |
||||||
|
<Word>else</Word> |
||||||
|
<Word>if</Word> |
||||||
|
<Word>switch</Word> |
||||||
|
<Word>case</Word> |
||||||
|
<Word>default</Word> |
||||||
|
<Word>do</Word> |
||||||
|
<Word>for</Word> |
||||||
|
<Word>foreach</Word> |
||||||
|
<Word>in</Word> |
||||||
|
<Word>while</Word> |
||||||
|
<Word>lock</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="GotoKeywords"> |
||||||
|
<Word>break</Word> |
||||||
|
<Word>continue</Word> |
||||||
|
<Word>goto</Word> |
||||||
|
<Word>return</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="ContextKeywords"> |
||||||
|
<Word>yield</Word> |
||||||
|
<Word>partial</Word> |
||||||
|
<Word>global</Word> |
||||||
|
<Word>where</Word> |
||||||
|
<Word>select</Word> |
||||||
|
<Word>group</Word> |
||||||
|
<Word>by</Word> |
||||||
|
<Word>into</Word> |
||||||
|
<Word>from</Word> |
||||||
|
<Word>ascending</Word> |
||||||
|
<Word>descending</Word> |
||||||
|
<Word>orderby</Word> |
||||||
|
<Word>let</Word> |
||||||
|
<Word>join</Word> |
||||||
|
<Word>on</Word> |
||||||
|
<Word>equals</Word> |
||||||
|
<Word>var</Word> |
||||||
|
<Word>dynamic</Word> |
||||||
|
<Word>await</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="ExceptionKeywords"> |
||||||
|
<Word>try</Word> |
||||||
|
<Word>throw</Word> |
||||||
|
<Word>catch</Word> |
||||||
|
<Word>finally</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="CheckedKeyword"> |
||||||
|
<Word>checked</Word> |
||||||
|
<Word>unchecked</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="UnsafeKeywords"> |
||||||
|
<Word>fixed</Word> |
||||||
|
<Word>unsafe</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="ValueTypes"> |
||||||
|
<Word>bool</Word> |
||||||
|
<Word>byte</Word> |
||||||
|
<Word>char</Word> |
||||||
|
<Word>decimal</Word> |
||||||
|
<Word>double</Word> |
||||||
|
<Word>enum</Word> |
||||||
|
<Word>float</Word> |
||||||
|
<Word>int</Word> |
||||||
|
<Word>long</Word> |
||||||
|
<Word>sbyte</Word> |
||||||
|
<Word>short</Word> |
||||||
|
<Word>struct</Word> |
||||||
|
<Word>uint</Word> |
||||||
|
<Word>ushort</Word> |
||||||
|
<Word>ulong</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="ReferenceTypes"> |
||||||
|
<Word>class</Word> |
||||||
|
<Word>interface</Word> |
||||||
|
<Word>delegate</Word> |
||||||
|
<Word>object</Word> |
||||||
|
<Word>string</Word> |
||||||
|
<Word>void</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="OperatorKeywords"> |
||||||
|
<Word>explicit</Word> |
||||||
|
<Word>implicit</Word> |
||||||
|
<Word>operator</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="ParameterModifiers"> |
||||||
|
<Word>params</Word> |
||||||
|
<Word>ref</Word> |
||||||
|
<Word>out</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="Modifiers"> |
||||||
|
<Word>abstract</Word> |
||||||
|
<Word>const</Word> |
||||||
|
<Word>event</Word> |
||||||
|
<Word>extern</Word> |
||||||
|
<Word>override</Word> |
||||||
|
<Word>readonly</Word> |
||||||
|
<Word>sealed</Word> |
||||||
|
<Word>static</Word> |
||||||
|
<Word>virtual</Word> |
||||||
|
<Word>volatile</Word> |
||||||
|
<Word>async</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="Visibility"> |
||||||
|
<Word>public</Word> |
||||||
|
<Word>protected</Word> |
||||||
|
<Word>private</Word> |
||||||
|
<Word>internal</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="NamespaceKeywords"> |
||||||
|
<Word>namespace</Word> |
||||||
|
<Word>using</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="GetSetAddRemove"> |
||||||
|
<Word>get</Word> |
||||||
|
<Word>set</Word> |
||||||
|
<Word>add</Word> |
||||||
|
<Word>remove</Word> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<Keywords color="NullOrValueKeywords"> |
||||||
|
<Word>null</Word> |
||||||
|
<!--<Word>value</Word>--> |
||||||
|
</Keywords> |
||||||
|
|
||||||
|
<!-- Digits --> |
||||||
|
<Rule color="NumberLiteral"> |
||||||
|
\b0[xX][0-9a-fA-F]+ # hex number |
||||||
|
| |
||||||
|
( \b\d+(\.[0-9]+)? #number with optional floating point |
||||||
|
| \.[0-9]+ #or just starting with floating point |
||||||
|
) |
||||||
|
([eE][+-]?[0-9]+)? # optional exponent |
||||||
|
</Rule> |
||||||
|
|
||||||
|
<Rule color="Punctuation"> |
||||||
|
[?,.;()\[\]{}+\-/%*<>^+~!|&]+ |
||||||
|
</Rule> |
||||||
|
</RuleSet> |
||||||
|
</SyntaxDefinition> |
@ -0,0 +1,261 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Diagnostics; |
||||||
|
using System.Linq; |
||||||
|
using System.Threading.Tasks; |
||||||
|
using ICSharpCode.AvalonEdit.Highlighting; |
||||||
|
using ICSharpCode.NRefactory; |
||||||
|
using ICSharpCode.NRefactory.CSharp; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||||
|
using ICSharpCode.NRefactory.Editor; |
||||||
|
using ICSharpCode.NRefactory.Semantics; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.SharpDevelop.Editor; |
||||||
|
using ICSharpCode.SharpDevelop.Parser; |
||||||
|
|
||||||
|
namespace CSharpBinding |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Semantic highlighting for C#.
|
||||||
|
/// </summary>
|
||||||
|
public class CSharpSemanticHighlighter : DepthFirstAstVisitor<object, object>, IHighlighter, IResolveVisitorNavigator |
||||||
|
{ |
||||||
|
readonly ITextEditor textEditor; |
||||||
|
readonly HighlightingColor typeReferenceColor; |
||||||
|
readonly HighlightingColor methodCallColor; |
||||||
|
readonly HighlightingColor fieldAccessColor; |
||||||
|
readonly HighlightingColor valueKeywordColor; |
||||||
|
|
||||||
|
int lineNumber; |
||||||
|
HighlightedLine line; |
||||||
|
ResolveVisitor resolveVisitor; |
||||||
|
|
||||||
|
bool isInAccessor; |
||||||
|
|
||||||
|
public CSharpSemanticHighlighter(ITextEditor textEditor, IHighlightingDefinition highlightingDefinition) |
||||||
|
{ |
||||||
|
if (textEditor == null) |
||||||
|
throw new ArgumentNullException("textEditor"); |
||||||
|
if (highlightingDefinition == null) |
||||||
|
throw new ArgumentNullException("highlightingDefinition"); |
||||||
|
this.textEditor = textEditor; |
||||||
|
this.typeReferenceColor = highlightingDefinition.GetNamedColor("TypeReferences"); |
||||||
|
this.methodCallColor = highlightingDefinition.GetNamedColor("MethodCall"); |
||||||
|
this.fieldAccessColor = highlightingDefinition.GetNamedColor("FieldAccess"); |
||||||
|
this.valueKeywordColor = highlightingDefinition.GetNamedColor("NullOrValueKeywords"); |
||||||
|
} |
||||||
|
|
||||||
|
public IDocument Document { |
||||||
|
get { return textEditor.Document; } |
||||||
|
} |
||||||
|
|
||||||
|
IEnumerable<HighlightingColor> IHighlighter.GetColorStack(int lineNumber) |
||||||
|
{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public HighlightedLine HighlightLine(int lineNumber) |
||||||
|
{ |
||||||
|
Task<ParseInformation> parseInfoTask = ParserService.ParseAsync(textEditor.FileName, textEditor.Document); |
||||||
|
if (!parseInfoTask.IsCompleted) { |
||||||
|
Debug.WriteLine("Semantic highlighting for line {0} - parser not completed", lineNumber); |
||||||
|
return null; |
||||||
|
} |
||||||
|
ParseInformation parseInfo = parseInfoTask.Result; |
||||||
|
CSharpParsedFile parsedFile = parseInfo.ParsedFile as CSharpParsedFile; |
||||||
|
CompilationUnit cu = parseInfo.Annotation<CompilationUnit>(); |
||||||
|
if (cu == null || parsedFile == null) |
||||||
|
return null; |
||||||
|
|
||||||
|
using (var ctx = ParserService.GetTypeResolveContext(parseInfo.ProjectContent).Synchronize()) { |
||||||
|
CSharpResolver resolver = new CSharpResolver(ctx); |
||||||
|
resolveVisitor = new ResolveVisitor(resolver, parsedFile, this); |
||||||
|
|
||||||
|
resolveVisitor.Scan(cu); |
||||||
|
|
||||||
|
HighlightedLine line = new HighlightedLine(textEditor.Document, textEditor.Document.GetLineByNumber(lineNumber)); |
||||||
|
this.line = line; |
||||||
|
this.lineNumber = lineNumber; |
||||||
|
cu.AcceptVisitor(this); |
||||||
|
this.line = null; |
||||||
|
this.resolveVisitor = null; |
||||||
|
Debug.WriteLine("Semantic highlighting for line {0} - added {1} sections", lineNumber, line.Sections.Count); |
||||||
|
return line; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
HighlightingColor GetColor(ResolveResult rr) |
||||||
|
{ |
||||||
|
if (rr is TypeResolveResult) |
||||||
|
return typeReferenceColor; |
||||||
|
MemberResolveResult mrr = rr as MemberResolveResult; |
||||||
|
if (mrr != null) { |
||||||
|
if (mrr.Member is IField) |
||||||
|
return fieldAccessColor; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
void Colorize(AstNode node, HighlightingColor color) |
||||||
|
{ |
||||||
|
if (node.IsNull || color == null) |
||||||
|
return; |
||||||
|
Colorize(node.StartLocation, node.EndLocation, color); |
||||||
|
} |
||||||
|
|
||||||
|
void Colorize(TextLocation start, TextLocation end, HighlightingColor color) |
||||||
|
{ |
||||||
|
if (color == null) |
||||||
|
return; |
||||||
|
if (start.Line == lineNumber && end.Line == lineNumber) { |
||||||
|
int lineStartOffset = line.DocumentLine.Offset; |
||||||
|
int startOffset = lineStartOffset + start.Column - 1; |
||||||
|
int endOffset = lineStartOffset + end.Column - 1; |
||||||
|
line.Sections.Add(new HighlightedSection { |
||||||
|
Offset = startOffset, |
||||||
|
Length = endOffset - startOffset, |
||||||
|
Color = color |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ResolveVisitorNavigationMode IResolveVisitorNavigator.Scan(AstNode node) |
||||||
|
{ |
||||||
|
if (node.StartLocation.Line <= lineNumber && node.EndLocation.Line >= lineNumber) { |
||||||
|
if (node is SimpleType || node is MemberType |
||||||
|
|| node is IdentifierExpression || node is MemberReferenceExpression |
||||||
|
|| node is InvocationExpression) |
||||||
|
{ |
||||||
|
return ResolveVisitorNavigationMode.Resolve; |
||||||
|
} else { |
||||||
|
return ResolveVisitorNavigationMode.Scan; |
||||||
|
} |
||||||
|
} else { |
||||||
|
return ResolveVisitorNavigationMode.Skip; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void IResolveVisitorNavigator.Resolved(AstNode node, ResolveResult result) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void IResolveVisitorNavigator.ProcessConversion(Expression expression, ResolveResult result, Conversion conversion, IType targetType) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
protected override object VisitChildren(AstNode node, object data) |
||||||
|
{ |
||||||
|
for (var child = node.FirstChild; child != null; child = child.NextSibling) { |
||||||
|
if (child.StartLocation.Line <= lineNumber && child.EndLocation.Line >= lineNumber) |
||||||
|
child.AcceptVisitor(this); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public override object VisitSimpleType(SimpleType simpleType, object data) |
||||||
|
{ |
||||||
|
if (resolveVisitor.GetResolveResult(simpleType) is TypeResolveResult) |
||||||
|
Colorize(simpleType.IdentifierToken, typeReferenceColor); |
||||||
|
foreach (AstNode node in simpleType.TypeArguments) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public override object VisitMemberType(MemberType memberType, object data) |
||||||
|
{ |
||||||
|
// Ensure we visit/colorize the children in the correct order.
|
||||||
|
// This is required so that the resulting HighlightedSections are sorted correctly.
|
||||||
|
memberType.Target.AcceptVisitor(this); |
||||||
|
if (resolveVisitor.GetResolveResult(memberType) is TypeResolveResult) |
||||||
|
Colorize(memberType.MemberNameToken, typeReferenceColor); |
||||||
|
foreach (AstNode node in memberType.TypeArguments) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) |
||||||
|
{ |
||||||
|
Identifier ident = identifierExpression.GetChildByRole(IdentifierExpression.Roles.Identifier); |
||||||
|
if (isInAccessor && identifierExpression.Identifier == "value") { |
||||||
|
Colorize(ident, valueKeywordColor); |
||||||
|
} else { |
||||||
|
ResolveResult rr = resolveVisitor.GetResolveResult(identifierExpression); |
||||||
|
Colorize(ident, GetColor(rr)); |
||||||
|
} |
||||||
|
|
||||||
|
foreach (AstNode node in identifierExpression.TypeArguments) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) |
||||||
|
{ |
||||||
|
memberReferenceExpression.Target.AcceptVisitor(this); |
||||||
|
|
||||||
|
ResolveResult rr = resolveVisitor.GetResolveResult(memberReferenceExpression); |
||||||
|
Colorize(memberReferenceExpression.MemberNameToken, GetColor(rr)); |
||||||
|
|
||||||
|
foreach (AstNode node in memberReferenceExpression.TypeArguments) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data) |
||||||
|
{ |
||||||
|
Expression target = invocationExpression.Target; |
||||||
|
target.AcceptVisitor(this); |
||||||
|
|
||||||
|
var rr = resolveVisitor.GetResolveResult(invocationExpression) as CSharpInvocationResolveResult; |
||||||
|
if (rr != null && !rr.IsDelegateInvocation) { |
||||||
|
if (target is IdentifierExpression || target is MemberReferenceExpression || target is PointerReferenceExpression) { |
||||||
|
Colorize(target.GetChildByRole(AstNode.Roles.Identifier), methodCallColor); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
foreach (AstNode node in invocationExpression.Arguments) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public override object VisitAccessor(Accessor accessor, object data) |
||||||
|
{ |
||||||
|
isInAccessor = true; |
||||||
|
try { |
||||||
|
return base.VisitAccessor(accessor, data); |
||||||
|
} finally { |
||||||
|
isInAccessor = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) |
||||||
|
{ |
||||||
|
methodDeclaration.ReturnType.AcceptVisitor(this); |
||||||
|
Colorize(methodDeclaration.NameToken, methodCallColor); |
||||||
|
foreach (var node in methodDeclaration.TypeParameters) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
foreach (var node in methodDeclaration.Parameters) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
foreach (var node in methodDeclaration.Constraints) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
methodDeclaration.Body.AcceptVisitor(this); |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) |
||||||
|
{ |
||||||
|
Colorize(typeDeclaration, typeReferenceColor); |
||||||
|
foreach (var node in typeDeclaration.TypeParameters) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
foreach (var node in typeDeclaration.BaseTypes) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
foreach (var node in typeDeclaration.Constraints) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
foreach (var node in typeDeclaration.Members) |
||||||
|
node.AcceptVisitor(this); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,39 +0,0 @@ |
|||||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
|
||||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Linq; |
|
||||||
|
|
||||||
using ICSharpCode.AvalonEdit; |
|
||||||
using ICSharpCode.AvalonEdit.Highlighting; |
|
||||||
|
|
||||||
namespace ICSharpCode.SharpDevelop.Editor.AvalonEdit |
|
||||||
{ |
|
||||||
public class AvalonEditSyntaxHighlighterAdapter : ISyntaxHighlighter |
|
||||||
{ |
|
||||||
ITextEditorComponent textEditor; |
|
||||||
|
|
||||||
public AvalonEditSyntaxHighlighterAdapter(ITextEditorComponent textEditor) |
|
||||||
{ |
|
||||||
if (textEditor == null) |
|
||||||
throw new ArgumentNullException("textEditor"); |
|
||||||
this.textEditor = textEditor; |
|
||||||
} |
|
||||||
|
|
||||||
public IEnumerable<string> GetSpanColorNamesFromLineStart(int lineNumber) |
|
||||||
{ |
|
||||||
IHighlighter highlighter = textEditor.GetService(typeof(IHighlighter)) as IHighlighter; |
|
||||||
if (highlighter != null) { |
|
||||||
// delayed evaluation doesn't cause a problem here: GetSpanStack is called immediately,
|
|
||||||
// only the where/select portian is evaluated later. But that won't be a problem because the
|
|
||||||
// HighlightingSpan instance shouldn't change once it's in use.
|
|
||||||
return from span in highlighter.GetSpanStack(lineNumber - 1) |
|
||||||
where span.SpanColor != null && span.SpanColor.Name != null |
|
||||||
select span.SpanColor.Name; |
|
||||||
} else { |
|
||||||
return Enumerable.Empty<string>(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue