public Solution (IExtendedPackageManagementProjectService projectService) { this.projectService = projectService; this.solution = projectService.OpenSolution; this.Projects = new Projects (projectService); // this.Globals = new SolutionGlobals (this); // this.SolutionBuild = new SolutionBuild (this, projectService.ProjectBuilder); CreateProperties (); }
internal SolutionId GetSolutionId(MonoDevelop.Projects.Solution solution) { if (solution == null) { throw new ArgumentNullException(nameof(solution)); } lock (solutionIdMap) { if (!solutionIdMap.TryGetValue(solution, out SolutionId result)) { solutionIdMap [solution] = result = SolutionId.CreateNewId(solution.Name); } return(result); } }
public static MonoDevelopWorkspace GetWorkspace(MonoDevelop.Projects.Solution solution) { if (solution == null) { throw new ArgumentNullException(nameof(solution)); } foreach (var ws in workspaces) { if (ws.MonoDevelopSolution == solution) { return(ws); } } return(emptyWorkspace); }
public Microsoft.CodeAnalysis.Workspace GetWorkspaceInternal(MonoDevelop.Projects.Solution solution) { if (solution == null) { return(miscellaneousFilesWorkspace); } foreach (var ws in workspaces) { if (ws.MonoDevelopSolution == solution) { return(ws); } } return(emptyWorkspace); }
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; }
bool IsModifiedWhileLoading(MonoDevelop.Projects.Solution solution) { List <MonoDevelop.Projects.DotNetProject> modifiedWhileLoading; lock (workspace.projectModifyLock) { modifiedWhileLoading = workspace.modifiedProjects; workspace.modifiedProjects = new List <MonoDevelop.Projects.DotNetProject> (); } foreach (var project in modifiedWhileLoading) { // TODO: Maybe optimize this so we don't do O(n^2) if (solution.ContainsItem(project)) { return(true); } } return(false); }
static DnxProject FindProjectByProjectJsonFileName(string fileName) { Solution solution = IdeApp.ProjectOperations.CurrentSelectedSolution; if (solution == null) { return(null); } DnxProject project = solution.FindProjectByProjectJsonFileName(fileName); if (project != null) { return(project); } LoggingService.LogWarning(String.Format("Unable to find project by json file. '{0}'", fileName)); return(null); }
void FileChanged(object sender, FileEventArgs e) { Solution solution = IdeApp.ProjectOperations.CurrentSelectedSolution; if (solution == null) { return; } if (!solution.HasDnxProjects()) { return; } if (!IsGlobalJsonFileChanged(e)) { return; } OnSolutionLoaded(solution); }
void LoadDnxProjectSystem(Solution solution) { UnloadProjectSystem(); applicationLifetime = new MonoDevelopApplicationLifetime(); context = new DnxContext(); var factory = new DnxProjectSystemFactory(); projectSystem = factory.CreateProjectSystem(solution, applicationLifetime, context); try { projectSystem.Initalize(); } catch (Win32Exception ex) { if (ex.NativeErrorCode == 2) { throw new DotNetCoreNotFoundException(); } else { throw; } } }
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); } }
public static async Task <MonoDevelopWorkspace> GetWorkspaceAsync(MonoDevelop.Projects.Solution solution, CancellationToken cancellationToken = default(CancellationToken)) { var workspace = GetWorkspace(solution); if (workspace != emptyWorkspace) { return(workspace); } var tcs = workspaceRequests.GetOrAdd(solution, _ => new TaskCompletionSource <MonoDevelopWorkspace> ()); try { workspace = GetWorkspace(solution); if (workspace != emptyWorkspace) { return(workspace); } cancellationToken.ThrowIfCancellationRequested(); cancellationToken.Register(() => tcs.TrySetCanceled()); workspace = await tcs.Task; } finally { workspaceRequests.TryRemove(solution, out tcs); } return(workspace); }
public static void TestLoadSaveSolutionFolders(string fileFormat) { List <string> ids = new List <string> (); Solution sol = new Solution(); sol.ConvertToFormat(Services.ProjectService.FileFormats.GetFileFormat(fileFormat), true); string dir = Util.CreateTmpDir("solution-folders-" + fileFormat); sol.FileName = Path.Combine(dir, "TestSolutionFolders"); sol.Name = "TheSolution"; DotNetAssemblyProject p1 = new DotNetAssemblyProject("C#"); p1.FileName = Path.Combine(dir, "p1"); sol.RootFolder.Items.Add(p1); string idp1 = p1.ItemId; Assert.IsFalse(string.IsNullOrEmpty(idp1)); Assert.IsFalse(ids.Contains(idp1)); ids.Add(idp1); SolutionFolder f1 = new SolutionFolder(); f1.Name = "f1"; sol.RootFolder.Items.Add(f1); string idf1 = f1.ItemId; Assert.IsFalse(string.IsNullOrEmpty(idf1)); Assert.IsFalse(ids.Contains(idf1)); ids.Add(idf1); DotNetAssemblyProject p2 = new DotNetAssemblyProject("C#"); p2.FileName = Path.Combine(dir, "p2"); f1.Items.Add(p2); string idp2 = p2.ItemId; Assert.IsFalse(string.IsNullOrEmpty(idp2)); Assert.IsFalse(ids.Contains(idp2)); ids.Add(idp2); SolutionFolder f2 = new SolutionFolder(); f2.Name = "f2"; f1.Items.Add(f2); string idf2 = f2.ItemId; Assert.IsFalse(string.IsNullOrEmpty(idf2)); Assert.IsFalse(ids.Contains(idf2)); ids.Add(idf2); DotNetAssemblyProject p3 = new DotNetAssemblyProject("C#"); p3.FileName = Path.Combine(dir, "p3"); f2.Items.Add(p3); string idp3 = p3.ItemId; Assert.IsFalse(string.IsNullOrEmpty(idp3)); Assert.IsFalse(ids.Contains(idp3)); ids.Add(idp3); DotNetAssemblyProject p4 = new DotNetAssemblyProject("C#"); p4.FileName = Path.Combine(dir, "p4"); f2.Items.Add(p4); string idp4 = p4.ItemId; Assert.IsFalse(string.IsNullOrEmpty(idp4)); Assert.IsFalse(ids.Contains(idp4)); ids.Add(idp4); sol.Save(Util.GetMonitor()); Solution sol2 = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), sol.FileName); Assert.AreEqual(4, sol2.Items.Count); Assert.AreEqual(2, sol2.RootFolder.Items.Count); Assert.AreEqual(typeof(DotNetAssemblyProject), sol2.RootFolder.Items [0].GetType()); Assert.AreEqual(typeof(SolutionFolder), sol2.RootFolder.Items [1].GetType()); Assert.AreEqual("p1", sol2.RootFolder.Items [0].Name); Assert.AreEqual("f1", sol2.RootFolder.Items [1].Name); Assert.AreEqual(idp1, sol2.RootFolder.Items [0].ItemId, "idp1"); Assert.AreEqual(idf1, sol2.RootFolder.Items [1].ItemId, "idf1"); f1 = (SolutionFolder)sol2.RootFolder.Items [1]; Assert.AreEqual(2, f1.Items.Count); Assert.AreEqual(typeof(DotNetAssemblyProject), f1.Items [0].GetType()); Assert.AreEqual(typeof(SolutionFolder), f1.Items [1].GetType()); Assert.AreEqual("p2", f1.Items [0].Name); Assert.AreEqual("f2", f1.Items [1].Name); Assert.AreEqual(idp2, f1.Items [0].ItemId, "idp2"); Assert.AreEqual(idf2, f1.Items [1].ItemId, "idf2"); f2 = (SolutionFolder)f1.Items [1]; Assert.AreEqual(2, f2.Items.Count); Assert.AreEqual(typeof(DotNetAssemblyProject), f2.Items [0].GetType()); Assert.AreEqual(typeof(DotNetAssemblyProject), f2.Items [1].GetType()); Assert.AreEqual("p3", f2.Items [0].Name); Assert.AreEqual("p4", f2.Items [1].Name); Assert.AreEqual(idp3, f2.Items [0].ItemId, "idp4"); Assert.AreEqual(idp4, f2.Items [1].ItemId, "idp4"); }
static async Task TestCompletion(string text, Action <ICompletionDataList> action, CompletionTriggerInfo triggerInfo) { DesktopService.Initialize(); 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); compExt.CurrentCompletionContext = new CodeCompletionContext { TriggerOffset = content.CursorPosition, TriggerWordLength = 1 }; content.Contents.Add(compExt); await doc.UpdateParseDocument(); var tmp = IdeApp.Preferences.EnableAutoCodeCompletion; IdeApp.Preferences.EnableAutoCodeCompletion.Set(false); var list = await compExt.HandleCodeCompletionAsync(compExt.CurrentCompletionContext, triggerInfo); try { action(list); } finally { IdeApp.Preferences.EnableAutoCodeCompletion.Set(tmp); project.Dispose(); } }
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); } }
internal Task <(MonoDevelop.Projects.Solution, SolutionInfo)> CreateSolutionInfoFromCache(MonoDevelop.Projects.Solution sol, CancellationToken ct) { return(Task.Run(delegate { return CreateSolutionInfoFromCacheInternal(sol, ct); })); async Task <(MonoDevelop.Projects.Solution, SolutionInfo)> CreateSolutionInfoFromCacheInternal(MonoDevelop.Projects.Solution solution, CancellationToken token) { projections.ClearOldProjectionList(); solutionData = new SolutionData(); workspaceCache.Load(solution); var projectInfos = await CreateProjectInfosFromCache(solution.GetAllProjects(), token).ConfigureAwait(false); if (projectInfos == null) { return(solution, null); } if (token.IsCancellationRequested) { return(solution, null); } var solutionId = GetSolutionId(solution); var solutionInfo = SolutionInfo.Create(solutionId, VersionStamp.Create(), solution.FileName, projectInfos); lock (addLock) { if (!added) { added = true; OnSolutionOpened(workspace, solutionInfo); } } // Clear modified projects during load. The projects will be loaded later. lock (workspace.projectModifyLock) { workspace.modifiedProjects.RemoveAll(p => p.ParentSolution == solution); } return(solution, solutionInfo); } }
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); } }
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(); }
internal Task <(MonoDevelop.Projects.Solution, SolutionInfo)> CreateSolutionInfo(MonoDevelop.Projects.Solution sol, CancellationToken ct) { return(Task.Run(delegate { return CreateSolutionInfoInternal(sol, ct); })); async Task <(MonoDevelop.Projects.Solution, SolutionInfo)> CreateSolutionInfoInternal(MonoDevelop.Projects.Solution solution, CancellationToken token) { using (var timer = Counters.AnalysisTimer.BeginTiming()) { projections.ClearOldProjectionList(); solutionData = new SolutionData(); var projectInfos = await CreateProjectInfos(solution.GetAllProjects(), token).ConfigureAwait(false); if (IsModifiedWhileLoading(solution)) { return(await CreateSolutionInfoInternal(solution, token).ConfigureAwait(false)); } if (token.IsCancellationRequested) { return(solution, null); } var solutionId = GetSolutionId(solution); var solutionInfo = SolutionInfo.Create(solutionId, VersionStamp.Create(), solution.FileName, projectInfos); lock (addLock) { if (!added) { added = true; OnSolutionOpened(workspace, solutionInfo); } } // Check for modified projects here after the solution has been added to the workspace // in case a NuGet package restore finished after the IsModifiedWhileLoading check. This // ensures the type system does not have missing references that may have been added by // the restore. ReloadModifiedProjects(); return(solution, solutionInfo); } } }
private void TryCloseDocumentInWorkspace(FilePath filePath, SourceTextContainer container, MonoDevelop.Projects.Solution solution) { var workspace = GetWorkspace(solution); if (workspace == emptyWorkspace) { return; } var documentIds = workspace.CurrentSolution.GetDocumentIdsWithFilePath(filePath); foreach (var documentId in documentIds) { workspace.InformDocumentClose(documentId, container); } }
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 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); }
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 SolutionItemEventArgs(SolutionItem entry, Solution solution) { this.solution = solution; this.entry = entry; }
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.Gac, "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.Gac, "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.Gac, "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.Gac, "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.Gac, "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.Gac, "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); }
public SolutionItemChangeEventArgs(SolutionItem item, Solution parentSolution, bool reloading) : base(item, parentSolution) { this.reloading = reloading; }