Skip to content

Add Async suffix to async methods #792

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

Merged
merged 1 commit into from
Nov 13, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public WebsocketClientChannel(string url)
this.serverUrl = url;
}

public override async Task WaitForConnection()
public override async Task WaitForConnectionAsync()
{
try
{
Expand All @@ -52,7 +52,7 @@ public override async Task WaitForConnection()
{
Logger.Write(LogLevel.Warning,
string.Format("Failed to connect to WebSocket server. Error was '{0}'", wsException.Message));

}

throw;
Expand Down Expand Up @@ -99,7 +99,7 @@ protected override void Shutdown()
}

/// <summary>
/// Extension of <see cref="MemoryStream"/> that sends data to a WebSocket during FlushAsync
/// Extension of <see cref="MemoryStream"/> that sends data to a WebSocket during FlushAsync
/// and reads during WriteAsync.
/// </summary>
internal class ClientWebSocketStream : MemoryStream
Expand All @@ -110,7 +110,7 @@ internal class ClientWebSocketStream : MemoryStream
/// Constructor
/// </summary>
/// <remarks>
/// It is expected that the socket is in an Open state.
/// It is expected that the socket is in an Open state.
/// </remarks>
/// <param name="socket"></param>
public ClientWebSocketStream(ClientWebSocket socket)
Expand All @@ -119,7 +119,7 @@ public ClientWebSocketStream(ClientWebSocket socket)
}

/// <summary>
/// Reads from the WebSocket.
/// Reads from the WebSocket.
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
Expand All @@ -138,7 +138,7 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
{
result = await socket.ReceiveAsync(new ArraySegment<byte>(buffer, offset, count), cancellationToken);
} while (!result.EndOfMessage);

