Skip to content

Commit

Permalink
FInal
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Apr 12, 2022
1 parent 362156b commit 5a8b5e2
Show file tree
Hide file tree
Showing 101 changed files with 551 additions and 252 deletions.
4 changes: 4 additions & 0 deletions eng/config/BannedSymbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ M:Microsoft.CodeAnalysis.Formatting.Formatter.Format(Microsoft.CodeAnalysis.Synt
M:Microsoft.CodeAnalysis.Formatting.Formatter.GetFormattedTextChanges(Microsoft.CodeAnalysis.SyntaxNode,Microsoft.CodeAnalysis.Workspace,Microsoft.CodeAnalysis.Options.OptionSet,System.Threading.CancellationToken); Use overload with SyntaxFormattingOptions instead
M:Microsoft.CodeAnalysis.Formatting.Formatter.GetFormattedTextChanges(Microsoft.CodeAnalysis.SyntaxNode,Microsoft.CodeAnalysis.Text.TextSpan,Microsoft.CodeAnalysis.Workspace,Microsoft.CodeAnalysis.Options.OptionSet,System.Threading.CancellationToken); Use overload with SyntaxFormattingOptions instead
M:Microsoft.CodeAnalysis.Formatting.Formatter.GetFormattedTextChanges(Microsoft.CodeAnalysis.SyntaxNode,System.Collections.Generic.IEnumerable{Microsoft.CodeAnalysis.Text.TextSpan},Microsoft.CodeAnalysis.Workspace,Microsoft.CodeAnalysis.Options.OptionSet,System.Threading.CancellationToken); Use overload with SyntaxFormattingOptions instead
M:Microsoft.CodeAnalysis.Simplification.Simplifier.ReduceAsync(Microsoft.CodeAnalysis.Document,Microsoft.CodeAnalysis.Options.OptionSet,System.Threading.CancellationToken); Use overload that takes SimplifierOptions
M:Microsoft.CodeAnalysis.Simplification.Simplifier.ReduceAsync(Microsoft.CodeAnalysis.Document,Microsoft.CodeAnalysis.SyntaxAnnotation,Microsoft.CodeAnalysis.Options.OptionSet,System.Threading.CancellationToken); Use overload that takes SimplifierOptions
M:Microsoft.CodeAnalysis.Simplification.Simplifier.ReduceAsync(Microsoft.CodeAnalysis.Document,Microsoft.CodeAnalysis.Text.TextSpan,Microsoft.CodeAnalysis.Options.OptionSet,System.Threading.CancellationToken); Use overload that takes SimplifierOptions
M:Microsoft.CodeAnalysis.Simplification.Simplifier.ReduceAsync(Microsoft.CodeAnalysis.Document,System.Collections.Generic.IEnumerable{Microsoft.CodeAnalysis.Text.TextSpan},Microsoft.CodeAnalysis.Options.OptionSet,System.Threading.CancellationToken); Use overload that takes SimplifierOptions
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ private class CustomFixAllProvider : FixAllProvider
fixAllContext.Project.Solution,
diagnostics,
fixAllContext.GetProgressTracker(),
#if CODE_STYLE
options: _ => default,
#else
fixAllContext.State.CodeActionOptionsProvider,
#endif
cancellationToken),
title);

Expand All @@ -67,6 +72,7 @@ private static async Task<Solution> FixAllByDocumentAsync(
Solution solution,
ImmutableArray<Diagnostic> diagnostics,
IProgressTracker progressTracker,
CodeActionOptionsProvider options,
CancellationToken cancellationToken)
{
// Use documentId instead of tree here because the
Expand All @@ -89,7 +95,7 @@ private static async Task<Solution> FixAllByDocumentAsync(
var document = newSolution.GetRequiredDocument(documentId);
using var _ = progressTracker.ItemCompletedScope(document.Name);

newSolution = await FixAllInDocumentAsync(document, diagnosticsInTree, cancellationToken).ConfigureAwait(false);
newSolution = await FixAllInDocumentAsync(document, diagnosticsInTree, options, cancellationToken).ConfigureAwait(false);
}

return newSolution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.AddImport;
using Microsoft.CodeAnalysis.Analyzers.MatchFolderAndNamespace;
using Microsoft.CodeAnalysis.ChangeNamespace;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Rename;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Simplification;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CodeFixes.MatchFolderAndNamespace
Expand All @@ -29,15 +33,21 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
context.RegisterCodeFix(
CodeAction.Create(
AnalyzersResources.Change_namespace_to_match_folder_structure,
cancellationToken => FixAllInDocumentAsync(context.Document, context.Diagnostics, cancellationToken),
cancellationToken => FixAllInDocumentAsync(context.Document, context.Diagnostics,
#if CODE_STYLE
options: _ => default,
#else
context.Options,
#endif
cancellationToken),
nameof(AnalyzersResources.Change_namespace_to_match_folder_structure)),
context.Diagnostics);
}

