Example #1
0
        public async Task ConfigurationsInNewProject()
        {
            string dir = Util.CreateTmpDir("ConfigurationsInNewProject");

            var sol = new Solution();

            sol.FileName = Path.Combine(dir, "TestSolution.sln");
            sol.AddConfiguration("Debug", true);

            var p = Services.ProjectService.CreateDotNetProject("C#");

            p.ItemId   = "{3A83F683-760F-486C-8844-B0F079B30B25}";
            p.FileName = Path.Combine(dir, "TestProject.csproj");
            sol.RootFolder.Items.Add(p);

            Assert.AreEqual(1, p.RunConfigurations.Count);
            var es = p.RunConfigurations [0];

            Assert.AreEqual("Default", es.Name);

            await sol.SaveAsync(Util.GetMonitor());

            Assert.IsFalse(File.Exists(p.FileName + ".user"));

            string projectXml    = File.ReadAllText(p.FileName);
            string projFile      = Util.GetSampleProject("run-configurations", "ConsoleProject", "ConsoleProject.new-project.csproj");
            string newProjectXml = File.ReadAllText(projFile);

            Assert.AreEqual(Util.ToWindowsEndings(newProjectXml), projectXml);

            sol.Dispose();
        }
Example #2
0
        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);
        }
Example #4
0
        static Solution WrapSolutionItem(SolutionItem item)
        {
            var sol    = new Solution();
            var config = sol.AddConfiguration("Debug", true);

            sol.RootFolder.Items.Add(item);
            config.GetEntryForItem(item).Build = true;
            return(sol);
        }
Example #5
0
        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 static Solution CreateConsoleSolution(string hint)
        {
            string dir = Util.CreateTmpDir(hint);

            Solution sol = new Solution();
            SolutionConfiguration scDebug = sol.AddConfiguration("Debug", true);

            DotNetAssemblyProject project = new DotNetAssemblyProject("C#");

            sol.RootFolder.Items.Add(project);
            Assert.AreEqual(0, project.Configurations.Count);

            InitializeProject(dir, project, "TestProject");
            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.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project.References.Add(new ProjectReference(ReferenceType.Package, "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Main.cs")));
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Resource.xml"), BuildAction.EmbeddedResource));
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Excluded.xml"), BuildAction.Content));
            ProjectFile pf = new ProjectFile(Path.Combine(dir, "Copy.xml"), BuildAction.Content);

            pf.CopyToOutputDirectory = FileCopyMode.Always;
            project.Files.Add(pf);
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Nothing.xml"), BuildAction.None));

            Assert.IsFalse(scDebug.GetEntryForItem(project).Build);
            scDebug.GetEntryForItem(project).Build = true;

            SolutionConfiguration scRelease = sol.AddConfiguration("Release", true);

            string file = Path.Combine(dir, "TestSolution.sln");

            sol.FileName = file;

            Assert.AreEqual(2, sol.Configurations.Count);
            Assert.AreEqual(1, scDebug.Configurations.Count);
            Assert.AreEqual(1, scRelease.Configurations.Count);
            Assert.AreEqual(2, project.Configurations.Count);

            return(sol);
        }
        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));
        }
		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);

			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;
		}
Example #9
0
        static async Task <List <SearchResult> > GatherReferences(string input, Func <MonoDevelop.Projects.Project, Task <IEnumerable <SearchResult> > > findRefsCallback)
        {
            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;

            content.Text = text;

            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);

            await doc.UpdateParseDocument();

            try {
                return((await findRefsCallback(project)).ToList());
            } finally {
                TypeSystemService.Unload(solution);
            }
        }
        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);
            }
        }
Example #11
0
        public void Configurations()
        {
            int configChangedEvs    = 0;
            int configChangedEvsSub = 0;

            Workspace ws = new Workspace();

            ws.ConfigurationsChanged += delegate { configChangedEvs++; };

            Workspace cws1 = new Workspace();

            cws1.ConfigurationsChanged += delegate { configChangedEvsSub++; };
            ws.Items.Add(cws1);

            Solution sol = new Solution();

            cws1.Items.Add(sol);

            ReadOnlyCollection <string> configs = ws.GetConfigurations();

            Assert.AreEqual(0, configs.Count);
            configs = cws1.GetConfigurations();
            Assert.AreEqual(0, configs.Count);

            // Add configurations

            configChangedEvs = configChangedEvsSub = 0;
            sol.AddConfiguration("c1", false);
            Assert.AreEqual(1, configChangedEvs);
            Assert.AreEqual(1, configChangedEvsSub);

            configs = ws.GetConfigurations();
            Assert.AreEqual(1, configs.Count);
            Assert.AreEqual("c1", configs[0]);
            configs = cws1.GetConfigurations();
            Assert.AreEqual(1, configs.Count);
            Assert.AreEqual("c1", configs[0]);

            configChangedEvs = configChangedEvsSub = 0;
            sol.AddConfiguration("c2", false);
            Assert.AreEqual(1, configChangedEvs);
            Assert.AreEqual(1, configChangedEvsSub);

            configs = ws.GetConfigurations();
            Assert.AreEqual(2, configs.Count);
            Assert.AreEqual("c1", configs[0]);
            Assert.AreEqual("c2", configs[1]);
            configs = cws1.GetConfigurations();
            Assert.AreEqual(2, configs.Count);
            Assert.AreEqual("c1", configs[0]);
            Assert.AreEqual("c2", configs[1]);

            // Add another solution

            Solution sol2 = new Solution();

            sol2.AddConfiguration("c3", false);
            sol2.AddConfiguration("c4", false);

            configChangedEvs = configChangedEvsSub = 0;
            cws1.Items.Add(sol2);
            Assert.AreEqual(1, configChangedEvs);
            Assert.AreEqual(1, configChangedEvsSub);

            configs = ws.GetConfigurations();
            Assert.AreEqual(4, configs.Count);
            Assert.AreEqual("c1", configs[0]);
            Assert.AreEqual("c2", configs[1]);
            Assert.AreEqual("c3", configs[2]);
            Assert.AreEqual("c4", configs[3]);
            configs = cws1.GetConfigurations();
            Assert.AreEqual(4, configs.Count);
            Assert.AreEqual("c1", configs[0]);
            Assert.AreEqual("c2", configs[1]);
            Assert.AreEqual("c3", configs[2]);
            Assert.AreEqual("c4", configs[3]);

            // Remove solution

            configChangedEvs = configChangedEvsSub = 0;
            cws1.Items.Remove(sol2);
            Assert.AreEqual(1, configChangedEvs);
            Assert.AreEqual(1, configChangedEvsSub);

            configs = ws.GetConfigurations();
            Assert.AreEqual(2, configs.Count);
            Assert.AreEqual("c1", configs[0]);
            Assert.AreEqual("c2", configs[1]);
            configs = cws1.GetConfigurations();
            Assert.AreEqual(2, configs.Count);
            Assert.AreEqual("c1", configs[0]);
            Assert.AreEqual("c2", configs[1]);

            // Remove configuration

            configChangedEvs = configChangedEvsSub = 0;
            sol.Configurations.RemoveAt(1);
            Assert.AreEqual(1, configChangedEvs);
            Assert.AreEqual(1, configChangedEvsSub);

            configs = ws.GetConfigurations();
            Assert.AreEqual(1, configs.Count);
            Assert.AreEqual("c1", configs[0]);
            configs = cws1.GetConfigurations();
            Assert.AreEqual(1, configs.Count);
            Assert.AreEqual("c1", configs[0]);

            // Remove child workspace

            configChangedEvs = configChangedEvsSub = 0;
            ws.Items.Remove(cws1);
            Assert.AreEqual(1, configChangedEvs);

            configs = ws.GetConfigurations();
            Assert.AreEqual(0, configs.Count);
        }
		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);
		}
        public static Solution CreateConsoleSolution(string hint)
        {
            string dir = Util.CreateTmpDir(hint);

            Solution sol = new Solution();
            SolutionConfiguration scDebug = sol.AddConfiguration("Debug", true);

            DotNetProject project = Services.ProjectService.CreateDotNetProject("C#");

            sol.RootFolder.Items.Add(project);
            Assert.AreEqual(0, project.Configurations.Count);

            InitializeProject(dir, project, "TestProject");
            project.References.Add(ProjectReference.CreateAssemblyReference("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project.References.Add(ProjectReference.CreateAssemblyReference("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project.References.Add(ProjectReference.CreateAssemblyReference("System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Program.cs")));
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Resource.xml"), BuildAction.EmbeddedResource));
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Excluded.xml"), BuildAction.Content));
            ProjectFile pf = new ProjectFile(Path.Combine(dir, "Copy.xml"), BuildAction.Content);

            pf.CopyToOutputDirectory = FileCopyMode.Always;
            project.Files.Add(pf);
            project.Files.Add(new ProjectFile(Path.Combine(dir, "Nothing.xml"), BuildAction.None));

            Assert.IsFalse(scDebug.GetEntryForItem(project).Build);
            scDebug.GetEntryForItem(project).Build = true;

            SolutionConfiguration scRelease = sol.AddConfiguration("Release", true);

            string file = Path.Combine(dir, "TestSolution.sln");

            sol.FileName = file;

            Assert.AreEqual(2, sol.Configurations.Count);
            Assert.AreEqual(1, scDebug.Configurations.Count);
            Assert.AreEqual(1, scRelease.Configurations.Count);
            Assert.AreEqual(2, project.Configurations.Count);
            foreach (var v in project.Files)
            {
                if (v.FilePath.FileName == "Program.cs")
                {
                    File.WriteAllText(v.FilePath,
                                      @"
using System;

namespace Foo {
	public class MainClass {
		public static void Main (string [] args)
		{
		}
	}
}");
                }
                else
                {
                    File.WriteAllText(v.FilePath, v.Name);
                }
            }
            return(sol);
        }
Example #14
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);
        }
        public static Solution CreateProjectWithFolders(string hint)
        {
            string dir = Util.CreateTmpDir(hint);

            Directory.CreateDirectory(Util.Combine(dir, "console-project"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution1"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution1", "library1"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution1", "library2"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2", "console-project2"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2", "nested-solution3"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2", "nested-solution3", "library3"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2", "nested-solution3", "library4"));

            Solution sol = new Solution();

            sol.FileName = Path.Combine(dir, "nested-solutions-mdp");
            SolutionConfiguration scDebug   = sol.AddConfiguration("Debug", true);
            SolutionConfiguration scRelease = sol.AddConfiguration("Release", true);

            DotNetProject project1 = CreateProject(Util.Combine(dir, "console-project"), "C#", "console-project");

            project1.Files.Add(new ProjectFile(Path.Combine(project1.BaseDirectory, "Main.cs")));
            project1.Files.Add(new ProjectFile(Path.Combine(project1.BaseDirectory, "AssemblyInfo.cs")));
            sol.RootFolder.Items.Add(project1);

            // nested-solution1

            SolutionFolder folder1 = new SolutionFolder();

            sol.RootFolder.Items.Add(folder1);
            folder1.Name = "nested-solution1";

            DotNetProject projectLib1 = CreateProject(Util.Combine(dir, "nested-solution1", "library1"), "C#", "library1");

            projectLib1.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            projectLib1.Files.Add(new ProjectFile(Path.Combine(projectLib1.BaseDirectory, "MyClass.cs")));
            projectLib1.Files.Add(new ProjectFile(Path.Combine(projectLib1.BaseDirectory, "AssemblyInfo.cs")));
            projectLib1.CompileTarget = CompileTarget.Library;
            folder1.Items.Add(projectLib1);

            DotNetProject projectLib2 = CreateProject(Util.Combine(dir, "nested-solution1", "library2"), "C#", "library2");

            projectLib2.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            projectLib2.Files.Add(new ProjectFile(Path.Combine(projectLib2.BaseDirectory, "MyClass.cs")));
            projectLib2.Files.Add(new ProjectFile(Path.Combine(projectLib2.BaseDirectory, "AssemblyInfo.cs")));
            projectLib2.CompileTarget = CompileTarget.Library;
            folder1.Items.Add(projectLib2);

            // nested-solution2

            SolutionFolder folder2 = new SolutionFolder();

            folder2.Name = "nested-solution2";
            sol.RootFolder.Items.Add(folder2);

            DotNetProject project2 = CreateProject(Util.Combine(dir, "nested-solution2", "console-project2"), "C#", "console-project2");

            project2.Files.Add(new ProjectFile(Path.Combine(project2.BaseDirectory, "Main.cs")));
            project2.Files.Add(new ProjectFile(Path.Combine(project2.BaseDirectory, "AssemblyInfo.cs")));
            project2.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));

            // nested-solution3

            SolutionFolder folder3 = new SolutionFolder();

            folder3.Name = "nested-solution3";

            DotNetProject projectLib3 = CreateProject(Util.Combine(dir, "nested-solution2", "nested-solution3", "library3"), "C#", "library3");

            projectLib3.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            projectLib3.Files.Add(new ProjectFile(Path.Combine(projectLib3.BaseDirectory, "MyClass.cs")));
            projectLib3.Files.Add(new ProjectFile(Path.Combine(projectLib3.BaseDirectory, "AssemblyInfo.cs")));
            projectLib3.CompileTarget = CompileTarget.Library;
            folder3.Items.Add(projectLib3);

            DotNetProject projectLib4 = CreateProject(Util.Combine(dir, "nested-solution2", "nested-solution3", "library4"), "C#", "library4");

            projectLib4.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            projectLib4.Files.Add(new ProjectFile(Path.Combine(projectLib4.BaseDirectory, "MyClass.cs")));
            projectLib4.Files.Add(new ProjectFile(Path.Combine(projectLib4.BaseDirectory, "AssemblyInfo.cs")));
            projectLib4.CompileTarget = CompileTarget.Library;
            folder3.Items.Add(projectLib4);

            folder2.Items.Add(folder3);
            folder2.Items.Add(project2);

            string file = Path.Combine(dir, "TestSolution.sln");

            sol.FileName = file;

            project1.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project1.References.Add(new ProjectReference(projectLib1));
            project1.References.Add(new ProjectReference(projectLib2));
            project1.References.Add(new ProjectReference(projectLib3));
            project1.References.Add(new ProjectReference(projectLib4));

            project2.References.Add(new ProjectReference(projectLib3));
            project2.References.Add(new ProjectReference(projectLib4));

            Assert.AreEqual(2, sol.Configurations.Count);
            Assert.AreEqual(6, scDebug.Configurations.Count);
            Assert.AreEqual(6, scRelease.Configurations.Count);

            return(sol);
        }
		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);

		}
