Example #1
0
            internal async Task <ProjectInfo> LoadProject(MonoDevelop.Projects.Project p, CancellationToken token, MonoDevelop.Projects.Project oldProject)
            {
                var projectId = projectMap.GetOrCreateId(p, oldProject);

                var config = IdeApp.Workspace != null?p.GetConfiguration(IdeApp.Workspace.ActiveConfiguration) as MonoDevelop.Projects.DotNetProjectConfiguration : null;

                MonoDevelop.Projects.DotNetCompilerParameters cp = config?.CompilationParameters;
                FilePath fileName = IdeApp.Workspace != null?p.GetOutputFileName(IdeApp.Workspace.ActiveConfiguration) : (FilePath)"";

                if (fileName.IsNullOrEmpty)
                {
                    fileName = new FilePath(p.Name + ".dll");
                }

                var(references, projectReferences) = await metadataHandler.Value.CreateReferences(p, token);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var sourceFiles = await p.GetSourceFilesAsync(config?.Selector).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                lock (workspace.updatingProjectDataLock) {
                    //when reloading e.g. after a save, preserve document IDs
                    using (var oldProjectData = projectMap.RemoveData(projectId)) {
                        var projectData = projectMap.CreateData(projectId, references);

                        var documents = CreateDocuments(projectData, p, token, sourceFiles, oldProjectData);
                        if (documents == null)
                        {
                            return(null);
                        }

                        // TODO: Pass in the WorkspaceMetadataFileReferenceResolver
                        var info = ProjectInfo.Create(
                            projectId,
                            VersionStamp.Create(),
                            p.Name,
                            fileName.FileNameWithoutExtension,
                            LanguageNames.CSharp,
                            p.FileName,
                            fileName,
                            cp?.CreateCompilationOptions(),
                            cp?.CreateParseOptions(config),
                            documents.Item1,
                            projectReferences,
                            references.Select(x => x.CurrentSnapshot),
                            additionalDocuments: documents.Item2
                            );
                        return(info);
                    }
                }
            }
Example #2
0
        Task <ProjectInfo> LoadProject(MonoDevelop.Projects.Project p, CancellationToken token)
        {
            if (!projectIdMap.ContainsKey(p))
            {
                p.FileAddedToProject     += OnFileAdded;
                p.FileRemovedFromProject += OnFileRemoved;
                p.FileRenamedInProject   += OnFileRenamed;
                p.Modified += OnProjectModified;
            }

            var projectId   = GetOrCreateProjectId(p);
            var projectData = GetOrCreateProjectData(projectId);

            return(Task.Run(async() => {
                var references = await CreateMetadataReferences(p, projectId, token).ConfigureAwait(false);
                if (token.IsCancellationRequested)
                {
                    return null;
                }
                var config = IdeApp.Workspace != null ? p.GetConfiguration(IdeApp.Workspace.ActiveConfiguration) as MonoDevelop.Projects.DotNetProjectConfiguration : null;
                MonoDevelop.Projects.DotNetCompilerParameters cp = null;
                if (config != null)
                {
                    cp = config.CompilationParameters;
                }
                FilePath fileName = IdeApp.Workspace != null ? p.GetOutputFileName(IdeApp.Workspace.ActiveConfiguration) : (FilePath)"";
                if (fileName.IsNullOrEmpty)
                {
                    fileName = new FilePath(p.Name + ".dll");
                }

                var sourceFiles = await p.GetSourceFilesAsync(config != null ? config.Selector : null).ConfigureAwait(false);

                var info = ProjectInfo.Create(
                    projectId,
                    VersionStamp.Create(),
                    p.Name,
                    fileName.FileNameWithoutExtension,
                    LanguageNames.CSharp,
                    p.FileName,
                    fileName,
                    cp != null ? cp.CreateCompilationOptions() : null,
                    cp != null ? cp.CreateParseOptions() : null,
                    CreateDocuments(projectData, p, token, sourceFiles),
                    CreateProjectReferences(p, token),
                    references
                    );
                projectData.Info = info;
                return info;
            }, token));
        }
Example #3
0
            internal async Task <ProjectInfo> LoadProject(MonoDevelop.Projects.Project p, CancellationToken token, MonoDevelop.Projects.Project oldProject)
            {
                var projectId = projectMap.GetOrCreateId(p, oldProject);

                var config = IdeApp.Workspace != null?p.GetConfiguration(IdeApp.Workspace.ActiveConfiguration) as MonoDevelop.Projects.DotNetProjectConfiguration : null;

                MonoDevelop.Projects.DotNetCompilerParameters cp = config?.CompilationParameters;
                FilePath fileName = IdeApp.Workspace != null?p.GetOutputFileName(IdeApp.Workspace.ActiveConfiguration) : (FilePath)"";

                if (fileName.IsNullOrEmpty)
                {
                    fileName = new FilePath(p.Name + ".dll");
                }

                var(references, projectReferences) = await metadataHandler.Value.CreateReferences(p, token).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var sourceFiles = await p.GetSourceFilesAsync(config?.Selector).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var analyzerFiles = await p.GetAnalyzerFilesAsync(config?.Selector).ConfigureAwait(false);

                if (token.IsCancellationRequested)
                {
                    return(null);
                }

                var loader = workspace.Services.GetService <IAnalyzerService> ().GetLoader();

                ProjectData         projectData, oldProjectData;
                List <DocumentInfo> mainDocuments, additionalDocuments;

                try {
                    await workspace.LoadLock.WaitAsync().ConfigureAwait(false);

                    //when reloading e.g. after a save, preserve document IDs
                    oldProjectData = projectMap.RemoveData(projectId);
                    projectData    = projectMap.CreateData(projectId, references);

                    var documents = await CreateDocuments(projectData, p, token, sourceFiles, oldProjectData).ConfigureAwait(false);

                    if (documents == null)
                    {
                        return(null);
                    }

                    mainDocuments       = documents.Item1;
                    additionalDocuments = documents.Item2;
                } finally {
                    workspace.LoadLock.Release();
                }

                // TODO: Pass in the WorkspaceMetadataFileReferenceResolver
                var info = ProjectInfo.Create(
                    projectId,
                    VersionStamp.Create(),
                    p.Name,
                    fileName.FileNameWithoutExtension,
                    (p as MonoDevelop.Projects.DotNetProject)?.RoslynLanguageName ?? LanguageNames.CSharp,
                    p.FileName,
                    fileName,
                    cp?.CreateCompilationOptions(),
                    cp?.CreateParseOptions(config),
                    mainDocuments,
                    projectReferences,
                    references.Select(x => x.CurrentSnapshot),
                    analyzerReferences: analyzerFiles.SelectAsArray(x => {
                    var analyzer = new MonoDevelopAnalyzer(x, hostDiagnosticUpdateSource.Value, projectId, workspace, loader, LanguageNames.CSharp);
                    return(analyzer.GetReference());
                }),
                    additionalDocuments: additionalDocuments
                    );

                return(info);
            }