提交 24ce744d 编写于 作者: J Jason Malinowski

Don't show nullability information in quick info if it's not enabled

We don't have this scenario fully polished and it can often be more
confusing because the information shown won't always be useful or
accurate.

Fixes https://github.com/dotnet/roslyn/issues/37314
上级 83e8f8f0
......@@ -6580,6 +6580,27 @@ public async Task NullableNotShownWithoutFeatureFlag()
using System.Collections.Generic;
class X
{
void N()
{
string s = """";
string s2 = $$s;
}
}",
MainDescription($"({FeaturesResources.local_variable}) string s"),
NullabilityAnalysis(""));
}
[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
public async Task NullableNotShownInNullableDisableContextEvenIfAnalysisIsRunning()
{
var options = TestOptions.Regular8.WithFeature(CompilerFeatureFlags.RunNullableAnalysis, "true");
await TestWithOptionsAsync(options,
@"#nullable disable
using System.Collections.Generic;
class X
{
void N()
......
......@@ -56,6 +56,14 @@ protected override ImmutableArray<TaggedText> TryGetNullabilityAnalysis(Workspac
return default;
}
// If the user doesn't have nullable enabled, don't show anything. For now we're not trying to be more precise if the user has just annotations or just
// warnings. If the user has annotations off then things that are oblivious might become non-null (which is a lie) and if the user has warnings off then
// that probably implies they're not actually trying to know if their code is correct. We can revisit this if we have specific user scenarios.
if (semanticModel.GetNullableContext(token.SpanStart) != NullableContext.Enabled)
{
return default;
}
var syntaxFacts = workspace.Services.GetLanguageServices(semanticModel.Language).GetRequiredService<ISyntaxFactsService>();
var bindableParent = syntaxFacts.GetBindableParent(token);
var symbolInfo = semanticModel.GetSymbolInfo(bindableParent, cancellationToken);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册