Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always expand indexables' full paths #1977

Merged
merged 1 commit into from
Apr 26, 2024
Merged

Always expand indexables' full paths #1977

merged 1 commit into from
Apr 26, 2024

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Apr 25, 2024

Motivation

Depends on the included_pattern's value, Dir.glob may return relative paths as its default base is the current working directory. For example, if the included_pattern is **/*.rb, the Dir.glob will return relative paths like lib/foo.rb instead of the full path like /path/to/project/lib/foo.rb.

Fixes #1971

Implementation

This commit ensures that the full paths are always expanded by using File.expand_path on the paths returned by Dir.glob.

Automated Tests

Manual Tests

@st0012 st0012 added the bugfix This PR will fix an existing bug label Apr 25, 2024
@st0012 st0012 self-assigned this Apr 25, 2024
@st0012 st0012 requested a review from a team as a code owner April 25, 2024 20:33
@st0012 st0012 requested review from andyw8 and vinistock April 25, 2024 20:33
@st0012 st0012 added the server This pull request should be included in the server gem's release notes label Apr 25, 2024
@@ -56,6 +56,7 @@ def indexables
load_path_entry = T.let(nil, T.nilable(String))

Dir.glob(pattern, File::FNM_PATHNAME | File::FNM_EXTGLOB).map! do |path|
path = File.expand_path(path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand path doesn't do anything if the path is already absolute, right? Trying to confirm that we'll continue supporting glob patterns based on absolute paths (e.g.: /Users/username/somewhere/**/*.rb)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't do anything in that case:

irb(main):005> File.expand_path("lib")
=> "/Users/hung-wulo/src/github.com/ruby/irb/lib"
irb(main):006> File.join(Dir.pwd, "lib")
=> "/Users/hung-wulo/src/github.com/ruby/irb/lib"
irb(main):007> File.expand_path(File.join(Dir.pwd, "lib"))
=> "/Users/hung-wulo/src/github.com/ruby/irb/lib"

Depends on the `included_pattern`'s value, `Dir.glob` may return relative
paths as its default base is the current working directory. For example,
if the `included_pattern` is `**/*.rb`, the `Dir.glob` will return
relative paths like `lib/foo.rb` instead of the full path like
`/path/to/project/lib/foo.rb`.

This commit ensures that the full paths are always expanded by using
`File.expand_path` on the paths returned by `Dir.glob`.

Fixes #1971
@st0012 st0012 merged commit 1c7199a into main Apr 26, 2024
42 checks passed
@st0012 st0012 deleted the fix-#1971 branch April 26, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error on goto defnition
3 participants