36 changed files with 466 additions and 382 deletions
@ -1,110 +0,0 @@
@@ -1,110 +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.IO; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.AvalonEdit.AddIn.Options; |
||||
using ICSharpCode.AvalonEdit.Document; |
||||
using ICSharpCode.AvalonEdit.Highlighting; |
||||
using ICSharpCode.NRefactory.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Editor.AvalonEdit; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.AddIn |
||||
{ |
||||
public class DocumentSyntaxHighlighter : ISyntaxHighlighter |
||||
{ |
||||
IDocument document; |
||||
IHighlighter highlighter; |
||||
string highlightingName; |
||||
|
||||
public DocumentSyntaxHighlighter(IDocument document, IHighlighter highlighter, string highlightingName) |
||||
{ |
||||
if (document == null) |
||||
throw new ArgumentNullException("document"); |
||||
this.document = document; |
||||
this.highlighter = highlighter; |
||||
this.highlightingName = highlightingName; |
||||
} |
||||
|
||||
public IEnumerable<string> GetSpanColorNamesFromLineStart(int lineNumber) |
||||
{ |
||||
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 color in highlighter.GetColorStack(lineNumber - 1) |
||||
where color.Name != null |
||||
select color.Name; |
||||
} else { |
||||
return Enumerable.Empty<string>(); |
||||
} |
||||
} |
||||
|
||||
public HighlightingColor GetNamedColor(string name) |
||||
{ |
||||
return CustomizableHighlightingColorizer.CustomizeColor(name, CustomizedHighlightingColor.FetchCustomizations(highlightingName)); |
||||
} |
||||
|
||||
public HighlightedInlineBuilder BuildInlines(int lineNumber) |
||||
{ |
||||
HighlightedInlineBuilder builder = new HighlightedInlineBuilder(document.GetText(document.GetLineByNumber(lineNumber))); |
||||
if (highlighter != null) { |
||||
HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber); |
||||
int startOffset = highlightedLine.DocumentLine.Offset; |
||||
// copy only the foreground and background colors
|
||||
foreach (HighlightedSection section in highlightedLine.Sections) { |
||||
if (section.Color.Foreground != null) { |
||||
builder.SetForeground(section.Offset - startOffset, section.Length, section.Color.Foreground.GetBrush(null)); |
||||
} |
||||
if (section.Color.Background != null) { |
||||
builder.SetBackground(section.Offset - startOffset, section.Length, section.Color.Background.GetBrush(null)); |
||||
} |
||||
} |
||||
} |
||||
return builder; |
||||
} |
||||
|
||||
public HighlightingColor DefaultTextColor { |
||||
get { |
||||
return GetNamedColor(CustomizableHighlightingColorizer.DefaultTextAndBackground); |
||||
} |
||||
} |
||||
|
||||
public event EventHandler VisibleDocumentLinesChanged; |
||||
|
||||
public IHighlightingDefinition HighlightingDefinition { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public void AddAdditionalHighlighter(IHighlighter highlighter) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void RemoveAdditionalHighlighter(IHighlighter highlighter) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void InvalidateLine(IDocumentLine line) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void InvalidateAll() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IEnumerable<IDocumentLine> GetVisibleDocumentLines() |
||||
{ |
||||
return Enumerable.Empty<IDocumentLine>(); |
||||
} |
||||
} |
||||
} |
||||
@ -1,99 +0,0 @@
@@ -1,99 +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.Highlighting; |
||||
using ICSharpCode.NRefactory.Editor; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// Represents the syntax highlighter inside the text editor.
|
||||
/// </summary>
|
||||
[TextEditorService] |
||||
public interface ISyntaxHighlighter |
||||
{ |
||||
/// <summary>
|
||||
/// Retrieves the names of the spans that are active at the start of the specified line.
|
||||
/// Nested spans are returned in inside-out order (first element of result enumerable is the innermost span).
|
||||
/// </summary>
|
||||
IEnumerable<string> GetSpanColorNamesFromLineStart(int lineNumber); |
||||
|
||||
/// <summary>
|
||||
/// Retrieves the HighlightingColor with the specified name. Returns null if no color matching the name is found.
|
||||
/// </summary>
|
||||
HighlightingColor GetNamedColor(string name); |
||||
|
||||
/// <summary>
|
||||
/// Gets the highlighting definition that is being used.
|
||||
/// </summary>
|
||||
IHighlightingDefinition HighlightingDefinition { get; } |
||||
|
||||
/// <summary>
|
||||
/// Adds an additional highlighting engine that runs in addition to the XSHD-based highlighting.
|
||||
/// </summary>
|
||||
void AddAdditionalHighlighter(IHighlighter highlighter); |
||||
|
||||
/// <summary>
|
||||
/// Removes an additional highlighting engine.
|
||||
/// </summary>
|
||||
void RemoveAdditionalHighlighter(IHighlighter highlighter); |
||||
|
||||
/// <summary>
|
||||
/// Invalidates a line, causing it to be re-highlighted.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method is intended to be called by additional highlighters that process external information
|
||||
/// (e.g. semantic highlighting).
|
||||
/// </remarks>
|
||||
void InvalidateLine(IDocumentLine line); |
||||
|
||||
/// <summary>
|
||||
/// Invalidates all lines, causing-them to be re-highlighted.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method is intended to be called by additional highlighters that process external information
|
||||
/// (e.g. semantic highlighting).
|
||||
/// </remarks>
|
||||
void InvalidateAll(); |
||||
|
||||
/// <summary>
|
||||
/// Gets the document lines that are currently visible in the editor.
|
||||
/// </summary>
|
||||
IEnumerable<IDocumentLine> GetVisibleDocumentLines(); |
||||
|
||||
/// <summary>
|
||||
/// Raised when the set of visible document lines has changed.
|
||||
/// </summary>
|
||||
event EventHandler VisibleDocumentLinesChanged; |
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="HighlightedInlineBuilder"/> for a specified line.
|
||||
/// </summary>
|
||||
HighlightedInlineBuilder BuildInlines(int lineNumber); |
||||
|
||||
/// <summary>
|
||||
/// Gets the default text color.
|
||||
/// </summary>
|
||||
HighlightingColor DefaultTextColor { get; } |
||||
} |
||||
|
||||
public static class SyntaxHighligherKnownSpanNames |
||||
{ |
||||
public const string Comment = "Comment"; |
||||
public const string String = "String"; |
||||
public const string Char = "Char"; |
||||
|
||||
public static bool IsLineStartInsideComment(this ISyntaxHighlighter highligher, int lineNumber) |
||||
{ |
||||
return highligher.GetSpanColorNamesFromLineStart(lineNumber).Contains(Comment); |
||||
} |
||||
|
||||
public static bool IsLineStartInsideString(this ISyntaxHighlighter highligher, int lineNumber) |
||||
{ |
||||
return highligher.GetSpanColorNamesFromLineStart(lineNumber).Contains(String); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
// 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.Highlighting; |
||||
using ICSharpCode.NRefactory.Editor; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Editor |
||||
{ |
||||
public static class SyntaxHighlighterKnownSpanNames |
||||
{ |
||||
public const string Comment = "Comment"; |
||||
public const string String = "String"; |
||||
public const string Char = "Char"; |
||||
|
||||
public static bool IsLineStartInsideComment(this IHighlighter highligher, int lineNumber) |
||||
{ |
||||
return highligher.GetColorStack(lineNumber).Any(c => c.Name == Comment); |
||||
} |
||||
|
||||
public static bool IsLineStartInsideString(this IHighlighter highligher, int lineNumber) |
||||
{ |
||||
return highligher.GetColorStack(lineNumber).Any(c => c.Name == String); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue