Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify some code #2370

Merged
merged 4 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/OmniSharp.Host/Endpoint/EndpointHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ public override Task<object> Handle(RequestPacket packet)
public async Task<object> Process(RequestPacket packet, LanguageModel model, JToken requestObject)
{
var request = requestObject.ToObject<TRequest>();
if (request is Request && _updateBufferHandler.Value != null)
if (request is Request realRequest && _updateBufferHandler.Value != null)
{
var realRequest = request as Request;
if (!string.IsNullOrWhiteSpace(realRequest.FileName) && (realRequest.Buffer != null || realRequest.Changes != null))
{
await _updateBufferHandler.Value.Process(packet, model, requestObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,12 @@ public async Task<IEnumerable<AutoCompleteResponse>> Handle(AutoCompleteRequest

private IEnumerable<AutoCompleteResponse> MakeSnippetedResponses(AutoCompleteRequest request, ISymbol symbol, string completionText, bool preselect, bool isSuggestionMode)
{
switch (symbol)
return symbol switch
{
case IMethodSymbol methodSymbol:
return MakeSnippetedResponses(request, methodSymbol, completionText, preselect, isSuggestionMode);
case INamedTypeSymbol typeSymbol:
return MakeSnippetedResponses(request, typeSymbol, completionText, preselect, isSuggestionMode);

default:
return new[] { MakeAutoCompleteResponse(request, symbol, completionText, preselect, isSuggestionMode) };
}
IMethodSymbol methodSymbol => MakeSnippetedResponses(request, methodSymbol, completionText, preselect, isSuggestionMode),
INamedTypeSymbol typeSymbol => MakeSnippetedResponses(request, typeSymbol, completionText, preselect, isSuggestionMode),
_ => new[] { MakeAutoCompleteResponse(request, symbol, completionText, preselect, isSuggestionMode) },
};
}

private IEnumerable<AutoCompleteResponse> MakeSnippetedResponses(AutoCompleteRequest request, IMethodSymbol methodSymbol, string completionText, bool preselect, bool isSuggestionMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,17 @@ public static string GetReturnType(ISymbol symbol)

private static ITypeSymbol GetReturnTypeSymbol(ISymbol symbol)
{
var methodSymbol = symbol as IMethodSymbol;
if (methodSymbol != null)
return symbol switch
{
if (methodSymbol.MethodKind != MethodKind.Constructor)
{
return methodSymbol.ReturnType;
}
}

var propertySymbol = symbol as IPropertySymbol;
if (propertySymbol != null)
{
return propertySymbol.Type;
}

var localSymbol = symbol as ILocalSymbol;
if (localSymbol != null)
{
return localSymbol.Type;
}

var parameterSymbol = symbol as IParameterSymbol;
if (parameterSymbol != null)
{
return parameterSymbol.Type;
}

var fieldSymbol = symbol as IFieldSymbol;
if (fieldSymbol != null)
{
return fieldSymbol.Type;
}

var eventSymbol = symbol as IEventSymbol;
if (eventSymbol != null)
{
return eventSymbol.Type;
}

return null;
IMethodSymbol methodSymbol when methodSymbol.MethodKind != MethodKind.Constructor
=> methodSymbol.ReturnType,
IPropertySymbol propertySymbol => propertySymbol.Type,
ILocalSymbol localSymbol => localSymbol.Type,
IParameterSymbol parameterSymbol => parameterSymbol.Type,
IFieldSymbol fieldSymbol => fieldSymbol.Type,
IEventSymbol eventSymbol => eventSymbol.Type,
_ => null
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ public string Generate(ISymbol symbol)
// only the containing type contains the type parameters
var parts = symbol.ContainingType.ToDisplayParts(_format);
RenderDisplayParts(symbol, parts);
parts = symbol.ToDisplayParts(_format);
RenderParameters(symbol as IMethodSymbol);
}
else
{
var symbolKind = symbol.Kind;
if (symbol.Kind == SymbolKind.Method)
{
RenderMethodSymbol(symbol as IMethodSymbol);
Expand Down Expand Up @@ -154,8 +152,7 @@ private IEnumerable<ISymbol> ParameterTypes(IMethodSymbol methodSymbol)

private IEnumerable<ISymbol> ExplodeTypes(ISymbol symbol)
{
var typeSymbol = symbol as INamedTypeSymbol;
if (typeSymbol != null)
if (symbol is INamedTypeSymbol typeSymbol)
{
var typeParams = typeSymbol.TypeArguments;

Expand Down
10 changes: 5 additions & 5 deletions tests/TestUtility/DotNetCliVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public static class DotNetCliVersionExtensions
{
public static string GetFolderName(this DotNetCliVersion dotNetCliVersion)
{
switch (dotNetCliVersion)
return dotNetCliVersion switch
{
case DotNetCliVersion.Current: return ".dotnet";
case DotNetCliVersion.Future: throw new InvalidOperationException("Test infrastructure does not support a future .NET Core SDK yet.");
default: throw new ArgumentException($"Unknown {nameof(dotNetCliVersion)}: {dotNetCliVersion}", nameof(dotNetCliVersion));
}
DotNetCliVersion.Current => ".dotnet",
DotNetCliVersion.Future => throw new InvalidOperationException("Test infrastructure does not support a future .NET Core SDK yet."),
_ => throw new ArgumentException($"Unknown {nameof(dotNetCliVersion)}: {dotNetCliVersion}", nameof(dotNetCliVersion)),
};
}
}
}