Esempio n. 1
0
 public TextStylePolicy(int fileWidth, int tabWidth, bool tabsToSpaces, bool noTabsAfterNonTabs, bool removeTrailingWhitespace, EolMarker eolMarker)
 {
     FileWidth                = fileWidth;
     TabWidth                 = tabWidth;
     TabsToSpaces             = tabsToSpaces;
     NoTabsAfterNonTabs       = noTabsAfterNonTabs;
     RemoveTrailingWhitespace = removeTrailingWhitespace;
     EolMarker                = eolMarker;
 }
Esempio n. 2
0
 public TextStylePolicy WithEolMarker(EolMarker eolMarker)
 {
     if (eolMarker == EolMarker)
     {
         return(this);
     }
     return(new TextStylePolicy(this)
     {
         EolMarker = eolMarker
     });
 }
Esempio n. 3
0
        public static string GetEolMarker(EolMarker eolMarker)
        {
            switch (eolMarker)
            {
            case EolMarker.Mac:
                return("\r");

            case EolMarker.Unix:
                return("\n");

            case EolMarker.Windows:
                return("\r\n");
            }
            return(Environment.NewLine);
        }
        static async Task Simulate(string input, Action <TestViewContent, EditorFormattingServiceTextEditorExtension> act, CSharpFormattingPolicy formattingPolicy = null, EolMarker eolMarker = EolMarker.Unix)
        {
            TestWorkbenchWindow tww = new TestWorkbenchWindow();
            var content             = new TestViewContent();

            content.Data.Options = new CustomEditorOptions {
                IndentStyle = IndentStyle.Auto
            };

            tww.ViewContent       = content;
            content.ContentName   = "/a.cs";
            content.Data.MimeType = "text/x-csharp";

            var doc = new Document(tww);

            var sb = new StringBuilder();
            int cursorPosition = 0, selectionStart = -1, selectionEnd = -1;

            for (int i = 0; i < input.Length; i++)
            {
                var ch = input [i];
                switch (ch)
                {
                case '$':
                    cursorPosition = sb.Length;
                    break;

                case '<':
                    if (i + 1 < input.Length)
                    {
                        if (input [i + 1] == '-')
                        {
                            selectionStart = sb.Length;
                            i++;
                            break;
                        }
                    }
                    goto default;

                case '-':
                    if (i + 1 < input.Length)
                    {
                        var next = input [i + 1];
                        if (next == '>')
                        {
                            selectionEnd = sb.Length;
                            i++;
                            break;
                        }
                    }
                    goto default;

                default:
                    sb.Append(ch);
                    break;
                }
            }
            content.Text           = sb.ToString();
            content.CursorPosition = cursorPosition;

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

            project.Name     = "test";
            project.FileName = "test.csproj";
            project.Files.Add(new ProjectFile(content.ContentName, BuildAction.Compile));
            var textStylePolicy = Projects.Policies.PolicyService.InvariantPolicies.Get <TextStylePolicy> ().WithTabsToSpaces(false)
                                  .WithEolMarker(eolMarker);

            project.Policies.Set(textStylePolicy, content.Data.MimeType);
            project.Policies.Set(formattingPolicy ?? Projects.Policies.PolicyService.InvariantPolicies.Get <CSharpFormattingPolicy> (), content.Data.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);

            var ext = new EditorFormattingServiceTextEditorExtension();

            ext.Initialize(doc.Editor, doc);
            content.Contents.Add(ext);

            await doc.UpdateParseDocument();

            if (selectionStart >= 0 && selectionEnd >= 0)
            {
                content.GetTextEditorData().SetSelection(selectionStart, selectionEnd);
            }

            using (var testCase = new Ide.TextEditorExtensionTestCase(doc, content, tww, null, false)) {
                act(content, ext);
            }
        }