// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team // // Permission is hereby granted, free of charge, to any person obtaining a copy of this // software and associated documentation files (the "Software"), to deal in the Software // without restriction, including without limitation the rights to use, copy, modify, merge, // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons // to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or // substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. using System; using System.Collections.Generic; #if NREFACTORY using ICSharpCode.NRefactory.Editor; #else using ICSharpCode.AvalonEdit.Document; #endif namespace ICSharpCode.AvalonEdit.Highlighting { /// /// Represents a highlighted document. /// /// This interface is used by the to register the highlighter as a TextView service. public interface IHighlighter : IDisposable { /// /// Gets the underlying text document. /// IDocument Document { get; } /// /// Gets the stack of active colors (the colors associated with the active spans) at the end of the specified line. /// -> GetColorStack(1) returns the colors at the start of the second line. /// /// /// GetColorStack(0) is valid and will return the empty stack. /// The elements are returned in inside-out order (first element of result enumerable is the color of the innermost span). /// IEnumerable GetColorStack(int lineNumber); // Starting with SD 5.0, this interface exports GetColorStack() instead of GetSpanStack(). // This was done because custom highlighter implementations might not use the HighlightingSpan class (AST-based highlighting). /// /// Highlights the specified document line. /// /// The line to highlight. /// A line object that represents the highlighted sections. HighlightedLine HighlightLine(int lineNumber); /// /// Enforces a highlighting state update (triggering the HighlightingStateChanged event if necessary) /// for all lines up to (and inclusive) the specified line number. /// void UpdateHighlightingState(int lineNumber); /// /// Notification when the highlighter detects that the highlighting state at the /// beginning of the specified lines has changed. /// fromLineNumber and toLineNumber are both inclusive; /// the common case of a single-line change is represented by fromLineNumber == toLineNumber. /// /// During highlighting, the highlighting of line X will cause this event to be raised /// for line X+1 if the highlighting state at the end of line X has changed from its previous state. /// This event may also be raised outside of the highlighting process to signalize that /// changes to external data (not the document text; but e.g. semantic information) /// require a re-highlighting of the specified lines. /// /// /// For implementers: there is the requirement that, during highlighting, /// if there was no state changed reported for the beginning of line X, /// and there were no document changes between the start of line X and the start of line Y (with Y > X), /// then this event must not be raised for any line between X and Y (inclusive). /// /// Equal input state + unchanged line = Equal output state. /// /// See the comment in the HighlightingColorizer.OnHighlightStateChanged implementation /// for details about the requirements for a correct custom IHighlighter. /// /// Outside of the highlighting process, this event can be raised without such restrictions. /// event HighlightingStateChangedEventHandler HighlightingStateChanged; /// /// Opens a group of calls. /// It is not necessary to call this method before calling , /// however, doing so can make the highlighting much more performant in some cases /// (e.g. the C# semantic highlighter in SharpDevelop will re-use the resolver within a highlighting group). /// /// /// The group is closed by either a or a call. /// Nested groups are not allowed. /// void BeginHighlighting(); /// /// Closes the currently opened group of calls. /// /// . void EndHighlighting(); /// /// Retrieves the HighlightingColor with the specified name. Returns null if no color matching the name is found. /// HighlightingColor GetNamedColor(string name); /// /// Gets the default text color. /// HighlightingColor DefaultTextColor { get; } } /// /// Event handler for /// public delegate void HighlightingStateChangedEventHandler(int fromLineNumber, int toLineNumber); }