Наследование: Microsoft.CodeAnalysis.Workspace
Пример #1
0
        internal async Task <MonoDevelopWorkspace> CreateEmptyWorkspace()
        {
            var ws = new MonoDevelopWorkspace(compositionManager.HostServices, null, this);
            await ws.Initialize();

            return(ws);
        }
        public void TestDataHandling()
        {
            using (var project = Services.ProjectService.CreateDotNetProject("C#"))
                using (var workspace = new MonoDevelopWorkspace(null)) {
                    var map = new MonoDevelopWorkspace.ProjectDataMap(workspace);

                    var pid  = map.GetOrCreateId(project, null);
                    var data = map.GetData(pid);

                    Assert.IsNull(data);
                    Assert.IsFalse(map.Contains(pid));

                    data = map.CreateData(pid, ImmutableArray <MonoDevelopMetadataReference> .Empty);

                    Assert.IsNotNull(data);
                    Assert.IsTrue(map.Contains(pid));

                    map.RemoveData(pid);

                    data = map.GetData(pid);

                    Assert.IsNull(data);
                    Assert.IsFalse(map.Contains(pid));
                }
        }
        public void TestSimpleCreation()
        {
            using (var project = Services.ProjectService.CreateDotNetProject("C#"))
                using (var workspace = new MonoDevelopWorkspace(null)) {
                    var map = new MonoDevelopWorkspace.ProjectDataMap(workspace);

                    var pid = map.GetId(project);
                    Assert.IsNull(pid);

                    pid = map.GetOrCreateId(project, null);
                    Assert.IsNotNull(pid);

                    var projectInMap = map.GetMonoProject(pid);
                    Assert.AreSame(project, projectInMap);

                    var projectRemovedFromMap = map.RemoveProject(pid);
                    Assert.AreSame(projectInMap, projectRemovedFromMap);

                    Assert.IsNull(map.GetId(project));

                    pid = map.GetOrCreateId(project, null);
                    map.RemoveProject(project);

                    Assert.IsNull(map.GetId(project));
                }
        }
Пример #4
0
        static async Task AddAssemblyReference(MonoDevelopWorkspace ws, DotNetProject from, DotNetProject to, string name)
        {
            var manager = ws.MetadataReferenceManager;

            var assemblies = await from.GetReferencedAssemblies(IdeApp.Workspace?.ActiveConfiguration ?? ConfigurationSelector.Default);

            var messagingAsm      = assemblies.Single(x => x.Metadata.GetValue <string> ("Filename") == name);
            var metadataReference = manager.GetOrCreateMetadataReference(messagingAsm.FilePath, MetadataReferenceProperties.Assembly);

            await FileWatcherService.Update();

            var roslynProj = ws.GetProjectId(to);

            var oldRefs     = ws.CurrentSolution.GetProject(roslynProj).MetadataReferences;
            var newRefs     = oldRefs.ToImmutableArray().Add(metadataReference.CurrentSnapshot);
            var newSolution = ws.CurrentSolution.WithProjectMetadataReferences(roslynProj, newRefs);

            Assert.IsTrue(ws.TryApplyChanges(newSolution));
            await ws.ProjectSaveTask;

            var reference = to.References.Single(x => x.Include == name);

            Assert.IsTrue(reference.HintPath.IsNull);
            Assert.AreEqual(ReferenceType.Package, reference.ReferenceType);
        }
Пример #5
0
            public ProjectSystemHandler(MonoDevelopWorkspace workspace, ProjectDataMap projectMap, ProjectionData projections)
            {
                this.workspace   = workspace;
                this.projectMap  = projectMap;
                this.projections = projections;

                metadataHandler = new Lazy <MetadataReferenceHandler> (() => new MetadataReferenceHandler(workspace.MetadataReferenceManager, projectMap));
            }
