示例#1
0
        public AbstractLegacyProject(
            string projectSystemName,
            IVsHierarchy hierarchy,
            string language,
            IServiceProvider serviceProvider,
            IThreadingContext threadingContext,
            string externalErrorReportingPrefix,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
            ICommandLineParserService commandLineParserServiceOpt)
            : base(threadingContext)
        {
            Contract.ThrowIfNull(hierarchy);

            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            Workspace = componentModel.GetService <VisualStudioWorkspace>();

            var projectFilePath = hierarchy.GetProjectFilePath();

            if (projectFilePath != null && !File.Exists(projectFilePath))
            {
                projectFilePath = null;
            }

            var projectFactory = componentModel.GetService <VisualStudioProjectFactory>();

            VisualStudioProject = projectFactory.CreateAndAddToWorkspace(
                projectSystemName,
                language,
                new VisualStudioProjectCreationInfo
            {
                // The workspace requires an assembly name so we can make compilations. We'll use
                // projectSystemName because they'll have a better one eventually.
                AssemblyName     = projectSystemName,
                FilePath         = projectFilePath,
                Hierarchy        = hierarchy,
                ProjectGuid      = GetProjectIDGuid(hierarchy),
                DefaultNamespace = GetDefaultNamespace(hierarchy, language)
            });

            Hierarchy = hierarchy;
            ConnectHierarchyEvents();
            RefreshBinOutputPath();

            // TODO: remove this terrible hack, which is working around shims throwing in not-good ways
            try
            {
                _externalErrorReporter  = new ProjectExternalErrorReporter(VisualStudioProject.Id, externalErrorReportingPrefix, serviceProvider);
                _editAndContinueProject = new VsENCRebuildableProjectImpl(Workspace, VisualStudioProject, serviceProvider);
            }
            catch (Exception)
            {
            }

            _batchScopeCreator = componentModel.GetService <SolutionEventsBatchScopeCreator>();
            _batchScopeCreator.StartTrackingProject(VisualStudioProject, Hierarchy);
        }
示例#2
0
        // TODO: this is a workaround. Factory has to be refactored so that all callers supply their own error reporters
        IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(
            string languageName,
            string projectUniqueName,
            string projectFilePath,
            Guid projectGuid,
            object hierarchy,
            string binOutputPath,
            ProjectExternalErrorReporter errorReporter)
        {
            var visualStudioProject = CreateVisualStudioProject(languageName, projectUniqueName, projectFilePath, (IVsHierarchy)hierarchy, projectGuid);

            return(new CPSProject(visualStudioProject, _workspace, _projectCodeModelFactory, errorReporter, projectGuid, binOutputPath));
        }
示例#3
0
        // TODO: this is a workaround. Factory has to be refactored so that all callers supply their own error reporters
        IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(
            string languageName,
            string projectDisplayName,
            string projectFilePath,
            Guid projectGuid,
            object hierarchy,
            string binOutputPath,
            ProjectExternalErrorReporter errorReporter)
        {
            // NOTE: It is acceptable for hierarchy to be null in Deferred Project Load scenarios.
            var vsHierarchy = hierarchy as IVsHierarchy;

            Func <ProjectId, IVsReportExternalErrors> getExternalErrorReporter = id => errorReporter;

            return(new CPSProject(_visualStudioWorkspace.GetProjectTrackerAndInitializeIfNecessary(ServiceProvider.GlobalProvider), getExternalErrorReporter, projectDisplayName, projectFilePath,
                                  vsHierarchy, languageName, projectGuid, binOutputPath, _serviceProvider, _visualStudioWorkspace, _hostDiagnosticUpdateSource,
                                  commandLineParserServiceOpt: _visualStudioWorkspace.Services.GetLanguageServices(languageName)?.GetService <ICommandLineParserService>()));
        }