Example #17
0
        private static async Task CheckAutoBracket(string mid, string expected)
        {
            var prefix = @"
class FooBar
{
	public static void Main (string[] args)
	{
		Console.WriteLine ("        ;


            var suffix = ");\n\t}\n}\n";

            var text = prefix + mid + "@" + suffix;

            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  handler = new CSharpAutoInsertBracketHandler();
            char ch      = mid [mid.Length - 1];

            handler.Handle(doc.Editor, doc, Ide.Editor.Extension.KeyDescriptor.FromGtk((Gdk.Key)ch, ch, Gdk.ModifierType.None));
            var newText = doc.Editor.GetTextAt(prefix.Length, doc.Editor.Length - prefix.Length - suffix.Length);

            Assert.AreEqual(expected, newText);

            project.Dispose();
        }
		static async Task Simulate (string input, Action<TestViewContent, CSharpTextEditorIndentation> act)
		{
			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)); 
			project.Policies.Set (Projects.Policies.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);
			
			var ext = new CSharpTextEditorIndentation ();
			CSharpTextEditorIndentation.OnTheFlyFormatting = true;
			ext.Initialize (doc.Editor, doc);
			content.Contents.Add (ext);
			
			await doc.UpdateParseDocument ();
			if (selectionStart >= 0 && selectionEnd >= 0)
				content.GetTextEditorData ().SetSelection (selectionStart, selectionEnd);
			try {
				act (content, ext);
			} finally {
				TypeSystemService.Unload (solution);
			}
		}