-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Replace Razor Source Generator reference with one loaded from a VSIX #63912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d81aa5a
Replace Razor Source Generator reference with one loaded from a VSIX
tmat 54e2fe8
Rename
tmat 061197b
Cleanup
tmat f61d0c4
Feedback
tmat 076b515
Feedbakc
tmat b94199e
Typo
tmat e1f6fdd
Fix tests
tmat d292fb1
Feedback
tmat f0f31f1
Feedback
tmat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/VisualStudio/Core/Def/Diagnostics/IVisualStudioDiagnosticAnalyzerProviderFactory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Microsoft.VisualStudio.LanguageServices.Implementation.Diagnostics | ||
| { | ||
| /// <summary> | ||
| /// Abstraction for testing purposes. | ||
| /// </summary> | ||
| internal interface IVisualStudioDiagnosticAnalyzerProviderFactory | ||
| { | ||
| Task<VisualStudioDiagnosticAnalyzerProvider> GetOrCreateProviderAsync(CancellationToken cancellationToken); | ||
| } | ||
| } | ||
60 changes: 60 additions & 0 deletions
60
src/VisualStudio/Core/Def/Diagnostics/VisualStudioDiagnosticAnalyzerProvider.Factory.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Composition; | ||
| using System.Reflection; | ||
| using System.Threading.Tasks; | ||
| using Roslyn.Utilities; | ||
| using Microsoft.CodeAnalysis.Host.Mef; | ||
| using Microsoft.CodeAnalysis.Editor.Shared.Utilities; | ||
| using Microsoft.VisualStudio.Shell; | ||
| using System.Threading; | ||
|
|
||
| namespace Microsoft.VisualStudio.LanguageServices.Implementation.Diagnostics | ||
| { | ||
| internal partial class VisualStudioDiagnosticAnalyzerProvider | ||
| { | ||
| [Export(typeof(IVisualStudioDiagnosticAnalyzerProviderFactory)), Shared] | ||
| internal sealed class Factory : IVisualStudioDiagnosticAnalyzerProviderFactory | ||
| { | ||
| private readonly IThreadingContext _threadingContext; | ||
| private readonly IServiceProvider _serviceProvider; | ||
|
|
||
| private VisualStudioDiagnosticAnalyzerProvider? _lazyProvider; | ||
|
|
||
| [ImportingConstructor] | ||
| [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
| public Factory(IThreadingContext threadingContext, SVsServiceProvider serviceProvider) | ||
| { | ||
| _threadingContext = threadingContext; | ||
| _serviceProvider = serviceProvider; | ||
| } | ||
|
|
||
| public async Task<VisualStudioDiagnosticAnalyzerProvider> GetOrCreateProviderAsync(CancellationToken cancellationToken) | ||
| { | ||
| // the following code requires UI thread: | ||
| await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); | ||
|
|
||
| if (_lazyProvider != null) | ||
| { | ||
| return _lazyProvider; | ||
| } | ||
|
|
||
| var dte = (EnvDTE.DTE)_serviceProvider.GetService(typeof(EnvDTE.DTE)); | ||
|
|
||
| // Microsoft.VisualStudio.ExtensionManager is non-versioned, so we need to dynamically load it, depending on the version of VS we are running on | ||
| // this will allow us to build once and deploy on different versions of VS SxS. | ||
| var vsDteVersion = Version.Parse(dte.Version.Split(' ')[0]); // DTE.Version is in the format of D[D[.D[D]]][ (?+)], so we need to split out the version part and check for uninitialized Major/Minor below | ||
|
|
||
| var assembly = Assembly.Load($"Microsoft.VisualStudio.ExtensionManager, Version={(vsDteVersion.Major == -1 ? 0 : vsDteVersion.Major)}.{(vsDteVersion.Minor == -1 ? 0 : vsDteVersion.Minor)}.0.0, PublicKeyToken=b03f5f7f11d50a3a"); | ||
| var typeIExtensionContent = assembly.GetType("Microsoft.VisualStudio.ExtensionManager.IExtensionContent"); | ||
| var type = assembly.GetType("Microsoft.VisualStudio.ExtensionManager.SVsExtensionManager"); | ||
| var extensionManager = _serviceProvider.GetService(type); | ||
|
|
||
| return _lazyProvider = new VisualStudioDiagnosticAnalyzerProvider(extensionManager, typeIExtensionContent); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.