示例#4
0
        IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(
            string languageName,
            string projectUniqueName,
            string projectFilePath,
            Guid projectGuid,
            object hierarchy,
            string binOutputPath)
        {
            var visualStudioProject = CreateVisualStudioProject(languageName, projectUniqueName, projectFilePath, (IVsHierarchy)hierarchy, projectGuid);

            ProjectExternalErrorReporter errorReporter = null;

            if (s_projectLanguageToErrorCodePrefixMap.TryGetKey(languageName, out var prefix))
            {
                errorReporter = new ProjectExternalErrorReporter(visualStudioProject.Id, prefix, _workspace, _externalErrorDiagnosticUpdateSource);
            }

            return(new CPSProject(visualStudioProject, _workspace, _projectCodeModelFactory, errorReporter, projectGuid, binOutputPath));
        }
示例#5
0
        private IVsReportExternalErrors GetExternalErrorReporter(ProjectId projectId, string languageName)
        {
            lock (_externalErrorReporterMap)
            {
                IVsReportExternalErrors errorReporter;
                if (!_externalErrorReporterMap.TryGetValue(languageName, out errorReporter))
                {
                    string errorCodePrefix;
                    if (!_projectLangaugeToErrorCodePrefixMap.TryGetValue(languageName, out errorCodePrefix))
                    {
                        throw new NotSupportedException(nameof(languageName));
                    }

                    errorReporter = new ProjectExternalErrorReporter(projectId, errorCodePrefix, _serviceProvider);
                    _externalErrorReporterMap.Add(languageName, errorReporter);
                }

                return(errorReporter);
            }
        }
示例#6
0
        private IVsReportExternalErrors GetExternalErrorReporter(ProjectId projectId, string languageName)
        {
            lock (_externalErrorReporterMap)
            {
                IVsReportExternalErrors errorReporter;
                if (!_externalErrorReporterMap.TryGetValue(languageName, out errorReporter))
                {
                    string errorCodePrefix;
                    if (!_projectLangaugeToErrorCodePrefixMap.TryGetValue(languageName, out errorCodePrefix))
                    {
                        Debug.Fail($"Unknown language '{languageName}'");
                        _projectLangaugeToErrorCodePrefixMap.Add(languageName, languageName);
                    }

                    errorReporter = new ProjectExternalErrorReporter(projectId, errorCodePrefix, _serviceProvider);
                    _externalErrorReporterMap.Add(languageName, errorReporter);
                }

                return(errorReporter);
            }
        }