Пример #6
0
        void LoadCache(Solution sol)
        {
            var solConfig = sol.GetConfiguration(IdeServices.Workspace.ActiveConfiguration);

            if (solConfig == null)
            {
                return;
            }

            var serializer = new JsonSerializer();

            foreach (var project in sol.GetAllProjects())
            {
                var config = solConfig.GetMappedConfiguration(project);

                var    projectFilePath = project.FileName;
                string cacheFilePath   = null;

                List <ProjectCache> cacheList = null;

                foreach (string framework in MonoDevelopWorkspace.GetFrameworks(project))
                {
                    try {
                        cacheFilePath = GetProjectCacheFile(project, config, framework);

                        if (!File.Exists(cacheFilePath))
                        {
                            continue;
                        }

                        using (var sr = File.OpenText(cacheFilePath)) {
                            var value = (ProjectCache)serializer.Deserialize(sr, typeof(ProjectCache));

                            if (format != value.Format)
                            {
                                continue;
                            }

                            value.Framework = framework;
                            if (cacheList == null)
                            {
                                cacheList = new List <ProjectCache> ();
                            }
                            cacheList.Add(value);
                        }
                    } catch (Exception ex) {
                        LoggingService.LogError("Could not deserialize project cache", ex);
                        TryDeleteFile(cacheFilePath);
                        continue;
                    }
                }

                if (cacheList != null)
                {
                    cachedItems [projectFilePath] = cacheList;
                }
            }
        }
Пример #7
0
            public ProjectSystemHandler(MonoDevelopWorkspace workspace, ProjectDataMap projectMap, ProjectionData projections)
            {
                this.workspace   = workspace;
                this.projectMap  = projectMap;
                this.projections = projections;

                metadataHandler            = new Lazy <MetadataReferenceHandler> (() => new MetadataReferenceHandler(workspace.MetadataReferenceManager, projectMap));
                hostDiagnosticUpdateSource = new Lazy <HostDiagnosticUpdateSource> (() => new HostDiagnosticUpdateSource(workspace, Composition.CompositionManager.GetExportedValue <IDiagnosticUpdateSourceRegistrationService> ()));
            }
Пример #8
0
        public void TestEmptyMetadataCreation()
        {
            var pid = ProjectId.CreateNewId();

            using (var workspace = new MonoDevelopWorkspace(null))
                using (var data = new MonoDevelopWorkspace.ProjectData(pid, ImmutableArray <MonoDevelopMetadataReference> .Empty, workspace)) {
                    // Do nothing, we just want to see it construct and dispose properly.
                }
        }
        public void TestMigration()
        {
            using (var project = Services.ProjectService.CreateDotNetProject("C#"))
                using (var project2 = Services.ProjectService.CreateDotNetProject("C#"))
                    using (var workspace = new MonoDevelopWorkspace(null)) {
                        var map = new MonoDevelopWorkspace.ProjectDataMap(workspace);

                        var pid = map.GetOrCreateId(project, null);
                        Assert.IsNotNull(pid);

                        var pid2 = map.GetOrCreateId(project2, project);
                        Assert.AreSame(pid, pid2);
                    }
        }
            internal void Complete(MonoDevelopWorkspace workspace)
            {
                if (workspace == null)
                {
                    throw new ArgumentNullException(nameof(workspace));
                }

                lock (requests) {
                    foreach (var request in requests.ToList())
                    {
                        // Requests are removed when completed.
                        request.TrySetResult(workspace);
                    }
                }
            }
Пример #11
0
        protected override async Task OnInitialize(ServiceProvider serviceProvider)
        {
            IntitializeTrackedProjectHandling();

            serviceProvider.WhenServiceInitialized <CompositionManager> (s => {
                miscellaneousFilesWorkspace = CompositionManager.Instance.GetExportedValue <MiscellaneousFilesWorkspace> ();
                serviceProvider.WhenServiceInitialized <DocumentManager> (dm => {
                    documentManager = dm;
                });
            });
            serviceProvider.WhenServiceInitialized <RootWorkspace> (s => {
                rootWorkspace = s;
                rootWorkspace.ActiveConfigurationChanged += HandleActiveConfigurationChanged;
            });

            RoslynServices.RoslynService.Initialize();
            CleanupCache();

                        #pragma warning disable CS0618, 612 // Type or member is obsolete
            parsers = AddinManager.GetExtensionNodes <TypeSystemParserNode> ("/MonoDevelop/TypeSystem/Parser");
            bool initialLoad = true;
            AddinManager.AddExtensionNodeHandler("/MonoDevelop/TypeSystem/Parser", delegate(object sender, ExtensionNodeEventArgs args) {
                //refresh entire list to respect insertbefore/insertafter ordering
                if (!initialLoad)
                {
                    parsers = AddinManager.GetExtensionNodes <TypeSystemParserNode> ("/MonoDevelop/TypeSystem/Parser");
                }
            });
                        #pragma warning restore CS0618, 612 // Type or member is obsolete
            initialLoad = false;

            try {
                compositionManager = await serviceProvider.GetService <CompositionManager> ().ConfigureAwait(false);

                emptyWorkspace = new MonoDevelopWorkspace(compositionManager.HostServices, null, this);
                await emptyWorkspace.Initialize().ConfigureAwait(false);
            } catch (Exception e) {
                LoggingService.LogFatalError("Can't create roslyn workspace", e);
            }

            FileService.FileChanged += FileService_FileChanged;
            FileService.FileRemoved += FileService_FileRemoved;

            desktopService = await serviceProvider.GetService <DesktopService> ();

            await serviceProvider.GetService <HelpService> ();
        }
Пример #12
0
        internal void Unload(MonoDevelop.Projects.WorkspaceItem item)
        {
            var ws = item as MonoDevelop.Projects.Workspace;

            if (ws != null)
            {
                foreach (var it in ws.Items)
                {
                    Unload(it);
                }
                ws.ItemAdded   -= OnWorkspaceItemAdded;
                ws.ItemRemoved -= OnWorkspaceItemRemoved;
                MonoDocDocumentationProvider.ClearCommentCache();
            }
            else
            {
                var solution = item as MonoDevelop.Projects.Solution;
                if (solution != null)
                {
                    MonoDevelopWorkspace result = GetWorkspace(solution);
                    if (result != emptyWorkspace)
                    {
                        lock (workspaceLock)
                            workspaces = workspaces.Remove(result);

                        result.Dispose();
                    }

                    lock (solution.ExtendedProperties.SyncRoot) {
                        if (solution.ExtendedProperties [typeof(WorkspaceRequestRegistration)] is WorkspaceRequestRegistration registration)
                        {
                            registration.Dispose();
                        }
                    }

                    solution.SolutionItemAdded   -= OnSolutionItemAdded;
                    solution.SolutionItemRemoved -= OnSolutionItemRemoved;
                    if (solution.ParentWorkspace == null)
                    {
                        MonoDocDocumentationProvider.ClearCommentCache();
                    }
                }
            }
        }
 static Task InternalLoad(List <MonoDevelopWorkspace> list, MonoDevelop.Projects.WorkspaceItem item, ProgressMonitor progressMonitor, CancellationToken cancellationToken = default(CancellationToken), bool showStatusIcon = true)
 {
     return(Task.Run(async() => {
         var ws = item as MonoDevelop.Projects.Workspace;
         if (ws != null)
         {
             foreach (var it in ws.Items)
             {
                 await InternalLoad(list, it, progressMonitor, cancellationToken).ConfigureAwait(false);
             }
             ws.ItemAdded += OnWorkspaceItemAdded;
             ws.ItemRemoved += OnWorkspaceItemRemoved;
         }
         else
         {
             var solution = item as MonoDevelop.Projects.Solution;
             if (solution != null)
             {
                 var workspace = new MonoDevelopWorkspace(solution);
                 lock (workspaceLock)
                     workspaces = workspaces.Add(workspace);
                 list.Add(workspace);
                 if (showStatusIcon)
                 {
                     workspace.ShowStatusIcon();
                 }
                 await workspace.TryLoadSolution(cancellationToken).ConfigureAwait(false);
                 solution.SolutionItemAdded += OnSolutionItemAdded;
                 solution.SolutionItemRemoved += OnSolutionItemRemoved;
                 TaskCompletionSource <MonoDevelopWorkspace> request;
                 if (workspaceRequests.TryGetValue(solution, out request))
                 {
                     request.TrySetResult(workspace);
                 }
                 if (showStatusIcon)
                 {
                     workspace.HideStatusIcon();
                 }
             }
         }
     }));
 }
        async Task CreateWorkspaces(WorkspaceItem item, List <MonoDevelopWorkspace> result)
        {
            if (item is MonoDevelop.Projects.Workspace ws)
            {
                foreach (var wsItem in ws.Items)
                {
                    await CreateWorkspaces(wsItem, result).ConfigureAwait(false);
                }
                ws.ItemAdded   += OnWorkspaceItemAdded;
                ws.ItemRemoved += OnWorkspaceItemRemoved;
            }
            else if (item is MonoDevelop.Projects.Solution solution)
            {
                var workspace = new MonoDevelopWorkspace(compositionManager.HostServices, solution, this);
                await workspace.Initialize().ConfigureAwait(false);

                lock (workspaceLock)
                    workspaces = workspaces.Add(workspace);
                solution.SolutionItemAdded   += OnSolutionItemAdded;
                solution.SolutionItemRemoved += OnSolutionItemRemoved;
                result.Add(workspace);
            }
        }
Пример #15
0
            public ProjectData(ProjectId projectId, ImmutableArray <MonoDevelopMetadataReference> metadataReferences, MonoDevelopWorkspace ws)
            {
                this.projectId          = projectId;
                workspaceRef            = new WeakReference <MonoDevelopWorkspace> (ws);
                DocumentData            = new DocumentMap(projectId);
                this.metadataReferences = new List <MonoDevelopMetadataReference> (metadataReferences.Length);

                System.Diagnostics.Debug.Assert(Monitor.IsEntered(ws.updatingProjectDataLock));
                foreach (var metadataReference in metadataReferences)
                {
                    AddMetadataReference_NoLock(metadataReference, ws);
                }
            }
            void AddMetadataReference_NoLock(MonoDevelopMetadataReference metadataReference, MonoDevelopWorkspace ws)
            {
                System.Diagnostics.Debug.Assert(Monitor.IsEntered(metadataReferences));

                metadataReferences.Add(metadataReference);
                metadataReference.SnapshotUpdated += OnMetadataReferenceUpdated;
            }
Пример #17
0
            void AddMetadataReference_NoLock(MonoDevelopMetadataReference metadataReference, MonoDevelopWorkspace ws)
            {
                System.Diagnostics.Debug.Assert(Monitor.IsEntered(ws.updatingProjectDataLock));

                metadataReferences.Add(metadataReference);
                metadataReference.UpdatedOnDisk += OnMetadataReferenceUpdated;
            }
Пример #18
0
            static void NotifySolutionModified(MonoDevelop.Projects.Solution sol, SolutionId solId, MonoDevelopWorkspace workspace)
            {
                if (string.IsNullOrWhiteSpace(sol.BaseDirectory))
                {
                    return;
                }

                var locService = (MonoDevelopPersistentStorageLocationService)workspace.Services.GetService <IPersistentStorageLocationService> ();

                locService.NotifyStorageLocationChanging(solId, sol.GetPreferencesDirectory());
            }
		static Task InternalLoad (List<MonoDevelopWorkspace> list, MonoDevelop.Projects.WorkspaceItem item, ProgressMonitor progressMonitor, CancellationToken cancellationToken = default(CancellationToken))
		{
			return Task.Run (async () => {
				var ws = item as MonoDevelop.Projects.Workspace;
				if (ws != null) {
					foreach (var it in ws.Items) {
						await InternalLoad (list, it, progressMonitor, cancellationToken);
					}
					ws.ItemAdded += OnWorkspaceItemAdded;
					ws.ItemRemoved += OnWorkspaceItemRemoved;
				} else {
					var solution = item as MonoDevelop.Projects.Solution;
					if (solution != null) {
						var workspace = new MonoDevelopWorkspace ();
						list.Add (workspace);
						workspace.ShowStatusIcon ();
						lock (workspaceLock)
							workspaces = workspaces.Add (workspace);
						await workspace.TryLoadSolution (solution, cancellationToken);
						solution.SolutionItemAdded += OnSolutionItemAdded;
						solution.SolutionItemRemoved += OnSolutionItemRemoved;
						workspace.HideStatusIcon ();
					}
				}
			});
		}
