public FallbackRazorProjectHost(
     IUnconfiguredProjectCommonServices commonServices,
     [Import(typeof(VisualStudioWorkspace))] Workspace workspace,
     ProjectConfigurationFilePathStore projectConfigurationFilePathStore)
     : base(commonServices, workspace, projectConfigurationFilePathStore)
 {
 }
Esempio n. 2
0
        public RazorProjectHostBase(
            IUnconfiguredProjectCommonServices commonServices,
            [Import(typeof(VisualStudioWorkspace))] Workspace workspace,
            ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
            ProjectConfigurationFilePathStore projectConfigurationFilePathStore)
            : base(commonServices.ThreadingService.JoinableTaskContext)
        {
            if (commonServices is null)
            {
                throw new ArgumentNullException(nameof(commonServices));
            }

            if (workspace is null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            if (projectSnapshotManagerDispatcher is null)
            {
                throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher));
            }

            CommonServices = commonServices;
            _workspace     = workspace;
            _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher;

            _lock             = new AsyncSemaphore(initialCount: 1);
            _currentDocuments = new Dictionary <string, HostDocument>(FilePathComparer.Instance);
            ProjectConfigurationFilePathStore = projectConfigurationFilePathStore;
        }
 internal FallbackRazorProjectHost(
     IUnconfiguredProjectCommonServices commonServices,
     Workspace workspace,
     ProjectConfigurationFilePathStore projectConfigurationFilePathStore,
     ProjectSnapshotManagerBase projectManager)
     : base(commonServices, workspace, projectConfigurationFilePathStore, projectManager)
 {
 }
 public DefaultRazorProjectHost(
     IUnconfiguredProjectCommonServices commonServices,
     [Import(typeof(VisualStudioWorkspace))] Workspace workspace,
     ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
     ProjectConfigurationFilePathStore projectConfigurationFilePathStore)
     : base(commonServices, workspace, projectSnapshotManagerDispatcher, projectConfigurationFilePathStore)
 {
 }
Esempio n. 5
0
 internal DefaultWindowsRazorProjectHost(
     IUnconfiguredProjectCommonServices commonServices,
     Workspace workspace,
     ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
     ProjectConfigurationFilePathStore projectConfigurationFilePathStore,
     ProjectSnapshotManagerBase projectManager)
     : base(commonServices, workspace, projectSnapshotManagerDispatcher, projectConfigurationFilePathStore, projectManager)
 {
 }
Esempio n. 6
0
 public DefaultWindowsRazorProjectHost(
     IUnconfiguredProjectCommonServices commonServices,
     [Import(typeof(VisualStudioWorkspace))] Workspace workspace,
     ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher,
     ProjectConfigurationFilePathStore projectConfigurationFilePathStore,
     VSLanguageServerFeatureOptions languageServerFeatureOptions)
     : base(commonServices, workspace, projectSnapshotManagerDispatcher, projectConfigurationFilePathStore)
 {
     _languageServerFeatureOptions = languageServerFeatureOptions;
 }
