Closed ChieftainY2k closed 7 months ago
@ChieftainY2k Thanks for reporting!
"Find usages" is a basic feature and should be available and fully functional. See the attached image for reference.
I can think of two possible causes:
build
is not parsed as a command. Could you enable Settings > Languages & Frameworks > BashSupport Pro > Highlight errors in shell scripts
and reopen the file, please? If there's a red squiggle in the file and the file is fully accepted by Bash itself, then it's a parsing error. I'll fix it if you provide the context where the squiggle is.isn't linked to BashSupport Pro? Please verify that
*.shis listed at
Settings > Editor > File Types > BashSupport Pro Script > File name patterns:`. If it's not in the list, please add it and restart the IDE.Thanks for such a quick reply.
It seems are settings are correct, and yet the problem is still there 🤔
This code results in the "Cannot search for usages from this location" message:
#!/usr/bin/env bash
xxxxbuild () {
echo "build"
}
case $command in
build) build "${@}" ;;
esac
whereas this seems to be ok:
#!/usr/bin/env bash
build () {
echo "build"
}
case $command in
build) build "${@}" ;;
esac
The settings are:
@ChieftainY2k Okay, I can see what's happening.
If "Find usages" is invoked from a function (e.g. on the name of foo() { :; }
), then it searches for invocations of the function.
If "Find usages" is invoked from an invocation, (e.g. foo $*
), then the IDE first locates the definition of foo
(same as "Go to definition") and then searches for usages of this definition (as in the 1st alternative).
In your example, you're starting from an invocation. But because there's no definition of build
, the message is shown:
#!/usr/bin/env bash
xxxxbuild () {
echo "build"
}
case $command in
build) build "${@}" ;;
esac
If you search for usages of xxxxbuild
, then you'll see something like this:
So far, it's working as it's supposed to. All languages of the IDE should be doing the same. But only few are ambiguous as Bash, which allows functions and commands for the same word build
.
In your original report, you mentioned that build
is defined in the same file. How is it defined? Is "go to definition" working on the "build" invocation?
It seems that even with the simplest bash file (nonexistent function) the issue is still there 🤔
#!/usr/bin/env bash
foobar
@ChieftainY2k Yes, but what would you expect instead of this message?
In Bash, if a command invocation doesn't match a function definition, then it's a command from $PATH
.
@jansorg The caret is already on the element so this message is.... strange ? :) I suggest... "no references or usages found" , that would be more informative and precise In my humble opinion.
The message is the default of the IDE, it's not part of BashSupport Pro.
I agree that it's not very helpful. What "Place the caret on the element to find usages for" really wants to say is "Place the caret on a definition to find usages for" :) Here's the same for a Java file:
I'll check if there's a way to let the IDE display a nicer message in shell scripts, but I don't think so.
Yeah , I've just check it with PHP files, same message there :) Well, will contact phpStorm devs about this then , thanks for your support on this , appreciate it :)
"Find Usages" does not work with .sh files, getting "Cannot search for usages from this location"
Steps to replicate:
System info: PhpStorm 2023.3.4 Build #PS-233.14475.35, built on February 13, 2024 Runtime version: 17.0.10+1-b1087.17 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Windows 11.0