Skip to content

Commit

Permalink
Add Async suffix to async methods (#792)
Browse files Browse the repository at this point in the history
[Ignore] no need for package sources (#803)

[Ignore] add null check for version
  • Loading branch information
dee-see authored and rjmholt committed Jan 18, 2019
1 parent 00f2805 commit 91f9b1a
Show file tree
Hide file tree
Showing 74 changed files with 850 additions and 832 deletions.
8 changes: 1 addition & 7 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,4 @@
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<clear />
<add key="CI Builds (dotnet-core)" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
</packageSources>
</configuration>
</configuration>
2 changes: 1 addition & 1 deletion PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, Packa
# dotnet --version can return a semver that System.Version can't handle
# e.g.: 2.1.300-preview-01. The replace operator is used to remove any build suffix.
$version = (& $dotnetExePath --version) -replace '[+-].*$',''
if ([version]$version -ge [version]$script:RequiredSdkVersion) {
if ($version -and [version]$version -ge [version]$script:RequiredSdkVersion) {
$script:dotnetExe = $dotnetExePath
}
else {
Expand Down
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 @@ -191,7 +191,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 @@ -201,7 +201,7 @@ public void StartLanguageService(
config.TransportType, config.Endpoint));
}

private async void OnLanguageServiceClientConnect(
private async void OnLanguageServiceClientConnectAsync(
object sender,
ChannelBase serverChannel)
{
Expand Down Expand Up @@ -231,7 +231,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 @@ -247,7 +247,7 @@ await this.editorSession.PowerShellContext.ImportCommandsModule(
.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
.AddParameter("Name", module);

await this.editorSession.PowerShellContext.ExecuteCommand<System.Management.Automation.PSObject>(
await this.editorSession.PowerShellContext.ExecuteCommandAsync<System.Management.Automation.PSObject>(
command,
sendOutputToHost: false,
sendErrorToHost: 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);
}
}
}
Loading

0 comments on commit 91f9b1a

Please sign in to comment.