Esempio n. 7
0
        internal async Task OnProjectChangedAsync(IProjectVersionedValue <IProjectSubscriptionUpdate> update)
        {
            if (IsDisposing || IsDisposed)
            {
                return;
            }

            await CommonServices.TasksService.LoadedProjectAsync(async() => await ExecuteWithLockAsync(async() =>
            {
                if (TryGetConfiguration(update.Value.CurrentState, out var configuration))
                {
                    TryGetRootNamespace(update.Value.CurrentState, out var rootNamespace);

                    // We need to deal with the case where the project was uninitialized, but now
                    // is valid for Razor. In that case we might have previously seen all of the documents
                    // but ignored them because the project wasn't active.
                    //
                    // So what we do to deal with this, is that we 'remove' all changed and removed items
                    // and then we 'add' all current items. This allows minimal churn to the PSM, but still
                    // makes us up to date.
                    var documents = GetCurrentDocuments(update.Value);
                    var changedDocuments = GetChangedAndRemovedDocuments(update.Value);

                    await UpdateAsync(() =>
                    {
                        var hostProject = new HostProject(CommonServices.UnconfiguredProject.FullPath, configuration, rootNamespace);

                        if (TryGetIntermediateOutputPath(update.Value.CurrentState, out var intermediatePath))
                        {
                            var projectConfigurationFile = Path.Combine(intermediatePath, _languageServerFeatureOptions.ProjectConfigurationFileName);
                            ProjectConfigurationFilePathStore.Set(hostProject.FilePath, projectConfigurationFile);
                        }

                        UpdateProjectUnsafe(hostProject);

                        for (var i = 0; i < changedDocuments.Length; i++)
                        {
                            RemoveDocumentUnsafe(changedDocuments[i]);
                        }

                        for (var i = 0; i < documents.Length; i++)
                        {
                            AddDocumentUnsafe(documents[i]);
                        }
                    }, CancellationToken.None).ConfigureAwait(false);
                }
                else
                {
                    // Ok we can't find a configuration. Let's assume this project isn't using Razor then.
                    await UpdateAsync(UninitializeProjectUnsafe, CancellationToken.None).ConfigureAwait(false);
                }
            }).ConfigureAwait(false), registerFaultHandler : true);
        }
        // Internal for testing
        protected RazorProjectHostBase(
            IUnconfiguredProjectCommonServices commonServices,
            Workspace workspace,
            ProjectConfigurationFilePathStore projectConfigurationFilePathStore,
            ProjectSnapshotManagerBase projectManager)
            : this(commonServices, workspace, projectConfigurationFilePathStore)
        {
            if (projectManager == null)
            {
                throw new ArgumentNullException(nameof(projectManager));
            }

            _projectManager = projectManager;
        }
        // Internal for testing
        internal async Task OnProjectChangedAsync(IProjectVersionedValue <IProjectSubscriptionUpdate> update)
        {
            if (IsDisposing || IsDisposed)
            {
                return;
            }

            await CommonServices.TasksService.LoadedProjectAsync(async() => await ExecuteWithLockAsync(async() =>
            {
                string mvcReferenceFullPath = null;
                if (update.Value.CurrentState.ContainsKey(ResolvedCompilationReference.SchemaName))
                {
                    var references = update.Value.CurrentState[ResolvedCompilationReference.SchemaName].Items;
                    foreach (var reference in references)
                    {
                        if (reference.Key.EndsWith(MvcAssemblyFileName, StringComparison.OrdinalIgnoreCase))
                        {
                            mvcReferenceFullPath = reference.Key;
                            break;
                        }
                    }
                }

                if (mvcReferenceFullPath == null)
                {
                    // Ok we can't find an MVC version. Let's assume this project isn't using Razor then.
                    await UpdateAsync(UninitializeProjectUnsafe, CancellationToken.None).ConfigureAwait(false);
                    return;
                }

                var version = GetAssemblyVersion(mvcReferenceFullPath);
                if (version == null)
                {
                    // Ok we can't find an MVC version. Let's assume this project isn't using Razor then.
                    await UpdateAsync(UninitializeProjectUnsafe, CancellationToken.None).ConfigureAwait(false);
                    return;
                }

                // We need to deal with the case where the project was uninitialized, but now
                // is valid for Razor. In that case we might have previously seen all of the documents
                // but ignored them because the project wasn't active.
                //
                // So what we do to deal with this, is that we 'remove' all changed and removed items
                // and then we 'add' all current items. This allows minimal churn to the PSM, but still
                // makes us up-to-date.
                var documents = GetCurrentDocuments(update.Value);
                var changedDocuments = GetChangedAndRemovedDocuments(update.Value);

                await UpdateAsync(() =>
                {
                    var configuration = FallbackRazorConfiguration.SelectConfiguration(version);
                    var hostProject = new HostProject(CommonServices.UnconfiguredProject.FullPath, configuration, rootNamespace: null);

                    if (TryGetIntermediateOutputPath(update.Value.CurrentState, out var intermediatePath))
                    {
                        var projectRazorJson = Path.Combine(intermediatePath, "project.razor.json");
                        ProjectConfigurationFilePathStore.Set(hostProject.FilePath, projectRazorJson);
                    }

                    UpdateProjectUnsafe(hostProject);

                    for (var i = 0; i < changedDocuments.Length; i++)
                    {
                        RemoveDocumentUnsafe(changedDocuments[i]);
                    }

                    for (var i = 0; i < documents.Length; i++)
                    {
                        AddDocumentUnsafe(documents[i]);
                    }
                }, CancellationToken.None).ConfigureAwait(false);
            }).ConfigureAwait(false), registerFaultHandler : true);
        }