提交 f8c2b554 编写于 作者: C Charles Stoner 提交者: GitHub

Merge branch 'dev15-rc2' into bp

......@@ -2,9 +2,9 @@
using System;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ChangeSignature;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.CodeRefactorings.ChangeSignature;
using Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Roslyn.Test.Utilities;
......@@ -15,14 +15,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ChangeSignature
public partial class ChangeSignatureTests : AbstractChangeSignatureTests
{
protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspace workspace)
{
return new ChangeSignatureCodeRefactoringProvider();
}
=> new ChangeSignatureCodeRefactoringProvider();
protected override string GetLanguage()
{
return LanguageNames.CSharp;
}
=> LanguageNames.CSharp;
protected override Task<TestWorkspace> CreateWorkspaceFromFileAsync(string definition, ParseOptions parseOptions, CompilationOptions compilationOptions)
{
......
......@@ -5,10 +5,9 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.CodeRefactorings.EncapsulateField;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.EncapsulateField;
using Microsoft.CodeAnalysis.Options;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -18,9 +17,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings.Encaps
public class EncapsulateFieldTests : AbstractCSharpCodeActionTest
{
protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspace workspace)
{
return new EncapsulateFieldRefactoringProvider();
}
=> new EncapsulateFieldRefactoringProvider();
private static readonly Dictionary<OptionKey, object> AllOptionsOff =
new Dictionary<OptionKey, object>
......
......@@ -3,7 +3,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.CodeFixes.FullyQualify;
using Microsoft.CodeAnalysis.CodeFixes.NamingStyles;
using Microsoft.CodeAnalysis.CSharp.Diagnostics.NamingStyles;
using Microsoft.CodeAnalysis.Diagnostics;
using Roslyn.Test.Utilities;
......@@ -14,7 +14,9 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.NamingStyle
public partial class NamingStylesTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal override Tuple<DiagnosticAnalyzer, CodeFixProvider> CreateDiagnosticProviderAndFixer(Workspace workspace) =>
new Tuple<DiagnosticAnalyzer, CodeFixProvider>(new CSharpNamingStyleDiagnosticAnalyzer(), new CSharpNamingStyleCodeFixProvider());
new Tuple<DiagnosticAnalyzer, CodeFixProvider>(
new CSharpNamingStyleDiagnosticAnalyzer(),
new NamingStyleCodeFixProvider());
[WpfFact, Trait(Traits.Feature, Traits.Features.NamingStyle)]
public async Task TestPascalCaseClass_CorrectName()
......
......@@ -133,7 +133,10 @@ private IStreamingFindReferencesPresenter GetStreamingPresenter()
await context.OnCompletedAsync().ConfigureAwait(false);
}
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
catch (OperationCanceledException)
{
}
catch (Exception e) when (FatalError.ReportWithoutCrash(e))
{
}
}
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.ChangeSignature
Imports Microsoft.CodeAnalysis.CodeRefactorings
Imports Microsoft.CodeAnalysis.Editor.UnitTests.ChangeSignature
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Extensions
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ChangeSignature
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.ChangeSignature
Partial Public Class ChangeSignatureTests
......
......@@ -2,7 +2,7 @@
Imports Microsoft.CodeAnalysis.CodeRefactorings
Imports Microsoft.CodeAnalysis.CodeStyle
Imports Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.EncapsulateField
Imports Microsoft.CodeAnalysis.EncapsulateField
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeRefactorings.EncapsulateField
Public Class EncapsulateFieldTests
......
......@@ -90,7 +90,6 @@
<Compile Include="UsePatternMatching\CSharpAsAndNullCheckDiagnosticAnalyzer.cs" />
<Compile Include="UsePatternMatching\CSharpAsAndNullCheckCodeFixProvider.cs" />
<Compile Include="Structure\Providers\BlockSyntaxStructureProvider.cs" />
<Compile Include="ChangeSignature\ChangeSignatureCodeRefactoringProvider.cs" />
<Compile Include="ChangeSignature\ChangeSignatureFormattingRule.cs" />
<Compile Include="ChangeSignature\CSharpChangeSignatureService.cs" />
<Compile Include="ChangeSignature\UnifiedArgumentSyntax.cs" />
......@@ -112,7 +111,6 @@
<Compile Include="CodeFixes\Iterator\CSharpAddYieldCodeFixProvider.cs" />
<Compile Include="CodeFixes\Iterator\CSharpChangeToIEnumerableCodeFixProvider.cs" />
<Compile Include="QualifyMemberAccess\CSharpQualifyMemberAccessCodeFixProvider.cs" />
<Compile Include="CodeFixes\NamingStyles\CSharpNamingStyleCodeFixProvider.cs" />
<Compile Include="CodeFixes\RemoveUnnecessaryCast\RemoveUnnecessaryCastCodeFixProvider.RemoveUnnecessaryCastFixAllProvider.cs" />
<Compile Include="CodeFixes\RemoveUnnecessaryCast\RemoveUnnecessaryCastCodeFixProvider.cs" />
<Compile Include="RemoveUnnecessaryImports\CSharpRemoveUnnecessaryImportsCodeFixProvider.cs" />
......@@ -123,8 +121,6 @@
<Compile Include="CodeFixes\TypeStyle\UseImplicitTypeCodeFixProvider.cs" />
<Compile Include="CodeLens\CSharpCodeLensDisplayInfoService.cs" />
<Compile Include="ConvertToInterpolatedString\CSharpConvertPlaceholderToInterpolatedStringRefactoringProvider.cs" />
<Compile Include="CodeRefactorings\EncapsulateField\EncapsulateFieldCodeRefactoringProvider.cs" />
<Compile Include="CodeRefactorings\ExtractInterface\ExtractInterfaceCodeRefactoringProvider.cs" />
<Compile Include="CodeRefactorings\InlineTemporary\InlineTemporaryCodeRefactoringProvider.cs" />
<Compile Include="CodeRefactorings\InlineTemporary\InlineTemporaryCodeRefactoringProvider.InitializerRewriter.cs" />
<Compile Include="CodeRefactorings\InlineTemporary\InlineTemporaryCodeRefactoringProvider.ReferenceRewriter.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.ChangeSignature;
using Microsoft.CodeAnalysis.CodeRefactorings;
namespace Microsoft.CodeAnalysis.CSharp.CodeRefactorings.ChangeSignature
{
[ExportCodeRefactoringProvider(LanguageNames.CSharp, Name = PredefinedCodeRefactoringProviderNames.ChangeSignature), Shared]
internal class ChangeSignatureCodeRefactoringProvider : AbstractChangeSignatureCodeRefactoringProvider
{
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeFixes.NamingStyles;
namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.FullyQualify
{
[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.ApplyNamingStyle), Shared]
internal class CSharpNamingStyleCodeFixProvider : AbstractNamingStyleCodeFixProvider
{
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CodeRefactorings.EncapsulateField;
namespace Microsoft.CodeAnalysis.CSharp.CodeRefactorings.EncapsulateField
{
[ExportCodeRefactoringProvider(LanguageNames.CSharp, Name = PredefinedCodeRefactoringProviderNames.EncapsulateField), Shared]
internal class EncapsulateFieldRefactoringProvider : AbstractEncapsulateFieldRefactoringProvider
{
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.ExtractInterface;
namespace Microsoft.CodeAnalysis.CSharp.CodeRefactorings.ExtractInterface
{
[ExportCodeRefactoringProvider(LanguageNames.CSharp, Name = PredefinedCodeRefactoringProviderNames.ExtractInterface), Shared]
internal class ExtractInterfaceCodeRefactoringProvider : AbstractExtractInterfaceCodeRefactoringProvider
{
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Shared.Extensions;
namespace Microsoft.CodeAnalysis.ChangeSignature
{
internal class AbstractChangeSignatureCodeRefactoringProvider : CodeRefactoringProvider
[ExportCodeRefactoringProvider(LanguageNames.CSharp, LanguageNames.VisualBasic,
Name = PredefinedCodeRefactoringProviderNames.ChangeSignature), Shared]
internal class ChangeSignatureCodeRefactoringProvider : CodeRefactoringProvider
{
public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
......@@ -15,4 +18,4 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
context.RegisterRefactorings(actions);
}
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -14,12 +15,12 @@
namespace Microsoft.CodeAnalysis.CodeFixes.NamingStyles
{
internal abstract class AbstractNamingStyleCodeFixProvider : CodeFixProvider
[ExportCodeFixProvider(LanguageNames.CSharp, LanguageNames.VisualBasic,
Name = PredefinedCodeFixProviderNames.ApplyNamingStyle), Shared]
internal class NamingStyleCodeFixProvider : CodeFixProvider
{
public override ImmutableArray<string> FixableDiagnosticIds
{
get { return ImmutableArray.Create(IDEDiagnosticIds.NamingRuleId); }
}
public override ImmutableArray<string> FixableDiagnosticIds { get; }
= ImmutableArray.Create(IDEDiagnosticIds.NamingRuleId);
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
......@@ -47,8 +48,8 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
symbol,
fixedName,
await document.GetOptionsAsync(c).ConfigureAwait(false),
c).ConfigureAwait(false),
nameof(AbstractNamingStyleCodeFixProvider)),
c).ConfigureAwait(false),
nameof(NamingStyleCodeFixProvider)),
diagnostic);
}
}
......@@ -61,4 +62,4 @@ public FixNameCodeAction(string title, Func<CancellationToken, Task<Solution>> c
}
}
}
}
}
\ No newline at end of file
......@@ -18,4 +18,4 @@ internal static void RegisterRefactorings(this CodeRefactoringContext context, I
}
}
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.EncapsulateField;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Shared.Extensions;
namespace Microsoft.CodeAnalysis.CodeRefactorings.EncapsulateField
namespace Microsoft.CodeAnalysis.EncapsulateField
{
internal abstract class AbstractEncapsulateFieldRefactoringProvider : CodeRefactoringProvider
[ExportCodeRefactoringProvider(LanguageNames.CSharp, LanguageNames.VisualBasic,
Name = PredefinedCodeRefactoringProviderNames.EncapsulateField), Shared]
internal class EncapsulateFieldRefactoringProvider : CodeRefactoringProvider
{
public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
......@@ -15,4 +18,4 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
context.RegisterRefactorings(actions);
}
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.Shared.Extensions;
namespace Microsoft.CodeAnalysis.ExtractInterface
{
internal abstract class AbstractExtractInterfaceCodeRefactoringProvider : CodeRefactoringProvider
[ExportCodeRefactoringProvider(LanguageNames.CSharp, LanguageNames.VisualBasic,
Name = PredefinedCodeRefactoringProviderNames.ExtractInterface), Shared]
internal class ExtractInterfaceCodeRefactoringProvider : CodeRefactoringProvider
{
public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
......@@ -15,4 +18,4 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
context.RegisterRefactorings(actions);
}
}
}
}
\ No newline at end of file
......@@ -101,6 +101,8 @@
<Compile Include="AddImport\CodeActions\PackageReference.InstallPackageAndAddImportCodeAction.cs" />
<Compile Include="AddImport\CodeActions\PackageReference.InstallWithPackageManagerCodeAction.cs" />
<Compile Include="ConvertToInterpolatedString\AbstractConvertConcatenationToInterpolatedStringRefactoringProvider.cs" />
<Compile Include="EncapsulateField\EncapsulateFieldRefactoringProvider.cs" />
<Compile Include="ExtractInterface\ExtractInterfaceCodeRefactoringProvider.cs" />
<Compile Include="FeaturesResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
......@@ -451,11 +453,9 @@
<Compile Include="EditAndContinue\RudeEditKind.cs" />
<Compile Include="EditAndContinue\RudeEditDiagnosticDescriptors.cs" />
<Compile Include="EditAndContinue\SessionReadOnlyReason.cs" />
<Compile Include="EncapsulateField\AbstractEncapsulateFieldCodeRefactoringProvider.cs" />
<Compile Include="EncapsulateField\AbstractEncapsulateFieldService.cs" />
<Compile Include="EncapsulateField\EncapsulateFieldCodeAction.cs" />
<Compile Include="EncapsulateField\EncapsulateFieldResult.cs" />
<Compile Include="ExtractInterface\AbstractExtractInterfaceCodeRefactoringProvider.cs" />
<Compile Include="ExtractInterface\AbstractExtractInterfaceService.cs" />
<Compile Include="ExtractInterface\ExtractInterfaceCodeAction.cs" />
<Compile Include="ExtractInterface\ExtractInterfaceOptionsResult.cs" />
......@@ -706,4 +706,4 @@
<ItemGroup />
<Import Project="..\..\..\Compilers\Core\AnalyzerDriver\AnalyzerDriver.projitems" Label="Shared" />
<Import Project="..\..\..\..\build\Targets\Imports.targets" />
</Project>
</Project>
\ No newline at end of file
......@@ -78,7 +78,6 @@
<Compile Include="..\..\..\Compilers\VisualBasic\Portable\Syntax\LambdaUtilities.vb">
<Link>InternalUtilities\LambdaUtilities.vb</Link>
</Compile>
<Compile Include="ChangeSignature\ChangeSignatureCodeRefactoringProvider.vb" />
<Compile Include="ChangeSignature\ChangeSignatureFormattingRule.vb" />
<Compile Include="ChangeSignature\UnifiedArgumentSyntax.vb" />
<Compile Include="ChangeSignature\VisualBasicChangeSignatureService.vb" />
......@@ -111,7 +110,6 @@
<Compile Include="CodeFixes\IncorrectFunctionReturnType\IncorrectFunctionReturnTypeCodeFixProvider.vb" />
<Compile Include="CodeFixes\MoveToTopOfFile\MoveToTopOfFileCodeFixProvider.MoveToLineCodeAction.vb" />
<Compile Include="CodeFixes\MoveToTopOfFile\MoveToTopOfFileCodeFixProvider.vb" />
<Compile Include="CodeFixes\NamingStyles\VisualBasicNamingStyleCodeFixProvider.vb" />
<Compile Include="CodeFixes\OverloadBase\OverloadBaseCodeFixProvider.AddOverloads.vb" />
<Compile Include="CodeFixes\OverloadBase\OverloadBaseCodeFixProvider.vb" />
<Compile Include="Structure\Providers\CollectionInitializerStructureProvider.vb" />
......@@ -128,8 +126,6 @@
<Compile Include="CodeLens\VisualBasicDisplayInfoService.vb" />
<Compile Include="ConvertToInterpolatedString\VisualBasicConvertConcatenationToInterpolatedStringRefactoringProvider.vb" />
<Compile Include="ConvertToInterpolatedString\VisualBasicConvertPlaceholderToInterpolatedStringRefactoringProvider.vb" />
<Compile Include="CodeRefactorings\EncapsulateField\EncapsulateFieldRefactoringProvider.vb" />
<Compile Include="CodeRefactorings\ExtractInterface\ExtractInterfaceCodeRefactoringProvider.vb" />
<Compile Include="CodeRefactorings\InlineTemporary\InlineTemporaryCodeRefactoringProvider.ReferenceRewriter.vb" />
<Compile Include="CodeRefactorings\InlineTemporary\InlineTemporaryCodeRefactoringProvider.vb" />
<Compile Include="CodeRefactorings\InvertIf\InvertIfCodeRefactoringProvider.vb" />
......@@ -474,4 +470,4 @@
</ItemGroup>
<Import Project="..\..\..\Compilers\VisualBasic\BasicAnalyzerDriver\BasicAnalyzerDriver.projitems" Label="Shared" />
<Import Project="..\..\..\..\build\Targets\Imports.targets" />
</Project>
</Project>
\ No newline at end of file
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition
Imports Microsoft.CodeAnalysis.ChangeSignature
Imports Microsoft.CodeAnalysis.CodeRefactorings
Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ChangeSignature
<ExportCodeRefactoringProvider(LanguageNames.VisualBasic, Name:=PredefinedCodeRefactoringProviderNames.ChangeSignature), [Shared]>
Friend Class ChangeSignatureCodeRefactoringProvider
Inherits AbstractChangeSignatureCodeRefactoringProvider
End Class
End Namespace
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.CodeFixes.NamingStyles
Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.NamingStyles
<ExportCodeFixProvider(LanguageNames.VisualBasic, Name:=PredefinedCodeFixProviderNames.ApplyNamingStyle), [Shared]>
Friend Class VisualBasicNamingStyleCodeFixProvider
Inherits AbstractNamingStyleCodeFixProvider
End Class
End Namespace
\ No newline at end of file
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition
Imports Microsoft.CodeAnalysis.CodeRefactorings
Imports Microsoft.CodeAnalysis.CodeRefactorings.EncapsulateField
Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.EncapsulateField
<ExportCodeRefactoringProvider(LanguageNames.VisualBasic, Name:=PredefinedCodeRefactoringProviderNames.EncapsulateField), [Shared]>
Friend Class EncapsulateFieldRefactoringProvider
Inherits AbstractEncapsulateFieldRefactoringProvider
End Class
End Namespace
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition
Imports Microsoft.CodeAnalysis.CodeRefactorings
Imports Microsoft.CodeAnalysis.ExtractInterface
Namespace Microsoft.CodeAnalysis.VisualBasic.CodeRefactorings.ExtractInterface
<ExportCodeRefactoringProvider(LanguageNames.VisualBasic, Name:=PredefinedCodeRefactoringProviderNames.ExtractInterface), [Shared]>
Friend Class ExtractInterfaceCodeRefactoringProvider
Inherits AbstractExtractInterfaceCodeRefactoringProvider
End Class
End Namespace
......@@ -42,7 +42,7 @@ public static void ResetLogger()
/// <summary>
/// let one such as ETA to set logger for the service layer
/// </summary>
internal static void SetLogger(IOptionService optionsService, string loggerName)
internal static void SetLogger(IGlobalOptionService optionsService, string loggerName)
{
if (loggerName == null)
{
......@@ -90,12 +90,12 @@ private static FunctionId GetFunctionId(string functionId)
return (FunctionId)Enum.Parse(typeof(FunctionId), functionId);
}
private static ILogger GetLogger(IOptionService optionsService, string loggerName)
private static ILogger GetLogger(IGlobalOptionService optionsService, string loggerName)
{
switch (loggerName)
{
case "EtwLogger":
return new EtwLogger(Logger.GetLoggingChecker(optionsService));
return new EtwLogger(optionsService);
case "TraceLogger":
return new TraceLogger(Logger.GetLoggingChecker(optionsService));
default:
......
......@@ -22,7 +22,7 @@ public TraceLogger()
{
}
public TraceLogger(IOptionService optionService)
public TraceLogger(IGlobalOptionService optionService)
: this(Logger.GetLoggingChecker(optionService))
{
}
......
......@@ -40,7 +40,7 @@ try
switch ($branchName)
{
"dev15-rc" { }
"dev15-rc2" { }
"master" { }
default
{
......
// Copyright (c) Microsoft. 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.LanguageServices.Setup
{
/// <summary>
/// This interface allows the host to set up a telemetry service during package initialization.
/// </summary>
internal interface IRoslynTelemetrySetup
{
void Initialize(IServiceProvider serviceProvider);
}
}
......@@ -33,7 +33,14 @@ internal sealed class LanguageSettingsPersister : ForegroundThreadAffinitizedObj
private readonly IComEventSink _textManagerEvents2Sink;
private readonly IBidirectionalMap<string, Guid> _languageMap;
/// <summary>
/// The mapping between language names and Visual Studio language service GUIDs.
/// </summary>
/// <remarks>
/// This is a map between string and <see cref="Tuple{Guid}"/> rather than just to <see cref="Guid"/>
/// to avoid a bunch of JIT during startup. Generics of value types like <see cref="Guid"/> will have to JIT
/// but the ngen image will exist for the basic map between two reference types, since those are reused.</remarks>
private readonly IBidirectionalMap<string, Tuple<Guid>> _languageMap;
/// <remarks>
/// We make sure this code is from the UI by asking for all serializers on the UI thread in <see cref="HACK_AbstractCreateServicesOnUiThread"/>.
......@@ -48,16 +55,16 @@ internal sealed class LanguageSettingsPersister : ForegroundThreadAffinitizedObj
_optionService = optionService;
// TODO: make this configurable
_languageMap = BidirectionalMap<string, Guid>.Empty.Add(LanguageNames.CSharp, Guids.CSharpLanguageServiceId)
.Add(LanguageNames.VisualBasic, Guids.VisualBasicLanguageServiceId)
.Add("TypeScript", new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77"))
.Add("F#", new Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B"))
.Add("Xaml", new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41"));
_languageMap = BidirectionalMap<string, Tuple<Guid>>.Empty.Add(LanguageNames.CSharp, Tuple.Create(Guids.CSharpLanguageServiceId))
.Add(LanguageNames.VisualBasic, Tuple.Create(Guids.VisualBasicLanguageServiceId))
.Add("TypeScript", Tuple.Create(new Guid("4a0dddb5-7a95-4fbf-97cc-616d07737a77")))
.Add("F#", Tuple.Create(new Guid("BC6DD5A5-D4D6-4dab-A00D-A51242DBAF1B")))
.Add("Xaml", Tuple.Create(new Guid("CD53C9A1-6BC2-412B-BE36-CC715ED8DD41")));
foreach (var languageGuid in _languageMap.Values)
{
var languagePreferences = new LANGPREFERENCES3[1];
languagePreferences[0].guidLang = languageGuid;
languagePreferences[0].guidLang = languageGuid.Item1;
// The function can potentially fail if that language service isn't installed
if (ErrorHandler.Succeeded(_textManager.GetUserPreferences4(pViewPrefs: null, pLangPrefs: languagePreferences, pColorPrefs: null)))
......@@ -100,7 +107,7 @@ private void RefreshLanguageSettings(LANGPREFERENCES3[] langPrefs)
this.AssertIsForeground();
string languageName;
if (_languageMap.TryGetKey(langPrefs[0].guidLang, out languageName))
if (_languageMap.TryGetKey(Tuple.Create(langPrefs[0].guidLang), out languageName))
{
foreach (var option in _supportedOptions)
{
......@@ -238,7 +245,7 @@ public bool TryPersist(OptionKey optionKey, object value)
return false;
}
Guid languageServiceGuid;
Tuple<Guid> languageServiceGuid;
if (!_languageMap.TryGetValue(optionKey.Language, out languageServiceGuid))
{
......@@ -247,7 +254,7 @@ public bool TryPersist(OptionKey optionKey, object value)
}
var languagePreferences = new LANGPREFERENCES3[1];
languagePreferences[0].guidLang = languageServiceGuid;
languagePreferences[0].guidLang = languageServiceGuid.Item1;
Marshal.ThrowExceptionForHR(_textManager.GetUserPreferences4(null, languagePreferences, null));
SetValueForOption(optionKey.Option, ref languagePreferences[0], value);
......
......@@ -21,7 +21,6 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
/// Manages metadata references for VS projects.
/// </summary>
/// <remarks>
/// The references correspond to hierarchy nodes in the Solution Explorer.
/// They monitor changes in the underlying files and provide snapshot references (subclasses of <see cref="PortableExecutableReference"/>)
/// that can be passed to the compiler. These snapshot references serve the underlying metadata blobs from a VS-wide storage, if possible,
/// from <see cref="ITemporaryStorageService"/>.
......@@ -34,29 +33,39 @@ internal sealed partial class VisualStudioMetadataReferenceManager : IWorkspaceS
private readonly MetadataCache _metadataCache;
private readonly ImmutableArray<string> _runtimeDirectories;
private readonly IVsFileChangeEx _fileChangeService;
private readonly IVsXMLMemberIndexService _xmlMemberIndexService;
private readonly IVsSmartOpenScope _smartOpenScopeService;
private readonly ITemporaryStorageService _temporaryStorageService;
internal IVsXMLMemberIndexService XmlMemberIndexService { get; }
/// <summary>
/// The smart open scope service. This can be null during shutdown when using the service might crash. Any
/// use of this field or derived types should be synchronized with <see cref="_readerWriterLock"/> to ensure
/// you don't grab the field and then use it while shutdown continues.
/// </summary>
private IVsSmartOpenScope SmartOpenScopeServiceOpt { get; set; }
internal IVsFileChangeEx FileChangeService { get; }
private readonly ReaderWriterLockSlim _readerWriterLock = new ReaderWriterLockSlim();
internal VisualStudioMetadataReferenceManager(IServiceProvider serviceProvider, ITemporaryStorageService temporaryStorageService)
{
_metadataCache = new MetadataCache();
_runtimeDirectories = GetRuntimeDirectories();
_xmlMemberIndexService = (IVsXMLMemberIndexService)serviceProvider.GetService(typeof(SVsXMLMemberIndexService));
_smartOpenScopeService = (IVsSmartOpenScope)serviceProvider.GetService(typeof(SVsSmartOpenScope));
XmlMemberIndexService = (IVsXMLMemberIndexService)serviceProvider.GetService(typeof(SVsXMLMemberIndexService));
SmartOpenScopeServiceOpt = (IVsSmartOpenScope)serviceProvider.GetService(typeof(SVsSmartOpenScope));
_fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));
FileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));
_temporaryStorageService = temporaryStorageService;
Debug.Assert(_xmlMemberIndexService != null);
Debug.Assert(_smartOpenScopeService != null);
Debug.Assert(_fileChangeService != null);
Debug.Assert(XmlMemberIndexService != null);
Debug.Assert(SmartOpenScopeServiceOpt != null);
Debug.Assert(FileChangeService != null);
Debug.Assert(temporaryStorageService != null);
}
public IEnumerable<ITemporaryStreamStorage> GetStorages(string fullPath, DateTime snapshotTimestamp)
internal IEnumerable<ITemporaryStreamStorage> GetStorages(string fullPath, DateTime snapshotTimestamp)
{
var key = new FileKey(fullPath, snapshotTimestamp);
......@@ -106,16 +115,6 @@ private static ImmutableArray<string> GetRuntimeDirectories()
}).Select(FileUtilities.NormalizeDirectoryPath).ToImmutableArray();
}
internal IVsXMLMemberIndexService XmlMemberIndexService
{
get { return _xmlMemberIndexService; }
}
internal IVsFileChangeEx FileChangeService
{
get { return _fileChangeService; }
}
/// <exception cref="IOException"/>
/// <exception cref="BadImageFormatException" />
internal Metadata GetMetadata(string fullPath, DateTime snapshotTimestamp)
......@@ -288,28 +287,38 @@ private ModuleMetadata CreateModuleMetadata(FileKey moduleFileKey, List<ITempora
private bool TryGetFileMappingFromMetadataImporter(FileKey fileKey, out IMetaDataInfo info, out IntPtr pImage, out long length)
{
// here, we don't care about timestamp since all those bits should be part of Fx. and we assume that
// it won't be changed in the middle of VS running.
var fullPath = fileKey.FullPath;
// We might not be able to use COM services to get this if VS is shutting down. We'll synchronize to make sure this
// doesn't race against
using (_readerWriterLock.DisposableRead())
{
// here, we don't care about timestamp since all those bits should be part of Fx. and we assume that
// it won't be changed in the middle of VS running.
var fullPath = fileKey.FullPath;
info = default(IMetaDataInfo);
pImage = default(IntPtr);
length = default(long);
info = default(IMetaDataInfo);
pImage = default(IntPtr);
length = default(long);
var ppUnknown = default(object);
if (ErrorHandler.Failed(_smartOpenScopeService.OpenScope(fullPath, (uint)CorOpenFlags.ReadOnly, s_IID_IMetaDataImport, out ppUnknown)))
{
return false;
}
if (SmartOpenScopeServiceOpt == null)
{
return false;
}
info = ppUnknown as IMetaDataInfo;
if (info == null)
{
return false;
}
var ppUnknown = default(object);
if (ErrorHandler.Failed(SmartOpenScopeServiceOpt.OpenScope(fullPath, (uint)CorOpenFlags.ReadOnly, s_IID_IMetaDataImport, out ppUnknown)))
{
return false;
}
CorFileMapping mappingType;
return ErrorHandler.Succeeded(info.GetFileMapping(out pImage, out length, out mappingType)) && mappingType == CorFileMapping.Flat;
info = ppUnknown as IMetaDataInfo;
if (info == null)
{
return false;
}
CorFileMapping mappingType;
return ErrorHandler.Succeeded(info.GetFileMapping(out pImage, out length, out mappingType)) && mappingType == CorFileMapping.Flat;
}
}
/// <exception cref="IOException"/>
......@@ -343,5 +352,15 @@ private bool TryGetFileMappingFromMetadataImporter(FileKey fileKey, out IMetaDat
return AssemblyMetadata.Create(
moduleBuilder.ToImmutableAndFree());
}
public void DisconnectFromVisualStudioNativeServices()
{
using (_readerWriterLock.DisposableWrite())
{
// IVsSmartOpenScope can't be used as we shutdown, and this is pretty commonly hit according to
// Windows Error Reporting as we try creating metadata for compilations.
SmartOpenScopeServiceOpt = null;
}
}
}
}
\ No newline at end of file
......@@ -30,6 +30,7 @@
using static Microsoft.CodeAnalysis.Utilities.ForegroundThreadDataKind;
using Task = System.Threading.Tasks.Task;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.LanguageServices.Telemetry;
namespace Microsoft.VisualStudio.LanguageServices.Setup
{
......@@ -69,11 +70,7 @@ protected override void Initialize()
// Ensure the options persisters are loaded since we have to fetch options from the shell
componentModel.GetExtensions<IOptionPersister>();
var telemetrySetupExtensions = componentModel.GetExtensions<IRoslynTelemetrySetup>();
foreach (var telemetrySetup in telemetrySetupExtensions)
{
telemetrySetup.Initialize(this);
}
RoslynTelemetrySetup.Initialize(this);
// set workspace output pane
_outputPane = new WorkspaceFailureOutputPane(this, _workspace);
......@@ -162,7 +159,7 @@ protected override void Dispose(bool disposing)
{
UnregisterFindResultsLibraryManager();
DisposeVisualStudioDocumentTrackingService();
DisposeVisualStudioServices();
UnregisterAnalyzerTracker();
UnregisterRuleSetEventHandler();
......@@ -216,12 +213,14 @@ private void UnregisterFindResultsLibraryManager()
}
}
private void DisposeVisualStudioDocumentTrackingService()
private void DisposeVisualStudioServices()
{
if (_workspace != null)
{
var documentTrackingService = _workspace.Services.GetService<IDocumentTrackingService>() as VisualStudioDocumentTrackingService;
documentTrackingService.Dispose();
_workspace.Services.GetService<VisualStudioMetadataReferenceManager>().DisconnectFromVisualStudioNativeServices();
}
}
......
......@@ -165,7 +165,6 @@
<Compile Include="Implementation\Workspace\VisualStudioNavigationOptions.cs" />
<Compile Include="Implementation\Workspace\VisualStudioNavigationOptionsProvider.cs" />
<Compile Include="Implementation\Workspace\VisualStudioProjectCacheHostServiceFactory.cs" />
<Compile Include="IRoslynTelemetrySetup.cs" />
<Compile Include="Packaging\Interop\SVsRemoteControlService.cs" />
<Compile Include="Packaging\IPackageServicesProxy.cs" />
<Compile Include="Storage\VisualStudioPersistentStorageLocationService.cs" />
......
......@@ -11,26 +11,18 @@
namespace Microsoft.VisualStudio.LanguageServices.Telemetry
{
[Export(typeof(IRoslynTelemetrySetup))]
internal class RoslynTelemetrySetup : IRoslynTelemetrySetup
internal static class RoslynTelemetrySetup
{
public void Initialize(IServiceProvider serviceProvider)
public static void Initialize(IServiceProvider serviceProvider)
{
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
var workspace = componentModel.GetService<VisualStudioWorkspace>();
// initialize host context on UI thread.
var projectTypeLookup = workspace.Services.GetService<IProjectTypeLookupService>();
// set initial logger
var optionService = workspace.Services.GetService<IOptionService>();
var loggingChecker = Logger.GetLoggingChecker(optionService);
var optionService = componentModel.GetService<IGlobalOptionService>();
var telemetryService = serviceProvider.GetService(typeof(SVsTelemetryService)) as IVsTelemetryService;
Logger.SetLogger(
AggregateLogger.Create(
CodeMarkerLogger.Instance,
new EtwLogger(loggingChecker),
new EtwLogger(optionService),
new VSTelemetryLogger(telemetryService),
new VSTelemetryActivityLogger(telemetryService),
Logger.GetLogger()));
......
......@@ -14,7 +14,7 @@ namespace Roslyn.VisualStudio.DiagnosticsWindow.OptionsPages
[Guid(Guids.RoslynOptionPagePerformanceLoggersIdString)]
internal class PerformanceLoggersPage : AbstractOptionPage
{
private IOptionService _optionService;
private IGlobalOptionService _optionService;
protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider)
{
......@@ -22,8 +22,7 @@ protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider s
{
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
var workspace = componentModel.GetService<VisualStudioWorkspace>();
_optionService = workspace.Services.GetService<IOptionService>();
_optionService = componentModel.GetService<IGlobalOptionService>();
}
return new InternalOptionsControl(nameof(LoggerOptions), serviceProvider);
......
......@@ -12,25 +12,25 @@ namespace Microsoft.CodeAnalysis.Internal.Log
/// </summary>
internal sealed class EtwLogger : ILogger
{
private readonly Func<FunctionId, bool> _loggingChecker;
private readonly Lazy<Func<FunctionId, bool>> _loggingChecker;
// Due to ETW specifics, RoslynEventSource.Instance needs to be initialized during EtwLogger construction
// so that we can enable the listeners synchronously before any events are logged.
private readonly RoslynEventSource _source = RoslynEventSource.Instance;
public EtwLogger(IOptionService optionService)
: this(Logger.GetLoggingChecker(optionService))
public EtwLogger(IGlobalOptionService optionService)
{
_loggingChecker = new Lazy<Func<FunctionId, bool>>(() => Logger.GetLoggingChecker(optionService));
}
public EtwLogger(Func<FunctionId, bool> loggingChecker)
{
_loggingChecker = loggingChecker;
_loggingChecker = new Lazy<Func<FunctionId, bool>>(() => loggingChecker);
}
public bool IsEnabled(FunctionId functionId)
{
return _source.IsEnabled() && (_loggingChecker == null || _loggingChecker(functionId));
return _source.IsEnabled() && _loggingChecker.Value(functionId);
}
public void Log(FunctionId functionId, LogMessage logMessage)
......
......@@ -340,7 +340,7 @@ public static IDisposable LogBlock(FunctionId functionId, LogMessage logMessage,
return CreateLogBlock(functionId, logMessage, GetNextUniqueBlockId(), token);
}
public static Func<FunctionId, bool> GetLoggingChecker(IOptionService optionService)
public static Func<FunctionId, bool> GetLoggingChecker(IGlobalOptionService optionService)
{
var functionIds = Enum.GetValues(typeof(FunctionId)).Cast<FunctionId>();
var functionIdOptions = functionIds.ToDictionary(id => id, id => optionService.GetOption(FunctionIdOptions.GetOption(id)));
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.CodeAnalysis.Emit;
......@@ -78,7 +77,12 @@ public static MetadataOnlyImage Create(Workspace workspace, ITemporaryStorageSer
return Empty;
}
private static readonly ConditionalWeakTable<MetadataReference, Stream> s_lifetime = new ConditionalWeakTable<MetadataReference, Stream>();
/// <summary>
/// A map to ensure that the streams from the temporary storage service that back the metadata we create stay alive as long
/// as the metadata is alive.
/// </summary>
private static readonly ConditionalWeakTable<AssemblyMetadata, ISupportDirectMemoryAccess> s_lifetime
= new ConditionalWeakTable<AssemblyMetadata, ISupportDirectMemoryAccess>();
public MetadataReference CreateReference(ImmutableArray<string> aliases, bool embedInteropTypes, DocumentationProvider documentationProvider)
{
......@@ -90,36 +94,32 @@ public MetadataReference CreateReference(ImmutableArray<string> aliases, bool em
// first see whether we can use native memory directly.
var stream = _storage.ReadStream();
var supportNativeMemory = stream as ISupportDirectMemoryAccess;
AssemblyMetadata metadata;
if (supportNativeMemory != null)
{
// this is unfortunate that if we give stream, compiler will just re-copy whole content to
// native memory again. this is a way to get around the issue by we getting native memory ourselves and then
// give them pointer to the native memory. also we need to handle lifetime ourselves.
var metadata = AssemblyMetadata.Create(ModuleMetadata.CreateFromImage(supportNativeMemory.GetPointer(), (int)stream.Length));
var referenceWithNativeMemory = metadata.GetReference(
documentation: documentationProvider,
aliases: aliases,
embedInteropTypes: embedInteropTypes,
display: _assemblyName);
// tie lifetime of stream to metadata reference we created. native memory's lifetime is tied to
// stream internally and stream is shared between same temporary storage. so here, we should be
// sharing same native memory for all skeleton assemblies from same project snapshot.
s_lifetime.GetValue(referenceWithNativeMemory, _ => stream);
metadata = AssemblyMetadata.Create(ModuleMetadata.CreateFromImage(supportNativeMemory.GetPointer(), (int)stream.Length));
return referenceWithNativeMemory;
// Tie lifetime of stream to metadata we created. It is important to tie this to the Metadata and not the
// metadata reference, as PE symbols hold onto just the Metadata. We can use Add here since we created
// a brand new object in AssemblyMetadata.Create above.
s_lifetime.Add(metadata, supportNativeMemory);
}
else
{
// Otherwise, we just let it use stream. Unfortunately, if we give stream, compiler will
// internally copy it to native memory again. since compiler owns lifetime of stream,
// it would be great if compiler can be little bit smarter on how it deals with stream.
// We don't deterministically release the resulting metadata since we don't know
// when we should. So we leave it up to the GC to collect it and release all the associated resources.
metadata = AssemblyMetadata.CreateFromStream(stream);
}
// Otherwise, we just let it use stream. Unfortunately, if we give stream, compiler will
// internally copy it to native memory again. since compiler owns lifetime of stream,
// it would be great if compiler can be little bit smarter on how it deals with stream.
// We don't deterministically release the resulting metadata since we don't know
// when we should. So we leave it up to the GC to collect it and release all the associated resources.
var metadataFromStream = AssemblyMetadata.CreateFromStream(stream);
return metadataFromStream.GetReference(
return metadata.GetReference(
documentation: documentationProvider,
aliases: aliases,
embedInteropTypes: embedInteropTypes,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册