示例#1
0
		string CreateInsertionPoint (string input, string text, NewLineInsertion before, NewLineInsertion after)
		{
			int idx = input.IndexOf ('$');
			Assert.Greater (idx, -1);
			TextEditorData data = new TextEditorData (new TextDocument (input.Substring (0, idx) + input.Substring (idx + 1)));
			InsertionPoint point = new InsertionPoint (data.Document.OffsetToLocation (idx), before, after);
			point.Insert (data, text);
			return data.Document.Text;
		}
示例#2
0
        string CreateInsertionPoint(string input, string text, NewLineInsertion before, NewLineInsertion after)
        {
            int idx = input.IndexOf('$');

            Assert.Greater(idx, -1);
            TextEditorData data  = new TextEditorData(new TextDocument(input.Substring(0, idx) + input.Substring(idx + 1)));
            InsertionPoint point = new InsertionPoint(data.Document.OffsetToLocation(idx), before, after);

            point.Insert(data, text);
            return(data.Document.Text);
        }
		string CreateInsertionPoint (string input, string text, NewLineInsertion before, NewLineInsertion after)
		{
			int idx = input.IndexOf ('$');
			Assert.Greater (idx, -1);
			TextEditor editor = new TextEditor ();
			editor.Document.Text = input.Substring (0, idx) + input.Substring (idx + 1);
			InsertionPoint point = new InsertionPoint (editor.Document.OffsetToLocation (idx), before, after);
			Console.WriteLine (point);
			point.Insert (editor, text);
			return editor.Document.Text;
			
		}
		public void InsertNewLine (TextEditorData editor, NewLineInsertion insertion, ref int offset)
		{
			string str = null;
			switch (insertion) {
			case NewLineInsertion.Eol:
				str = editor.EolMarker;
				break;
			case NewLineInsertion.BlankLine:
				str = editor.EolMarker + editor.EolMarker;
				break;
			default:
				return;
			}
			
			offset += editor.Insert (offset, str);
		}
		public void InsertNewLine (ITextDocument editor, NewLineInsertion insertion, ref int offset)
		{
			string str = null;
			switch (insertion) {
			case NewLineInsertion.Eol:
				str = editor.GetEolMarker ();
				break;
			case NewLineInsertion.BlankLine:
				str = editor.GetEolMarker () + editor.GetEolMarker ();
				break;
			default:
				return;
		}

			editor.InsertText (offset, str);
			offset += str.Length;
		}
示例#6
0
		void InsertNewLine (IDocument document, NewLineInsertion insertion, ref int offset)
		{
			string eolMarker = DocumentUtilities.GetLineTerminator(document, 1);
			string str = null;
			switch (insertion) {
				case NewLineInsertion.Eol:
					str = eolMarker;
					break;
				case NewLineInsertion.BlankLine:
					str = eolMarker + eolMarker;
					break;
				default:
					return;
			}
			
			document.Insert (offset, str);
			offset += str.Length;
		}
        public void InsertNewLine(TextEditorData editor, NewLineInsertion insertion, ref int offset)
        {
            string str = null;

            switch (insertion)
            {
            case NewLineInsertion.Eol:
                str = editor.EolMarker;
                break;

            case NewLineInsertion.BlankLine:
                str = editor.EolMarker + editor.EolMarker;
                break;

            default:
                return;
            }

            offset += editor.Insert(offset, str);
        }
示例#8
0
        public void InsertNewLine(ITextDocument editor, NewLineInsertion insertion, ref int offset)
        {
            string str = null;

            switch (insertion)
            {
            case NewLineInsertion.Eol:
                str = editor.GetEolMarker();
                break;

            case NewLineInsertion.BlankLine:
                str = editor.GetEolMarker() + editor.GetEolMarker();
                break;

            default:
                return;
            }

            editor.InsertText(offset, str);
            offset += str.Length;
        }
        void InsertNewLine(IDocument document, NewLineInsertion insertion, ref int offset)
        {
            string eolMarker = DocumentUtilities.GetLineTerminator(document, 1);
            string str       = null;

            switch (insertion)
            {
            case NewLineInsertion.Eol:
                str = eolMarker;
                break;

            case NewLineInsertion.BlankLine:
                str = eolMarker + eolMarker;
                break;

            default:
                return;
            }

            document.Insert(offset, str);
            offset += str.Length;
        }
		public InsertionPoint (DocumentLocation location, NewLineInsertion lineBefore, NewLineInsertion lineAfter)
		{
			this.Location = location;
			this.LineBefore = lineBefore;
			this.LineAfter = lineAfter;
		}
 public InsertionPoint(DocumentLocation location, NewLineInsertion lineBefore, NewLineInsertion lineAfter)
 {
     this.Location   = location;
     this.LineBefore = lineBefore;
     this.LineAfter  = lineAfter;
 }
