PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code

Home Page:https://marketplace.visualstudio.com/items/ms-vscode.PowerShell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Completions don't work in a completely empty script file

MartinGC94 opened this issue · comments

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

In this PR: PowerShell/PowerShell#21171 I've added the ability to complete keywords without having to write a partial name, this works great except when the file is completely empty in VS code. The console host and even ISE handles completely empty input without any problems.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.5.0-preview.1
PSEdition                      Core
GitCommitId                    7.5.0-preview.1-9-g0ecf5c46ddc68356ae8ef8be2bb0655b8a43023c
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name             : Visual Studio Code Host
Version          : 2024.0.0
InstanceId       : 17ccb628-ca60-4f48-8f98-1d70a9d57022
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : da-DK
CurrentUICulture : da-DK
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

1.86.0-insider
5d344004f839677def958534b58e854a9ae26fd0
x64

Extension Version

ms-vscode.powershell@2024.0.0

Steps to Reproduce

  1. Download a build from the branch
  2. Launch the pwsh executable and check the PID $pid
  3. From VS code, type in Enter-PSHostProcess <PID from before>
  4. Press Ctrl+Space in an empty file

Visuals

No response

Logs

No response

@MartinGC94 is the new empty file set to PowerShell language?

@andyleejordan Yes. I get completions as soon as I press space, but if I backspace and press Ctrl+Space the results are empty.

Interesting. Have you tried other languages, like can you get C# completions in an empty file? I'm wondering if it's a VS Code thing in general or something we're doing.

I just tried opening an empty .cs file and I got keyword completions so it must be related to the extension/editor services.

@MartinGC94 in the latest extension prerelease version there's a language server trace setting in the powershell options, can you enable that, reproduce the behavior, and send the logs from the PowerShell Editor Services Client output pane? That can go a decent way to help troubleshoot what's going on.

EDIT: Sorry I forgot that change hasn't landed yet, you can install this latest commit VSIX:
https://github.com/PowerShell/vscode-powershell/actions/runs/7763944519/artifacts/1216865107

Also this step in your repro process:

From VS code, type in Enter-PSHostProcess <PID from before>

I'm not 100% the LSP is gonna use that pwsh instance with the language client once you do that? @andyleejordan?

Good to know, we'll take a look at it.

I'm not 100% the LSP is gonna use that pwsh instance with the language client once you do that? @andyleejordan?

No, not it is not. Good catch 😄

@JustinGrote Logs:

[Trace - 7:42:59 PM] Sending request 'textDocument/completion - (62)'. Params: { "textDocument": { "uri": "untitled:Untitled-1" }, "position": { "line": 0, "character": 0 }, "context": { "triggerKind": 1 } }

[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Finding descriptors for textDocument/completion | Method='textDocument/completion'"
}

OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Finding descriptors for textDocument/completion | Method='textDocument/completion'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Found attributes 1, powershell::untitled:Untitled-1 | Count='1' Attributes='System.Linq.Enumerable+SelectListIterator`2[OmniSharp.Extensions.LanguageServer.Protocol.Document.TextDocumentAttributes,System.String]'"
}

OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Found attributes 1, powershell::untitled:Untitled-1 | Count='1' Attributes='System.Linq.Enumerable+SelectListIterator`2[OmniSharp.Extensions.LanguageServer.Protocol.Document.TextDocumentAttributes,System.String]'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Looking for handler for descriptors textDocument/completion | Method='textDocument/completion'"
}

OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Looking for handler for descriptors textDocument/completion | Method='textDocument/completion'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Checking handler textDocument/completion:Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler | Method='textDocument/completion' Handler='Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler'"
}

OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Checking handler textDocument/completion:Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler | Method='textDocument/completion' Handler='Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Registration options OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionRegistrationOptions | OptionsName='OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionRegistrationOptions'"
}

OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Registration options OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionRegistrationOptions | OptionsName='OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionRegistrationOptions'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Document Selector [powershell], [pwsh], [ps1], [psm1], [psd1], [/.ps1] | TextDocumentSelector='[powershell], [pwsh], [ps1], [psm1], [psd1], [/.ps1]'"
}

OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Document Selector [powershell], [pwsh], [ps1], [psm1], [psd1], [/.ps1] | TextDocumentSelector='[powershell], [pwsh], [ps1], [psm1], [psd1], [/.ps1]'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Handler Selected: Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler a6035ec2-abc9-44d3-8fcb-08735ce619ba via [powershell], [pwsh], [ps1], [psm1], [psd1], [**/.ps1] (targeting OmniSharp.Extensions.JsonRpc.IJsonRpcRequestHandler2[[OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams, OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022],[OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionList, OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022]]) | Handler='Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler' Id='a6035ec2-abc9-44d3-8fcb-08735ce619ba' TextDocumentSelector='[powershell], [pwsh], [ps1], [psm1], [psd1], [**/*.ps*1]' HandlerInterface='OmniSharp.Extensions.JsonRpc.IJsonRpcRequestHandler2[[OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams, OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022],[OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionList, OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022]]'"
}