示例#7
0
        public AbstractLegacyProject(
            string projectSystemName,
            IVsHierarchy hierarchy,
            string language,
            bool isVsIntellisenseProject,
            IServiceProvider serviceProvider,
            IThreadingContext threadingContext,
            string externalErrorReportingPrefix
            ) : base(threadingContext, assertIsForeground: true)
        {
            Contract.ThrowIfNull(hierarchy);

            var componentModel = (IComponentModel)serviceProvider.GetService(
                typeof(SComponentModel)
                );

            Workspace = componentModel.GetService <VisualStudioWorkspace>();
            var workspaceImpl = (VisualStudioWorkspaceImpl)Workspace;

            var projectFilePath = hierarchy.TryGetProjectFilePath();

            if (projectFilePath != null && !File.Exists(projectFilePath))
            {
                projectFilePath = null;
            }

            if (projectFilePath != null)
            {
                _projectDirectory = Path.GetDirectoryName(projectFilePath);
            }

            if (isVsIntellisenseProject)
            {
                // IVsIntellisenseProjects are usually used for contained language cases, which means these projects don't have any real
                // output path that we should consider. Since those point to the same IVsHierarchy as another project, we end up with two projects
                // with the same output path, which potentially breaks conversion of metadata references to project references. However they're
                // also used for database projects and a few other cases where there there isn't a "primary" IVsHierarchy.
                // As a heuristic here we'll ignore the output path if we already have another project tied to the IVsHierarchy.
                foreach (var projectId in Workspace.CurrentSolution.ProjectIds)
                {
                    if (Workspace.GetHierarchy(projectId) == hierarchy)
                    {
                        _ignoreOutputPath = true;
                        break;
                    }
                }
            }

            var projectFactory = componentModel.GetService <VisualStudioProjectFactory>();

            VisualStudioProject = threadingContext.JoinableTaskFactory.Run(
                () =>
                projectFactory.CreateAndAddToWorkspaceAsync(
                    projectSystemName,
                    language,
                    new VisualStudioProjectCreationInfo
            {
                // The workspace requires an assembly name so we can make compilations. We'll use
                // projectSystemName because they'll have a better one eventually.
                AssemblyName = projectSystemName,
                FilePath     = projectFilePath,
                Hierarchy    = hierarchy,
                ProjectGuid  = GetProjectIDGuid(hierarchy),
            },
                    CancellationToken.None
                    )
                );

            workspaceImpl.AddProjectRuleSetFileToInternalMaps(
                VisualStudioProject,
                () => VisualStudioProjectOptionsProcessor.EffectiveRuleSetFilePath
                );

            // Right now VB doesn't have the concept of "default namespace". But we conjure one in workspace
            // by assigning the value of the project's root namespace to it. So various feature can choose to
            // use it for their own purpose.
            // In the future, we might consider officially exposing "default namespace" for VB project
            // (e.g. through a <defaultnamespace> msbuild property)
            VisualStudioProject.DefaultNamespace = GetRootNamespacePropertyValue(hierarchy);

            if (
                TryGetPropertyValue(
                    hierarchy,
                    AdditionalPropertyNames.MaxSupportedLangVersion,
                    out var maxLangVer
                    )
                )
            {
                VisualStudioProject.MaxLangVersion = maxLangVer;
            }

            if (
                TryGetBoolPropertyValue(
                    hierarchy,
                    AdditionalPropertyNames.RunAnalyzers,
                    out var runAnayzers
                    )
                )
            {
                VisualStudioProject.RunAnalyzers = runAnayzers;
            }

            if (
                TryGetBoolPropertyValue(
                    hierarchy,
                    AdditionalPropertyNames.RunAnalyzersDuringLiveAnalysis,
                    out var runAnayzersDuringLiveAnalysis
                    )
                )
            {
                VisualStudioProject.RunAnalyzersDuringLiveAnalysis = runAnayzersDuringLiveAnalysis;
            }

            Hierarchy = hierarchy;
            ConnectHierarchyEvents();
            RefreshBinOutputPath();

            workspaceImpl.SubscribeExternalErrorDiagnosticUpdateSourceToSolutionBuildEvents();

            _externalErrorReporter = new ProjectExternalErrorReporter(
                VisualStudioProject.Id,
                externalErrorReportingPrefix,
                language,
                workspaceImpl
                );
            _batchScopeCreator = componentModel.GetService <SolutionEventsBatchScopeCreator>();
            _batchScopeCreator.StartTrackingProject(VisualStudioProject, Hierarchy);
        }
示例#8
0
        public AbstractLegacyProject(
            string projectSystemName,
            IVsHierarchy hierarchy,
            string language,
            IServiceProvider serviceProvider,
            IThreadingContext threadingContext,
            string externalErrorReportingPrefix,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
            ICommandLineParserService commandLineParserServiceOpt)
            : base(threadingContext)
        {
            Contract.ThrowIfNull(hierarchy);

            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            Workspace = componentModel.GetService <VisualStudioWorkspace>();

            var projectFilePath = hierarchy.TryGetProjectFilePath();

            if (projectFilePath != null && !File.Exists(projectFilePath))
            {
                projectFilePath = null;
            }

            var projectFactory = componentModel.GetService <VisualStudioProjectFactory>();

            VisualStudioProject = projectFactory.CreateAndAddToWorkspace(
                projectSystemName,
                language,
                new VisualStudioProjectCreationInfo
            {
                // The workspace requires an assembly name so we can make compilations. We'll use
                // projectSystemName because they'll have a better one eventually.
                AssemblyName = projectSystemName,
                FilePath     = projectFilePath,
                Hierarchy    = hierarchy,
                ProjectGuid  = GetProjectIDGuid(hierarchy),
            });

            // Right now VB doesn't have the concept of "default namespace". But we conjure one in workspace
            // by assigning the value of the project's root namespace to it. So various feature can choose to
            // use it for their own purpose.
            // In the future, we might consider officially exposing "default namespace" for VB project
            // (e.g. through a <defaultnamespace> msbuild property)
            VisualStudioProject.DefaultNamespace = GetRootNamespacePropertyValue(hierarchy);

            Hierarchy = hierarchy;
            ConnectHierarchyEvents();
            RefreshBinOutputPath();

            // TODO: remove this terrible hack, which is working around shims throwing in not-good ways
            try
            {
                _externalErrorReporter  = new ProjectExternalErrorReporter(VisualStudioProject.Id, externalErrorReportingPrefix, serviceProvider);
                _editAndContinueProject = new VsENCRebuildableProjectImpl(Workspace, VisualStudioProject, serviceProvider);
            }
            catch (Exception)
            {
            }

            _batchScopeCreator = componentModel.GetService <SolutionEventsBatchScopeCreator>();
            _batchScopeCreator.StartTrackingProject(VisualStudioProject, Hierarchy);
        }