return Task.CompletedTask;
}

private static async Task<Solution> FixAllInDocumentAsync(Document document, ImmutableArray<Diagnostic> diagnostics, CancellationToken cancellationToken)
private static async Task<Solution> FixAllInDocumentAsync(Document document, ImmutableArray<Diagnostic> diagnostics, CodeActionOptionsProvider options, CancellationToken cancellationToken)
{
// All the target namespaces should be the same for a given document
Debug.Assert(diagnostics.Select(diagnostic => diagnostic.Properties[MatchFolderAndNamespaceConstants.TargetNamespace]).Distinct().Count() == 1);
Expand All @@ -54,6 +64,9 @@ private static async Task<Solution> FixAllInDocumentAsync(Document document, Imm
var renameActionSet = await Renamer.RenameDocumentAsync(
documentWithInvalidFolders,
new DocumentRenameOptions(),
#if !CODE_STYLE
ChangeNamespaceOptions.CreateProvider(options),
#endif
documentWithInvalidFolders.Name,
newDocumentFolders: targetFolders,
cancellationToken: cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.EncapsulateField;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Operations;
Expand All @@ -27,8 +28,9 @@ internal class EncapsulateFieldCommandHandler : AbstractEncapsulateFieldCommandH
public EncapsulateFieldCommandHandler(
IThreadingContext threadingContext,
ITextBufferUndoManagerProvider undoManager,
IGlobalOptionService globalOptions,
IAsynchronousOperationListenerProvider listenerProvider)
: base(threadingContext, undoManager, listenerProvider)
: base(threadingContext, undoManager, globalOptions, listenerProvider)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Service()
{
}

public SimplifierOptions GetSimplifierOptions(IGlobalOptionService globalOptions)
public SimplifierOptions GetOptions(IGlobalOptionService globalOptions)
=> GetCSharpSimplifierOptions(globalOptions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ChangeNamespace;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
Expand Down Expand Up @@ -1124,6 +1125,7 @@ void Method() { }
var actions = await testState.MoveToNamespaceService.GetCodeActionsAsync(
testState.InvocationDocument,
testState.TestInvocationDocument.SelectedSpans.Single(),
language => ChangeNamespaceOptions.GetDefault(testState.InvocationDocument.Project.LanguageServices),
CancellationToken.None);

Assert.Empty(actions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
Expand All @@ -30,18 +31,21 @@ internal abstract class AbstractSnippetExpansionClient : IExpansionClient
protected readonly ITextView TextView;
protected readonly ITextBuffer SubjectBuffer;

public readonly IGlobalOptionService GlobalOptions;

protected bool _indentCaretOnCommit;
protected int _indentDepth;
protected bool _earlyEndExpansionHappened;

public IExpansionSession? ExpansionSession { get; private set; }

public AbstractSnippetExpansionClient(IContentType languageServiceGuid, ITextView textView, ITextBuffer subjectBuffer, IExpansionServiceProvider expansionServiceProvider)
public AbstractSnippetExpansionClient(IContentType languageServiceGuid, ITextView textView, ITextBuffer subjectBuffer, IExpansionServiceProvider expansionServiceProvider, IGlobalOptionService globalOptions)
{
this.LanguageServiceGuid = languageServiceGuid;
this.TextView = textView;
this.SubjectBuffer = subjectBuffer;
this.ExpansionServiceProvider = expansionServiceProvider;
LanguageServiceGuid = languageServiceGuid;
TextView = textView;
SubjectBuffer = subjectBuffer;
ExpansionServiceProvider = expansionServiceProvider;
GlobalOptions = globalOptions;
}

public abstract IExpansionFunction? GetExpansionFunction(XElement xmlFunctionNode, string fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected override AbstractSnippetExpansionClient GetSnippetExpansionClient(ITex
{
if (!textView.Properties.TryGetProperty(typeof(AbstractSnippetExpansionClient), out AbstractSnippetExpansionClient expansionClient))
{
expansionClient = new SnippetExpansionClient(subjectBuffer.ContentType, textView, subjectBuffer, ExpansionServiceProvider);
expansionClient = new SnippetExpansionClient(subjectBuffer.ContentType, textView, subjectBuffer, ExpansionServiceProvider, GlobalOptions);
textView.Properties.AddProperty(typeof(AbstractSnippetExpansionClient), expansionClient);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.LanguageServices.CSharp.Snippets.SnippetFunctions;
using Microsoft.VisualStudio.LanguageServices.Implementation.Snippets;
using Microsoft.VisualStudio.Text;
Expand All @@ -17,8 +18,8 @@ namespace Microsoft.VisualStudio.LanguageServices.CSharp.Snippets
{
internal sealed partial class SnippetExpansionClient : AbstractSnippetExpansionClient
{
public SnippetExpansionClient(IContentType languageServiceGuid, ITextView textView, ITextBuffer subjectBuffer, IExpansionServiceProvider expansionServiceProvider)
: base(languageServiceGuid, textView, subjectBuffer, expansionServiceProvider)
public SnippetExpansionClient(IContentType languageServiceGuid, ITextView textView, ITextBuffer subjectBuffer, IExpansionServiceProvider expansionServiceProvider, IGlobalOptionService globalOptions)
: base(languageServiceGuid, textView, subjectBuffer, expansionServiceProvider, globalOptions)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ protected override bool TryGetSimplifiedTypeNameInCaseContext(Document document,
var updatedRoot = syntaxRoot.ReplaceNode(nodeToReplace, nodeToReplace.WithAdditionalAnnotations(typeAnnotation, Simplifier.Annotation));
var documentWithAnnotations = documentWithCaseAdded.WithSyntaxRoot(updatedRoot);

var simplifiedDocument = Simplifier.ReduceAsync(documentWithAnnotations, cancellationToken: cancellationToken).Result;
var simplifierOptions = _snippetExpansionClient.GlobalOptions.GetSimplifierOptionsAsync(document, cancellationToken).WaitAndGetResult(cancellationToken);
var simplifiedDocument = Simplifier.ReduceAsync(documentWithAnnotations, simplifierOptions, cancellationToken).WaitAndGetResult(cancellationToken);
simplifiedTypeName = simplifiedDocument.GetRequiredSyntaxRootSynchronously(cancellationToken).GetAnnotatedNodesAndTokens(typeAnnotation).Single().ToString();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected override bool TryGetSimplifiedTypeName(Document documentWithFullyQuali
var updatedRoot = syntaxRoot.ReplaceNode(nodeToReplace, nodeToReplace.WithAdditionalAnnotations(typeAnnotation, Simplifier.Annotation));
var documentWithAnnotations = documentWithFullyQualifiedTypeName.WithSyntaxRoot(updatedRoot);

var simplifiedDocument = Simplifier.ReduceAsync(documentWithAnnotations, cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken);
var simplifierOptions = _snippetExpansionClient.GlobalOptions.GetSimplifierOptionsAsync(documentWithAnnotations, cancellationToken).WaitAndGetResult(cancellationToken);
var simplifiedDocument = Simplifier.ReduceAsync(documentWithAnnotations, simplifierOptions, cancellationToken).WaitAndGetResult(cancellationToken);
simplifiedTypeName = simplifiedDocument.GetRequiredSyntaxRootSynchronously(cancellationToken).GetAnnotatedNodesAndTokens(typeAnnotation).Single().ToString();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EditorFeatures/Core.Wpf/Peek/DefinitionPeekableItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void FindResults(string relationshipName, IPeekResultCollection resultCol
if (!sourceLocations.Any())
{
// It's a symbol from metadata, so we want to go produce it from metadata
var options = _peekableItem._globalOptions.GetMetadataAsSourceOptions();
var options = _peekableItem._globalOptions.GetMetadataAsSourceOptions(project.LanguageServices);
var declarationFile = _peekableItem._metadataAsSourceFileService.GetGeneratedFileAsync(project, symbol, signaturesOnly: true, options, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken);
var peekDisplayInfo = new PeekResultDisplayInfo(declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle);
var identifierSpan = declarationFile.IdentifierLocation.GetLineSpan().Span;
Expand Down
11 changes: 6 additions & 5 deletions src/EditorFeatures/Core/CodeActions/CodeActionOptionsStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.ImplementType;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.CodeAnalysis.ExtractMethod;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.ImplementType;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.SymbolSearch;

namespace Microsoft.CodeAnalysis.CodeActions
{
Expand All @@ -26,7 +27,7 @@ private static CodeActionOptions GetCodeActionOptions(this IGlobalOptionService
SearchOptions: globalOptions.GetSymbolSearchOptions(languageServices.Language),
ImplementTypeOptions: globalOptions.GetImplementTypeOptions(languageServices.Language),
ExtractMethodOptions: globalOptions.GetExtractMethodOptions(languageServices.Language),
FallbackSimplifierOptions: languageServices.GetService<ISimplifierOptionsStorage>()?.GetSimplifierOptions(globalOptions),
SimplifierOptions: globalOptions.GetFallbackSimplifierOptions(languageServices),
HideAdvancedMembers: globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, languageServices.Language),
IsBlocking: isBlocking);

Expand All @@ -39,7 +40,7 @@ internal static CodeActionOptionsProvider GetCodeActionOptionsProvider(this IGlo
internal static CodeActionOptionsProvider GetBlockingCodeActionOptionsProvider(this IGlobalOptionService globalOptions)
{
var cache = ImmutableDictionary<string, CodeActionOptions>.Empty;
return language => ImmutableInterlocked.GetOrAdd(ref cache, language, (language, options) => GetBlockingCodeActionOptions(options, language), globalOptions);
return languageService => ImmutableInterlocked.GetOrAdd(ref cache, languageService.Language, (language, options) => GetBlockingCodeActionOptions(options, languageService), globalOptions);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ internal async Task<ImmutableArray<CodeDefinitionWindowLocation>> GetContextFrom
}
else if (_metadataAsSourceFileService.IsNavigableMetadataSymbol(symbol))
{
var options = _globalOptions.GetMetadataAsSourceOptions();
var options = _globalOptions.GetMetadataAsSourceOptions(document.Project.LanguageServices);
var declarationFile = await _metadataAsSourceFileService.GetGeneratedFileAsync(document.Project, symbol, signaturesOnly: false, options, cancellationToken).ConfigureAwait(false);
var identifierSpan = declarationFile.IdentifierLocation.GetLineSpan().Span;
return ImmutableArray.Create(new CodeDefinitionWindowLocation(symbol.ToDisplayString(), declarationFile.FilePath, identifierSpan.Start));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
using Microsoft.VisualStudio.Text.Operations;
Expand All @@ -23,17 +25,20 @@ internal abstract class AbstractEncapsulateFieldCommandHandler : ICommandHandler
{
private readonly IThreadingContext _threadingContext;
private readonly ITextBufferUndoManagerProvider _undoManager;
private readonly IGlobalOptionService _globalOptions;
private readonly IAsynchronousOperationListener _listener;

public string DisplayName => EditorFeaturesResources.Encapsulate_Field;

public AbstractEncapsulateFieldCommandHandler(
IThreadingContext threadingContext,
ITextBufferUndoManagerProvider undoManager,
IGlobalOptionService globalOptions,
IAsynchronousOperationListenerProvider listenerProvider)
{
_threadingContext = threadingContext;
_undoManager = undoManager;
_globalOptions = globalOptions;
_listener = listenerProvider.GetListener(FeatureAttribute.EncapsulateField);
}

Expand Down Expand Up @@ -65,7 +70,10 @@ private bool Execute(EncapsulateFieldCommandArgs args, IUIThreadOperationScope w

var service = document.GetLanguageService<AbstractEncapsulateFieldService>();

var result = service.EncapsulateFieldsInSpanAsync(document, spans.First().Span.ToTextSpan(), true, cancellationToken).WaitAndGetResult(cancellationToken);
var fallbackOptions = new EncapsulateFieldOptions(
SimplifierOptions: _globalOptions.GetFallbackSimplifierOptions(document.Project.LanguageServices));

var result = service.EncapsulateFieldsInSpanAsync(document, spans.First().Span.ToTextSpan(), fallbackOptions, useDefaultBehavior: true, cancellationToken).WaitAndGetResult(cancellationToken);

// We are about to show a modal UI dialog so we should take over the command execution
// wait context. That means the command system won't attempt to show its own wait dialog
Expand Down
Loading

0 comments on commit 5a8b5e2

Please sign in to comment.