diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotWorker.cs b/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotWorker.cs index fde6e33cb2..5a9a3900bb 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotWorker.cs +++ b/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/DefaultProjectSnapshotWorker.cs @@ -48,7 +48,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem // Don't block the main thread if (_foregroundDispatcher.IsForegroundThread) { - return Task.Factory.StartNew(ProjectUpdatesCoreAsync, update, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.BackgroundScheduler); + return Task.Factory.StartNew(ProjectUpdatesCoreAsync, update, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.BackgroundScheduler); } return ProjectUpdatesCoreAsync(update); @@ -63,7 +63,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem var configuration = await _configurationFactory.GetConfigurationAsync(update.UnderlyingProject); update.Configuration = configuration; - var result = await _tagHelperResolver.GetTagHelpersAsync(update.UnderlyingProject); + var result = await _tagHelperResolver.GetTagHelpersAsync(update.UnderlyingProject, CancellationToken.None); update.TagHelpers = result.Descriptors; } } diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs b/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs index a16f46400b..9c278133b2 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs +++ b/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperResolver.cs @@ -11,12 +11,6 @@ namespace Microsoft.CodeAnalysis.Razor { public abstract TagHelperResolutionResult GetTagHelpers(Compilation compilation); - public virtual async Task GetTagHelpersAsync( - Project project, - CancellationToken cancellationToken = default(CancellationToken)) - { - var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); - return GetTagHelpers(compilation); - } + public abstract Task GetTagHelpersAsync(Project project, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.CodeAnalysis.Remote.Razor/DefaultTagHelperResolver.cs b/src/Microsoft.CodeAnalysis.Remote.Razor/DefaultTagHelperResolver.cs index 43b55a5b50..ddd8600b1f 100644 --- a/src/Microsoft.CodeAnalysis.Remote.Razor/DefaultTagHelperResolver.cs +++ b/src/Microsoft.CodeAnalysis.Remote.Razor/DefaultTagHelperResolver.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis.Razor; @@ -42,5 +44,11 @@ namespace Microsoft.CodeAnalysis.Remote.Razor return resolutionResult; } + + public override async Task GetTagHelpersAsync(Project project, CancellationToken cancellationToken) + { + var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + return GetTagHelpers(compilation); + } } } diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs index 31713fb3b2..0090d056d3 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultTagHelperResolver.cs @@ -3,15 +3,12 @@ using System; using System.Collections.Generic; -using System.Composition; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -28,7 +25,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor _workspace = workspace; } - public async Task GetTagHelpersAsync(Project project) + public override async Task GetTagHelpersAsync(Project project, CancellationToken cancellationToken) { if (project == null) { @@ -39,11 +36,9 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor { TagHelperResolutionResult result; - // We're being overly defensive here because the OOP host can return null for the client/session/operation + // We're being defensive here because the OOP host can return null for the client/session/operation // when it's disconnected (user stops the process). - // - // This will change in the future to an easier to consume API but for VS RTM this is what we have. - var client = await RazorLanguageServiceClientFactory.CreateAsync(_workspace, CancellationToken.None); + var client = await RazorLanguageServiceClientFactory.CreateAsync(_workspace, cancellationToken); if (client != null) { using (var session = await client.CreateSessionAsync(project.Solution)) @@ -53,7 +48,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor var jsonObject = await session.InvokeAsync( "GetTagHelpersAsync", new object[] { project.Id.Id, "Foo", }, - CancellationToken.None).ConfigureAwait(false); + cancellationToken).ConfigureAwait(false); result = GetTagHelperResolutionResult(jsonObject); @@ -66,7 +61,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor } // The OOP host is turned off, so let's do this in process. - var compilation = await project.GetCompilationAsync(CancellationToken.None).ConfigureAwait(false); + var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); result = GetTagHelpers(compilation); return result; } diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ITagHelperResolver.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ITagHelperResolver.cs deleted file mode 100644 index a0ae0eb27e..0000000000 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/ITagHelperResolver.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Razor; - -namespace Microsoft.VisualStudio.LanguageServices.Razor -{ - // ---------------------------------------------------------------------------------------------------- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead - // use the Microsoft.CodeAnalysis.Razor variant from Microsoft.CodeAnalysis.Razor.Workspaces - // ---------------------------------------------------------------------------------------------------- - public interface ITagHelperResolver - { - Task GetTagHelpersAsync(Project project); - } -} \ No newline at end of file diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTagHelperResolver.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTagHelperResolver.cs deleted file mode 100644 index ed6cc73313..0000000000 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Legacy/LegacyTagHelperResolver.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.ComponentModel.Composition; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Razor; - -namespace Microsoft.VisualStudio.LanguageServices.Razor -{ - // ---------------------------------------------------------------------------------------------------- - // NOTE: This is only here for VisualStudio binary compatibility. This type should not be used; instead - // use TagHelperResolver. - // ---------------------------------------------------------------------------------------------------- - [Export(typeof(ITagHelperResolver))] - internal class LegacyTagHelperResolver : DefaultTagHelperResolver, ITagHelperResolver - { - [ImportingConstructor] - public LegacyTagHelperResolver( - [Import(typeof(VisualStudioWorkspace))] Workspace workspace) - : base(workspace.Services.GetRequiredService(), workspace) - { - } - } -} \ No newline at end of file diff --git a/tooling/Microsoft.VisualStudio.RazorExtension/RazorInfo/RazorInfoViewModel.cs b/tooling/Microsoft.VisualStudio.RazorExtension/RazorInfo/RazorInfoViewModel.cs index 14bfdba4cf..c4098c3876 100644 --- a/tooling/Microsoft.VisualStudio.RazorExtension/RazorInfo/RazorInfoViewModel.cs +++ b/tooling/Microsoft.VisualStudio.RazorExtension/RazorInfo/RazorInfoViewModel.cs @@ -18,6 +18,7 @@ using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.TextManager.Interop; using System.IO; using Microsoft.CodeAnalysis.Razor; +using System.Threading; namespace Microsoft.VisualStudio.RazorExtension.RazorInfo { @@ -177,7 +178,7 @@ namespace Microsoft.VisualStudio.RazorExtension.RazorInfo .Select(reference => reference.Display) .Select(filter => Path.GetFileNameWithoutExtension(filter)); var projectFilters = project.AllProjectReferences.Select(filter => solution.GetProject(filter.ProjectId).AssemblyName); - var resolutionResult = await _tagHelperResolver.GetTagHelpersAsync(project); + var resolutionResult = await _tagHelperResolver.GetTagHelpersAsync(project, CancellationToken.None); var files = GetCshtmlDocuments(project);