public void TestBug682466() { Document document = new Mono.TextEditor.Document(); document.Text = @"0 1 2 +[3 4 5 6] 7 8 9 10"; var segments = GetFoldSegments(document); document.UpdateFoldSegments(segments, false); Assert.AreEqual(true, document.FoldSegments.FirstOrDefault().IsFolded); segments = GetFoldSegments(document); segments[0].IsFolded = false; document.UpdateFoldSegments(segments, false); Assert.AreEqual(5, document.LogicalToVisualLine(8)); }
public void TestGetStartFoldingsGetStartFoldings() { Document document = new Mono.TextEditor.Document(); document.Text = @"+[1 2 3 +[4 5 +[6 7] 8] +[9 10 11] 12] +[13 14] 15 16"; var segments = GetFoldSegments(document); document.UpdateFoldSegments(segments, false); document.UpdateFoldSegments(segments, false); document.UpdateFoldSegments(segments, false); Assert.AreEqual(1, document.GetStartFoldings(1).Count()); Assert.AreEqual(1, document.GetStartFoldings(4).Count()); Assert.AreEqual(1, document.GetStartFoldings(6).Count()); Assert.AreEqual(1, document.GetStartFoldings(9).Count()); Assert.AreEqual(1, document.GetStartFoldings(13).Count()); }
public void TestLogicalToVisualLine() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[1 +[2 3 ]4 5 +[6 +[7 +[8 9 ]10 ]11 ]12 ]13 14 +[15 16 ]17 18"; document.UpdateFoldSegments(GetFoldSegments(document), false); Assert.AreEqual(4, document.LogicalToVisualLine(12)); Assert.AreEqual(6, document.LogicalToVisualLine(16)); Assert.AreEqual(7, document.LogicalToVisualLine(17)); }
public void TestDocumentRemove() { Document document = new Mono.TextEditor.Document(); string top = "1234567890\n"; string testText = "12345678\n" + "1234567\n" + "123456\n" + "12345\n" + "1234\n" + "123\n" + "12\n" + "1\n" + "\n"; document.Text = top + testText; ((IBuffer)document).Remove(0, top.Length); Assert.AreEqual(document.Text, testText); ((IBuffer)document).Remove(0, document.Length); LineSegment line = document.GetLine(0); Assert.AreEqual(0, line.Offset); Assert.AreEqual(0, line.Length); Assert.AreEqual(0, document.Length); Assert.AreEqual(1, document.LineCount); }
public void TestDocumentRemove () { Document document = new Mono.TextEditor.Document (); string top = "1234567890\n"; string testText = "12345678\n" + "1234567\n" + "123456\n" + "12345\n" + "1234\n" + "123\n" + "12\n" + "1\n" + "\n"; document.Text = top + testText; ((IBuffer)document).Remove (0, top.Length); Assert.AreEqual (document.Text, testText); ((IBuffer)document).Remove (0, document.Length); LineSegment line = document.GetLine (0); Assert.AreEqual (0, line.Offset); Assert.AreEqual (0, line.Length); Assert.AreEqual (0, document.Length); Assert.AreEqual (1, document.LineCount); }
public void TestIsFoldedUnsetFolded() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[1 2 3 +[4 5 +[6 7] 8] -[9 10 11] 12] -[13 14] 15 16"; var segments = GetFoldSegments(document); document.UpdateFoldSegments(segments, false); Assert.AreEqual(11, document.LogicalToVisualLine(15)); document.GetStartFoldings(6).First().IsFolded = false; document.GetStartFoldings(4).First().IsFolded = false; Assert.AreEqual(15, document.LogicalToVisualLine(15)); }
public FindMemberAstVisitor(NRefactoryResolver resolver, IEditableTextFile file, MonoDevelop.Projects.Dom.INode searchedMember) { fileName = file.Name; text = new Mono.TextEditor.Document(); text.Text = file.Text; Init(resolver, searchedMember); }
public void TestVisualToLogicalLine () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[0 +[1 2 ]3 4 +[5 +[6 +[7 8 ]9 ]10 ]11 ]12 13 +[14 15 ]16 17"; document.UpdateFoldSegments (GetFoldSegments (document), false); Assert.AreEqual (4, document.LogicalToVisualLine (12)); Assert.AreEqual (6, document.LogicalToVisualLine (16)); Assert.AreEqual (7, document.LogicalToVisualLine (17)); }
public void TestVisualToLogicalLineStartLine() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[1 -[2 3 ]4 5 -[6 +[7 -[8 9 ]10 ]11 ]12 ]13 14 -[15 16 ]17 18"; document.UpdateFoldSegments(GetFoldSegments(document), false); Assert.AreEqual(7, document.VisualToLogicalLine(7)); }
public void TestVisualToLogicalLineCase2() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[1 +[2 3 ]4 5 +[6 +[7 +[8 9 ]10 ]11 ]12 ]13 14 +[15 16 ]17 18"; document.UpdateFoldSegments(GetFoldSegments(document), false); Assert.AreEqual(6, document.VisualToLogicalLine(4)); Assert.AreEqual(14, document.VisualToLogicalLine(6)); Assert.AreEqual(15, document.VisualToLogicalLine(7)); }
public void TestVisualToLogicalLine() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[0 +[1 2 ]3 4 +[5 +[6 +[7 8 ]9 ]10 ]11 ]12 13 +[14 15 ]16 17"; document.UpdateFoldSegments(GetFoldSegments(document)); do { Gtk.Application.RunIteration(); } while (!document.HasFoldSegments); Assert.AreEqual(4, document.LogicalToVisualLine(12)); Assert.AreEqual(6, document.LogicalToVisualLine(16)); Assert.AreEqual(7, document.LogicalToVisualLine(17)); }
public void TestUpdateFoldSegmentBug2() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[0 1 +[2 3] 4 +[5 6] 7 8 9 10 11 12 13] 14 15"; var segments = GetFoldSegments(document); document.UpdateFoldSegments(segments, false); Assert.AreEqual(10, document.VisualToLogicalLine(8)); int start = document.GetLine(2).Offset; int end = document.GetLine(8).Offset; ((IBuffer)document).Remove(start, end - start); Assert.AreEqual(10, document.LogicalToVisualLine(10)); }
public void TestVisualToLogicalLine () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[0 +[1 2 ]3 4 +[5 +[6 +[7 8 ]9 ]10 ]11 ]12 13 +[14 15 ]16 17"; document.UpdateFoldSegments (GetFoldSegments (document)); do { Gtk.Application.RunIteration (); } while (!document.HasFoldSegments); Assert.AreEqual (4, document.LogicalToVisualLine (12)); Assert.AreEqual (6, document.LogicalToVisualLine (16)); Assert.AreEqual (7, document.LogicalToVisualLine (17)); }
static void CheckLine(Mono.TextEditor.Document doc, Mono.TextEditor.LineSegment line, out bool isBlank, out bool isBracket) { isBlank = true; isBracket = false; if (line == null) { return; } for (int i = 0; i < line.Length; i++) { char c = doc.GetCharAt(line.Offset + i); if (c == '{') { isBracket = true; isBlank = false; } else if (!Char.IsWhiteSpace(c)) { isBlank = false; if (isBracket) { isBracket = false; break; } } } }
public void TestLogicalToVisualLine () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[1 +[2 3 ]4 5 +[6 +[7 +[8 9 ]10 ]11 ]12 ]13 14 +[15 16 ]17 18"; document.UpdateFoldSegments (GetFoldSegments (document), false); Assert.AreEqual (4, document.LogicalToVisualLine (12)); Assert.AreEqual (6, document.LogicalToVisualLine (16)); Assert.AreEqual (7, document.LogicalToVisualLine (17)); }
public void TestVisualToLogicalLine() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[0 +[1 2 ]3 4 +[5 +[6 +[7 8 ]9 ]10 ]11 ]12 13 +[14 15 ]16 17"; document.UpdateFoldSegments(GetFoldSegments(document), false); Assert.AreEqual(4, document.LogicalToVisualLine(12)); Assert.AreEqual(6, document.LogicalToVisualLine(16)); Assert.AreEqual(7, document.LogicalToVisualLine(17)); }
public void TestUpdateFoldSegmentBug2() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[1 2 +[3 4] 5 +[6 7] 8 9 10 11 12 13 14] 15 16"; var segments = GetFoldSegments(document); document.UpdateFoldSegments(segments, false); Assert.AreEqual(10, document.VisualToLogicalLine(8)); Assert.AreEqual(3, document.FoldSegments.Count()); int start = document.GetLine(2).Offset; int end = document.GetLine(8).Offset; ((IBuffer)document).Remove(start, end - start); Assert.AreEqual(1, document.FoldSegments.Count()); Assert.AreEqual(10, document.LogicalToVisualLine(10)); }
// Returns a stream with the content of the file. // project and language parameters are optional public virtual Stream CreateFileContent(SolutionItem policyParent, Project project, string language, string fileName, string identifier) { Dictionary <string, string> tags = new Dictionary <string, string> (); ModifyTags(policyParent, project, language, identifier, fileName, ref tags); string content = CreateContent(project, tags, language); content = StringParserService.Parse(content, tags); string mime = DesktopService.GetMimeTypeForUri(fileName); CodeFormatter formatter = !string.IsNullOrEmpty(mime) ? CodeFormatterService.GetFormatter(mime) : null; if (formatter != null) { var formatted = formatter.FormatText(policyParent != null ? policyParent.Policies : null, content); if (formatted != null) { content = formatted; } } MemoryStream ms = new MemoryStream(); byte[] data; if (AddStandardHeader) { string header = StandardHeaderService.GetHeader(policyParent, fileName, true); data = System.Text.Encoding.UTF8.GetBytes(header); ms.Write(data, 0, data.Length); } Mono.TextEditor.Document doc = new Mono.TextEditor.Document(); doc.Text = content; TextStylePolicy textPolicy = policyParent != null?policyParent.Policies.Get <TextStylePolicy> ("text/plain") : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <TextStylePolicy> ("text/plain"); string eolMarker = TextStylePolicy.GetEolMarker(textPolicy.EolMarker); byte[] eolMarkerBytes = System.Text.Encoding.UTF8.GetBytes(eolMarker); var tabToSpaces = textPolicy.TabsToSpaces? new string (' ', textPolicy.TabWidth) : null; foreach (Mono.TextEditor.LineSegment line in doc.Lines) { var lineText = doc.GetTextAt(line.Offset, line.EditableLength); if (tabToSpaces != null) { lineText = lineText.Replace("\t", tabToSpaces); } data = System.Text.Encoding.UTF8.GetBytes(lineText); ms.Write(data, 0, data.Length); ms.Write(eolMarkerBytes, 0, eolMarkerBytes.Length); } ms.Position = 0; return(ms); }
public FindMemberAstVisitor(Mono.TextEditor.Document document, MonoDevelop.Projects.Dom.INode searchedMember = null) { fileName = document.FileName; this.text = document; if (searchedMember != null) { Init(searchedMember); } }
static bool IsBlankLine(Mono.TextEditor.Document doc, Mono.TextEditor.LineSegment line) { for (int i = 0; i < line.EditableLength; i++) { if (!Char.IsWhiteSpace(doc.GetCharAt(line.Offset + i))) { return(false); } } return(true); }
public void TestUpdateFoldSegmentBug() { Document document = new Mono.TextEditor.Document(); document.Text = @"-[0 1 +[2 3 4 5 6 7 8 9 10] 11 ]12 13 +[14 15 16 17 18 19 20 21 22] 23 24 25 26"; var segments = GetFoldSegments(document); document.UpdateFoldSegments(segments, false); Assert.AreEqual(25, document.VisualToLogicalLine(9)); Assert.AreEqual(3, document.FoldSegments.Count()); segments.RemoveAt(1); document.UpdateFoldSegments(segments, false); Assert.AreEqual(2, document.FoldSegments.Count()); Assert.AreEqual(17, document.LogicalToVisualLine(25)); segments.RemoveAt(1); document.UpdateFoldSegments(segments, false); Assert.AreEqual(1, document.FoldSegments.Count()); Assert.AreEqual(25, document.LogicalToVisualLine(25)); }
internal static string CreateWrapperClassForMember(IMember member, string fileName, TextEditor editor) { if (member == null) { return(""); } StringBuilder result = new StringBuilder(); int startLine = member.Location.Line; int endLine = member.Location.Line; if (!member.BodyRegion.IsEmpty) { endLine = member.BodyRegion.End.Line + 1; } string text; result.Append("class " + member.DeclaringType.Name + " {"); if (editor != null) { int col, maxLine; editor.GetLineColumnFromPosition(editor.TextLength - 1, out col, out maxLine); endLine = System.Math.Max(endLine, maxLine); int endPos = editor.GetPositionFromLineColumn(endLine, editor.GetLineLength(endLine)); if (endPos < 0) { endPos = editor.TextLength; } int startPos = Math.Max(0, editor.GetPositionFromLineColumn(startLine, 0)); text = editor.GetText(startPos, endPos); } else { Mono.TextEditor.Document doc = new Mono.TextEditor.Document(); doc.Text = File.ReadAllText(fileName) ?? ""; startLine = Math.Min(doc.LineCount, Math.Max(1, startLine)); endLine = Math.Min(doc.LineCount, Math.Max(1, endLine)); int startOffset = doc.LocationToOffset(startLine - 1, 0); text = doc.GetTextAt(startOffset, doc.LocationToOffset(endLine - 1, doc.GetLine(endLine - 1).EditableLength) - startOffset); } if (!string.IsNullOrEmpty(text)) { result.Append(text); } result.Append("}"); return(result.ToString()); }
public static RemoveInfo GetRemoveInfo(Mono.TextEditor.Document document, ref int pos) { int len = 0; while (pos > 0 && IsWhiteSpace(document.GetCharAt(pos))) { --pos; ++len; } if (len > 0) { pos++; return(new RemoveInfo(pos, len)); } return(Empty); }
public static void InformAutoSaveThread(Mono.TextEditor.Document content) { if (content == null) { return; } if (content.IsDirty) { queue.Enqueue(new FileContent(content.FileName, content)); resetEvent.Set(); } else { RemoveAutoSaveFile(content.FileName); } }
public void TestDocumentBug2Test() { Document document = new Mono.TextEditor.Document(); string top = "123\n456\n789\n0"; string testText = "Hello World!"; document.Text = top; ((IBuffer)document).Insert(top.Length, testText); LineSegment line = document.GetLine(document.LineCount - 1); Assert.AreEqual(top.Length - 1, line.Offset); Assert.AreEqual(testText.Length + 1, line.Length); }
static string StripHeaderAndBlankLines(string text, CodeDomProvider provider) { Mono.TextEditor.Document doc = new Mono.TextEditor.Document(); doc.Text = text; int realStartLine = 0; for (int i = 0; i < doc.LineCount; i++) { var lineSegment = doc.GetLine(i); if (lineSegment == null) { continue; } string lineText = doc.GetTextAt(lineSegment); // Microsoft.NET generates "auto-generated" tags where Mono generates "autogenerated" tags. if (lineText.Contains("</autofgenerated>") || lineText.Contains("</auto-generated>")) { realStartLine = i + 2; break; } } // The Mono provider inserts additional blank lines, so strip them out // But blank lines might actually be significant in other languages. // We reformat the C# generated output to the user's coding style anyway, but the reformatter preserves blank lines if (provider is Microsoft.CSharp.CSharpCodeProvider) { bool previousWasBlank = false; for (int i = 0; i < doc.LineCount; i++) { Mono.TextEditor.LineSegment line = doc.GetLine(i); bool isBlank, isBracket; CheckLine(doc, line, out isBlank, out isBracket); if (isBlank && previousWasBlank && line.Length > 0) { ((Mono.TextEditor.IBuffer)doc).Remove(line.Offset, line.Length); i--; } previousWasBlank = isBlank || isBracket; } } int offset = doc.GetLine(realStartLine).Offset; return(doc.GetTextAt(offset, doc.Length - offset)); }
public void InformAutoSaveThread(Mono.TextEditor.Document content) { if (FileName == null || content == null) { return; } if (!autoSaveThreadRunning) { StartAutoSaveThread(); } IsDirty = true; lock (contentLock) { fileChanged = true; this.content = new FileContent(FileName, content); resetEvent.Set(); } }
public void TestDocumentBug1Test() { Document document = new Mono.TextEditor.Document(); string top = "1234567890"; document.Text = top; Assert.AreEqual(document.GetLine(0).Length, document.Length); ((IBuffer)document).Remove(0, document.Length); LineSegment line = document.GetLine(0); Assert.AreEqual(0, line.Offset); Assert.AreEqual(0, line.Length); Assert.AreEqual(0, document.Length); Assert.AreEqual(1, document.LineCount); }
public override Annotation[] GetAnnotations(FilePath localPath) { List <Annotation> annotations = new List <Annotation> (Svn.GetAnnotations(this, localPath, SvnRevision.First, SvnRevision.Base)); Annotation nextRev = new Annotation(GettextCatalog.GetString("working copy"), "", DateTime.MinValue); var baseDocument = new Mono.TextEditor.Document(File.ReadAllText(GetPathToBaseText(localPath))); var workingDocument = new Mono.TextEditor.Document(File.ReadAllText(localPath)); // "SubversionException: blame of the WORKING revision is not supported" foreach (var hunk in baseDocument.Diff(workingDocument)) { annotations.RemoveRange(hunk.InsertStart, hunk.Inserted); for (int i = 0; i < hunk.Inserted; ++i) { annotations.Insert(hunk.InsertStart, nextRev); } } return(annotations.ToArray()); }
public override IEnumerable<MemberReference> FindReferences (ProjectDom dom, FilePath fileName, INode member) { var editor = TextFileProvider.Instance.GetTextEditorData (fileName); AspNetAppProject project = dom.Project as AspNetAppProject; System.Console.WriteLine ("project:" + project); if (project == null) yield break; var unit = AspNetParserService.GetCompileUnit (project, fileName, true); System.Console.WriteLine ("unit:" + unit); if (unit == null) yield break; System.Console.WriteLine ("go "); var refman = new DocumentReferenceManager (project); var parsedAspDocument = (AspNetParsedDocument)new AspNetParser ().Parse (dom, fileName, editor.Text); refman.Doc = parsedAspDocument; var usings = refman.GetUsings (); var documentInfo = new DocumentInfo (unit, usings, refman.GetDoms ()); var builder = new AspLanguageBuilder (); var buildDocument = new Mono.TextEditor.Document (); var offsetInfos = new List<LocalDocumentInfo.OffsetInfo> (); buildDocument.Text = builder.BuildDocumentString (documentInfo, editor, offsetInfos, true); var parsedDocument = AspLanguageBuilder.Parse (fileName, buildDocument.Text); var resolver = new NRefactoryResolver (dom, parsedDocument.CompilationUnit, ICSharpCode.NRefactory.SupportedLanguage.CSharp, editor, fileName); FindMemberAstVisitor visitor = new FindMemberAstVisitor (buildDocument, resolver, member); visitor.IncludeXmlDocumentation = IncludeDocumentation; visitor.RunVisitor (); foreach (var result in visitor.FoundReferences) { var offsetInfo = offsetInfos.FirstOrDefault (info => info.ToOffset <= result.Position && result.Position < info.ToOffset + info.Length); if (offsetInfo == null) continue; var offset = offsetInfo.FromOffset + result.Position - offsetInfo.ToOffset; var loc = editor.OffsetToLocation (offset); yield return new MemberReference (null, fileName, offset, loc.Line, loc.Column, result.Name, null); } }
public override IEnumerable <MemberReference> FindReferences(ProjectDom dom, FilePath fileName, IEnumerable <INode> searchedMembers) { var editor = TextFileProvider.Instance.GetTextEditorData(fileName); AspNetAppProject project = dom.Project as AspNetAppProject; if (project == null) { yield break; } var unit = AspNetParserService.GetCompileUnit(project, fileName, true); if (unit == null) { yield break; } var refman = new DocumentReferenceManager(project); var parsedAspDocument = (AspNetParsedDocument) new AspNetParser().Parse(dom, fileName, editor.Text); refman.Doc = parsedAspDocument; var usings = refman.GetUsings(); var documentInfo = new DocumentInfo(dom, unit, usings, refman.GetDoms()); var builder = new AspLanguageBuilder(); var buildDocument = new Mono.TextEditor.Document(); var offsetInfos = new List <LocalDocumentInfo.OffsetInfo> (); buildDocument.Text = builder.BuildDocumentString(documentInfo, editor, offsetInfos, true); var parsedDocument = AspLanguageBuilder.Parse(dom, fileName, buildDocument.Text); foreach (var member in searchedMembers) { foreach (var reference in SearchMember(member, dom, fileName, editor, buildDocument, offsetInfos, parsedDocument)) { yield return(reference); } } }
public void TestDocumentInsert() { Document document = new Mono.TextEditor.Document(); string top = "1234567890\n"; string text = "12345678\n" + "1234567\n" + "123456\n" + "12345\n" + "1234\n" + "123\n" + "12\n" + "1\n" + "\n"; document.Text = top; ((IBuffer)document).Insert(top.Length, text); Assert.AreEqual(top + text, document.Text); }
public void TestDocumentCreation () { Document document = new Mono.TextEditor.Document (); string text = "1234567890\n" + "12345678\n" + "1234567\n" + "123456\n" + "12345\n" + "1234\n" + "123\n" + "12\n" + "1\n" + "\n"; document.Text = text; Assert.AreEqual (text, document.Text); Assert.AreEqual (11, document.LineCount); }
public void TestDocumentInsert () { Document document = new Mono.TextEditor.Document (); string top = "1234567890\n"; string text = "12345678\n" + "1234567\n" + "123456\n" + "12345\n" + "1234\n" + "123\n" + "12\n" + "1\n" + "\n"; document.Text = top; ((IBuffer)document).Insert (top.Length, text); Assert.AreEqual (top + text, document.Text); }
public void TestDocumentCreation() { Document document = new Mono.TextEditor.Document(); string text = "1234567890\n" + "12345678\n" + "1234567\n" + "123456\n" + "12345\n" + "1234\n" + "123\n" + "12\n" + "1\n" + "\n"; document.Text = text; Assert.AreEqual(text, document.Text); Assert.AreEqual(11, document.LineCount); }
public void SplitterTest() { Document document = new Mono.TextEditor.Document(); for (int i = 0; i < 100; i++) { ((IBuffer)document).Insert(0, new string ('c', i) + Environment.NewLine); } Assert.AreEqual(101, document.LineCount); for (int i = 0; i < 100; i++) { LineSegment line = document.GetLine(i); Assert.AreEqual(99 - i, line.EditableLength); Assert.AreEqual(Environment.NewLine.Length, line.DelimiterLength); } for (int i = 0; i < 100; i++) { LineSegment line = document.GetLine(0); ((IBuffer)document).Remove(line.EditableLength, line.DelimiterLength); } Assert.AreEqual(1, document.LineCount); }
public override IEnumerable<MemberReference> FindReferences (ProjectDom dom, FilePath fileName, IEnumerable<INode> searchedMembers) { var editor = TextFileProvider.Instance.GetTextEditorData (fileName); AspNetAppProject project = dom.Project as AspNetAppProject; if (project == null) yield break; var unit = AspNetParserService.GetCompileUnit (project, fileName, true); if (unit == null) yield break; var refman = new DocumentReferenceManager (project); var parsedAspDocument = (AspNetParsedDocument)new AspNetParser ().Parse (dom, fileName, editor.Text); refman.Doc = parsedAspDocument; var usings = refman.GetUsings (); var documentInfo = new DocumentInfo (dom, unit, usings, refman.GetDoms ()); var builder = new AspLanguageBuilder (); var buildDocument = new Mono.TextEditor.Document (); var offsetInfos = new List<LocalDocumentInfo.OffsetInfo> (); buildDocument.Text = builder.BuildDocumentString (documentInfo, editor, offsetInfos, true); var parsedDocument = AspLanguageBuilder.Parse (dom, fileName, buildDocument.Text); foreach (var member in searchedMembers) { foreach (var reference in SearchMember (member, dom, fileName, editor, buildDocument, offsetInfos, parsedDocument)) { yield return reference; } } }
public void TestUpdateFoldSegmentBug2 () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[1 2 +[3 4] 5 +[6 7] 8 9 10 11 12 13 14] 15 16"; var segments = GetFoldSegments (document); document.UpdateFoldSegments (segments, false); Assert.AreEqual (10, document.VisualToLogicalLine (8)); Assert.AreEqual (3, document.FoldSegments.Count ()); int start = document.GetLine (2).Offset; int end = document.GetLine (8).Offset; ((IBuffer)document).Remove (start, end - start); Assert.AreEqual (1, document.FoldSegments.Count ()); Assert.AreEqual (10, document.LogicalToVisualLine (10)); }
public void GoToDeclaration () { if (item is CompoundType) { CompoundType compoundType = (CompoundType)item; monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true); using (monitor) { foreach (IType part in compoundType.Parts) { FileProvider provider = new FileProvider (part.CompilationUnit.FileName); Mono.TextEditor.Document doc = new Mono.TextEditor.Document (); System.IO.TextReader textReader = provider.Open (); doc.Text = textReader.ReadToEnd (); textReader.Close (); int position = doc.LocationToOffset (part.Location.Line, part.Location.Column); while (position + part.Name.Length < doc.Length) { if (doc.GetTextAt (position, part.Name.Length) == part.Name) break; position++; } monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult (provider, position, part.Name.Length)); } } return; } IdeApp.ProjectOperations.JumpToDeclaration (item); }
public void TestUpdateFoldSegmentBug2 () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[0 1 +[2 3] 4 +[5 6] 7 8 9 10 11 12 13] 14 15"; var segments = GetFoldSegments (document); document.UpdateFoldSegments (segments, false); Assert.AreEqual (10, document.VisualToLogicalLine (8)); int start = document.GetLine (2).Offset; int end = document.GetLine (8).Offset; ((IBuffer)document).Remove (start, end - start); Assert.AreEqual (10, document.LogicalToVisualLine (10)); }
public void TestUpdateFoldSegmentBug () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[0 1 +[2 3 4 5 6 7 8 9 10] 11 ]12 13 +[14 15 16 17 18 19 20 21 22] 23 24 25 26"; var segments = GetFoldSegments (document); document.UpdateFoldSegments (segments, false); Assert.AreEqual (25, document.VisualToLogicalLine (9)); segments.RemoveAt (1); document.UpdateFoldSegments (segments, false); Assert.AreEqual (17, document.LogicalToVisualLine (25)); segments.RemoveAt (1); document.UpdateFoldSegments (segments, false); Assert.AreEqual (25, document.LogicalToVisualLine (25)); }
public void TestDocumentBug2Test() { Document document = new Mono.TextEditor.Document (); string top = "123\n456\n789\n0"; string testText = "Hello World!"; document.Text = top; ((IBuffer)document).Insert (top.Length, testText); LineSegment line = document.GetLine (document.LineCount - 1); Assert.AreEqual (top.Length - 1, line.Offset); Assert.AreEqual (testText.Length + 1, line.Length); }
public void SplitterTest () { Document document = new Mono.TextEditor.Document (); for (int i = 0; i < 100; i++) { ((IBuffer)document).Insert (0, new string ('c', i) + Environment.NewLine); } Assert.AreEqual (101, document.LineCount); for (int i = 0; i < 100; i++) { LineSegment line = document.GetLine (i); Assert.AreEqual (99 - i, line.EditableLength); Assert.AreEqual (Environment.NewLine.Length, line.DelimiterLength); } for (int i = 0; i < 100; i++) { LineSegment line = document.GetLine (0); ((IBuffer)document).Remove (line.EditableLength, line.DelimiterLength); } Assert.AreEqual (1, document.LineCount); }
internal static string CreateWrapperClassForMember(IMember member, string fileName, TextEditor editor) { if (member == null) return ""; StringBuilder result = new StringBuilder (); int startLine = member.Location.Line; int endLine = member.Location.Line; if (!member.BodyRegion.IsEmpty) endLine = member.BodyRegion.End.Line + 1; string text; result.Append ("class " + member.DeclaringType.Name + " {"); if (editor != null) { int col, maxLine; editor.GetLineColumnFromPosition (editor.TextLength - 1, out col, out maxLine); endLine = System.Math.Max (endLine, maxLine); int endPos = editor.GetPositionFromLineColumn (endLine, editor.GetLineLength (endLine)); if (endPos < 0) endPos = editor.TextLength; text = editor.GetText (editor.GetPositionFromLineColumn (startLine, 0), endPos); } else { Mono.TextEditor.Document doc = new Mono.TextEditor.Document (); doc.Text = File.ReadAllText (fileName) ?? ""; startLine = Math.Min (doc.LineCount, Math.Max (1, startLine)); endLine = Math.Min (doc.LineCount, Math.Max (1, endLine)); int startOffset = doc.LocationToOffset (startLine - 1, 0); text = doc.GetTextAt (startOffset, doc.LocationToOffset (endLine - 1, doc.GetLine (endLine - 1).EditableLength) - startOffset); } if (!string.IsNullOrEmpty (text)) result.Append (text); result.Append ("}"); return result.ToString (); }
static string StripHeaderAndBlankLines (string text, CodeDomProvider provider) { Mono.TextEditor.Document doc = new Mono.TextEditor.Document (); doc.Text = text; int realStartLine = 0; for (int i = 1; i <= doc.LineCount; i++) { string lineText = doc.GetTextAt (doc.GetLine (i)); // Microsoft.NET generates "auto-generated" tags where Mono generates "autogenerated" tags. if (lineText.Contains ("</autogenerated>") || lineText.Contains ("</auto-generated>")) { realStartLine = i + 2; break; } } // The Mono provider inserts additional blank lines, so strip them out // But blank lines might actually be significant in other languages. // We reformat the C# generated output to the user's coding style anyway, but the reformatter preserves blank lines if (provider is Microsoft.CSharp.CSharpCodeProvider) { bool previousWasBlank = false; for (int i = 1; i <= doc.LineCount; i++) { Mono.TextEditor.LineSegment line = doc.GetLine (i); bool isBlank, isBracket; CheckLine (doc, line, out isBlank, out isBracket); if (isBlank && previousWasBlank && line.Length > 0) { ((Mono.TextEditor.IBuffer)doc).Remove (line.Offset, line.Length); i--; } previousWasBlank = isBlank || isBracket; } } int offset = doc.GetLine (realStartLine).Offset; return doc.GetTextAt (offset, doc.Length - offset); }
public override List<Change> PerformChanges (RefactoringOptions options, object properties) { List<Change> result = new List<Change> (); IType type = options.SelectedItem as IType; if (type == null) return result; string newName = GetCorrectFileName (type); if (type.CompilationUnit.Types.Count == 1) { result.Add (new RenameFileChange (type.CompilationUnit.FileName, newName)); } else { StringBuilder content = new StringBuilder (); if (options.Dom.Project is DotNetProject) content.Append (StandardHeaderService.GetHeader (options.Dom.Project, type.CompilationUnit.FileName, true) + Environment.NewLine); INRefactoryASTProvider provider = options.GetASTProvider (); Mono.TextEditor.TextEditorData data = options.GetTextEditorData (); ICSharpCode.NRefactory.Ast.CompilationUnit unit = provider.ParseFile (options.Document.TextEditor.Text); TypeFilterTransformer typeFilterTransformer = new TypeFilterTransformer ((type is InstantiatedType) ? ((InstantiatedType)type).UninstantiatedType.DecoratedFullName : type.DecoratedFullName); unit.AcceptVisitor (typeFilterTransformer, null); if (typeFilterTransformer.TypeDeclaration == null) return result; Mono.TextEditor.Document generatedDocument = new Mono.TextEditor.Document (); generatedDocument.Text = provider.OutputNode (options.Dom, unit); int startLine = -1; int minLine = typeFilterTransformer.TypeDeclaration.StartLocation.Line; foreach (var attr in typeFilterTransformer.TypeDeclaration.Attributes) { minLine = Math.Min (minLine, attr.StartLocation.Line); } for (int i = minLine - 2; i >= 0; i--) { string lineText = data.Document.GetTextAt (data.Document.GetLine (i)).Trim (); if (string.IsNullOrEmpty (lineText)) continue; if (lineText.StartsWith ("///")) { startLine = i; } else { break; } } int start; if (startLine >= 0) { start = data.Document.GetLine (startLine).Offset; } else { var startLocation = typeFilterTransformer.TypeDeclaration.StartLocation; startLocation.Column = 0; foreach (var attr in typeFilterTransformer.TypeDeclaration.Attributes) { if (attr.StartLocation < startLocation) startLocation = attr.StartLocation; } start = data.Document.LocationToOffset (startLocation.Line - 1, 0); } int length = data.Document.LocationToOffset (typeFilterTransformer.TypeDeclaration.EndLocation.Line - 1, typeFilterTransformer.TypeDeclaration.EndLocation.Column) - start; ICSharpCode.NRefactory.Ast.CompilationUnit generatedCompilationUnit = provider.ParseFile (generatedDocument.Text); TypeSearchVisitor typeSearchVisitor = new TypeSearchVisitor (); generatedCompilationUnit.AcceptVisitor (typeSearchVisitor, null); int genStart = generatedDocument.LocationToOffset (typeSearchVisitor.Types[0].StartLocation.Line - 1, 0); foreach (var attr in typeSearchVisitor.Types[0].Attributes) { genStart = Math.Min (genStart, generatedDocument.LocationToOffset (attr.StartLocation.Line - 1, 0)); } int genEnd = generatedDocument.LocationToOffset (typeSearchVisitor.Types[0].EndLocation.Line - 1, typeSearchVisitor.Types[0].EndLocation.Column - 1); ((Mono.TextEditor.IBuffer)generatedDocument).Replace (genStart, genEnd - genStart, data.Document.GetTextAt (start, length)); content.Append (generatedDocument.Text); result.Add (new CreateFileChange (newName, content.ToString ())); TextReplaceChange removeDeclaration = new TextReplaceChange (); removeDeclaration.Description = "Remove type declaration"; removeDeclaration.FileName = type.CompilationUnit.FileName; removeDeclaration.Offset = start; removeDeclaration.RemovedChars = length; result.Add (removeDeclaration); } result.Add (new SaveProjectChange (options.Document.Project)); return result; }
public void TestLogicalToVisualLineStartLine () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[1 -[2 3 ]4 5 -[6 +[7 -[8 9 ]10 ]11 ]12 ]13 14 -[15 16 ]17 18"; document.UpdateFoldSegments (GetFoldSegments (document), false); Assert.AreEqual (7, document.LogicalToVisualLine (7)); }
public HiddenTextEditorViewContent () { document = new Mono.TextEditor.Document (); data = new Mono.TextEditor.TextEditorData (document); Name = ""; }
public void TestBug682466 () { Document document = new Mono.TextEditor.Document (); document.Text = @"0 1 2 +[3 4 5 6] 7 8 9 10"; var segments = GetFoldSegments (document); document.UpdateFoldSegments (segments, false); Assert.AreEqual (true, document.FoldSegments.FirstOrDefault ().IsFolded); segments = GetFoldSegments (document); segments[0].IsFolded = false; document.UpdateFoldSegments (segments, false); Assert.AreEqual (5, document.LogicalToVisualLine (8)); }
public FileContent (string fileName, Mono.TextEditor.Document content) { this.FileName = fileName; this.Content = content; }
public void TestIsFoldedUnsetFolded () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[1 2 3 +[4 5 +[6 7] 8] -[9 10 11] 12] -[13 14] 15 16"; var segments = GetFoldSegments (document); document.UpdateFoldSegments (segments, false); Assert.AreEqual (11, document.LogicalToVisualLine (15)); document.GetStartFoldings (6).First ().IsFolded = false; document.GetStartFoldings (4).First ().IsFolded = false; Assert.AreEqual (15, document.LogicalToVisualLine (15)); }
// Returns a stream with the content of the file. // project and language parameters are optional public virtual Stream CreateFileContent (SolutionItem policyParent, Project project, string language, string fileName) { Dictionary<string, string> tags = new Dictionary<string, string> (); ModifyTags (policyParent, project, language, null, fileName, ref tags); string content = CreateContent (project, tags, language); content = StringParserService.Parse (content, tags); string mime = DesktopService.GetMimeTypeForUri (fileName); Formatter formatter = !String.IsNullOrEmpty (mime) ? TextFileService.GetFormatter (mime) : null; if (formatter != null) content = formatter.FormatText (policyParent != null ? policyParent.Policies : null, content); MemoryStream ms = new MemoryStream (); byte[] data; if (AddStandardHeader) { string header = StandardHeaderService.GetHeader (policyParent, fileName, true); data = System.Text.Encoding.UTF8.GetBytes (header); ms.Write (data, 0, data.Length); } Mono.TextEditor.Document doc = new Mono.TextEditor.Document (); doc.Text = content; TextStylePolicy textPolicy = policyParent != null ? policyParent.Policies.Get<TextStylePolicy> ("text/plain") : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<TextStylePolicy> ("text/plain"); string eolMarker = TextStylePolicy.GetEolMarker (textPolicy.EolMarker); byte[] eolMarkerBytes = System.Text.Encoding.UTF8.GetBytes (eolMarker); foreach (Mono.TextEditor.LineSegment line in doc.Lines) { data = System.Text.Encoding.UTF8.GetBytes (doc.GetTextAt (line.Offset, line.EditableLength)); ms.Write (data, 0, data.Length); ms.Write (eolMarkerBytes, 0, eolMarkerBytes.Length); } ms.Position = 0; return ms; }
public void TestGetStartFoldingsGetStartFoldings () { Document document = new Mono.TextEditor.Document (); document.Text = @"+[1 2 3 +[4 5 +[6 7] 8] +[9 10 11] 12] +[13 14] 15 16"; var segments = GetFoldSegments (document); document.UpdateFoldSegments (segments, false); document.UpdateFoldSegments (segments, false); document.UpdateFoldSegments (segments, false); Assert.AreEqual (1, document.GetStartFoldings (1).Count ()); Assert.AreEqual (1, document.GetStartFoldings (4).Count ()); Assert.AreEqual (1, document.GetStartFoldings (6).Count ()); Assert.AreEqual (1, document.GetStartFoldings (9).Count ()); Assert.AreEqual (1, document.GetStartFoldings (13).Count ()); }
public override Annotation[] GetAnnotations (FilePath localPath) { List<Annotation> annotations = new List<Annotation> (Svn.GetAnnotations (this, localPath, SvnRevision.First, SvnRevision.Base)); Annotation nextRev = new Annotation (GettextCatalog.GetString ("working copy"), "", DateTime.MinValue); var baseDocument = new Mono.TextEditor.Document (File.ReadAllText (GetPathToBaseText (localPath))); var workingDocument = new Mono.TextEditor.Document (File.ReadAllText (localPath)); // "SubversionException: blame of the WORKING revision is not supported" foreach (var hunk in baseDocument.Diff (workingDocument)) { annotations.RemoveRange (hunk.InsertStart, hunk.Inserted); for (int i = 0; i < hunk.Inserted; ++i) { annotations.Insert (hunk.InsertStart, nextRev); } } return annotations.ToArray (); }
void HandleTreeviewFilesTestExpandRow (object o, TestExpandRowArgs args) { string[] diff = changedpathstore.GetValue (args.Iter, colDiff) as string[]; if (diff != null) { return; } TreeIter iter; if (changedpathstore.IterChildren (out iter, args.Iter)) { string path = (string)changedpathstore .GetValue (args.Iter, colPath); changedpathstore.SetValue (iter, colDiff, new string[] { GettextCatalog.GetString ("Loading data...") }); var rev = SelectedRevision; ThreadPool.QueueUserWorkItem (delegate { string text; try { text = info.Repository.GetTextAtRevision (path, rev); } catch (Exception e) { Application.Invoke (delegate { LoggingService.LogError ("Error while getting revision text", e); MessageService.ShowError ("Error while getting revision text.", "The file may not be part of the working copy."); }); return; } Revision prevRev = null; try { prevRev = rev.GetPrevious (); } catch (Exception e) { Application.Invoke (delegate { LoggingService.LogError ("Error while getting previous revision", e); MessageService.ShowException (e, "Error while getting previous revision."); }); return; } string[] lines; var changedDocument = new Mono.TextEditor.Document (text); if (prevRev == null) { lines = new string[changedDocument.LineCount]; for (int i = 0; i < changedDocument.LineCount; i++) { lines[i] = "+ " + changedDocument.GetLineText (i); } } else { string prevRevisionText; try { prevRevisionText = info.Repository.GetTextAtRevision (path, prevRev); } catch (Exception e) { Application.Invoke (delegate { LoggingService.LogError ("Error while getting revision text", e); MessageService.ShowError ("Error while getting revision text.", "The file may not be part of the working copy."); }); return; } var originalDocument = new Mono.TextEditor.Document (prevRevisionText); originalDocument.FileName = "Revision " + prevRev.ToString (); changedDocument.FileName = "Revision " + rev.ToString (); lines = Mono.TextEditor.Utils.Diff.GetDiffString (originalDocument, changedDocument).Split ('\n'); } Application.Invoke (delegate { changedpathstore.SetValue (iter, colDiff, lines); }); }); } }
public void TestDocumentBug1Test() { Document document = new Mono.TextEditor.Document (); string top = "1234567890"; document.Text = top; Assert.AreEqual (document.GetLine (0).Length, document.Length); ((IBuffer)document).Remove(0, document.Length); LineSegment line = document.GetLine (0); Assert.AreEqual(0, line.Offset); Assert.AreEqual(0, line.Length); Assert.AreEqual(0, document.Length); Assert.AreEqual(1, document.LineCount); }
public FileContent(string fileName, Mono.TextEditor.Document content) { this.FileName = fileName; this.Content = content; }
public void TestVisualToLogicalLineCase2 () { Document document = new Mono.TextEditor.Document (); document.Text = @"-[1 +[2 3 ]4 5 +[6 +[7 +[8 9 ]10 ]11 ]12 ]13 14 +[15 16 ]17 18"; document.UpdateFoldSegments (GetFoldSegments (document), false); Assert.AreEqual (6, document.VisualToLogicalLine (4)); Assert.AreEqual (14, document.VisualToLogicalLine (6)); Assert.AreEqual (15, document.VisualToLogicalLine (7)); }