Example #1
0
        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 override void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, Gdk.Key closeChar, char keyChar, Gdk.ModifierType modifier)
        {
            if (customCompletionText == null)
            {
                if (Node != null && !string.IsNullOrEmpty(Node.Name))
                {
                    base.InsertCompletionText(window, ref ka, closeChar, keyChar, modifier);
                }
                return;
            }

            Ide.Gui.Document guiDoc = null;
            var ed = window.CompletionWidget as SourceEditor.SourceEditorView;

            foreach (var gdoc in Ide.IdeApp.Workbench.Documents)
            {
                if (gdoc.Editor.Document == ed.Document)
                {
                    guiDoc = gdoc;
                    break;
                }
            }

            if (guiDoc == null)
            {
                return;
            }

            var f = new Formatting.DCodeFormatter();
            var insertionOffset = window.CodeCompletionContext.TriggerOffset;

            ed.Document.Insert(insertionOffset, customCompletionText, ICSharpCode.NRefactory.Editor.AnchorMovementType.AfterInsertion);

            guiDoc.UpdateParseDocument();

            f.OnTheFlyFormat(guiDoc, insertionOffset, insertionOffset + customCompletionText.Length);
        }