bashsupport-pro icon indicating copy to clipboard operation
bashsupport-pro copied to clipboard

"Find Usages" does not work with .sh files, getting "Cannot search for usages from this location"

Open ChieftainY2k opened this issue 1 year ago • 8 comments

"Find Usages" does not work with .sh files, getting "Cannot search for usages from this location"

Steps to replicate:

  • create .sh file
  • create a function
  • use this function in the bash file
  • try to find usages of the function

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

bash support pro Screenshot 2024-02-28 121353

ChieftainY2k avatar Feb 28 '24 11:02 ChieftainY2k

@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:

  • There's a parsing error in the script and 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.
  • Is it perhaps possible that the JetBrains Shell plugin is still enabled and linked to *.sh or that *.sh isn't linked to BashSupport Pro? Please verify that *.sh is 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.

image

jansorg avatar Feb 28 '24 11:02 jansorg

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

image

whereas this seems to be ok:

#!/usr/bin/env bash

build () {
  echo "build"
}

case $command in
  build) build "${@}" ;;
esac

The settings are: image

image

ChieftainY2k avatar Feb 28 '24 12:02 ChieftainY2k

@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: image

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?

jansorg avatar Feb 28 '24 13:02 jansorg

It seems that even with the simplest bash file (nonexistent function) the issue is still there 🤔

#!/usr/bin/env bash

foobar

image

ChieftainY2k avatar Feb 28 '24 13:02 ChieftainY2k

@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 avatar Feb 28 '24 13:02 jansorg

@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.

ChieftainY2k avatar Feb 28 '24 13:02 ChieftainY2k

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: image

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.

jansorg avatar Feb 28 '24 13:02 jansorg

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 :)

ChieftainY2k avatar Feb 28 '24 13:02 ChieftainY2k