示例#12
0
        static async Task TestInsertionPoints(string text)
        {
            var tww     = new TestWorkbenchWindow();
            var content = new TestViewContent();

            tww.ViewContent       = content;
            content.ContentName   = "/a.cs";
            content.Data.MimeType = "text/x-csharp";
            MonoDevelop.AnalysisCore.AnalysisOptions.EnableUnitTestEditorIntegration.Set(true);
            var doc = new MonoDevelop.Ide.Gui.Document(tww);

            var data = doc.Editor;
            List <InsertionPoint> loc = new List <InsertionPoint> ();

            for (int i = 0; i < text.Length; i++)
            {
                char ch = text [i];
                if (ch == '@')
                {
                    i++;
                    ch = text [i];
                    NewLineInsertion insertBefore = NewLineInsertion.None;
                    NewLineInsertion insertAfter  = NewLineInsertion.None;

                    switch (ch)
                    {
                    case 'n':
                        break;

                    case 'd':
                        insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'D':
                        insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 'u':
                        insertBefore = NewLineInsertion.Eol;
                        break;

                    case 'U':
                        insertBefore = NewLineInsertion.BlankLine;
                        break;

                    case 's':
                        insertBefore = insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'S':
                        insertBefore = insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 't':
                        insertBefore = NewLineInsertion.Eol;
                        insertAfter  = NewLineInsertion.BlankLine;
                        break;

                    case 'T':
                        insertBefore = NewLineInsertion.None;
                        insertAfter  = NewLineInsertion.BlankLine;
                        break;

                    case 'v':
                        insertBefore = NewLineInsertion.BlankLine;
                        insertAfter  = NewLineInsertion.Eol;
                        break;

                    case 'V':
                        insertBefore = NewLineInsertion.None;
                        insertAfter  = NewLineInsertion.Eol;
                        break;

                    default:
                        Assert.Fail("unknown insertion point:" + ch);
                        break;
                    }
                    var vv = data.OffsetToLocation(data.Length);
                    loc.Add(new InsertionPoint(new DocumentLocation(vv.Line, vv.Column), insertBefore, insertAfter));
                }
                else
                {
                    data.InsertText(data.Length, ch.ToString());
                }
            }


            var project = Services.ProjectService.CreateProject("C#");

            project.Name     = "test";
            project.FileName = "test.csproj";
            project.Files.Add(new ProjectFile("/a.cs", BuildAction.Compile));

            var solution = new MonoDevelop.Projects.Solution();

            solution.AddConfiguration("", true);
            solution.DefaultSolutionFolder.AddItem(project);
            using (var monitor = new ProgressMonitor())
                await TypeSystemService.Load(solution, monitor);
            content.Project = project;
            doc.SetProject(project);
            var parsedFile = await doc.UpdateParseDocument();

            var model = parsedFile.GetAst <SemanticModel> ();
            var sym   = model?.GetEnclosingSymbol(data.Text.IndexOf('{'));
            var type  = sym as INamedTypeSymbol ?? sym?.ContainingType;

            if (type != null)
            {
                var foundPoints = InsertionPointService.GetInsertionPoints(doc.Editor, parsedFile, type, type.Locations.First());
                Assert.AreEqual(loc.Count, foundPoints.Count, "point count doesn't match");
                for (int i = 0; i < loc.Count; i++)
                {
                    Assert.AreEqual(loc [i].Location, foundPoints [i].Location, "point " + i + " doesn't match");
                    Assert.AreEqual(loc [i].LineAfter, foundPoints [i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match");
                    Assert.AreEqual(loc [i].LineBefore, foundPoints [i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match");
                }
            }

            TypeSystemService.Unload(solution);
        }
        static void TestInsertionPoints(string text)
        {
            TextEditorData        data = new TextEditorData();
            List <InsertionPoint> loc  = new List <InsertionPoint> ();

            for (int i = 0; i < text.Length; i++)
            {
                char ch = text[i];
                if (ch == '@')
                {
                    i++;
                    ch = text[i];
                    NewLineInsertion insertBefore = NewLineInsertion.None;
                    NewLineInsertion insertAfter  = NewLineInsertion.None;

                    switch (ch)
                    {
                    case 'n':
                        break;

                    case 'd':
                        insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'D':
                        insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 'u':
                        insertBefore = NewLineInsertion.Eol;
                        break;

                    case 'U':
                        insertBefore = NewLineInsertion.BlankLine;
                        break;

                    case 's':
                        insertBefore = insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'S':
                        insertBefore = insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 't':
                        insertBefore = NewLineInsertion.Eol;
                        insertAfter  = NewLineInsertion.BlankLine;
                        break;

                    case 'v':
                        insertBefore = NewLineInsertion.BlankLine;
                        insertAfter  = NewLineInsertion.Eol;
                        break;

                    default:
                        Assert.Fail("unknown insertion point:" + ch);
                        break;
                    }
                    loc.Add(new InsertionPoint(data.Document.OffsetToLocation(data.Document.Length), insertBefore, insertAfter));
                }
                else
                {
                    data.Insert(data.Document.Length, ch.ToString());
                }
            }

            var parseResult = new NRefactoryParser().Parse(null, "a.cs", data.Document.Text);

            var foundPoints = HelperMethods.GetInsertionPoints(data.Document, parseResult.CompilationUnit.Types[0]);

            Assert.AreEqual(loc.Count, foundPoints.Count, "point count doesn't match");
            for (int i = 0; i < loc.Count; i++)
            {
                Console.WriteLine(loc[i] + "/" + foundPoints[i]);
                Assert.AreEqual(loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match");
                Assert.AreEqual(loc[i].LineAfter, foundPoints[i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match");
                Assert.AreEqual(loc[i].LineBefore, foundPoints[i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match");
            }
        }
示例#14
0
        async Task TestInsertionPoints(string text)
        {
            MonoDevelop.AnalysisCore.AnalysisOptions.EnableUnitTestEditorIntegration.Set(true);
            using (var testCase = await SetupTestCase("")) {
                var doc  = testCase.Document;
                var data = doc.Editor;

                List <InsertionPoint> loc = new List <InsertionPoint> ();
                for (int i = 0; i < text.Length; i++)
                {
                    char ch = text [i];
                    if (ch == '@')
                    {
                        i++;
                        ch = text [i];
                        NewLineInsertion insertBefore = NewLineInsertion.None;
                        NewLineInsertion insertAfter  = NewLineInsertion.None;

                        switch (ch)
                        {
                        case 'n':
                            break;

                        case 'd':
                            insertAfter = NewLineInsertion.Eol;
                            break;

                        case 'D':
                            insertAfter = NewLineInsertion.BlankLine;
                            break;

                        case 'u':
                            insertBefore = NewLineInsertion.Eol;
                            break;

                        case 'U':
                            insertBefore = NewLineInsertion.BlankLine;
                            break;

                        case 's':
                            insertBefore = insertAfter = NewLineInsertion.Eol;
                            break;

                        case 'S':
                            insertBefore = insertAfter = NewLineInsertion.BlankLine;
                            break;

                        case 't':
                            insertBefore = NewLineInsertion.Eol;
                            insertAfter  = NewLineInsertion.BlankLine;
                            break;

                        case 'T':
                            insertBefore = NewLineInsertion.None;
                            insertAfter  = NewLineInsertion.BlankLine;
                            break;

                        case 'v':
                            insertBefore = NewLineInsertion.BlankLine;
                            insertAfter  = NewLineInsertion.Eol;
                            break;

                        case 'V':
                            insertBefore = NewLineInsertion.None;
                            insertAfter  = NewLineInsertion.Eol;
                            break;

                        default:
                            Assert.Fail("unknown insertion point:" + ch);
                            break;
                        }
                        var vv = data.OffsetToLocation(data.Length);
                        loc.Add(new InsertionPoint(new DocumentLocation(vv.Line, vv.Column), insertBefore, insertAfter));
                    }
                    else
                    {
                        data.InsertText(data.Length, ch.ToString());
                    }
                }
                var model = await doc.AnalysisDocument.GetSemanticModelAsync();

                var sym  = model?.GetEnclosingSymbol(data.Text.IndexOf('{'));
                var type = sym as INamedTypeSymbol ?? sym?.ContainingType;
                if (type != null)
                {
                    var foundPoints = InsertionPointService.GetInsertionPoints(doc.Editor, model, type, type.Locations.First());
                    Assert.AreEqual(loc.Count, foundPoints.Count, "point count doesn't match");
                    for (int i = 0; i < loc.Count; i++)
                    {
                        Assert.AreEqual(loc [i].Location, foundPoints [i].Location, "point " + i + " doesn't match");
                        Assert.AreEqual(loc [i].LineAfter, foundPoints [i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match");
                        Assert.AreEqual(loc [i].LineBefore, foundPoints [i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match");
                    }
                }
            }
        }
示例#15
0
        static void TestInsertionPoints(string text)
        {
            TestWorkbenchWindow tww     = new TestWorkbenchWindow();
            TestViewContent     sev     = new TestViewContent();
            DotNetProject       project = new DotNetAssemblyProject("C#");

            project.FileName = GetTempFile(".csproj");

            string file = GetTempFile(".cs");

            project.AddFile(file);
            sev.Project     = project;
            sev.ContentName = file;
            tww.ViewContent = sev;
            var doc  = new MonoDevelop.Ide.Gui.Document(tww);
            var data = doc.Editor;
            List <InsertionPoint> loc = new List <InsertionPoint> ();

            for (int i = 0; i < text.Length; i++)
            {
                char ch = text[i];
                if (ch == '@')
                {
                    i++;
                    ch = text[i];
                    NewLineInsertion insertBefore = NewLineInsertion.None;
                    NewLineInsertion insertAfter  = NewLineInsertion.None;

                    switch (ch)
                    {
                    case 'n':
                        break;

                    case 'd':
                        insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'D':
                        insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 'u':
                        insertBefore = NewLineInsertion.Eol;
                        break;

                    case 'U':
                        insertBefore = NewLineInsertion.BlankLine;
                        break;

                    case 's':
                        insertBefore = insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'S':
                        insertBefore = insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 't':
                        insertBefore = NewLineInsertion.Eol;
                        insertAfter  = NewLineInsertion.BlankLine;
                        break;

                    case 'T':
                        insertBefore = NewLineInsertion.None;
                        insertAfter  = NewLineInsertion.BlankLine;
                        break;

                    case 'v':
                        insertBefore = NewLineInsertion.BlankLine;
                        insertAfter  = NewLineInsertion.Eol;
                        break;

                    case 'V':
                        insertBefore = NewLineInsertion.None;
                        insertAfter  = NewLineInsertion.Eol;
                        break;

                    default:
                        Assert.Fail("unknown insertion point:" + ch);
                        break;
                    }
                    loc.Add(new InsertionPoint(data.Document.OffsetToLocation(data.Document.Length), insertBefore, insertAfter));
                }
                else
                {
                    data.Insert(data.Document.Length, ch.ToString());
                }
            }


            doc.ParsedDocument = new McsParser().Parse(null, "a.cs", data.Document.Text);

            var foundPoints = CodeGenerationService.GetInsertionPoints(doc, doc.ParsedDocument.CompilationUnit.Types[0]);

            Assert.AreEqual(loc.Count, foundPoints.Count, "point count doesn't match");
            for (int i = 0; i < loc.Count; i++)
            {
                Assert.AreEqual(loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match");
                Assert.AreEqual(loc[i].LineAfter, foundPoints[i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match");
                Assert.AreEqual(loc[i].LineBefore, foundPoints[i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match");
            }
        }
示例#16
0
        static void TestInsertionPoints(string text)
        {
            TestWorkbenchWindow tww = new TestWorkbenchWindow();
            TestViewContent     sev = new TestViewContent();
            var project             = new UnknownProject();

            project.FileName = "test.csproj";

            TypeSystemService.LoadProject(project);

            sev.Project     = project;
            tww.ViewContent = sev;
            var doc  = new MonoDevelop.Ide.Gui.Document(tww);
            var data = doc.Editor;
            List <InsertionPoint> loc = new List <InsertionPoint> ();

            for (int i = 0; i < text.Length; i++)
            {
                char ch = text [i];
                if (ch == '@')
                {
                    i++;
                    ch = text [i];
                    NewLineInsertion insertBefore = NewLineInsertion.None;
                    NewLineInsertion insertAfter  = NewLineInsertion.None;

                    switch (ch)
                    {
                    case 'n':
                        break;

                    case 'd':
                        insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'D':
                        insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 'u':
                        insertBefore = NewLineInsertion.Eol;
                        break;

                    case 'U':
                        insertBefore = NewLineInsertion.BlankLine;
                        break;

                    case 's':
                        insertBefore = insertAfter = NewLineInsertion.Eol;
                        break;

                    case 'S':
                        insertBefore = insertAfter = NewLineInsertion.BlankLine;
                        break;

                    case 't':
                        insertBefore = NewLineInsertion.Eol;
                        insertAfter  = NewLineInsertion.BlankLine;
                        break;

                    case 'T':
                        insertBefore = NewLineInsertion.None;
                        insertAfter  = NewLineInsertion.BlankLine;
                        break;

                    case 'v':
                        insertBefore = NewLineInsertion.BlankLine;
                        insertAfter  = NewLineInsertion.Eol;
                        break;

                    case 'V':
                        insertBefore = NewLineInsertion.None;
                        insertAfter  = NewLineInsertion.Eol;
                        break;

                    default:
                        Assert.Fail("unknown insertion point:" + ch);
                        break;
                    }
                    loc.Add(new InsertionPoint(data.Document.OffsetToLocation(data.Document.TextLength), insertBefore, insertAfter));
                }
                else
                {
                    data.Insert(data.Document.TextLength, ch.ToString());
                }
            }

            var parsedFile = TypeSystemService.ParseFile(project, "program.cs", "text/x-csharp", data.Document.Text);

            var foundPoints = CodeGenerationService.GetInsertionPoints(doc.Editor, parsedFile, parsedFile.TopLevelTypeDefinitions.First());

            Assert.AreEqual(loc.Count, foundPoints.Count, "point count doesn't match");
            for (int i = 0; i < loc.Count; i++)
            {
                Assert.AreEqual(loc[i].Location, foundPoints[i].Location, "point " + i + " doesn't match");
                Assert.AreEqual(loc[i].LineAfter, foundPoints[i].LineAfter, "point " + i + " ShouldInsertNewLineAfter doesn't match");
                Assert.AreEqual(loc[i].LineBefore, foundPoints[i].LineBefore, "point " + i + " ShouldInsertNewLineBefore doesn't match");
            }
        }
示例#17
0
        static InsertionPoint GetInsertionPosition(Document doc, int line, int column)
        {
            int bodyEndOffset = doc.LocationToOffset(line, column) + 1;

            LineSegment curLine = doc.GetLine(line);

            if (curLine != null)
            {
                if (bodyEndOffset < curLine.Offset + curLine.EditableLength)
                {
                    return(new InsertionPoint(new DocumentLocation(line, column + 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine));
                }
            }

            LineSegment nextLine = doc.GetLine(line + 1);

            int endOffset = nextLine != null ? nextLine.Offset : doc.Length;

            for (int i = bodyEndOffset; i < endOffset; i++)
            {
                char ch = doc.GetCharAt(i);
                if (!char.IsWhiteSpace(ch))
                {
                    return(new InsertionPoint(doc.OffsetToLocation(i), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine));
                }
            }

            if (nextLine == null)
            {
                return(new InsertionPoint(doc.OffsetToLocation(bodyEndOffset - 1), NewLineInsertion.BlankLine, NewLineInsertion.BlankLine));
            }
            int oldLine = line;

            while (line + 1 < doc.LineCount && doc.GetLineIndent(line + 1).Length == doc.GetLine(line + 1).EditableLength)
            {
                line++;
            }
            NewLineInsertion insertBefore = NewLineInsertion.None;
            NewLineInsertion insertAfter  = NewLineInsertion.None;
            int delta      = line - oldLine;
            int lineNumber = line + 1;

            if (delta == 0)
            {
                insertBefore = NewLineInsertion.BlankLine;
                insertAfter  = NewLineInsertion.BlankLine;
            }
            else if (delta == 1)
            {
                insertAfter = NewLineInsertion.BlankLine;
            }
            else if (delta == 2)
            {
                lineNumber--;
                insertAfter = NewLineInsertion.BlankLine;
            }
            else if (delta >= 3)
            {
                lineNumber -= 2;
                insertAfter = NewLineInsertion.None;
            }

            return(new InsertionPoint(new DocumentLocation(lineNumber, doc.GetLineIndent(lineNumber).Length), insertBefore, insertAfter));
        }