PowerShellEditorServices icon indicating copy to clipboard operation
PowerShellEditorServices copied to clipboard

Peek/Go to Definition not working on script scoped function

Open rkeithhill opened this issue 8 years ago • 6 comments

VS Code 1.8.1 / PSES v0.9.0.526

I have a function in a script defined like so:

function script:gitRemoteBranches { ... }

Later in the same script it is called but where it is called, if I try to peek or go to definition, PSES does not take me to the above definition. It does nothing.

I see these relevant messages in the log:

    READ MESSAGE:
    
    {
      "jsonrpc": "2.0",
      "id": 5,
      "method": "textDocument/definition",
      "params": {
        "uri": "file:///c%3A/Users/Keith/GitHub/dahlbyk/posh-git/src/GitTabExpansion.ps1",
        "position": {
          "line": 261,
          "character": 29
        }
      }
    }
...
1/31/2017 8:32:47 PM [ERROR] - Method "ExecuteCommand" at line 454 of C:\projects\powershelleditorservices\src\PowerShellEditorServices\Session\PowerShellContext.cs

    Execution completed with errors:
    
    The term 'gitRemoteBranches' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    The term 'gitRemoteBranches' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    The term 'gitRemoteBranches' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

BTW if I change the callsite to script:gitRemoteBranches then PSES can find the function. It doesn't seem like that should be necessary.

rkeithhill avatar Feb 01 '17 03:02 rkeithhill

Scoped variables never really worked before, that's an area we need to improve upon pretty soon. Planning to do that as part of the module-wide analysis effort. I'll mark it for 0.10.0 in case we get a chance to do it then, otherwise it'll probably come with 0.11.0.

daviwil avatar Feb 01 '17 03:02 daviwil

Sounds good.

rkeithhill avatar Feb 01 '17 03:02 rkeithhill

Looks like this is no longer reproing 😄 I'm closing it - you know what to do.

TylerLeonhardt avatar Jan 12 '18 03:01 TylerLeonhardt

Yes, it still repros. You have to a location modifier on the variable e.g.:

image

rkeithhill avatar Jan 12 '18 03:01 rkeithhill

Ah. I did this and that worked:

function script:gitRemoteBranches { ... }

script:gitRemoteBranches

Cool - we'll keep it open

TylerLeonhardt avatar Jan 12 '18 03:01 TylerLeonhardt

Should this be kept open until proper scoping support is possible? Or would it be an option to trim scope from definition and/or call to match them? Would show multiple definitions and count references wrong if name is reused though.

fflaten avatar Feb 07 '23 18:02 fflaten