public void TestBug17766() { var data = Create(@" class Foo { $void Bar () { } } "); var engine = new CSharpTextEditorIndentation(); var tww = new TestWorkbenchWindow(); var content = new TestViewContent(data); tww.ViewContent = content; content.ContentName = "a.cs"; engine.Initialize(new Document(tww)); MiscActions.RemoveTab(data); engine.KeyPress(Gdk.Key.Tab, '\t', Gdk.ModifierType.ShiftMask); CheckOutput(data, @" class Foo { $void Bar () { } } ", engine); }
public async Task TestBug58473() { var text = @"$"; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } var project = Ide.Services.ProjectService.CreateDotNetProject("C#"); project.Name = "test"; project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("mscorlib")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System.Core")); 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); var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; content.Project = project; content.Text = text; content.CursorPosition = Math.Max(0, endPos); var doc = new MonoDevelop.Ide.Gui.Document(tww); doc.SetProject(project); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); await doc.UpdateParseDocument(); var ctx = new CodeCompletionContext(); var tmp = IdeApp.Preferences.EnableAutoCodeCompletion; IdeApp.Preferences.EnableAutoCodeCompletion.Set(false); var list = await compExt.HandleCodeCompletionAsync(ctx, CompletionTriggerInfo.CodeCompletionCommand); Assert.IsNotNull(list); IdeApp.Preferences.EnableAutoCodeCompletion.Set(tmp); project.Dispose(); }
public async Task TestBug60365() { var tww = new TestWorkbenchWindow(); TestViewContent content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; var doc = new MonoDevelop.Ide.Gui.Document(tww); var text = "@c$"; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } content.Text = text; content.CursorPosition = System.Math.Max(0, endPos); var project = MonoDevelop.Projects.Services.ProjectService.CreateProject("C#"); project.Name = "test"; project.FileName = "test.csproj"; project.Files.Add(new ProjectFile(content.ContentName, 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 ext = new CSharpCompletionTextEditorExtension(); ext.Initialize(doc.Editor, doc); var listWindow = new CompletionListWindow(); var widget = new TestCompletionWidget(ext.Editor, ext.DocumentContext); listWindow.CompletionWidget = widget; listWindow.CodeCompletionContext = widget.CurrentCodeCompletionContext; var list = await ext.HandleCodeCompletionAsync(widget.CurrentCodeCompletionContext, new CompletionTriggerInfo (CompletionTriggerReason.CharTyped, 'c')); var ka = KeyActions.Complete; list.First(d => d.CompletionText == "class").InsertCompletionText(listWindow, ref ka, KeyDescriptor.Tab); Assert.AreEqual("@class", content.Text); content.Contents.Add(ext); await doc.UpdateParseDocument(); TypeSystemService.Unload(solution); }
async Task <RazorCSharpParsedDocument> Parse(string text, bool isPreprocessed) { var project = Services.ProjectService.CreateDotNetProject("C#", "AspNetApp"); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(".cshtml"); ProjectFile projectFile = project.AddFile(file); if (isPreprocessed) { projectFile.Generator = "RazorTemplatePreprocessor"; } var sev = new TestViewContent(); await sev.Initialize(new FileDescriptor (file, null, project), null); sev.Text = text; sev.Editor.FileName = sev.FilePath; solution = new MonoDevelop.Projects.Solution(); solution.DefaultSolutionFolder.AddItem(project); solution.AddConfiguration("", true); await TypeSystemServiceTestExtensions.LoadSolution(solution); var parser = new RazorTestingParser { Editor = sev.Editor }; var options = new ParseOptions { Project = project, FileName = file, Content = new StringTextSource(text) }; return((RazorCSharpParsedDocument)parser.Parse(options, default(CancellationToken)).Result); }
async Task <string> Test(string input, string type, string member, Gdk.Key key = Gdk.Key.Return, bool isDelegateExpected = false) { var s = await Setup(input); var ext = s.Item1; TestViewContent content = s.Item2; var listWindow = new CompletionListWindow(); var widget = new TestCompletionWidget(ext.Editor, ext.DocumentContext); listWindow.CompletionWidget = widget; listWindow.CodeCompletionContext = widget.CurrentCodeCompletionContext; var model = ext.DocumentContext.ParsedDocument.GetAst <SemanticModel> (); Ide.IdeApp.Preferences.AddParenthesesAfterCompletion.Set(true); Ide.IdeApp.Preferences.AddOpeningOnly.Set(false); var t = model.Compilation.GetTypeByMetadataName(type); var method = member != null?t.GetMembers().First(m => m.Name == member) : t.GetMembers().OfType <IMethodSymbol> ().First(m => m.MethodKind == MethodKind.Constructor); var factory = new RoslynCodeCompletionFactory(ext, model); var data = new RoslynSymbolCompletionData(null, factory, method); data.IsDelegateExpected = isDelegateExpected; KeyActions ka = KeyActions.Process; data.InsertCompletionText(listWindow, ref ka, KeyDescriptor.FromGtk(key, (char)key, Gdk.ModifierType.None)); return(widget.CompletedWord); }
public void TestBug58764() { var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; var document = new Document(tww); var editor = TextEditorFactory.CreateNewEditor(document); editor.MimeType = "text/xml"; const string originalText = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ContentPage xmlns=""http://xamarin.com/schemas/2014/forms"" xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" x:Class=""XamlSamples.HelloXamlPage""> <Grid HeightRequest= </ContentPage>"; editor.Text = originalText; var offset = editor.Text.IndexOf("HeightRequest=", StringComparison.Ordinal) + "HeightRequest=".Length; editor.GetContent <ITextEditorImpl> ().CaretOffset = offset; //Reason why we use GetNativeWidget, and navigate to ExtensibleTextEditor child //and execute KeyPress on it instead something more abstract is... //EditSession key processing is done inside ExtensibleTextEditor. var extensibleEditor = FindChild <ExtensibleTextEditor> (editor.GetNativeWidget <Container> ()); extensibleEditor.OnIMProcessedKeyPressEvent((Gdk.Key) '"', '"', Gdk.ModifierType.None); extensibleEditor.OnIMProcessedKeyPressEvent(Gdk.Key.BackSpace, '\0', Gdk.ModifierType.None); extensibleEditor.OnIMProcessedKeyPressEvent((Gdk.Key) '"', '"', Gdk.ModifierType.None); Assert.AreEqual(originalText.Insert(offset, "\"\""), editor.Text); }
public static IDocumentIndentEngine CreateEngine(string text) { var sb = new StringBuilder(); int offset = 0; for (int i = 0; i < text.Length; i++) { var ch = text [i]; if (ch == '$') { offset = i; continue; } sb.Append(ch); } var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.json"; content.Data.MimeType = "application/json"; content.Data.Text = sb.ToString(); var doc = new MonoDevelop.Ide.Gui.Document(tww); var csi = new JSonIndentEngine(content.Data, doc); var result = new CacheIndentEngine(csi); result.Update(content.Data, offset); return(result); }
public async Task TestBug58764() { DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = true; var content = new TestViewContent(); await content.Initialize(new FileDescriptor ("foo.xml", null, null)); using (var testCase = await TextEditorExtensionTestCase.Create(content, null, false)) { var document = testCase.Document; var editor = content.Editor; editor.MimeType = "text/xml"; const string originalText = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ContentPage xmlns=""http://xamarin.com/schemas/2014/forms"" xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" x:Class=""XamlSamples.HelloXamlPage""> <Grid HeightRequest= </ContentPage>"; editor.Text = originalText; var offset = editor.Text.IndexOf("HeightRequest=", StringComparison.Ordinal) + "HeightRequest=".Length; editor.GetContent <ITextEditorImpl> ().CaretOffset = offset; //Reason why we use GetNativeWidget, and navigate to ExtensibleTextEditor child //and execute KeyPress on it instead something more abstract is... //EditSession key processing is done inside ExtensibleTextEditor. var extensibleEditor = editor.GetContent <SourceEditorView> ().TextEditor; extensibleEditor.OnIMProcessedKeyPressEvent((Gdk.Key) '"', '"', Gdk.ModifierType.None); extensibleEditor.OnIMProcessedKeyPressEvent(Gdk.Key.BackSpace, '\0', Gdk.ModifierType.None); extensibleEditor.OnIMProcessedKeyPressEvent((Gdk.Key) '"', '"', Gdk.ModifierType.None); Assert.AreEqual(originalText.Insert(offset, "\"\""), editor.Text); } }
public static async Task <CompletionDataList> CreateProvider(string text, string extension, bool isCtrlSpace = false) { var result = await CreateEditor(text, extension); var textEditorCompletion = result.Extension; string editorText = result.EditorText; TestViewContent sev = result.ViewContent; int cursorPosition = text.IndexOf('$'); var ctx = textEditorCompletion.GetCodeCompletionContext(sev); if (isCtrlSpace) { return(await textEditorCompletion.HandleCodeCompletionAsync(ctx, CompletionTriggerInfo.CodeCompletionCommand) as CompletionDataList); } else { var task = textEditorCompletion.HandleCodeCompletionAsync(ctx, new CompletionTriggerInfo(CompletionTriggerReason.CharTyped, editorText [cursorPosition - 1])); if (task != null) { return(await task as CompletionDataList); } return(null); } }
static Document Setup(string input) { var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "a.cs"; content.GetTextEditorData().Document.MimeType = "text/x-csharp"; var doc = new Document(tww); var text = input; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } content.Text = text; content.CursorPosition = Math.Max(0, endPos); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc); content.Contents.Add(compExt); doc.UpdateParseDocument(); return(doc); }
async Task <string> Test(string input, string type, string member, Gdk.Key key = Gdk.Key.Return) { var s = await Setup(input); var ext = s.Item1; TestViewContent content = s.Item2; var listWindow = new CompletionListWindow(); var widget = new TestCompletionWidget(ext.Editor, ext.DocumentContext); listWindow.CompletionWidget = widget; listWindow.CodeCompletionContext = widget.CurrentCodeCompletionContext; var sm = ext.DocumentContext.ParsedDocument.GetAst <SemanticModel> (); var t = sm.Compilation.GetTypeByMetadataName(type); var foundMember = t.GetMembers().First(m => m.Name == member); var factory = new RoslynCodeCompletionFactory(ext, sm); var data = new RoslynSymbolCompletionData(null, factory, foundMember); data.DisplayFlags |= DisplayFlags.NamedArgument; KeyActions ka = KeyActions.Process; data.InsertCompletionText(listWindow, ref ka, KeyDescriptor.FromGtk(key, (char)key, Gdk.ModifierType.None)); return(widget.CompletedWord); }
async Task <string> Test(string input, string type, string member, Gdk.Key key = Gdk.Key.Return, bool isDelegateExpected = false) { var s = await Setup(input); var ext = s.Item1; TestViewContent content = s.Item2; var listWindow = new CompletionListWindow(); var widget = new TestCompletionWidget(ext.Editor, ext.DocumentContext); listWindow.CompletionWidget = widget; listWindow.CodeCompletionContext = widget.CurrentCodeCompletionContext; var model = await ext.DocumentContext.AnalysisDocument.GetSemanticModelAsync(); DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = true; var t = model.Compilation.GetTypeByMetadataName(type); var method = member != null?model.LookupSymbols(s.Item1.Editor.CaretOffset).OfType <IMethodSymbol> ().First(m => m.Name == member) : t.GetMembers().OfType <IMethodSymbol> ().First(m => m.MethodKind == MethodKind.Constructor); var factory = new RoslynCodeCompletionFactory(ext, model); var data = new RoslynSymbolCompletionData(null, factory, method); data.IsDelegateExpected = isDelegateExpected; KeyActions ka = KeyActions.Process; data.InsertCompletionText(listWindow, ref ka, KeyDescriptor.FromGtk(key, (char)key, Gdk.ModifierType.None)); return(widget.CompletedWord); }
static async Task <Tuple <CodeActionEditorExtension, Projects.Solution> > GatherFixesNoDispose <T> (string input, Action <ResultsEditorExtension, TaskCompletionSource <T> > callback, params int[] caretLocations) { await Ide.Composition.CompositionManager.InitializeAsync(); TestWorkbenchWindow tww = new TestWorkbenchWindow(); TestViewContent content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; var doc = new Ide.Gui.Document(tww); var text = input; content.Text = text; var project = Projects.Services.ProjectService.CreateProject("C#"); project.Name = "test"; project.FileName = "test.csproj"; project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile)); var solution = new Projects.Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); content.Project = project; doc.SetProject(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); var resultsExt = new ResultsEditorExtension(); resultsExt.Initialize(doc.Editor, doc); content.Contents.Add(resultsExt); var compExt = new CodeActionEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); var tcs = new TaskCompletionSource <T> (); var cts = new CancellationTokenSource(); cts.CancelAfter(60 * 1000); cts.Token.Register(() => tcs.TrySetCanceled()); resultsExt.TasksUpdated += delegate { callback(resultsExt, tcs); }; await doc.UpdateParseDocument(); await Task.Run(() => tcs.Task); return(Tuple.Create(compExt, solution)); }
public TextEditorExtensionTestCase(Document doc, TestViewContent content, TestWorkbenchWindow window, EditorExtensionTestData data, bool wrap) { Document = doc; Content = content; Window = window; TestData = data; Wrap = wrap; }
protected async Task <TextEditorExtensionTestCase> SetupTestCase(string input, int cursorPosition = -1, bool wrap = false) { await Composition.CompositionManager.InitializeAsync(); var data = GetContentData(); var content = new TestViewContent { ContentName = data.FileName, Text = input, }; content.Data.MimeType = data.MimeType; if (cursorPosition != -1) { content.CursorPosition = cursorPosition; } var tww = new TestWorkbenchWindow { ViewContent = content, }; var project = Services.ProjectService.CreateDotNetProject(data.Language); project.Name = Path.GetFileNameWithoutExtension(data.ProjectFileName); project.FileName = data.ProjectFileName; project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile)); foreach (var reference in data.References) { project.References.Add(ProjectReference.CreateAssemblyReference(reference)); } var solution = new Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); content.Project = project; if (wrap && !IdeApp.IsInitialized) { IdeApp.Initialize(new ProgressMonitor()); } Document doc = wrap ? IdeApp.Workbench.WrapDocument(tww) : new Document(tww); doc.SetProject(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); foreach (var ext in GetEditorExtensions()) { ext.Initialize(doc.Editor, doc); content.Contents.Add(ext); } await doc.UpdateParseDocument(); return(new TextEditorExtensionTestCase(doc, content, tww, data, wrap)); }
public async static Task <TextEditorExtensionTestCase> Create(TestViewContent content, EditorExtensionTestData data, bool wrap) { var test = new TextEditorExtensionTestCase(); await test.Init(content, data, wrap); test.Document = await test.DocumentManager.OpenDocument(content); return(test); }
async Task Init(TestViewContent content, EditorExtensionTestData data, bool wrap) { //serviceProvider = ServiceHelper.SetupMockShell (); documentManager = await Runtime.GetService <DocumentManager> (); Content = content; TestData = data; Wrap = wrap; }
static async Task <CreateEditorResult> CreateEditor(string text, string extension) { string editorText; TestViewContent sev; string parsedText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var project = Services.ProjectService.CreateDotNetProject("C#"); project.References.Add(ProjectReference.CreateAssemblyReference("System")); project.References.Add(ProjectReference.CreateAssemblyReference("System.Web")); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(extension); project.AddFile(file); sev = new TestViewContent(); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow(); tww.ViewContent = sev; var doc = new TestDocument(tww); doc.Editor.FileName = sev.ContentName; var parser = new WebFormsParser(); var options = new ParseOptions { Project = project, FileName = sev.ContentName, Content = new StringTextSource(parsedText) }; var parsedDoc = await parser.Parse(options, default(CancellationToken)) as WebFormsParsedDocument; doc.HiddenParsedDocument = parsedDoc; return(new CreateEditorResult { Extension = new WebFormsTestingEditorExtension(doc), EditorText = editorText, ViewContent = sev }); }
async Task <Document> CreateDocument(string input) { var text = input; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } if (solution != null) { TypeSystemService.Unload(solution); solution.Dispose(); } var project = Services.ProjectService.CreateDotNetProject("C#"); project.Name = "test"; project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("mscorlib")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); project.References.Add(MonoDevelop.Projects.ProjectReference.CreateAssemblyReference("System.Core")); project.FileName = "test.csproj"; project.Files.Add(new ProjectFile("/a.cs", BuildAction.Compile)); solution = new MonoDevelop.Projects.Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); using (var monitor = new ProgressMonitor()) await TypeSystemService.Load(solution, monitor); var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; content.Project = project; content.Text = text; content.CursorPosition = Math.Max(0, endPos); var doc = new Document(tww); doc.SetProject(project); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); await doc.UpdateParseDocument(); return(doc); }
public void TestProjectionCompletion() { var editor = TextEditorFactory.CreateNewEditor(); var options = new CustomEditorOptions(editor.Options); options.EditorTheme = "Tango"; editor.Options = options; editor.Text = "12345678901234567890"; var projectedDocument = TextEditorFactory.CreateNewDocument( new StringTextSource("__12__34__56__78__90"), "a" ); var segments = new List <ProjectedSegment> (); for (int i = 0; i < 5; i++) { segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2)); } var projection = new Projection.Projection(projectedDocument, segments); var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; var originalContext = new Document(tww); var projectedEditor = projection.CreateProjectedEditor(originalContext); TestCompletionExtension orignalExtension; editor.SetExtensionChain(originalContext, new [] { orignalExtension = new TestCompletionExtension(editor) { CompletionWidget = new EmptyCompletionWidget(editor) } }); TestCompletionExtension projectedExtension; projectedEditor.SetExtensionChain(originalContext, new [] { projectedExtension = new TestCompletionExtension(editor) { CompletionWidget = new EmptyCompletionWidget(projectedEditor) } }); editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.None); editor.CaretOffset = 1; var service = new CommandManager(); service.LoadCommands("/MonoDevelop/Ide/Commands"); service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter); Assert.IsFalse(orignalExtension.CompletionRun); Assert.IsTrue(projectedExtension.CompletionRun); editor.CaretOffset = 15; CompletionWindowManager.HideWindow(); service.DispatchCommand(TextEditorCommands.ShowCompletionWindow, null, editor.CommandRouter); Assert.IsTrue(orignalExtension.CompletionRun); }
static async Task <CreateEditorResult> CreateEditor(string text, string extension) { string editorText; TestViewContent sev; string parsedText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var project = Services.ProjectService.CreateDotNetProject("C#"); project.References.Add(ProjectReference.CreateAssemblyReference("System")); project.References.Add(ProjectReference.CreateAssemblyReference("System.Web")); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(extension); project.AddFile(file); sev = new TestViewContent(); await sev.Initialize(new FileDescriptor (file, null, project), null); sev.Text = editorText; sev.CursorPosition = cursorPosition; var parser = new WebFormsParser(); var options = new ParseOptions { Project = project, FileName = file, Content = new StringTextSource(parsedText) }; sev.Editor.FileName = sev.FilePath; var parsedDoc = await parser.Parse(options, default(CancellationToken)) as WebFormsParsedDocument; var documentContext = sev.GetContent <RoslynDocumentContext> (); documentContext.SetParsedDocument(parsedDoc); return(new CreateEditorResult { Extension = new WebFormsTestingEditorExtension(sev.Editor, documentContext), EditorText = editorText, ViewContent = sev }); }
public CodeCompletionContext GetCodeCompletionContext(TestViewContent sev) { var ctx = new CodeCompletionContext { TriggerOffset = sev.CursorPosition }; sev.GetLineColumnFromPosition(ctx.TriggerOffset, out int line, out int column); ctx.TriggerLine = line; ctx.TriggerLineOffset = column - 1; return(ctx); }
static WebFormsTestingEditorExtension CreateEditor(string text, string extension, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var project = new AspNetAppProject("C#"); project.References.Add(new ProjectReference(ReferenceType.Package, "System")); project.References.Add(new ProjectReference(ReferenceType.Package, "System.Web")); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(extension); project.AddFile(file); var pcw = TypeSystemService.LoadProject(project); TypeSystemService.ForceUpdate(pcw); pcw.ReconnectAssemblyReferences(); sev = new TestViewContent(); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow(); tww.ViewContent = sev; var doc = new TestDocument(tww); doc.Editor.Document.FileName = sev.ContentName; var parser = new WebFormsParser(); var parsedDoc = (WebFormsParsedDocument)parser.Parse(false, sev.ContentName, new StringReader(parsedText), project); doc.HiddenParsedDocument = parsedDoc; return(new WebFormsTestingEditorExtension(doc)); }
protected async Task <TextEditorExtensionTestCase> SetupTestCase(string input, int cursorPosition = -1, bool wrap = false) { await Runtime.GetService <CompositionManager> (); var data = GetContentData(); var content = new TestViewContent(); await content.Initialize(new FileDescriptor (data.FileName, null, null)); content.Text = input; content.Editor.MimeType = data.MimeType; if (cursorPosition != -1) { content.CursorPosition = cursorPosition; } var project = Services.ProjectService.CreateDotNetProject(data.Language); project.Name = Path.GetFileNameWithoutExtension(data.ProjectFileName); project.FileName = data.ProjectFileName; project.Files.Add(new ProjectFile(content.FilePath, BuildAction.Compile)); foreach (var reference in data.References) { project.References.Add(ProjectReference.CreateAssemblyReference(reference)); } var solution = new Solution(); solution.AddConfiguration("", true); solution.DefaultSolutionFolder.AddItem(project); content.Owner = project; using (var monitor = new ProgressMonitor()) await IdeApp.TypeSystemService.Load(solution, monitor); var testCase = await TextEditorExtensionTestCase.Create(content, data, wrap); var doc = testCase.Document; foreach (var ext in GetEditorExtensions()) { ext.Initialize(doc.Editor, doc.DocumentContext); content.AddContent(ext); } await doc.DocumentContext.UpdateParseDocument(); return(testCase); }
static RazorTestingEditorExtension CreateEditor(string text, bool isInCSharpContext, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var project = new AspMvc3Project("C#"); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(extension); project.AddFile(file); var pcw = TypeSystemService.LoadProject(project); TypeSystemService.ForceUpdate(pcw); pcw.ReloadAssemblyReferences(project); sev = new TestViewContent(); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow(); tww.ViewContent = sev; var doc = new Document(tww); var parser = new RazorTestingParser() { Doc = doc }; var parsedDoc = parser.Parse(false, sev.ContentName, new StringReader(parsedText), project); return(new RazorTestingEditorExtension(doc, parsedDoc as RazorCSharpParsedDocument, isInCSharpContext)); }
static async Task <Tuple <CSharpCompletionTextEditorExtension, TestViewContent> > Setup(string input) { TestWorkbenchWindow tww = new TestWorkbenchWindow(); TestViewContent content = new TestViewContent(); tww.ViewContent = content; content.ContentName = "/a.cs"; content.Data.MimeType = "text/x-csharp"; var doc = new MonoDevelop.Ide.Gui.Document(tww); var text = input; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } content.Text = text; content.CursorPosition = System.Math.Max(0, endPos); var project = Services.ProjectService.CreateProject("C#"); project.Name = "test"; project.FileName = "test.csproj"; project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile)); project.Policies.Set(PolicyService.InvariantPolicies.Get <CSharpFormattingPolicy> (), CSharpFormatter.MimeType); 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 compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc.Editor, doc); content.Contents.Add(compExt); await doc.UpdateParseDocument(); TypeSystemService.Unload(solution); return(Tuple.Create(compExt, content)); }
static Document Setup(string input) { var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); var project = new DotNetAssemblyProject("C#"); project.Name = "test"; project.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")); project.References.Add(new ProjectReference(ReferenceType.Package, "System.Core")); project.FileName = "test.csproj"; var wrapper = TypeSystemService.LoadProject(project); wrapper.EnsureReferencesAreLoaded(); wrapper.ReconnectAssemblyReferences(); content.Project = project; tww.ViewContent = content; content.ContentName = "a.cs"; content.GetTextEditorData().Document.MimeType = "text/x-csharp"; var doc = new Document(tww); var text = input; int endPos = text.IndexOf('$'); if (endPos >= 0) { text = text.Substring(0, endPos) + text.Substring(endPos + 1); } content.Text = text; content.CursorPosition = Math.Max(0, endPos); var compExt = new CSharpCompletionTextEditorExtension(); compExt.Initialize(doc); content.Contents.Add(compExt); doc.UpdateParseDocument(); return(doc); }
static CodeCompletionContext GetCodeCompletionContext(bool cSharpContext, TestViewContent sev, UnderlyingDocument underlyingDocument) { var ctx = new CodeCompletionContext(); if (!cSharpContext) { ctx.TriggerOffset = sev.CursorPosition; } else { ctx.TriggerOffset = underlyingDocument.Editor.CaretOffset; } int line, column; sev.GetLineColumnFromPosition(ctx.TriggerOffset, out line, out column); ctx.TriggerLine = line; ctx.TriggerLineOffset = column - 1; return(ctx); }
public async Task TestVSTS615849() { DefaultSourceEditorOptions.Instance.AutoInsertMatchingBracket = true; var content = new TestViewContent(); await content.Initialize(new FileDescriptor ("foo.xml", null, null)); using (var testCase = await TextEditorExtensionTestCase.Create(content, null, false)) { var document = testCase.Document; var editor = content.Editor; editor.MimeType = "text/xml"; const string originalText = @""; editor.Text = originalText; var extensibleEditor = editor.GetContent <SourceEditorView> ().TextEditor; extensibleEditor.OnIMProcessedKeyPressEvent((Gdk.Key) '"', '"', Gdk.ModifierType.None); extensibleEditor.OnIMProcessedKeyPressEvent(Gdk.Key.Right, '\0', Gdk.ModifierType.None); extensibleEditor.OnIMProcessedKeyPressEvent(Gdk.Key.BackSpace, '\0', Gdk.ModifierType.None); Assert.AreEqual("\"", editor.Text); } }
public void TestProjectionUpdate() { var editor = TextEditorFactory.CreateNewEditor(); editor.Text = "1234567890"; var projectedDocument = TextEditorFactory.CreateNewDocument( new StringTextSource("__12__34__56__78__90"), "a" ); var segments = new List <ProjectedSegment> (); for (int i = 0; i < 5; i++) { segments.Add(new ProjectedSegment(i * 2, 2 + i * 4, 2)); } var projection = new Projection.Projection(projectedDocument, segments); var tww = new TestWorkbenchWindow(); var content = new TestViewContent(); tww.ViewContent = content; var originalContext = new Document(tww); using (var testCase = new TextEditorExtensionTestCase(originalContext, content, tww, null, false)) { var projectedEditor = projection.CreateProjectedEditor(originalContext); editor.SetOrUpdateProjections(originalContext, new [] { projection }, TypeSystem.DisabledProjectionFeatures.All); editor.InsertText(1, "foo"); Assert.AreEqual("__1foo2__34__56__78__90", projectedEditor.Text); Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(0).ProjectedOffset); Assert.AreEqual(2 + "foo".Length, projection.ProjectedSegments.ElementAt(0).Length); for (int i = 1; i < 5; i++) { Assert.AreEqual(2 + i * 4 + "foo".Length, projection.ProjectedSegments.ElementAt(i).ProjectedOffset); Assert.AreEqual(2, projection.ProjectedSegments.ElementAt(i).Length); } } }