Skip to content

Commit fcf2ee7

Browse files
committed
Fix GetMostRecentCodeActionsForFileAsync to take DocumentUri again
This was actually the documented parameter, but at some point it changed to take a file. It was better to use the `_workspaceService` service directly and safely attempt to get the file than to require the user to do that beforehand.
1 parent b8e8397 commit fcf2ee7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,15 @@ public async Task<string> GetCommentHelpText(string functionText, string helpLoc
223223
/// </summary>
224224
/// <param name="documentUri">The URI string of the file to get code actions for.</param>
225225
/// <returns>A threadsafe readonly dictionary of the code actions of the particular file.</returns>
226-
public async Task<IReadOnlyDictionary<string, MarkerCorrection>> GetMostRecentCodeActionsForFileAsync(ScriptFile scriptFile)
226+
public async Task<IReadOnlyDictionary<string, MarkerCorrection>> GetMostRecentCodeActionsForFileAsync(DocumentUri uri)
227227
{
228-
if (!_mostRecentCorrectionsByFile.TryGetValue(scriptFile, out CorrectionTableEntry corrections))
228+
ScriptFile file = null;
229+
if (!_workspaceService.TryGetFile(uri, out file))
230+
{
231+
return null;
232+
}
233+
234+
if (!_mostRecentCorrectionsByFile.TryGetValue(file, out CorrectionTableEntry corrections))
229235
{
230236
return null;
231237
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
5252
{
5353
if (cancellationToken.IsCancellationRequested)
5454
{
55-
_logger.LogDebug("CodeAction request canceled at range: {0}", request.Range);
55+
_logger.LogDebug($"CodeAction request canceled at range: {request.Range}");
5656
return Array.Empty<CommandOrCodeAction>();
5757
}
5858

59-
// On Windows, VSCode still gives us file URIs like "file:///c%3a/...", so we need to escape them
60-
IReadOnlyDictionary<string, MarkerCorrection> corrections = await _analysisService.GetMostRecentCodeActionsForFileAsync(
61-
_workspaceService.GetFile(request.TextDocument.Uri)).ConfigureAwait(false);
59+
IReadOnlyDictionary<string, MarkerCorrection> corrections = await
60+
_analysisService.GetMostRecentCodeActionsForFileAsync(request.TextDocument.Uri).ConfigureAwait(false);
6261

6362
if (corrections == null)
6463
{

0 commit comments

Comments
 (0)