Go to Declaration

Basic Usage

BashSupport Pro helps you to quickly navigate in shell scripts.

Place the text cursor on an element in a shell script and choose Navigate → Declaration or Usages… to navigate to the declaration (JetBrains help pages).

BashSupport Pro lets you navigate to the declarations of these elements:

Function Calls
It navigates to the declaration of the function.
Variable References
It navigates to the closest declaration of the variable. For example, it navigates to export myVar if you invoke it for $myVar.
Variable Declarations
It navigates to the closest, earlier declaration of a variable declaration.
For example, for myVar=1; myVar=2; export myVar, it will navigate to myVar=2 if you call it for the exported definition. When you invoke the action again on myVar=2, then it will navigate to myVar=1.
If you prefer to always navigate to the earliest declaration, then see below for a setting to configure this behaviour.
Predefined Variables
Variables defined by Bash or POSIX, e.g. $HOME or $RANDOM, are contained in stub files. Go to Declaration will open such a stub file if you navigate to the declaration of a predefined variable.

Supported Shell Commands

Local Scope

BashSupport Pro supports the local variable scope. local allows to restrict the visibility of variables to the current function. It’s only available for Bash scripts, i.e. it’s not available in POSIX scripts.

Go to… supports local scope. If you call it within a function, then it will only navigate to the local declarations. If you call it outside a function, then it will ignore variables declared as local.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
myVar=1

myFunction() {
    # will NOT navigate to the global declaration
    local myVar="local value" 
    
    # navigates to the local definition above
    printf "$myVar"
}

# navigates to myVar=1, skips the local declaration
echo $myVar 

Unset

BashSupport Pro supports the unset command. unset allows you to make a variable unavailable to all following commands. The plugin considers variables, which have been unset as a new variable.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
a=1
echo $a
# 'Go To Declaration' on a
# navigates to a=1
# Rename will rename this a and previous occurrences 
unset a

# $a is unresolved here, 
# because it was unset 
echo $a

# 'Go To Declaration' on a 
# will not navigate to previous declarations
# because it was unset.
# Rename will only rename this a and the line below
a=2
echo $a

Scratch Files

BashSupport Pro allows you to navigate in scratch files. The complete feature-set is available, but limited to the current file.

Code Injection

BashSupport Pro allows you to navigate in code with an injected language. The complete feature-set is available, but limited to the code block. Navigation between multiple blocks is only supported where smart language injection is performed, for example in Makefile files with the Makefile language plugin installed.

Settings

By default, Go To Declaration navigates to the closest (re)declaration of a variable. In our opinion, this is the most useful implementation to navigate within complex shell scripts.

If you don’t like this, then the setting Prefer the closest definition for Go To Declaration lets you change the behaviour. To do this, disable the checkbox in the settings at Settings → Languages & Frameworks → BashSupport Pro.

© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal