Closed jhinder closed 1 year ago
Does anybody know which source code file is responsible for the autocompletion of return new
please?
@MartyIX Probably ObjectCreationCompletionProvider
, if not, it will be SymbolCompletionProvider
Root cause might be https://github.com/dotnet/roslyn/issues/30559, but can't confirm without debugging through this.
This should also work for the following:
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
class C
{
async MyTask<string> M()
{
return new $$
}
}
[AsyncMethodBuilder(typeof(Task<>))]
struct MyTask<T>
{
}
Adding the following test
[Fact]
public async Task InAsyncMethodReturnValueTask()
{
var markup =
@"using System;
using System.Threading.Tasks;
class Program
{
async ValueTask<string> M2Async()
{
return new $$;
}
}";
await VerifyItemExistsAsync(markup, "string");
}
to src\EditorFeatures\CSharpTest\Completion\CompletionProviders\ObjectCreationCompletionProviderTests.cs
and modifying https://github.com/dotnet/roslyn/blob/39485811c4d1b869ed1531f50fdbcc43bd3dfa48/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs#L2025-L2042
with
private ITypeSymbol UnwrapTaskLike(ITypeSymbol type, bool isAsync)
{
if (isAsync)
{
if (type.OriginalDefinition.Equals(this.Compilation.TaskOfTType()) || type.OriginalDefinition.Equals(this.Compilation.ValueTaskOfTType()))
{
var namedTypeSymbol = (INamedTypeSymbol)type;
return namedTypeSymbol.TypeArguments[0];
}
if (type.OriginalDefinition.Equals(this.Compilation.TaskType()) || type.OriginalDefinition.Equals(this.Compilation.ValueTaskType()))
{
return this.Compilation.GetSpecialType(SpecialType.System_Void);
}
}
return type;
}
does not help because this.Compilation.ValueTaskOfTType()
is null
and I'm not too sure why. Probably because it is available only in
@MartyIX You can use .NET 6 in tests by doing something like this:
Thanks! I tried that and it seems to work... as far as I understand.
Version Used: VS 2022 17.3.6
Steps to Reproduce:
new
keywords.Expected Behavior: In both cases
string
is suggested, as the methods are marked asasync
.Actual Behavior:
object
is suggested in theTask
method.ValueTask<object>
is suggested in theValueTask
method.Accepting the autocompletion of
ValueTask<string>
leads to error CS4016.