static void CheckStartPoint(IReadonlyTextDocument doc, InsertionPoint point, bool isEndPoint) { var line = doc.GetLine(point.Location.Line); if (line == null) { return; } if (doc.GetLineIndent(line).Length + 1 == point.Location.Column) { int lineNr = point.Location.Line; while (lineNr > 1 && doc.GetLineIndent(lineNr - 1).Length == doc.GetLine(lineNr - 1).Length) { lineNr--; } line = doc.GetLine(lineNr); point.Location = new DocumentLocation(lineNr, doc.GetLineIndent(line).Length + 1); } if (doc.GetLineIndent(line).Length + 1 < point.Location.Column) { point.LineBefore = NewLineInsertion.Eol; } if (point.Location.Column < line.Length + 1) { point.LineAfter = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine; } }
/// <inheritdoc /> public void Update(IReadonlyTextDocument sourceText, int lineNumber) { if (currentEngine.LineNumber == lineNumber) { //positions match, nothing to be done return; } else if (currentEngine.LineNumber > lineNumber) { //moving backwards, so reset from previous saved location ResetEngineToPosition(lineNumber); } // get the engine caught up int nextSave = (cachedEngines.Count == 0) ? cacheRate : cachedEngines.Peek().LineNumber + cacheRate; if (currentEngine.LineNumber + 1 == lineNumber) { var line = sourceText.GetLine(currentEngine.LineNumber + 1); currentEngine.Push(sourceText, line); if (currentEngine.LineNumber == nextSave) { cachedEngines.Push(currentEngine.Clone()); } } else { //bulk copy characters in case buffer is unmanaged //(faster if we reduce managed/unmanaged transitions) while (currentEngine.LineNumber < lineNumber) { var line = sourceText.GetLine(currentEngine.LineNumber + 1); if (line == null) { break; } int endCut = Math.Min(currentEngine.LineNumber + cacheRate, lineNumber); for (int i = currentEngine.LineNumber; line != null && i < endCut; i++) { currentEngine.Push(sourceText, line); if (currentEngine.LineNumber == nextSave) { cachedEngines.Push(currentEngine.Clone()); nextSave += cacheRate; } line = line.NextLine; } } } }
static InsertionPoint GetInsertionPosition(IReadonlyTextDocument doc, int line, int column) { int bodyEndOffset = doc.LocationToOffset(line, column) + 1; var curLine = doc.GetLine(line); if (curLine != null) { if (bodyEndOffset < curLine.Offset + curLine.Length) { // case1: positition is somewhere inside the start line return(new InsertionPoint(new DocumentLocation(line, column + 1), NewLineInsertion.Eol, NewLineInsertion.BlankLine)); } } // -> if position is at line end check next line var nextLine = doc.GetLine(line + 1); if (nextLine == null) // check for 1 line case. { return(new InsertionPoint(new DocumentLocation(line, column + 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine)); } for (int i = nextLine.Offset; i < nextLine.EndOffset; i++) { char ch = doc.GetCharAt(i); if (!char.IsWhiteSpace(ch)) { // case2: next line contains non ws chars. return(new InsertionPoint(new DocumentLocation(line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.BlankLine)); } } var nextLine2 = doc.GetLine(line + 2); if (nextLine2 != null) { for (int i = nextLine2.Offset; i < nextLine2.EndOffset; i++) { char ch = doc.GetCharAt(i); if (!char.IsWhiteSpace(ch)) { // case3: one blank line return(new InsertionPoint(new DocumentLocation(line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol)); } } } // case4: more than 1 blank line return(new InsertionPoint(new DocumentLocation(line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.None)); }
// public static void QueueQuickFixAnalysis (Document doc, TextLocation loc, CancellationToken token, Action<List<CodeAction>> callback) // { // var ext = doc.GetContent<MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> (); // var issues = ext != null ? ext.GetResultsAtOffset (doc.Editor.LocationToOffset (loc), token).OrderBy (r => r.Level).ToList () : new List<Result> (); // // ThreadPool.QueueUserWorkItem (delegate { // try { // var result = new List<CodeAction> (); // foreach (var r in issues) { // if (token.IsCancellationRequested) // return; // var fresult = r as FixableResult; // if (fresult == null) // continue; //// foreach (var action in FixOperationsHandler.GetActions (doc, fresult)) { //// result.Add (new AnalysisContextActionProvider.AnalysisCodeAction (action, r) { //// DocumentRegion = action.DocumentRegion //// }); //// } // } // result.AddRange (GetValidActions (doc, loc).Result); // callback (result); // } catch (Exception ex) { // LoggingService.LogError ("Error in analysis service", ex); // } // }); // } public static MonoDevelop.Ide.Editor.DocumentLocation GetCorrectResolveLocation(IReadonlyTextDocument editor, MonoDevelop.Ide.Editor.DocumentLocation location) { if (editor == null || location.Column == 1) { return(location); } /*if (editor is TextEditor) { * if (((TextEditor)editor).IsSomethingSelected) * return ((TextEditor)editor).SelectionRegion.Begin; * }*/ var line = editor.GetLine(location.Line); if (line == null || location.Column > line.LengthIncludingDelimiter) { return(location); } int offset = editor.LocationToOffset(location); if (offset > 0 && !char.IsLetterOrDigit(editor.GetCharAt(offset)) && char.IsLetterOrDigit(editor.GetCharAt(offset - 1))) { return(new MonoDevelop.Ide.Editor.DocumentLocation(location.Line, location.Column - 1)); } return(location); }
public static IEnumerable <IDocumentLine> GetLinesBetween(this IReadonlyTextDocument document, int startLine, int endLine) { if (document == null) { throw new ArgumentNullException("document"); } if (startLine < 1 || startLine > document.LineCount) { throw new ArgumentOutOfRangeException("startLine", startLine, string.Format("value should be between 1 and {0}", document.LineCount)); } if (endLine < 1 || endLine > document.LineCount) { throw new ArgumentOutOfRangeException("endLine", endLine, string.Format("value should be between 1 and {0}", document.LineCount)); } var curLine = document.GetLine(startLine); int count = endLine - startLine; while (curLine != null && count-- > 0) { yield return(curLine); curLine = curLine.NextLine; } }
public static string GetLineIndent(this IReadonlyTextDocument document, int lineNumber) { if (document == null) { throw new ArgumentNullException("document"); } return(document.GetLineIndent(document.GetLine(lineNumber))); }
static IEnumerable <IFoldSegment> GenerateFoldingsFromIndentationStack(IReadonlyTextDocument doc, CancellationToken token) { var foldings = new List <FoldSegment> (); var indentStack = new Stack <LineInfo> (); var line = doc.GetLine(1); indentStack.Push(new LineInfo(line, line.GetIndentation(doc).Length, 1)); int curLineNumber = 0; while ((line = line.NextLine) != null) { if (token.IsCancellationRequested) { return(Enumerable.Empty <IFoldSegment> ()); } var stackIndent = indentStack.Peek(); var curIndent = line.GetIndentation(doc); if (curIndent.Length == line.Length) { continue; } var curIndentLength = line.GetIndentation(doc).Length; curLineNumber++; if (stackIndent.indentLength < curIndentLength) { indentStack.Push(new LineInfo(line.PreviousLine, curIndentLength, curLineNumber)); } else { while (curIndent.Length < stackIndent.indentLength) { if (token.IsCancellationRequested) { return(Enumerable.Empty <IFoldSegment> ()); } indentStack.Pop(); if (curLineNumber - stackIndent.nonWsLineNumber >= 2) { foldings.Add(new FoldSegment(stackIndent.line.EndOffset, line.EndOffset - stackIndent.line.EndOffset)); } if (indentStack.Count == 0) { indentStack.Push(stackIndent); break; } stackIndent = indentStack.Peek(); } } } return(foldings); }
public static string GetLineText(this IReadonlyTextDocument document, int lineNumber, bool includeDelimiter = false) { if (document == null) { throw new ArgumentNullException("document"); } var line = document.GetLine(lineNumber); return(document.GetTextAt(includeDelimiter ? line.SegmentIncludingDelimiter : line)); }
static bool NeedsDocumentation(IReadonlyTextDocument data, ISymbol member) { int lineNr = data.OffsetToLineNumber(member.Locations.First().SourceSpan.Start) - 1; IDocumentLine line; do { line = data.GetLine(lineNr--); } while (lineNr > 0 && data.GetLineIndent(line).Length == line.Length); return(!data.GetTextAt(line).TrimStart().StartsWith("///", StringComparison.Ordinal)); }
void DrawTextLine(Cairo.Context g, IReadonlyTextDocument document, int lineNumber, ref int y) { using (var drawingLayout = new Pango.Layout(this.PangoContext)) { drawingLayout.FontDescription = fontDescription; var line = document.GetLine(lineNumber); var correctedIndentLength = CorrectIndent(document, line, indentLength); drawingLayout.SetText(document.GetTextAt(line.Offset + Math.Min(correctedIndentLength, line.Length), Math.Max(0, line.Length - correctedIndentLength))); g.Save(); g.Translate(textBorder, y); g.ShowLayout(drawingLayout); g.Restore(); y += lineHeight; } }
public static IEnumerable <IDocumentLine> GetLinesReverseStartingAt(this IReadonlyTextDocument document, int startLine) { if (startLine < 1 || startLine > document.LineCount) { throw new ArgumentOutOfRangeException("startLine", startLine, string.Format("value should be between 1 and {0}", document.LineCount)); } var curLine = document.GetLine(startLine); while (curLine != null) { yield return(curLine); curLine = curLine.PreviousLine; } }
static void CheckEndPoint(IReadonlyTextDocument doc, InsertionPoint point, bool isStartPoint) { var line = doc.GetLine(point.Location.Line); if (line == null) { return; } if (doc.GetLineIndent(line).Length + 1 < point.Location.Column) { point.LineBefore = NewLineInsertion.BlankLine; } if (point.Location.Column < line.Length + 1) { point.LineAfter = NewLineInsertion.Eol; } }
public static string GetEolMarker(this IReadonlyTextDocument document) { if (document == null) { throw new ArgumentNullException("document"); } string eol = null; if (document.LineCount > 0) { var line = document.GetLine(1); if (line.DelimiterLength > 0) { eol = document.GetTextAt(line.Length, line.DelimiterLength); } } return(!string.IsNullOrEmpty(eol) ? eol : DefaultSourceEditorOptions.Instance.DefaultEolMarker); }
void MeasureLine(IReadonlyTextDocument document, int lineNumber, ref int x, ref int y) { using (var drawingLayout = new Pango.Layout(this.PangoContext)) { drawingLayout.FontDescription = fontDescription; var line = document.GetLine(lineNumber); var indent = line.GetIndentation(document); var curLineIndent = CalcIndentLength(indent); if (line.Length == curLineIndent) { y += lineHeight; return; } if (this.indentLength < 0 || this.indentLength > curLineIndent) { this.indentLength = curLineIndent; } drawingLayout.SetText(document.GetTextAt(line)); int w, h; drawingLayout.GetPixelSize(out w, out h); x = Math.Max(x, w); y += lineHeight; } }
static bool IsBlankLine(IReadonlyTextDocument doc, int i) { var line = doc.GetLine(i); return(line.Length == line.GetIndentation(doc).Length); }
static bool NeedsDocumentation (IReadonlyTextDocument data, ISymbol member) { int lineNr = data.OffsetToLineNumber (member.Locations.First().SourceSpan.Start) - 1; IDocumentLine line; do { line = data.GetLine (lineNr--); } while (lineNr > 0 && data.GetLineIndent (line).Length == line.Length); return !data.GetTextAt (line).TrimStart ().StartsWith ("///", StringComparison.Ordinal); }
// public static void QueueQuickFixAnalysis (Document doc, TextLocation loc, CancellationToken token, Action<List<CodeAction>> callback) // { // var ext = doc.GetContent<MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> (); // var issues = ext != null ? ext.GetResultsAtOffset (doc.Editor.LocationToOffset (loc), token).OrderBy (r => r.Level).ToList () : new List<Result> (); // // ThreadPool.QueueUserWorkItem (delegate { // try { // var result = new List<CodeAction> (); // foreach (var r in issues) { // if (token.IsCancellationRequested) // return; // var fresult = r as FixableResult; // if (fresult == null) // continue; //// foreach (var action in FixOperationsHandler.GetActions (doc, fresult)) { //// result.Add (new AnalysisContextActionProvider.AnalysisCodeAction (action, r) { //// DocumentRegion = action.DocumentRegion //// }); //// } // } // result.AddRange (GetValidActions (doc, loc).Result); // callback (result); // } catch (Exception ex) { // LoggingService.LogError ("Error in analysis service", ex); // } // }); // } public static MonoDevelop.Ide.Editor.DocumentLocation GetCorrectResolveLocation (IReadonlyTextDocument editor, MonoDevelop.Ide.Editor.DocumentLocation location) { if (editor == null || location.Column == 1) return location; /*if (editor is TextEditor) { if (((TextEditor)editor).IsSomethingSelected) return ((TextEditor)editor).SelectionRegion.Begin; }*/ var line = editor.GetLine (location.Line); if (line == null || location.Column > line.LengthIncludingDelimiter) return location; int offset = editor.LocationToOffset (location); if (offset > 0 && !char.IsLetterOrDigit (editor.GetCharAt (offset)) && char.IsLetterOrDigit (editor.GetCharAt (offset - 1))) return new MonoDevelop.Ide.Editor.DocumentLocation (location.Line, location.Column - 1); return location; }
static InsertionPoint GetInsertionPosition (IReadonlyTextDocument doc, int line, int column) { int bodyEndOffset = doc.LocationToOffset (line, column) + 1; var curLine = doc.GetLine (line); if (curLine != null) { if (bodyEndOffset < curLine.Offset + curLine.Length) { // case1: positition is somewhere inside the start line return new InsertionPoint (new DocumentLocation (line, column + 1), NewLineInsertion.Eol, NewLineInsertion.BlankLine); } } // -> if position is at line end check next line var nextLine = doc.GetLine (line + 1); if (nextLine == null) // check for 1 line case. return new InsertionPoint (new DocumentLocation (line, column + 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine); for (int i = nextLine.Offset; i < nextLine.EndOffset; i++) { char ch = doc.GetCharAt (i); if (!char.IsWhiteSpace (ch)) { // case2: next line contains non ws chars. return new InsertionPoint (new DocumentLocation (line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.BlankLine); } } var nextLine2 = doc.GetLine (line + 2); if (nextLine2 != null) { for (int i = nextLine2.Offset; i < nextLine2.EndOffset; i++) { char ch = doc.GetCharAt (i); if (!char.IsWhiteSpace (ch)) { // case3: one blank line return new InsertionPoint (new DocumentLocation (line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.Eol); } } } // case4: more than 1 blank line return new InsertionPoint (new DocumentLocation (line + 1, 1), NewLineInsertion.Eol, NewLineInsertion.None); }
static bool IsBlankLine (IReadonlyTextDocument doc, int i) { var line = doc.GetLine (i); return line.Length == line.GetIndentation (doc).Length; }
public override TextLine this [int index] { get { var line = textDoc.GetLine(index + 1); return(TextLine.FromSpan(parent, new TextSpan(line.Offset, line.Length))); } }
void DrawTextLine (Cairo.Context g, IReadonlyTextDocument document, int lineNumber, ref int y) { using (var drawingLayout = new Pango.Layout (this.PangoContext)) { drawingLayout.FontDescription = fontDescription; var line = document.GetLine (lineNumber); var correctedIndentLength = CorrectIndent (document, line, indentLength); drawingLayout.SetText (document.GetTextAt (line.Offset + Math.Min (correctedIndentLength, line.Length), Math.Max (0, line.Length - correctedIndentLength))); g.Save (); g.Translate (textBorder, y); g.ShowLayout (drawingLayout); g.Restore (); y += lineHeight; } }
static void CheckEndPoint (IReadonlyTextDocument doc, InsertionPoint point, bool isStartPoint) { var line = doc.GetLine (point.Location.Line); if (line == null) return; if (doc.GetLineIndent (line).Length + 1 < point.Location.Column) point.LineBefore = NewLineInsertion.BlankLine; if (point.Location.Column < line.Length + 1) point.LineAfter = NewLineInsertion.Eol; }
void MeasureLine (IReadonlyTextDocument document, int lineNumber, ref int x, ref int y) { using (var drawingLayout = new Pango.Layout (this.PangoContext)) { drawingLayout.FontDescription = fontDescription; var line = document.GetLine (lineNumber); var indent = line.GetIndentation (document); var curLineIndent = CalcIndentLength(indent); if (line.Length == curLineIndent) { y += lineHeight; return; } if (this.indentLength < 0 || this.indentLength > curLineIndent) this.indentLength = curLineIndent; drawingLayout.SetText (document.GetTextAt (line)); int w, h; drawingLayout.GetPixelSize (out w, out h); x = Math.Max (x, w); y += lineHeight; } }
static void CheckStartPoint (IReadonlyTextDocument doc, InsertionPoint point, bool isEndPoint) { var line = doc.GetLine (point.Location.Line); if (line == null) return; if (doc.GetLineIndent (line).Length + 1 == point.Location.Column) { int lineNr = point.Location.Line; while (lineNr > 1 && doc.GetLineIndent (lineNr - 1).Length == doc.GetLine (lineNr - 1).Length) { lineNr--; } line = doc.GetLine (lineNr); point.Location = new DocumentLocation (lineNr, doc.GetLineIndent (line).Length + 1); } if (doc.GetLineIndent (line).Length + 1 < point.Location.Column) point.LineBefore = NewLineInsertion.Eol; if (point.Location.Column < line.Length + 1) point.LineAfter = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine; }