OmniSharp.Extensions.LanguageServer.Server.Matchers.TextDocumentMatcher: Handler Selected: Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler a6035ec2-abc9-44d3-8fcb-08735ce619ba via [powershell], [pwsh], [ps1], [psm1], [psd1], [**/.ps1] (targeting OmniSharp.Extensions.JsonRpc.IJsonRpcRequestHandler2[[OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams, OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022],[OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionList, OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022]]) | Handler='Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler' Id='a6035ec2-abc9-44d3-8fcb-08735ce619ba' TextDocumentSelector='[powershell], [pwsh], [ps1], [psm1], [psd1], [**/*.ps*1]' HandlerInterface='OmniSharp.Extensions.JsonRpc.IJsonRpcRequestHandler2[[OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams, OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022],[OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionList, OmniSharp.Extensions.LanguageProtocol, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022]]'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.JsonRpc.ProcessScheduler: Swapping from Parallel to Serial | From='Parallel' To='Serial'"
}

OmniSharp.Extensions.JsonRpc.ProcessScheduler: Swapping from Parallel to Serial | From='Parallel' To='Serial'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.JsonRpc.ProcessScheduler: Cancelling any outstanding requests (switch from parallel to serial) | "
}

OmniSharp.Extensions.JsonRpc.ProcessScheduler: Cancelling any outstanding requests (switch from parallel to serial) |
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.JsonRpc.ProcessScheduler: Completing existing request process type Parallel | Type='Parallel'"
}

OmniSharp.Extensions.JsonRpc.ProcessScheduler: Completing existing request process type Parallel | Type='Parallel'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.JsonRpc.ProcessScheduler: Queueing Serial:textDocument/completion:62 request for processing | Type='Serial' Name='textDocument/completion:62'"
}

OmniSharp.Extensions.JsonRpc.ProcessScheduler: Queueing Serial:textDocument/completion:62 request for processing | Type='Serial' Name='textDocument/completion:62'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Starting: Processing request textDocument/completion 62 | Method='textDocument/completion' ResponseId='62'"
}

OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Starting: Processing request textDocument/completion 62 | Method='textDocument/completion' ResponseId='62'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Starting: Routing Request (62) textDocument/completion | Id='62' Method='textDocument/completion'"
}

OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Starting: Routing Request (62) textDocument/completion | Id='62' Method='textDocument/completion'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Converting params for Request (62) textDocument/completion to OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams | Id='62' Method='textDocument/completion' Type='OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams'"
}

OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Converting params for Request (62) textDocument/completion to OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams | Id='62' Method='textDocument/completion' Type='OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Converting params for Notification textDocument/completion to OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams | Method='textDocument/completion' Type='OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams'"
}

OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Converting params for Notification textDocument/completion to OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams | Method='textDocument/completion' Type='OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionParams'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Getting completions at offset 0 (line: 1, column: 1) | "
}

Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: Getting completions at offset 0 (line: 1, column: 1) |
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: IntelliSense completed in 0ms - WordToComplete: "(null)" MatchCount: 0 | elapsed='0' word='' count='0'"
}

Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler: IntelliSense completed in 0ms - WordToComplete: "(null)" MatchCount: 0 | elapsed='0' word='' count='0'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline: Updating Resolve items with wrapped data for textDocument/completion:Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler | Method='textDocument/completion' Handler='Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler'"
}

OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline: Updating Resolve items with wrapped data for textDocument/completion:Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler | Method='textDocument/completion' Handler='Microsoft.PowerShell.EditorServices.Handlers.PsesCompletionHandler'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Response value was OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionList | Type='OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionList'"
}

OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Response value was OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionList | Type='OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionList'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Finished: Routing Request (62) textDocument/completion in 71ms | Id='62' Method='textDocument/completion' ElapsedMilliseconds='71'"
}

OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Finished: Routing Request (62) textDocument/completion in 71ms | Id='62' Method='textDocument/completion' ElapsedMilliseconds='71'
[Trace - 7:42:59 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Finished: Processing request textDocument/completion 62 in 71ms | Method='textDocument/completion' ResponseId='62' ElapsedMilliseconds='71'"
}

OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Finished: Processing request textDocument/completion 62 in 71ms | Method='textDocument/completion' ResponseId='62' ElapsedMilliseconds='71'
[Trace - 7:42:59 PM] Received response 'textDocument/completion - (62)' in 75ms.
Result: {
"isIncomplete": true,
"items": []
}

To my untrained eyes there's nothing interesting in that log.

As for Enter-PSHostProcess that was just for convenience. On my machine I've added my custom build as one of the PowerShell version options. I've tried using Enter-PSHostProcess from the normal extension version of pwsh and I get my new completions as expected so it doesn't matter if you add a custom executable, or use Enter-PSHostProcess.