Skip to content

Commit 91f9b1a

Browse files
dee-seerjmholt
authored andcommitted
Add Async suffix to async methods (PowerShell#792)
[Ignore] no need for package sources (PowerShell#803) [Ignore] add null check for version
1 parent 00f2805 commit 91f9b1a

File tree

74 files changed

+850
-832
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+850
-832
lines changed

NuGet.Config

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@
33
<solution>
44
<add key="disableSourceControlIntegration" value="true" />
55
</solution>
6-
<packageSources>
7-
<clear />
8-
<add key="CI Builds (dotnet-core)" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
9-
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
10-
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
11-
</packageSources>
12-
</configuration>
6+
</configuration>

PowerShellEditorServices.build.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServer, TestProtocol, Packa
198198
# dotnet --version can return a semver that System.Version can't handle
199199
# e.g.: 2.1.300-preview-01. The replace operator is used to remove any build suffix.
200200
$version = (& $dotnetExePath --version) -replace '[+-].*$',''
201-
if ([version]$version -ge [version]$script:RequiredSdkVersion) {
201+
if ($version -and [version]$version -ge [version]$script:RequiredSdkVersion) {
202202
$script:dotnetExe = $dotnetExePath
203203
}
204204
else {

src/PowerShellEditorServices.Channel.WebSocket/WebsocketClientChannel.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public WebsocketClientChannel(string url)
3939
this.serverUrl = url;
4040
}
4141

42-
public override async Task WaitForConnection()
42+
public override async Task WaitForConnectionAsync()
4343
{
4444
try
4545
{
@@ -52,7 +52,7 @@ public override async Task WaitForConnection()
5252
{
5353
Logger.Write(LogLevel.Warning,
5454
string.Format("Failed to connect to WebSocket server. Error was '{0}'", wsException.Message));
55-
55+
5656
}
5757

5858
throw;
@@ -99,7 +99,7 @@ protected override void Shutdown()
9999
}
100100

101101
/// <summary>
102-
/// Extension of <see cref="MemoryStream"/> that sends data to a WebSocket during FlushAsync
102+
/// Extension of <see cref="MemoryStream"/> that sends data to a WebSocket during FlushAsync
103103
/// and reads during WriteAsync.
104104
/// </summary>
105105
internal class ClientWebSocketStream : MemoryStream
@@ -110,7 +110,7 @@ internal class ClientWebSocketStream : MemoryStream
110110
/// Constructor
111111
/// </summary>
112112
/// <remarks>
113-
/// It is expected that the socket is in an Open state.
113+
/// It is expected that the socket is in an Open state.
114114
/// </remarks>
115115
/// <param name="socket"></param>
116116
public ClientWebSocketStream(ClientWebSocket socket)
@@ -119,7 +119,7 @@ public ClientWebSocketStream(ClientWebSocket socket)
119119
}
120120

121121
/// <summary>
122-
/// Reads from the WebSocket.
122+
/// Reads from the WebSocket.
123123
/// </summary>
124124
/// <param name="buffer"></param>
125125
/// <param name="offset"></param>
@@ -138,7 +138,7 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
138138
{
139139
result = await socket.ReceiveAsync(new ArraySegment<byte>(buffer, offset, count), cancellationToken);
140140
} while (!result.EndOfMessage);
141-
141+
142142
if (result.MessageType == WebSocketMessageType.Close)
143143
{
144144
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing", cancellationToken);

src/PowerShellEditorServices.Channel.WebSocket/WebsocketServerChannel.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
namespace Microsoft.PowerShell.EditorServices.Channel.WebSocket
1818
{
1919
/// <summary>
20-
/// Implementation of <see cref="ChannelBase"/> that implements the streams necessary for
21-
/// communicating via OWIN WebSockets.
20+
/// Implementation of <see cref="ChannelBase"/> that implements the streams necessary for
21+
/// communicating via OWIN WebSockets.
2222
/// </summary>
2323
public class WebSocketServerChannel : ChannelBase
2424
{
@@ -42,22 +42,22 @@ protected override void Initialize(IMessageSerializer messageSerializer)
4242

4343
this.MessageWriter =
4444
new MessageWriter(
45-
new WebSocketStream(socketConnection),
45+
new WebSocketStream(socketConnection),
4646
messageSerializer);
4747
}
4848

4949
/// <summary>
50-
/// Dispatches data received during calls to OnMessageReceived in the <see cref="WebSocketConnection"/> class.
50+
/// Dispatches data received during calls to OnMessageReceivedAsync in the <see cref="WebSocketConnection"/> class.
5151
/// </summary>
5252
/// <remarks>
53-
/// This method calls an overriden version of the <see cref="MessageDispatcher"/> that dispatches messages on
54-
/// demand rather than running on a background thread.
53+
/// This method calls an overriden version of the <see cref="MessageDispatcher"/> that dispatches messages on
54+
/// demand rather than running on a background thread.
5555
/// </remarks>
5656
/// <param name="message"></param>
5757
/// <returns></returns>
58-
public async Task Dispatch(ArraySegment<byte> message)
58+
public async Task DispatchAsync(ArraySegment<byte> message)
5959
{
60-
//Clear our stream
60+
//Clear our stream
6161
inStream.SetLength(0);
6262

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

73-
public override Task WaitForConnection()
73+
public override Task WaitForConnectionAsync()
7474
{
7575
// TODO: Need to update behavior here
7676
return Task.FromResult(true);
7777
}
7878
}
7979

8080
/// <summary>
81-
/// Overriden <see cref="MemoryStream"/> that sends data through a <see cref="WebSocketConnection"/> during the FlushAsync call.
81+
/// Overriden <see cref="MemoryStream"/> that sends data through a <see cref="WebSocketConnection"/> during the FlushAsync call.
8282
/// </summary>
8383
/// <remarks>
8484
/// FlushAsync will send data via the SendBinary method of the <see cref="WebSocketConnection"/> class. The memory streams length will
85-
/// then be set to 0 to reset the stream for additional data to be written.
85+
/// then be set to 0 to reset the stream for additional data to be written.
8686
/// </remarks>
8787
internal class WebSocketStream : MemoryStream
8888
{
@@ -106,7 +106,7 @@ public override async Task FlushAsync(CancellationToken cancellationToken)
106106
/// </summary>
107107
public abstract class EditorServiceWebSocketConnection : WebSocketConnection
108108
{
109-
protected EditorServiceWebSocketConnection()
109+
protected EditorServiceWebSocketConnection()
110110
{
111111
Channel = new WebSocketServerChannel(this);
112112
}
@@ -120,9 +120,9 @@ public override void OnOpen()
120120
Server.Start();
121121
}
122122

123-
public override async Task OnMessageReceived(ArraySegment<byte> message, WebSocketMessageType type)
123+
public override async Task OnMessageReceivedAsync(ArraySegment<byte> message, WebSocketMessageType type)
124124
{
125-
await Channel.Dispatch(message);
125+
await Channel.DispatchAsync(message);
126126
}
127127

128128
public override Task OnCloseAsync(WebSocketCloseStatus? closeStatus, string closeStatusDescription)

src/PowerShellEditorServices.Host/CodeLens/CodeLensFeature.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public static CodeLensFeature Create(
4949

5050
messageHandlers.SetRequestHandler(
5151
CodeLensRequest.Type,
52-
codeLenses.HandleCodeLensRequest);
52+
codeLenses.HandleCodeLensRequestAsync);
5353

5454
messageHandlers.SetRequestHandler(
5555
CodeLensResolveRequest.Type,
56-
codeLenses.HandleCodeLensResolveRequest);
56+
codeLenses.HandleCodeLensResolveRequestAsync);
5757

5858
codeLenses.Providers.Add(
5959
new ReferencesCodeLensProvider(
@@ -111,7 +111,7 @@ public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
111111
/// </summary>
112112
/// <param name="codeLensParams">Parameters on the CodeLens request that was received.</param>
113113
/// <param name="requestContext"></param>
114-
private async Task HandleCodeLensRequest(
114+
private async Task HandleCodeLensRequestAsync(
115115
CodeLensRequest codeLensParams,
116116
RequestContext<LanguageServer.CodeLens[]> requestContext)
117117
{
@@ -132,15 +132,15 @@ private async Task HandleCodeLensRequest(
132132
_jsonSerializer);
133133
}
134134

135-
await requestContext.SendResult(codeLensResponse);
135+
await requestContext.SendResultAsync(codeLensResponse);
136136
}
137137

138138
/// <summary>
139139
/// Handle a CodeLens resolve request from VSCode.
140140
/// </summary>
141141
/// <param name="codeLens">The CodeLens to be resolved/updated.</param>
142142
/// <param name="requestContext"></param>
143-
private async Task HandleCodeLensResolveRequest(
143+
private async Task HandleCodeLensResolveRequestAsync(
144144
LanguageServer.CodeLens codeLens,
145145
RequestContext<LanguageServer.CodeLens> requestContext)
146146
{
@@ -178,13 +178,13 @@ await originalProvider.ResolveCodeLensAsync(
178178
originalCodeLens,
179179
CancellationToken.None);
180180

181-
await requestContext.SendResult(
181+
await requestContext.SendResultAsync(
182182
resolvedCodeLens.ToProtocolCodeLens(
183183
_jsonSerializer));
184184
}
185185
else
186186
{
187-
await requestContext.SendError(
187+
await requestContext.SendErrorAsync(
188188
$"Could not find provider for the original CodeLens: {codeLensData.ProviderId}");
189189
}
190190
}

src/PowerShellEditorServices.Host/CodeLens/ReferencesCodeLensProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public async Task<CodeLens> ResolveCodeLensAsync(
8282
codeLens.ScriptExtent.StartLineNumber,
8383
codeLens.ScriptExtent.StartColumnNumber);
8484

85-
FindReferencesResult referencesResult = await _editorSession.LanguageService.FindReferencesOfSymbol(
85+
FindReferencesResult referencesResult = await _editorSession.LanguageService.FindReferencesOfSymbolAsync(
8686
foundSymbol,
8787
references,
8888
_editorSession.Workspace);

src/PowerShellEditorServices.Host/EditorServicesHost.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void StartLanguageService(
191191

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

194-
this.languageServiceListener.ClientConnect += this.OnLanguageServiceClientConnect;
194+
this.languageServiceListener.ClientConnect += this.OnLanguageServiceClientConnectAsync;
195195
this.languageServiceListener.Start();
196196

197197
this.logger.Write(
@@ -201,7 +201,7 @@ public void StartLanguageService(
201201
config.TransportType, config.Endpoint));
202202
}
203203

204-
private async void OnLanguageServiceClientConnect(
204+
private async void OnLanguageServiceClientConnectAsync(
205205
object sender,
206206
ChannelBase serverChannel)
207207
{
@@ -231,7 +231,7 @@ private async void OnLanguageServiceClientConnect(
231231
this.serverCompletedTask,
232232
this.logger);
233233

234-
await this.editorSession.PowerShellContext.ImportCommandsModule(
234+
await this.editorSession.PowerShellContext.ImportCommandsModuleAsync(
235235
Path.Combine(
236236
Path.GetDirectoryName(this.GetType().GetTypeInfo().Assembly.Location),
237237
@"..\Commands"));
@@ -247,7 +247,7 @@ await this.editorSession.PowerShellContext.ImportCommandsModule(
247247
.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
248248
.AddParameter("Name", module);
249249

250-
await this.editorSession.PowerShellContext.ExecuteCommand<System.Management.Automation.PSObject>(
250+
await this.editorSession.PowerShellContext.ExecuteCommandAsync<System.Management.Automation.PSObject>(
251251
command,
252252
sendOutputToHost: false,
253253
sendErrorToHost: true);

src/PowerShellEditorServices.Host/PSHost/PromptHandlers.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected override void ShowPrompt(PromptStyle promptStyle)
3737
base.ShowPrompt(promptStyle);
3838

3939
messageSender
40-
.SendRequest(
40+
.SendRequestAsync(
4141
ShowChoicePromptRequest.Type,
4242
new ShowChoicePromptRequest
4343
{
@@ -51,7 +51,7 @@ protected override void ShowPrompt(PromptStyle promptStyle)
5151
.ConfigureAwait(false);
5252
}
5353

54-
protected override Task<string> ReadInputString(CancellationToken cancellationToken)
54+
protected override Task<string> ReadInputStringAsync(CancellationToken cancellationToken)
5555
{
5656
this.readLineTask = new TaskCompletionSource<string>();
5757
return this.readLineTask.Task;
@@ -120,7 +120,7 @@ protected override void ShowFieldPrompt(FieldDetails fieldDetails)
120120
base.ShowFieldPrompt(fieldDetails);
121121

122122
messageSender
123-
.SendRequest(
123+
.SendRequestAsync(
124124
ShowInputPromptRequest.Type,
125125
new ShowInputPromptRequest
126126
{
@@ -131,7 +131,7 @@ protected override void ShowFieldPrompt(FieldDetails fieldDetails)
131131
.ConfigureAwait(false);
132132
}
133133

134-
protected override Task<string> ReadInputString(CancellationToken cancellationToken)
134+
protected override Task<string> ReadInputStringAsync(CancellationToken cancellationToken)
135135
{
136136
this.readLineTask = new TaskCompletionSource<string>();
137137
return this.readLineTask.Task;
@@ -176,7 +176,7 @@ private void HandlePromptResponse(
176176
this.readLineTask = null;
177177
}
178178

179-
protected override Task<SecureString> ReadSecureString(CancellationToken cancellationToken)
179+
protected override Task<SecureString> ReadSecureStringAsync(CancellationToken cancellationToken)
180180
{
181181
// TODO: Write a message to the console
182182
throw new NotImplementedException();

src/PowerShellEditorServices.Host/PSHost/ProtocolPSHostUserInterface.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void Dispose()
4747
// Make sure remaining output is flushed before exiting
4848
if (this.outputDebouncer != null)
4949
{
50-
this.outputDebouncer.Flush().Wait();
50+
this.outputDebouncer.FlushAsync().Wait();
5151
this.outputDebouncer = null;
5252
}
5353
}
@@ -82,7 +82,7 @@ public override void WriteOutput(
8282
ConsoleColor backgroundColor)
8383
{
8484
// TODO: This should use a synchronous method!
85-
this.outputDebouncer.Invoke(
85+
this.outputDebouncer.InvokeAsync(
8686
new OutputWrittenEventArgs(
8787
outputString,
8888
includeNewLine,
@@ -102,7 +102,7 @@ protected override void UpdateProgress(
102102
{
103103
}
104104

105-
protected override Task<string> ReadCommandLine(CancellationToken cancellationToken)
105+
protected override Task<string> ReadCommandLineAsync(CancellationToken cancellationToken)
106106
{
107107
// This currently does nothing because the "evaluate" request
108108
// will cancel the current prompt and execute the user's

src/PowerShellEditorServices.Host/Symbols/DocumentSymbolFeature.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public DocumentSymbolFeature(
3333

3434
messageHandlers.SetRequestHandler(
3535
DocumentSymbolRequest.Type,
36-
this.HandleDocumentSymbolRequest);
36+
this.HandleDocumentSymbolRequestAsync);
3737
}
3838

3939
public static DocumentSymbolFeature Create(
@@ -69,7 +69,7 @@ public IEnumerable<SymbolReference> ProvideDocumentSymbols(
6969
.SelectMany(r => r);
7070
}
7171

72-
protected async Task HandleDocumentSymbolRequest(
72+
protected async Task HandleDocumentSymbolRequestAsync(
7373
DocumentSymbolParams documentSymbolParams,
7474
RequestContext<SymbolInformation[]> requestContext)
7575
{
@@ -109,7 +109,7 @@ protected async Task HandleDocumentSymbolRequest(
109109
symbols = new SymbolInformation[0];
110110
}
111111

112-
await requestContext.SendResult(symbols);
112+
await requestContext.SendResultAsync(symbols);
113113
}
114114
}
115115
}

0 commit comments

Comments
 (0)