diff --git a/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectChangeKind.cs b/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectChangeKind.cs index 000ebd1953..c2ff3feacf 100644 --- a/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectChangeKind.cs +++ b/src/Microsoft.CodeAnalysis.Razor.Workspaces/ProjectSystem/ProjectChangeKind.cs @@ -8,5 +8,6 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem Added, Removed, Changed, + TagHelpersChanged, } } diff --git a/src/Microsoft.VisualStudio.Editor.Razor/ContextChangeEventArgs.cs b/src/Microsoft.VisualStudio.Editor.Razor/ContextChangeEventArgs.cs new file mode 100644 index 0000000000..ad28406a15 --- /dev/null +++ b/src/Microsoft.VisualStudio.Editor.Razor/ContextChangeEventArgs.cs @@ -0,0 +1,17 @@ +// 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.VisualStudio.Editor.Razor +{ + public sealed class ContextChangeEventArgs : EventArgs + { + public ContextChangeEventArgs(ContextChangeKind kind) + { + Kind = kind; + } + + public ContextChangeKind Kind { get; } + } +} \ No newline at end of file diff --git a/src/Microsoft.VisualStudio.Editor.Razor/ContextChangeKind.cs b/src/Microsoft.VisualStudio.Editor.Razor/ContextChangeKind.cs new file mode 100644 index 0000000000..867fa9857f --- /dev/null +++ b/src/Microsoft.VisualStudio.Editor.Razor/ContextChangeKind.cs @@ -0,0 +1,12 @@ +// 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. + +namespace Microsoft.VisualStudio.Editor.Razor +{ + public enum ContextChangeKind + { + ProjectChanged, + EditorSettingsChanged, + TagHelpersChanged, + } +} \ No newline at end of file diff --git a/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioRazorParser.cs b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioRazorParser.cs index 4962d978ee..99a7163ba8 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioRazorParser.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/DefaultVisualStudioRazorParser.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -133,7 +132,7 @@ namespace Microsoft.VisualStudio.Editor.Razor } // Internal for testing - internal void DocumentTracker_ContextChanged(object sender, EventArgs args) + internal void DocumentTracker_ContextChanged(object sender, ContextChangeEventArgs args) { _dispatcher.AssertForegroundThread(); diff --git a/src/Microsoft.VisualStudio.Editor.Razor/VisualStudioDocumentTracker.cs b/src/Microsoft.VisualStudio.Editor.Razor/VisualStudioDocumentTracker.cs index 9c9159fafb..efd1016bd1 100644 --- a/src/Microsoft.VisualStudio.Editor.Razor/VisualStudioDocumentTracker.cs +++ b/src/Microsoft.VisualStudio.Editor.Razor/VisualStudioDocumentTracker.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor.Editor; using Microsoft.CodeAnalysis.Razor.ProjectSystem; @@ -13,12 +14,14 @@ namespace Microsoft.VisualStudio.Editor.Razor { public abstract class VisualStudioDocumentTracker { - public abstract event EventHandler ContextChanged; + public abstract event EventHandler ContextChanged; internal abstract ProjectExtensibilityConfiguration Configuration { get; } public abstract EditorSettings EditorSettings { get; } + public abstract IReadOnlyList TagHelpers { get; } + public abstract bool IsSupportedProject { get; } public abstract string FilePath { get; } diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultVisualStudioDocumentTracker.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultVisualStudioDocumentTracker.cs index e68c049d8b..1cc76169aa 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultVisualStudioDocumentTracker.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/Editor/DefaultVisualStudioDocumentTracker.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Razor; using Microsoft.CodeAnalysis.Razor.Editor; @@ -27,7 +28,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor private ProjectSnapshot _project; private string _projectPath; - public override event EventHandler ContextChanged; + public override event EventHandler ContextChanged; public DefaultVisualStudioDocumentTracker( string filePath, @@ -81,6 +82,8 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor public override EditorSettings EditorSettings => _editorSettingsManager.Current; + public override IReadOnlyList TagHelpers => Array.Empty(); + public override bool IsSupportedProject => _isSupportedProject; public override Project Project => _workspace.CurrentSolution.GetProject(_project.UnderlyingProject.Id); @@ -176,7 +179,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor _projectManager.Changed += ProjectManager_Changed; _editorSettingsManager.Changed += EditorSettingsManager_Changed; - OnContextChanged(_project); + OnContextChanged(_project, ContextChangeKind.ProjectChanged); } private void Unsubscribe() @@ -187,17 +190,17 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor // Detached from project. _isSupportedProject = false; _project = null; - OnContextChanged(project: null); + OnContextChanged(project: null, kind: ContextChangeKind.ProjectChanged); } - private void OnContextChanged(ProjectSnapshot project) + private void OnContextChanged(ProjectSnapshot project, ContextChangeKind kind) { _project = project; var handler = ContextChanged; if (handler != null) { - handler(this, EventArgs.Empty); + handler(this, new ContextChangeEventArgs(kind)); } } @@ -206,14 +209,21 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Editor if (_projectPath != null && string.Equals(_projectPath, e.Project.UnderlyingProject.FilePath, StringComparison.OrdinalIgnoreCase)) { - OnContextChanged(e.Project); + if (e.Kind == ProjectChangeKind.TagHelpersChanged) + { + OnContextChanged(e.Project, ContextChangeKind.TagHelpersChanged); + } + else + { + OnContextChanged(e.Project, ContextChangeKind.ProjectChanged); + } } } // Internal for testing internal void EditorSettingsManager_Changed(object sender, EditorSettingsChangedEventArgs args) { - OnContextChanged(_project); + OnContextChanged(_project, ContextChangeKind.EditorSettingsChanged); } } }