bash-lsp / bash-language-server

A language server for Bash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoToDefinition forces functions to be defined before, even if incorrect

leonschreuder opened this issue · comments

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.