示例#9
0
        public AbstractLegacyProject(
            string projectSystemName,
            IVsHierarchy hierarchy,
            string language,
            IServiceProvider serviceProvider,
            IThreadingContext threadingContext,
            string externalErrorReportingPrefix,
            HostDiagnosticUpdateSource hostDiagnosticUpdateSourceOpt,
            ICommandLineParserService commandLineParserServiceOpt)
            : base(threadingContext, assertIsForeground: true)
        {
            Contract.ThrowIfNull(hierarchy);

            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            Workspace = componentModel.GetService <VisualStudioWorkspace>();
            var workspaceImpl = (VisualStudioWorkspaceImpl)Workspace;

            var projectFilePath = hierarchy.TryGetProjectFilePath();

            if (projectFilePath != null && !File.Exists(projectFilePath))
            {
                projectFilePath = null;
            }

            if (projectFilePath != null)
            {
                _projectDirectory = Path.GetDirectoryName(projectFilePath);
            }

            var projectFactory = componentModel.GetService <VisualStudioProjectFactory>();

            VisualStudioProject = projectFactory.CreateAndAddToWorkspace(
                projectSystemName,
                language,
                new VisualStudioProjectCreationInfo
            {
                // The workspace requires an assembly name so we can make compilations. We'll use
                // projectSystemName because they'll have a better one eventually.
                AssemblyName = projectSystemName,
                FilePath     = projectFilePath,
                Hierarchy    = hierarchy,
                ProjectGuid  = GetProjectIDGuid(hierarchy),
            });

            workspaceImpl.AddProjectRuleSetFileToInternalMaps(
                VisualStudioProject,
                () => VisualStudioProjectOptionsProcessor.EffectiveRuleSetFilePath);

            // Right now VB doesn't have the concept of "default namespace". But we conjure one in workspace
            // by assigning the value of the project's root namespace to it. So various feature can choose to
            // use it for their own purpose.
            // In the future, we might consider officially exposing "default namespace" for VB project
            // (e.g. through a <defaultnamespace> msbuild property)
            VisualStudioProject.DefaultNamespace = GetRootNamespacePropertyValue(hierarchy);

            Hierarchy = hierarchy;
            ConnectHierarchyEvents();
            RefreshBinOutputPath();

            workspaceImpl.SubscribeExternalErrorDiagnosticUpdateSourceToSolutionBuildEvents();

            _externalErrorReporter = new ProjectExternalErrorReporter(VisualStudioProject.Id, externalErrorReportingPrefix, workspaceImpl);
            _batchScopeCreator     = componentModel.GetService <SolutionEventsBatchScopeCreator>();
            _batchScopeCreator.StartTrackingProject(VisualStudioProject, Hierarchy);
        }
 public IWorkspaceProjectContext CreateProjectContext(string languageName, string projectDisplayName, string projectFilePath, Guid projectGuid, object hierarchy, string binOutputPath, ProjectExternalErrorReporter errorReporter)
 {
     return(new WorkspaceProjectContext());
 }