Skip to content

Commit

Permalink
MemberDisplayOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Jul 12, 2024
1 parent 12dc70c commit ecd3348
Show file tree
Hide file tree
Showing 87 changed files with 377 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6365,7 +6365,7 @@ static void Main(string[] args)
</Workspace>";

await TestMissingAsync(initialWorkspace, new TestParameters(
globalOptions: Option(MemberDisplayOptionsStorage.HideAdvancedMembers, true),
options: Option(MemberDisplayOptionsStorage.HideAdvancedMembers, true),
testHost: testHost));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.SignatureHelp;
using Microsoft.VisualStudio.Text;
Expand Down Expand Up @@ -82,15 +83,12 @@ private async Task<Model> ComputeModelInBackgroundAsync(
}
}

var options = Controller.GlobalOptions.GetSignatureHelpOptions(document.Project.Language);

// first try to query the providers that can trigger on the specified character
var (provider, items) = await SignatureHelpService.GetSignatureHelpAsync(
providers,
document,
caretPosition,
triggerInfo,
options,
cancellationToken).ConfigureAwait(false);

if (provider == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,10 @@ private async Task ExecuteAsync(Document document, SnapshotSpan snapshotSpan, IT
await TaskScheduler.Default;

var addMissingImportsService = document.GetRequiredLanguageService<IAddMissingImportsFeatureService>();

var cleanupOptions = await document.GetCodeCleanupOptionsAsync(cancellationToken).ConfigureAwait(false);

var options = new AddMissingImportsOptions(
CleanupOptions: cleanupOptions,
HideAdvancedMembers: _globalOptions.GetOption(MemberDisplayOptionsStorage.HideAdvancedMembers, document.Project.Language));

var textSpan = snapshotSpan.Span.ToTextSpan();

var updatedDocument = await addMissingImportsService.AddMissingImportsAsync(
document, textSpan, options, backgroundWorkContext.GetCodeAnalysisProgress(), cancellationToken).ConfigureAwait(false);
document, textSpan, backgroundWorkContext.GetCodeAnalysisProgress(), cancellationToken).ConfigureAwait(false);

if (updatedDocument is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.AddMissingImports;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;

Expand All @@ -19,45 +17,35 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.UnitTestGenerator.Api;
[Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal class UnitTestGeneratorAddMissingImportsFeatureServiceAccessor(IGlobalOptionService globalOptions)
internal class UnitTestGeneratorAddMissingImportsFeatureServiceAccessor()
{
private readonly IGlobalOptionService _globalOptions = globalOptions;

#pragma warning disable CA1822 // Mark members as static
internal async Task<Document> AddMissingImportsAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
#pragma warning restore CA1822
{
var options = await GetOptionsAsync(document, cancellationToken).ConfigureAwait(false);
var service = document.Project.GetRequiredLanguageService<IAddMissingImportsFeatureService>();

// Unfortunately, the unit testing system doesn't have a way to report progress.
return await service.AddMissingImportsAsync(document, textSpan, options, CodeAnalysisProgress.None, cancellationToken).ConfigureAwait(false);
return await service.AddMissingImportsAsync(document, textSpan, CodeAnalysisProgress.None, cancellationToken).ConfigureAwait(false);
}

#pragma warning disable CA1822 // Mark members as static
internal async Task<WrappedMissingImportsAnalysisResult> AnalyzeAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
#pragma warning restore CA1822
{
var options = await GetOptionsAsync(document, cancellationToken).ConfigureAwait(false);
var service = document.Project.GetRequiredLanguageService<IAddMissingImportsFeatureService>();
var result = await service.AnalyzeAsync(document, textSpan, options, cancellationToken).ConfigureAwait(false);
var result = await service.AnalyzeAsync(document, textSpan, cancellationToken).ConfigureAwait(false);
return new WrappedMissingImportsAnalysisResult(result.AddImportFixData.SelectAsArray(data => new WrappedAddImportFixData(data)));
}

#pragma warning disable CA1822 // Mark members as static
internal async Task<Document> AddMissingImportsAsync(Document document, WrappedMissingImportsAnalysisResult analysisResult, CancellationToken cancellationToken)
#pragma warning restore CA1822
{
var options = await GetOptionsAsync(document, cancellationToken).ConfigureAwait(false);
var service = document.Project.GetRequiredLanguageService<IAddMissingImportsFeatureService>();
var unwrappedResult = new AddMissingImportsAnalysisResult(analysisResult.AddImportFixDatas.SelectAsArray(result => result.Underlying));

// Unfortunately, the unit testing system doesn't have a way to report progress.
return await service.AddMissingImportsAsync(document, unwrappedResult, options.CleanupOptions.FormattingOptions, CodeAnalysisProgress.None, cancellationToken).ConfigureAwait(false);
}

private async Task<AddMissingImportsOptions> GetOptionsAsync(Document document, CancellationToken cancellationToken)
{
var cleanupOptions = await document.GetCodeCleanupOptionsAsync(cancellationToken).ConfigureAwait(false);

var options = new AddMissingImportsOptions(
CleanupOptions: cleanupOptions,
HideAdvancedMembers: _globalOptions.GetOption(MemberDisplayOptionsStorage.HideAdvancedMembers, document.Project.Language));

return options;
return await service.AddMissingImportsAsync(document, unwrappedResult, CodeAnalysisProgress.None, cancellationToken).ConfigureAwait(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ public TestParameters WithCompilationOptions(CompilationOptions compilationOptio
internal TestParameters WithOptions(OptionsCollectionAlias options)
=> new(parseOptions, compilationOptions, options, globalOptions, fixProviderData, index, priority, retainNonFixableDiagnostics, includeDiagnosticsOutsideSelection, title, testHost, workspaceKind, includeNonLocalDocumentDiagnostics, treatPositionIndicatorsAsCode);

internal TestParameters WithGlobalOptions(OptionsCollectionAlias globalOptions)
=> new(parseOptions, compilationOptions, options, globalOptions, fixProviderData, index, priority, retainNonFixableDiagnostics, includeDiagnosticsOutsideSelection, title, testHost, workspaceKind, includeNonLocalDocumentDiagnostics, treatPositionIndicatorsAsCode);

public TestParameters WithFixProviderData(object fixProviderData)
=> new(parseOptions, compilationOptions, options, globalOptions, fixProviderData, index, priority, retainNonFixableDiagnostics, includeDiagnosticsOutsideSelection, title, testHost, workspaceKind, includeNonLocalDocumentDiagnostics, treatPositionIndicatorsAsCode);

Expand Down Expand Up @@ -408,15 +405,14 @@ internal Task TestInRegularAndScriptAsync(
CodeActionPriority? priority = null,
CompilationOptions compilationOptions = null,
OptionsCollectionAlias options = null,
OptionsCollectionAlias globalOptions = null,
object fixProviderData = null,
ParseOptions parseOptions = null,
string title = null,
TestHost testHost = TestHost.OutOfProcess)
{
return TestInRegularAndScript1Async(
initialMarkup, expectedMarkup,
new TestParameters(parseOptions, compilationOptions, options, globalOptions, fixProviderData, index, priority, title: title, testHost: testHost));
new TestParameters(parseOptions, compilationOptions, options, globalOptions: null, fixProviderData, index, priority, title: title, testHost: testHost));
}

internal Task TestInRegularAndScript1Async(
Expand Down Expand Up @@ -449,15 +445,14 @@ internal Task TestAsync(
CompilationOptions compilationOptions = null,
int index = 0,
OptionsCollectionAlias options = null,
OptionsCollectionAlias globalOptions = null,
object fixProviderData = null,
CodeActionPriority? priority = null,
TestHost testHost = TestHost.OutOfProcess)
{
return TestAsync(
initialMarkup,
expectedMarkup,
new TestParameters(parseOptions, compilationOptions, options, globalOptions, fixProviderData, index, priority, testHost: testHost));
new TestParameters(parseOptions, compilationOptions, options, globalOptions: null, fixProviderData, index, priority, testHost: testHost));
}

private async Task TestAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,22 @@ private protected async Task TestDiagnosticInfoAsync(
string diagnosticId,
DiagnosticSeverity diagnosticSeverity,
OptionsCollectionAlias options = null,
OptionsCollectionAlias globalOptions = null,
LocalizableString diagnosticMessage = null)
{
await TestDiagnosticInfoAsync(initialMarkup, parseOptions: null, compilationOptions: null, options, globalOptions, diagnosticId, diagnosticSeverity, diagnosticMessage);
await TestDiagnosticInfoAsync(initialMarkup, GetScriptOptions(), compilationOptions: null, options, globalOptions, diagnosticId, diagnosticSeverity, diagnosticMessage);
await TestDiagnosticInfoAsync(initialMarkup, parseOptions: null, compilationOptions: null, options, diagnosticId, diagnosticSeverity, diagnosticMessage);
await TestDiagnosticInfoAsync(initialMarkup, GetScriptOptions(), compilationOptions: null, options, diagnosticId, diagnosticSeverity, diagnosticMessage);
}

private protected async Task TestDiagnosticInfoAsync(
string initialMarkup,
ParseOptions parseOptions,
CompilationOptions compilationOptions,
OptionsCollectionAlias options,
OptionsCollectionAlias globalOptions,
string diagnosticId,
DiagnosticSeverity diagnosticSeverity,
LocalizableString diagnosticMessage = null)
{
var testOptions = new TestParameters(parseOptions, compilationOptions, options: options, globalOptions: globalOptions);
var testOptions = new TestParameters(parseOptions, compilationOptions, options: options);
using var workspace = CreateWorkspaceFromOptions(initialMarkup, testOptions);
var diagnostics = (await GetDiagnosticsAsync(workspace, testOptions)).ToImmutableArray();
diagnostics = diagnostics.WhereAsArray(d => d.Id == diagnosticId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,11 @@ private protected Task TestActionCountInAllFixesAsync(
ParseOptions parseOptions = null,
CompilationOptions compilationOptions = null,
OptionsCollectionAlias options = null,
OptionsCollectionAlias globalOptions = null,
object fixProviderData = null)
{
return TestActionCountInAllFixesAsync(
initialMarkup,
new TestParameters(parseOptions, compilationOptions, options, globalOptions, fixProviderData),
new TestParameters(parseOptions, compilationOptions, options, globalOptions: null, fixProviderData),
count);
}

Expand Down
2 changes: 1 addition & 1 deletion src/EditorFeatures/Test/Options/GlobalOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void ReadingOptionsFromGlobalOptions(string language)
VerifyDataMembersHaveNonDefaultValues(globalOptions.GetDocumentationCommentOptions(globalOptions.GetLineFormattingOptions(language), language), DocumentationCommentOptions.Default, language);
VerifyDataMembersHaveNonDefaultValues(globalOptions.GetImplementTypeOptions(language), ImplementTypeOptions.Default, language);
VerifyDataMembersHaveNonDefaultValues(globalOptions.GetMetadataAsSourceOptions(), MetadataAsSourceOptions.Default, language);
VerifyDataMembersHaveNonDefaultValues(globalOptions.GetSignatureHelpOptions(language), SignatureHelpOptions.Default, language);
VerifyDataMembersHaveNonDefaultValues(globalOptions.GetMemberDisplayOptions(language), MemberDisplayOptions.Default, language);
VerifyDataMembersHaveNonDefaultValues(globalOptions.GetSymbolSearchOptions(language), SymbolSearchOptions.Default, language);
VerifyDataMembersHaveNonDefaultValues(globalOptions.GetWorkspaceConfigurationOptions(), WorkspaceConfigurationOptions.Default);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense

<WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/985007")>
Public Sub UpKeyShouldNotCrashWhenSessionIsDismissed()
Dim options = New SignatureHelpOptions()
Dim options = New MemberDisplayOptions()

' Create a provider that will return an empty state when queried the second time
Dim slowProvider = New Mock(Of ISignatureHelpProvider)(MockBehavior.Strict)
Expand Down Expand Up @@ -108,7 +108,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense

<WpfFact, WorkItem("https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workItems?id=179726&_a=edit")>
Public Sub DownKeyShouldNotBlockOnModelComputation()
Dim options = New SignatureHelpOptions()
Dim options = New MemberDisplayOptions()
Dim mre = New ManualResetEvent(False)
Dim controller = CreateController(CreateWorkspace(), items:=CreateItems(2), waitForPresentation:=False)
Dim slowProvider = New Mock(Of ISignatureHelpProvider)(MockBehavior.Strict)
Expand All @@ -128,7 +128,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense

<WpfFact, WorkItem("https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workItems?id=179726&_a=edit")>
Public Sub UpKeyShouldNotBlockOnModelComputation()
Dim options = New SignatureHelpOptions()
Dim options = New MemberDisplayOptions()
Dim mre = New ManualResetEvent(False)
Dim controller = CreateController(CreateWorkspace(), items:=CreateItems(2), waitForPresentation:=False)
Dim slowProvider = New Mock(Of ISignatureHelpProvider)(MockBehavior.Strict)
Expand All @@ -148,7 +148,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense

<WpfFact, WorkItem("https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workItems?id=179726&_a=edit")>
Public Async Function UpKeyShouldBlockOnRecomputationAfterPresentation() As Task
Dim options = New SignatureHelpOptions()
Dim options = New MemberDisplayOptions()
Dim workspace = CreateWorkspace()
Dim threadingContext = workspace.GetService(Of IThreadingContext)()

Expand Down Expand Up @@ -352,7 +352,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense

Public Property GetItemsCount As Integer

Public Function GetItemsAsync(document As Document, position As Integer, triggerInfo As SignatureHelpTriggerInfo, options As SignatureHelpOptions, cancellationToken As CancellationToken) As Task(Of SignatureHelpItems) Implements ISignatureHelpProvider.GetItemsAsync
Public Function GetItemsAsync(document As Document, position As Integer, triggerInfo As SignatureHelpTriggerInfo, options As MemberDisplayOptions, cancellationToken As CancellationToken) As Task(Of SignatureHelpItems) Implements ISignatureHelpProvider.GetItemsAsync
GetItemsCount += 1
Return Task.FromResult(If(_items.Any(),
New SignatureHelpItems(_items, TextSpan.FromBounds(position, position), selectedItem:=0, argumentIndex:=0, argumentCount:=0, argumentName:=Nothing),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private CompletionOptions GetCompletionOptions()
options = options with { ForceExpandedCompletionIndexCreation = ForceExpandedCompletionIndexCreation.Value };

if (HideAdvancedMembers.HasValue)
options = options with { HideAdvancedMembers = HideAdvancedMembers.Value };
options = options with { MemberDisplayOptions = new() { HideAdvancedMembers = HideAdvancedMembers.Value } };

if (ShowNameSuggestions.HasValue)
options = options with { ShowNameSuggestions = ShowNameSuggestions.Value };
Expand Down
Loading

0 comments on commit ecd3348

Please sign in to comment.