Пример #20
0
            bool RemoveMetadataReference_NoLock(MonoDevelopMetadataReference metadataReference, MonoDevelopWorkspace ws)
            {
                System.Diagnostics.Debug.Assert(Monitor.IsEntered(ws.updatingProjectDataLock));

                metadataReference.UpdatedOnDisk -= OnMetadataReferenceUpdated;
                return(metadataReferences.Remove(metadataReference));
            }
Пример #21
0
        async void OnSolutionItemAdded(object sender, MonoDevelop.Projects.SolutionItemChangeEventArgs args)
        {
            try {
                var project = args.SolutionItem as MonoDevelop.Projects.Project;
                if (project != null)
                {
                    var ws         = GetWorkspace(args.Solution);
                    var oldProject = args.ReplacedItem as MonoDevelop.Projects.Project;

                    // when loading a project that was unloaded manually before
                    // args.ReplacedItem is the UnloadedSolutionItem, which is not useful
                    // we need to find what was the real project previously
                    if (args.Reloading && oldProject == null)
                    {
                        var existingRoslynProject = ws.CurrentSolution.Projects.FirstOrDefault(p => p.FilePath == project.FileName);
                        if (existingRoslynProject != null)
                        {
                            oldProject = ws.GetMonoProject(existingRoslynProject.Id);
                        }
                    }

                    HashSet <ProjectId> oldProjectIds = null;
                    if (oldProject != null)
                    {
                        oldProjectIds = ws.GetProjectIds(oldProject).ToHashSet();
                    }

                    foreach (string framework in MonoDevelopWorkspace.GetFrameworks(project))
                    {
                        var projectInfo = await ws.LoadProject(project, CancellationToken.None, oldProject, framework);

                        if (oldProject != null)
                        {
                            if (oldProjectIds.Remove(projectInfo.Id))
                            {
                                ws.OnProjectReloaded(projectInfo);
                            }
                            else
                            {
                                ws.OnProjectAdded(projectInfo);
                            }
                        }
                        else
                        {
                            ws.OnProjectAdded(projectInfo);
                        }
                    }

                    if (oldProjectIds != null)
                    {
                        foreach (var removedProjectId in oldProjectIds)
                        {
                            ws.OnProjectRemoved(removedProjectId);
                        }
                    }

                    ws.ReloadModifiedProject(project);
                    Runtime.RunInMainThread(() => IdeServices.TypeSystemService.UpdateRegisteredOpenDocuments()).Ignore();
                }
            } catch (Exception ex) {
                LoggingService.LogError("OnSolutionItemAdded failed", ex);
            }
        }
 public ProjectData(ProjectId projectId, ImmutableArray <MonoDevelopMetadataReference> metadataReferences, MonoDevelopWorkspace ws)
 {
     this.projectId          = projectId;
     workspaceRef            = new WeakReference <MonoDevelopWorkspace> (ws);
     DocumentData            = new DocumentMap(projectId);
     this.metadataReferences = new List <MonoDevelopMetadataReference> (metadataReferences);
 }
            bool RemoveMetadataReference_NoLock(MonoDevelopMetadataReference metadataReference, MonoDevelopWorkspace ws)
            {
                System.Diagnostics.Debug.Assert(Monitor.IsEntered(metadataReferences));

                metadataReference.SnapshotUpdated -= OnMetadataReferenceUpdated;
                return(metadataReferences.Remove(metadataReference));
            }