if (result.MessageType == WebSocketMessageType.Close)
{
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
namespace Microsoft.PowerShell.EditorServices.Channel.WebSocket
{
/// <summary>
/// Implementation of <see cref="ChannelBase"/> that implements the streams necessary for
/// communicating via OWIN WebSockets.
/// Implementation of <see cref="ChannelBase"/> that implements the streams necessary for
/// communicating via OWIN WebSockets.
/// </summary>
public class WebSocketServerChannel : ChannelBase
{
Expand All @@ -42,22 +42,22 @@ protected override void Initialize(IMessageSerializer messageSerializer)

this.MessageWriter =
new MessageWriter(
new WebSocketStream(socketConnection),
new WebSocketStream(socketConnection),
messageSerializer);
}

/// <summary>
/// Dispatches data received during calls to OnMessageReceived in the <see cref="WebSocketConnection"/> class.
/// Dispatches data received during calls to OnMessageReceivedAsync in the <see cref="WebSocketConnection"/> class.
/// </summary>
/// <remarks>
/// This method calls an overriden version of the <see cref="MessageDispatcher"/> that dispatches messages on
/// demand rather than running on a background thread.
/// This method calls an overriden version of the <see cref="MessageDispatcher"/> that dispatches messages on
/// demand rather than running on a background thread.
/// </remarks>
/// <param name="message"></param>
/// <returns></returns>
public async Task Dispatch(ArraySegment<byte> message)
public async Task DispatchAsync(ArraySegment<byte> message)
{
//Clear our stream
//Clear our stream
inStream.SetLength(0);

//Write data and dispatch to handlers
Expand All @@ -70,19 +70,19 @@ protected override void Shutdown()
this.socketConnection.Close(WebSocketCloseStatus.NormalClosure, "Server shutting down");
}

public override Task WaitForConnection()
public override Task WaitForConnectionAsync()
{
// TODO: Need to update behavior here
return Task.FromResult(true);
}
}

/// <summary>
/// Overriden <see cref="MemoryStream"/> that sends data through a <see cref="WebSocketConnection"/> during the FlushAsync call.
/// Overriden <see cref="MemoryStream"/> that sends data through a <see cref="WebSocketConnection"/> during the FlushAsync call.
/// </summary>
/// <remarks>
/// FlushAsync will send data via the SendBinary method of the <see cref="WebSocketConnection"/> class. The memory streams length will
/// then be set to 0 to reset the stream for additional data to be written.
/// then be set to 0 to reset the stream for additional data to be written.
/// </remarks>
internal class WebSocketStream : MemoryStream
{
Expand All @@ -106,7 +106,7 @@ public override async Task FlushAsync(CancellationToken cancellationToken)
/// </summary>
public abstract class EditorServiceWebSocketConnection : WebSocketConnection
{
protected EditorServiceWebSocketConnection()
protected EditorServiceWebSocketConnection()
{
Channel = new WebSocketServerChannel(this);
}
Expand All @@ -120,9 +120,9 @@ public override void OnOpen()
Server.Start();
}

public override async Task OnMessageReceived(ArraySegment<byte> message, WebSocketMessageType type)
public override async Task OnMessageReceivedAsync(ArraySegment<byte> message, WebSocketMessageType type)
{
await Channel.Dispatch(message);
await Channel.DispatchAsync(message);
}

public override Task OnCloseAsync(WebSocketCloseStatus? closeStatus, string closeStatusDescription)
Expand Down
14 changes: 7 additions & 7 deletions src/PowerShellEditorServices.Host/CodeLens/CodeLensFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public static CodeLensFeature Create(

messageHandlers.SetRequestHandler(
CodeLensRequest.Type,
codeLenses.HandleCodeLensRequest);
codeLenses.HandleCodeLensRequestAsync);

messageHandlers.SetRequestHandler(
CodeLensResolveRequest.Type,
codeLenses.HandleCodeLensResolveRequest);
codeLenses.HandleCodeLensResolveRequestAsync);

codeLenses.Providers.Add(
new ReferencesCodeLensProvider(
Expand Down Expand Up @@ -111,7 +111,7 @@ public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
/// </summary>
/// <param name="codeLensParams">Parameters on the CodeLens request that was received.</param>
/// <param name="requestContext"></param>
private async Task HandleCodeLensRequest(
private async Task HandleCodeLensRequestAsync(
CodeLensRequest codeLensParams,
RequestContext<LanguageServer.CodeLens[]> requestContext)
{
Expand All @@ -132,15 +132,15 @@ private async Task HandleCodeLensRequest(
_jsonSerializer);
}

await requestContext.SendResult(codeLensResponse);
await requestContext.SendResultAsync(codeLensResponse);
}

/// <summary>
/// Handle a CodeLens resolve request from VSCode.
/// </summary>
/// <param name="codeLens">The CodeLens to be resolved/updated.</param>
/// <param name="requestContext"></param>
private async Task HandleCodeLensResolveRequest(
private async Task HandleCodeLensResolveRequestAsync(
LanguageServer.CodeLens codeLens,
RequestContext<LanguageServer.CodeLens> requestContext)
{
Expand Down Expand Up @@ -178,13 +178,13 @@ await originalProvider.ResolveCodeLensAsync(
originalCodeLens,
CancellationToken.None);

await requestContext.SendResult(
await requestContext.SendResultAsync(
resolvedCodeLens.ToProtocolCodeLens(
_jsonSerializer));
}
else
{
await requestContext.SendError(
await requestContext.SendErrorAsync(
$"Could not find provider for the original CodeLens: {codeLensData.ProviderId}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task<CodeLens> ResolveCodeLensAsync(
codeLens.ScriptExtent.StartLineNumber,
codeLens.ScriptExtent.StartColumnNumber);

FindReferencesResult referencesResult = await _editorSession.LanguageService.FindReferencesOfSymbol(
FindReferencesResult referencesResult = await _editorSession.LanguageService.FindReferencesOfSymbolAsync(
foundSymbol,
references,
_editorSession.Workspace);
Expand Down
8 changes: 4 additions & 4 deletions src/PowerShellEditorServices.Host/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void StartLanguageService(

this.languageServiceListener = CreateServiceListener(MessageProtocolType.LanguageServer, config);

this.languageServiceListener.ClientConnect += this.OnLanguageServiceClientConnect;
this.languageServiceListener.ClientConnect += this.OnLanguageServiceClientConnectAsync;
this.languageServiceListener.Start();

this.logger.Write(
Expand All @@ -184,7 +184,7 @@ public void StartLanguageService(
config.TransportType, config.Endpoint));
}

private async void OnLanguageServiceClientConnect(
private async void OnLanguageServiceClientConnectAsync(
object sender,
ChannelBase serverChannel)
{
Expand Down Expand Up @@ -214,7 +214,7 @@ private async void OnLanguageServiceClientConnect(
this.serverCompletedTask,
this.logger);

await this.editorSession.PowerShellContext.ImportCommandsModule(
await this.editorSession.PowerShellContext.ImportCommandsModuleAsync(
Path.Combine(
Path.GetDirectoryName(this.GetType().GetTypeInfo().Assembly.Location),
@"..\Commands"));
Expand All @@ -225,7 +225,7 @@ await this.editorSession.PowerShellContext.ImportCommandsModule(
// gets initialized when that is done earlier than LanguageServer.Initialize
foreach (string module in this.additionalModules)
{
await this.editorSession.PowerShellContext.ExecuteCommand<System.Management.Automation.PSObject>(
await this.editorSession.PowerShellContext.ExecuteCommandAsync<System.Management.Automation.PSObject>(
new System.Management.Automation.PSCommand().AddCommand("Import-Module").AddArgument(module),
false,
true);
Expand Down
10 changes: 5 additions & 5 deletions src/PowerShellEditorServices.Host/PSHost/PromptHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override void ShowPrompt(PromptStyle promptStyle)
base.ShowPrompt(promptStyle);

messageSender
.SendRequest(
.SendRequestAsync(
ShowChoicePromptRequest.Type,
new ShowChoicePromptRequest
{
Expand All @@ -51,7 +51,7 @@ protected override void ShowPrompt(PromptStyle promptStyle)
.ConfigureAwait(false);
}

protected override Task<string> ReadInputString(CancellationToken cancellationToken)
protected override Task<string> ReadInputStringAsync(CancellationToken cancellationToken)
{
this.readLineTask = new TaskCompletionSource<string>();
return this.readLineTask.Task;
Expand Down Expand Up @@ -120,7 +120,7 @@ protected override void ShowFieldPrompt(FieldDetails fieldDetails)
base.ShowFieldPrompt(fieldDetails);

messageSender
.SendRequest(
.SendRequestAsync(
ShowInputPromptRequest.Type,
new ShowInputPromptRequest
{
Expand All @@ -131,7 +131,7 @@ protected override void ShowFieldPrompt(FieldDetails fieldDetails)
.ConfigureAwait(false);
}

protected override Task<string> ReadInputString(CancellationToken cancellationToken)
protected override Task<string> ReadInputStringAsync(CancellationToken cancellationToken)
{
this.readLineTask = new TaskCompletionSource<string>();
return this.readLineTask.Task;
Expand Down Expand Up @@ -176,7 +176,7 @@ private void HandlePromptResponse(
this.readLineTask = null;
}

protected override Task<SecureString> ReadSecureString(CancellationToken cancellationToken)
protected override Task<SecureString> ReadSecureStringAsync(CancellationToken cancellationToken)
{
// TODO: Write a message to the console
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Dispose()
// Make sure remaining output is flushed before exiting
if (this.outputDebouncer != null)
{
this.outputDebouncer.Flush().Wait();
this.outputDebouncer.FlushAsync().Wait();
this.outputDebouncer = null;
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public override void WriteOutput(
ConsoleColor backgroundColor)
{
// TODO: This should use a synchronous method!
this.outputDebouncer.Invoke(
this.outputDebouncer.InvokeAsync(
new OutputWrittenEventArgs(
outputString,
includeNewLine,
Expand All @@ -102,7 +102,7 @@ protected override void UpdateProgress(
{
}

protected override Task<string> ReadCommandLine(CancellationToken cancellationToken)
protected override Task<string> ReadCommandLineAsync(CancellationToken cancellationToken)
{
// This currently does nothing because the "evaluate" request
// will cancel the current prompt and execute the user's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public DocumentSymbolFeature(

messageHandlers.SetRequestHandler(
DocumentSymbolRequest.Type,
this.HandleDocumentSymbolRequest);
this.HandleDocumentSymbolRequestAsync);
}

public static DocumentSymbolFeature Create(
Expand Down Expand Up @@ -69,7 +69,7 @@ public IEnumerable<SymbolReference> ProvideDocumentSymbols(
.SelectMany(r => r);
}

protected async Task HandleDocumentSymbolRequest(
protected async Task HandleDocumentSymbolRequestAsync(
DocumentSymbolParams documentSymbolParams,
RequestContext<SymbolInformation[]> requestContext)
{
Expand Down Expand Up @@ -109,7 +109,7 @@ protected async Task HandleDocumentSymbolRequest(
symbols = new SymbolInformation[0];
}

await requestContext.SendResult(symbols);
await requestContext.SendResultAsync(symbols);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public DebugAdapterClient(ChannelBase clientChannel, ILogger logger)
logger);
}

public async Task Start()
public async Task StartAsync()
{
this.protocolEndpoint.Start();

// Initialize the debug adapter
await this.SendRequest(
await this.SendRequestAsync(
InitializeRequest.Type,
new InitializeRequestArguments
{
Expand All @@ -48,34 +48,34 @@ public void Stop()
this.protocolEndpoint.Stop();
}

public async Task LaunchScript(string scriptFilePath)
public async Task LaunchScriptAsync(string scriptFilePath)
{
await this.SendRequest(
await this.SendRequestAsync(
LaunchRequest.Type,
new LaunchRequestArguments {
Script = scriptFilePath
},
true);

await this.SendRequest(
await this.SendRequestAsync(
ConfigurationDoneRequest.Type,
null,
true);
}

public Task SendEvent<TParams, TRegistrationOptions>(NotificationType<TParams, TRegistrationOptions> eventType, TParams eventParams)
public Task SendEventAsync<TParams, TRegistrationOptions>(NotificationType<TParams, TRegistrationOptions> eventType, TParams eventParams)
{
return ((IMessageSender)protocolEndpoint).SendEvent(eventType, eventParams);
return ((IMessageSender)protocolEndpoint).SendEventAsync(eventType, eventParams);
}

public Task<TResult> SendRequest<TParams, TResult, TError, TRegistrationOptions>(RequestType<TParams, TResult, TError, TRegistrationOptions> requestType, TParams requestParams, bool waitForResponse)
public Task<TResult> SendRequestAsync<TParams, TResult, TError, TRegistrationOptions>(RequestType<TParams, TResult, TError, TRegistrationOptions> requestType, TParams requestParams, bool waitForResponse)
{
return ((IMessageSender)protocolEndpoint).SendRequest(requestType, requestParams, waitForResponse);
return ((IMessageSender)protocolEndpoint).SendRequestAsync(requestType, requestParams, waitForResponse);
}

public Task<TResult> SendRequest<TResult, TError, TRegistrationOptions>(RequestType0<TResult, TError, TRegistrationOptions> requestType0)
public Task<TResult> SendRequestAsync<TResult, TError, TRegistrationOptions>(RequestType0<TResult, TError, TRegistrationOptions> requestType0)
{
return ((IMessageSender)protocolEndpoint).SendRequest(requestType0);
return ((IMessageSender)protocolEndpoint).SendRequestAsync(requestType0);
}

public void SetRequestHandler<TParams, TResult, TError, TRegistrationOptions>(RequestType<TParams, TResult, TError, TRegistrationOptions> requestType, Func<TParams, RequestContext<TResult>, Task> requestHandler)
Expand Down
Loading