From 163c09f9849258cc50e80277d319014936cb5b55 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 15 Oct 2019 10:29:33 -0700 Subject: [PATCH] Add support for partial component class editing -> refresh components. - We now do aggressive detection on the type of C# class that's being edited. In order to not impact C# scenarios we only do work if C# assets are available to us. Meaning, we inspect the old document and if that document has its' semantic model available we spend cycles to determine if it's a component. In the case that we find a C# component class that wasn't previously caught we enqueue an update. - Added several tests to ensure we enqueue and that we properly detect component classes. aspnet/AspNetCoredotnet/aspnetcore-tooling#14646 \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/d8b62e121fe748f2c581066ac451918e67bf77a5 --- .../src/ComponentDetectionConventions.cs | 28 +++++++++++++++++++ .../ComponentTagHelperDescriptorProvider.cs | 6 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentDetectionConventions.cs diff --git a/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentDetectionConventions.cs b/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentDetectionConventions.cs new file mode 100644 index 0000000000..214f9e36a4 --- /dev/null +++ b/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentDetectionConventions.cs @@ -0,0 +1,28 @@ +// 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; + +namespace Microsoft.CodeAnalysis.Razor +{ + internal static class ComponentDetectionConventions + { + public static bool IsComponent(INamedTypeSymbol symbol, INamedTypeSymbol icomponentSymbol) + { + if (symbol is null) + { + throw new ArgumentNullException(nameof(symbol)); + } + + if (icomponentSymbol is null) + { + throw new ArgumentNullException(nameof(icomponentSymbol)); + } + + return + symbol.DeclaredAccessibility == Accessibility.Public && + !symbol.IsAbstract && + symbol.AllInterfaces.Contains(icomponentSymbol); + } + } +} diff --git a/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentTagHelperDescriptorProvider.cs b/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentTagHelperDescriptorProvider.cs index f160b53a90..ebc1947ca7 100644 --- a/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentTagHelperDescriptorProvider.cs +++ b/src/Razor/Microsoft.CodeAnalysis.Razor/src/ComponentTagHelperDescriptorProvider.cs @@ -573,10 +573,8 @@ namespace Microsoft.CodeAnalysis.Razor return false; } - return - symbol.DeclaredAccessibility == Accessibility.Public && - !symbol.IsAbstract && - symbol.AllInterfaces.Contains(_symbols.IComponent); + var isComponent = ComponentDetectionConventions.IsComponent(symbol, _symbols.IComponent); + return isComponent; } } }