-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Razor Source Generator reference with one loaded from a VSIX
- Loading branch information
Showing
9 changed files
with
126 additions
and
40 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/VisualStudio/Core/Def/Diagnostics/VisualStudioDiagnosticAnalyzerProvider.Factory.cs
This file contains 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,64 @@ | ||
// 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; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Diagnostics | ||
{ | ||
internal partial class VisualStudioDiagnosticAnalyzerProvider | ||
{ | ||
[Export, Shared] | ||
internal sealed class Factory | ||
{ | ||
private readonly IThreadingContext _threadingContext; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
private VisualStudioDiagnosticAnalyzerProvider? _lazyProvider; | ||
|
||
[ImportingConstructor] | ||
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
public Factory(IThreadingContext threadingContext, IServiceProvider serviceProvider) | ||
{ | ||
_threadingContext = threadingContext; | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public async Task<VisualStudioDiagnosticAnalyzerProvider> GetOrCreateProviderAsync() | ||
{ | ||
// the following code requires UI thread: | ||
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(); | ||
return GetOrCreateProviderOnMainThread(); | ||
} | ||
|
||
public VisualStudioDiagnosticAnalyzerProvider GetOrCreateProviderOnMainThread() | ||
{ | ||
Contract.ThrowIfFalse(_threadingContext.JoinableTaskContext.IsOnMainThread); | ||
|
||
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 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 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 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 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 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 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 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.