public EditorDocumentMock(string content, string filePath = null) { var tb = new TextBufferMock(content, RContentTypeDefinition.ContentType); EditorTree = new EditorTreeMock(new EditorBuffer(tb), RParser.Parse(content)); tb.AddService(this); if (!string.IsNullOrEmpty(filePath)) { tb.Properties.AddProperty(typeof(ITextDocument), new TextDocumentMock(tb, filePath)); } }
public static void GetCompletions(IServiceContainer services, string content, int caretPosition, IList <CompletionSet> completionSets, ITextRange selectedRange = null) { var ast = RParser.Parse(content); var textBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType); var textView = new TextViewMock(textBuffer, caretPosition); var document = Substitute.For <IREditorDocument>(); document.EditorTree.AstRoot.Returns(ast); textBuffer.AddService(document); if (selectedRange != null) { textView.Selection.Select(new SnapshotSpan(textBuffer.CurrentSnapshot, selectedRange.Start, selectedRange.Length), false); } var completionSession = new CompletionSessionMock(textView, completionSets, caretPosition); var completionSource = new RCompletionSource(textBuffer, services); completionSource.PopulateCompletionList(caretPosition, completionSession, completionSets, ast); }