Skip to content

Commit 483dd6f

Browse files
committed
Squash
1 parent e3c0229 commit 483dd6f

15 files changed

+163
-105
lines changed

src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33

44
#nullable enable
55

6-
using System;
7-
using System.Collections.Concurrent;
8-
using System.Collections.Generic;
9-
using System.Linq;
10-
using System.Management.Automation;
11-
using System.Management.Automation.Language;
12-
using System.Threading;
13-
using System.Threading.Tasks;
146
using Microsoft.Extensions.Logging;
157
using Microsoft.PowerShell.EditorServices.CodeLenses;
168
using Microsoft.PowerShell.EditorServices.Logging;
@@ -21,6 +13,14 @@
2113
using Microsoft.PowerShell.EditorServices.Services.Symbols;
2214
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
2315
using Microsoft.PowerShell.EditorServices.Utility;
16+
using System;
17+
using System.Collections.Concurrent;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Management.Automation;
21+
using System.Management.Automation.Language;
22+
using System.Threading;
23+
using System.Threading.Tasks;
2424

2525
namespace Microsoft.PowerShell.EditorServices.Services
2626
{
@@ -333,11 +333,11 @@ internal async Task ScanWorkspacePSFiles(CancellationToken cancellationToken = d
333333
if (scanTask is null)
334334
{
335335
scanTask = Task.Run(
336-
() =>
336+
async () =>
337337
{
338-
foreach (string file in _workspaceService.EnumeratePSFiles())
338+
foreach (string file in await _workspaceService.EnumeratePSFiles(cancellationToken).ConfigureAwait(false))
339339
{
340-
if (_workspaceService.TryGetFile(file, out ScriptFile scriptFile))
340+
if ((await _workspaceService.TryGetFile(file).ConfigureAwait(false)) is ScriptFile scriptFile)
341341
{
342342
scriptFile.References.EnsureInitialized();
343343
}

src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Threading;
8-
using System.Threading.Tasks;
94
using Microsoft.Extensions.Logging;
105
using Microsoft.PowerShell.EditorServices.CodeLenses;
116
using Microsoft.PowerShell.EditorServices.Services;
@@ -14,6 +9,11 @@
149
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1510
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
1611
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
12+
using System;
13+
using System.Collections.Generic;
14+
using System.Linq;
15+
using System.Threading;
16+
using System.Threading.Tasks;
1717

1818
namespace Microsoft.PowerShell.EditorServices.Handlers
1919
{
@@ -37,19 +37,19 @@ public PsesCodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsServic
3737
ResolveProvider = true
3838
};
3939

40-
public override Task<CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken)
40+
public override async Task<CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken)
4141
{
4242
_logger.LogDebug($"Handling code lens request for {request.TextDocument.Uri}");
4343

44-
ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);
44+
ScriptFile scriptFile = await _workspaceService.GetFile(request.TextDocument.Uri).ConfigureAwait(false);
4545
IEnumerable<CodeLens> codeLensResults = ProvideCodeLenses(scriptFile);
4646

4747
return cancellationToken.IsCancellationRequested
48-
? Task.FromResult(s_emptyCodeLensContainer)
49-
: Task.FromResult(new CodeLensContainer(codeLensResults));
48+
? s_emptyCodeLensContainer
49+
: new CodeLensContainer(codeLensResults);
5050
}
5151

52-
public override Task<CodeLens> Handle(CodeLens request, CancellationToken cancellationToken)
52+
public override async Task<CodeLens> Handle(CodeLens request, CancellationToken cancellationToken)
5353
{
5454
// TODO: Catch deserialization exception on bad object
5555
CodeLensData codeLensData = request.Data.ToObject<CodeLensData>();
@@ -58,8 +58,8 @@ public override Task<CodeLens> Handle(CodeLens request, CancellationToken cancel
5858
.GetCodeLensProviders()
5959
.FirstOrDefault(provider => provider.ProviderId.Equals(codeLensData.ProviderId, StringComparison.Ordinal));
6060

61-
ScriptFile scriptFile = _workspaceService.GetFile(codeLensData.Uri);
62-
return originalProvider.ResolveCodeLens(request, scriptFile, cancellationToken);
61+
ScriptFile scriptFile = await _workspaceService.GetFile(codeLensData.Uri).ConfigureAwait(false);
62+
return await originalProvider.ResolveCodeLens(request, scriptFile, cancellationToken).ConfigureAwait(false);
6363
}
6464

6565
/// <summary>

src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Management.Automation;
8-
using System.Text;
9-
using System.Text.RegularExpressions;
10-
using System.Threading;
11-
using System.Threading.Tasks;
124
using Microsoft.Extensions.Logging;
135
using Microsoft.PowerShell.EditorServices.Services;
146
using Microsoft.PowerShell.EditorServices.Services.PowerShell;
@@ -20,6 +12,14 @@
2012
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
2113
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
2214
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Management.Automation;
19+
using System.Text;
20+
using System.Text.RegularExpressions;
21+
using System.Threading;
22+
using System.Threading.Tasks;
2323

2424
namespace Microsoft.PowerShell.EditorServices.Handlers
2525
{
@@ -68,7 +68,7 @@ public override async Task<CompletionList> Handle(CompletionParams request, Canc
6868
int cursorLine = request.Position.Line + 1;
6969
int cursorColumn = request.Position.Character + 1;
7070

71-
ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);
71+
ScriptFile scriptFile = await _workspaceService.GetFile(request.TextDocument.Uri).ConfigureAwait(false);
7272
try
7373
{
7474
(bool isIncomplete, IReadOnlyList<CompletionItem> completionResults) = await GetCompletionsInFileAsync(

src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
using System.Threading;
6-
using System.Threading.Tasks;
74
using Microsoft.PowerShell.EditorServices.Services;
85
using Microsoft.PowerShell.EditorServices.Services.Symbols;
96
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
@@ -12,6 +9,9 @@
129
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1310
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
1411
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
12+
using System.Collections.Generic;
13+
using System.Threading;
14+
using System.Threading.Tasks;
1515

1616
namespace Microsoft.PowerShell.EditorServices.Handlers
1717
{
@@ -36,7 +36,7 @@ public PsesDefinitionHandler(
3636

3737
public override async Task<LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken cancellationToken)
3838
{
39-
ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);
39+
ScriptFile scriptFile = await _workspaceService.GetFile(request.TextDocument.Uri).ConfigureAwait(false);
4040

4141
SymbolReference foundSymbol =
4242
SymbolsService.FindSymbolAtLocation(

src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#nullable enable
55

6-
using System.Threading;
7-
using System.Threading.Tasks;
86
using MediatR;
97
using Microsoft.Extensions.FileSystemGlobbing;
108
using Microsoft.PowerShell.EditorServices.Services;
@@ -13,7 +11,8 @@
1311
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1412
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
1513
using OmniSharp.Extensions.LanguageServer.Protocol.Workspace;
16-
14+
using System.Threading;
15+
using System.Threading.Tasks;
1716
// Using an alias since this is conflicting with System.IO.FileSystemWatcher and ends up really finicky.
1817
using OmniSharpFileSystemWatcher = OmniSharp.Extensions.LanguageServer.Protocol.Models.FileSystemWatcher;
1918

@@ -53,12 +52,12 @@ public DidChangeWatchedFilesRegistrationOptions GetRegistrationOptions(
5352
},
5453
};
5554

56-
public Task<Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
55+
public async Task<Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
5756
{
5857
LanguageServerSettings currentSettings = _configurationService.CurrentSettings;
5958
if (currentSettings.AnalyzeOpenDocumentsOnly)
6059
{
61-
return Task.FromResult(Unit.Value);
60+
return Unit.Value;
6261
}
6362

6463
// Honor `search.exclude` settings in the watcher.
@@ -71,7 +70,7 @@ public Task<Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken
7170
continue;
7271
}
7372

74-
if (!_workspaceService.TryGetFile(change.Uri, out ScriptFile scriptFile))
73+
if ((await _workspaceService.TryGetFile(change.Uri).ConfigureAwait(false)) is not ScriptFile scriptFile)
7574
{
7675
continue;
7776
}
@@ -100,7 +99,7 @@ public Task<Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken
10099
string fileContents;
101100
try
102101
{
103-
fileContents = WorkspaceService.ReadFileContents(change.Uri);
102+
fileContents = await _workspaceService.ReadFileContents(change.Uri).ConfigureAwait(false);
104103
}
105104
catch
106105
{
@@ -112,6 +111,6 @@ public Task<Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken
112111
}
113112
}
114113

115-
return Task.FromResult(Unit.Value);
114+
return Unit.Value;
116115
}
117116
}

src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
using System.Threading;
6-
using System.Threading.Tasks;
74
using Microsoft.Extensions.Logging;
85
using Microsoft.PowerShell.EditorServices.Services;
96
using Microsoft.PowerShell.EditorServices.Services.Symbols;
@@ -12,6 +9,9 @@
129
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1310
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
1411
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
12+
using System.Collections.Generic;
13+
using System.Threading;
14+
using System.Threading.Tasks;
1515

1616
namespace Microsoft.PowerShell.EditorServices.Handlers
1717
{
@@ -34,11 +34,11 @@ public PsesDocumentHighlightHandler(
3434
DocumentSelector = LspUtils.PowerShellDocumentSelector
3535
};
3636

37-
public override Task<DocumentHighlightContainer> Handle(
37+
public override async Task<DocumentHighlightContainer> Handle(
3838
DocumentHighlightParams request,
3939
CancellationToken cancellationToken)
4040
{
41-
ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);
41+
ScriptFile scriptFile = await _workspaceService.GetFile(request.TextDocument.Uri).ConfigureAwait(false);
4242

4343
IEnumerable<SymbolReference> occurrences = SymbolsService.FindOccurrencesInFile(
4444
scriptFile,
@@ -58,8 +58,8 @@ public override Task<DocumentHighlightContainer> Handle(
5858
_logger.LogDebug("Highlights: " + highlights);
5959

6060
return cancellationToken.IsCancellationRequested || highlights.Count == 0
61-
? Task.FromResult(s_emptyHighlightContainer)
62-
: Task.FromResult(new DocumentHighlightContainer(highlights));
61+
? s_emptyHighlightContainer
62+
: new DocumentHighlightContainer(highlights);
6363
}
6464
}
6565
}

src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System.Collections.Generic;
5-
using System.Diagnostics;
6-
using System.Threading;
7-
using System.Threading.Tasks;
84
using Microsoft.Extensions.Logging;
95
using Microsoft.PowerShell.EditorServices.Services;
106
using Microsoft.PowerShell.EditorServices.Services.Symbols;
@@ -13,6 +9,10 @@
139
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1410
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
1511
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
12+
using System.Collections.Generic;
13+
using System.Diagnostics;
14+
using System.Threading;
15+
using System.Threading.Tasks;
1616

1717
namespace Microsoft.PowerShell.EditorServices.Handlers
1818
{
@@ -148,7 +148,7 @@ public override async Task<SymbolInformationOrDocumentSymbolContainer> Handle(Do
148148
{
149149
_logger.LogDebug($"Handling document symbols for {request.TextDocument.Uri}");
150150

151-
ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);
151+
ScriptFile scriptFile = await _workspaceService.GetFile(request.TextDocument.Uri).ConfigureAwait(false);
152152

153153
List<HierarchicalSymbol> hierarchicalSymbols = new();
154154

src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,28 @@ public PsesFoldingRangeHandler(ILoggerFactory factory, ConfigurationService conf
3333
DocumentSelector = LspUtils.PowerShellDocumentSelector
3434
};
3535

36-
public override Task<Container<FoldingRange>> Handle(FoldingRangeRequestParam request, CancellationToken cancellationToken)
36+
public override async Task<Container<FoldingRange>> Handle(FoldingRangeRequestParam request, CancellationToken cancellationToken)
3737
{
3838
if (cancellationToken.IsCancellationRequested)
3939
{
4040
_logger.LogDebug("FoldingRange request canceled for file: {Uri}", request.TextDocument.Uri);
41-
return Task.FromResult(s_emptyFoldingRangeContainer);
41+
return s_emptyFoldingRangeContainer;
4242
}
4343

4444
// TODO: Should be using dynamic registrations
4545
if (!_configurationService.CurrentSettings.CodeFolding.Enable)
4646
{
47-
return Task.FromResult(s_emptyFoldingRangeContainer);
47+
return s_emptyFoldingRangeContainer;
4848
}
4949

5050
// Avoid crash when using untitled: scheme or any other scheme where the document doesn't
5151
// have a backing file. https://github.com/PowerShell/vscode-powershell/issues/1676
5252
// Perhaps a better option would be to parse the contents of the document as a string
5353
// as opposed to reading a file but the scenario of "no backing file" probably doesn't
5454
// warrant the extra effort.
55-
if (!_workspaceService.TryGetFile(request.TextDocument.Uri, out ScriptFile scriptFile))
55+
if ((await _workspaceService.TryGetFile(request.TextDocument.Uri).ConfigureAwait(false)) is not ScriptFile scriptFile)
5656
{
57-
return Task.FromResult(s_emptyFoldingRangeContainer);
57+
return s_emptyFoldingRangeContainer;
5858
}
5959

6060
// If we're showing the last line, decrement the Endline of all regions by one.
@@ -78,8 +78,8 @@ public override Task<Container<FoldingRange>> Handle(FoldingRangeRequestParam re
7878
}
7979

8080
return folds.Count == 0
81-
? Task.FromResult(s_emptyFoldingRangeContainer)
82-
: Task.FromResult(new Container<FoldingRange>(folds));
81+
? s_emptyFoldingRangeContainer
82+
: new Container<FoldingRange>(folds);
8383
}
8484
}
8585
}

src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public override async Task<TextEditContainer> Handle(DocumentFormattingParams re
4646
return s_emptyTextEditContainer;
4747
}
4848

49-
Services.TextDocument.ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);
49+
Services.TextDocument.ScriptFile scriptFile = await _workspaceService.GetFile(request.TextDocument.Uri).ConfigureAwait(false);
5050
System.Collections.Hashtable pssaSettings = _configurationService.CurrentSettings.CodeFormatting.GetPSSASettingsHashtable(
5151
request.Options.TabSize,
5252
request.Options.InsertSpaces,
@@ -131,7 +131,7 @@ public override async Task<TextEditContainer> Handle(DocumentRangeFormattingPara
131131
return s_emptyTextEditContainer;
132132
}
133133

134-
Services.TextDocument.ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);
134+
Services.TextDocument.ScriptFile scriptFile = await _workspaceService.GetFile(request.TextDocument.Uri).ConfigureAwait(false);
135135
System.Collections.Hashtable pssaSettings = _configurationService.CurrentSettings.CodeFormatting.GetPSSASettingsHashtable(
136136
request.Options.TabSize,
137137
request.Options.InsertSpaces,

src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override async Task<Hover> Handle(HoverParams request, CancellationToken
4444
return null;
4545
}
4646

47-
ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);
47+
ScriptFile scriptFile = await _workspaceService.GetFile(request.TextDocument.Uri).ConfigureAwait(false);
4848

4949
SymbolDetails symbolDetails =
5050
await _symbolsService.FindSymbolDetailsAtLocationAsync(

src/PowerShellEditorServices/Services/TextDocument/Handlers/PsesSemanticTokensHandler.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ internal class PsesSemanticTokensHandler : SemanticTokensHandlerBase
3232

3333
public PsesSemanticTokensHandler(WorkspaceService workspaceService) => _workspaceService = workspaceService;
3434

35-
protected override Task Tokenize(SemanticTokensBuilder builder, ITextDocumentIdentifierParams identifier,
35+
protected override async Task Tokenize(SemanticTokensBuilder builder, ITextDocumentIdentifierParams identifier,
3636
CancellationToken cancellationToken)
3737
{
38-
ScriptFile file = _workspaceService.GetFile(identifier.TextDocument.Uri);
38+
ScriptFile file = await _workspaceService.GetFile(identifier.TextDocument.Uri).ConfigureAwait(false);
3939
foreach (Token token in file.ScriptTokens)
4040
{
4141
PushToken(token, builder);
4242
}
43-
return Task.CompletedTask;
4443
}
4544

4645
private static void PushToken(Token token, SemanticTokensBuilder builder)

0 commit comments

Comments
 (0)