Skip to content

Peek/Go to Definition not working on script scoped function #362

Closed

Description

@rkeithhill

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.

Activity

  1. added this to the 0.11.0 milestone on Feb 1, 2017
  2. daviwil commented on Feb 1, 2017

    @daviwil
    Contributor

    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.

  3. rkeithhill commented on Feb 1, 2017

    @rkeithhill
    ContributorAuthor

    Sounds good.

  4. modified the milestones: 0.10.0, on Mar 14, 2017
  5. modified the milestones: June 2017, on Oct 27, 2017
  6. TylerLeonhardt commented on Jan 12, 2018

    @TylerLeonhardt
    Member

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

  7. rkeithhill commented on Jan 12, 2018

    @rkeithhill
    ContributorAuthor

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

    image

  8. TylerLeonhardt commented on Jan 12, 2018

    @TylerLeonhardt
    Member

    Ah. I did this and that worked:

    function script:gitRemoteBranches { ... }
    
    script:gitRemoteBranches
    

    Cool - we'll keep it open

  9. removed this from the milestone on Aug 17, 2021
  10. fflaten commented on Feb 7, 2023

    @fflaten
    Contributor

    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.

  11. andyleejordan commented on Jun 15, 2026

    @andyleejordan
    Member

    Resolved by #1990 (v3.8.1) — script:-scoped function definitions/references now match correctly (same scope-qualifier root cause as #16). Closing as completed.


    Drafted by GitHub Copilot (Claude Opus 4.8) at Andy Jordan (@andyleejordan)'s request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions