BashSupport-Pro / bashsupport-pro

Public issue tracking for BashSupport Pro. This is a plugin, which provides advanced support for Bash scripts for JetBrains IDEs.
https://www.bashsupport.com
48 stars 2 forks source link

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

Closed ChieftainY2k closed 7 months ago

ChieftainY2k commented 9 months ago

"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

bash support pro Screenshot 2024-02-28 121353

jansorg commented 9 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:

image

ChieftainY2k commented 9 months ago

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

jansorg commented 9 months ago

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

ChieftainY2k commented 9 months ago

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

#!/usr/bin/env bash

foobar

image

jansorg commented 9 months ago

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

ChieftainY2k commented 9 months ago

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

jansorg commented 9 months ago

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.

ChieftainY2k commented 9 months ago

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