Skip to content

GoToDefinition forces functions to be defined before, even if incorrect #1125

Open
@leonschreuder

Description

@leonschreuder

Code editor

neovim

Platform

Linux

Version

5.1.2

What steps will reproduce the bug?

To preserve a top-down structuring in my scripts, I tend to create a main function at the top of the file, any other functions below it, and call the main function in the last line. Shellcheck has no problem with this, but the bash-language-server enforces functions to be defined before they are called, even if the load order is correct.
The following code might describe the problem a little better:

#!/bin/bash

function1() { :; }

main() {
  function1 # GoToDefinition etc works
  function2 # GoToDefinition not available
}

function2() { :; }

main "$@"

How often does it reproduce? Is there a required condition?

always

What is the expected behavior?

For the bash-language-server to support language features despite custom function ordering similar to shellcheck.

What do you see instead?

Language features don't work for function2 despite valid availability in the scope.

Additional information

If this is hard to fix/change, I could also imagine a ALWAYS_IN_SCOPE type config option, that simply puts the whole file in scope. Shellcheck seems to catch any scoping errors as a fallback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions