@@ -16,15 +16,19 @@ class Configuration
16
16
T ::Hash [ String , T . untyped ] ,
17
17
)
18
18
19
+ sig { params ( workspace_path : String ) . void }
20
+ attr_writer :workspace_path
21
+
19
22
sig { void }
20
23
def initialize
24
+ @workspace_path = T . let ( Dir . pwd , String )
21
25
@excluded_gems = T . let ( initial_excluded_gems , T ::Array [ String ] )
22
26
@included_gems = T . let ( [ ] , T ::Array [ String ] )
23
- @excluded_patterns = T . let ( [ File . join ( "**" , "*_test.rb" ) , File . join ( "**" , " tmp", "**" , "*" ) ] , T ::Array [ String ] )
27
+ @excluded_patterns = T . let ( [ File . join ( "**" , "*_test.rb" ) , File . join ( "tmp" , "**" , "*" ) ] , T ::Array [ String ] )
24
28
path = Bundler . settings [ "path" ]
25
- @excluded_patterns << File . join ( File . expand_path ( path , Dir . pwd ) , "**" , "*.rb" ) if path
29
+ @excluded_patterns << File . join ( path , "**" , "*.rb" ) if path
26
30
27
- @included_patterns = T . let ( [ File . join ( Dir . pwd , "**" , "*.rb" ) ] , T ::Array [ String ] )
31
+ @included_patterns = T . let ( [ File . join ( "**" , "*.rb" ) ] , T ::Array [ String ] )
28
32
@excluded_magic_comments = T . let (
29
33
[
30
34
"frozen_string_literal:" ,
@@ -55,12 +59,12 @@ def indexables
55
59
indexables = @included_patterns . flat_map do |pattern |
56
60
load_path_entry = T . let ( nil , T . nilable ( String ) )
57
61
58
- Dir . glob ( pattern , File ::FNM_PATHNAME | File ::FNM_EXTGLOB ) . map! do |path |
62
+ Dir . glob ( File . join ( @workspace_path , pattern ) , File ::FNM_PATHNAME | File ::FNM_EXTGLOB ) . map! do |path |
59
63
path = File . expand_path ( path )
60
64
# All entries for the same pattern match the same $LOAD_PATH entry. Since searching the $LOAD_PATH for every
61
65
# entry is expensive, we memoize it until we find a path that doesn't belong to that $LOAD_PATH. This happens
62
- # on repositories that define multiple gems, like Rails. All frameworks are defined inside the Dir.pwd, but
63
- # each one of them belongs to a different $LOAD_PATH entry
66
+ # on repositories that define multiple gems, like Rails. All frameworks are defined inside the current
67
+ # workspace directory, but each one of them belongs to a different $LOAD_PATH entry
64
68
if load_path_entry . nil? || !path . start_with? ( load_path_entry )
65
69
load_path_entry = $LOAD_PATH. find { |load_path | path . start_with? ( load_path ) }
66
70
end
@@ -69,9 +73,19 @@ def indexables
69
73
end
70
74
end
71
75
76
+ # If the patterns are relative, we make it relative to the workspace path. If they are absolute, then we shouldn't
77
+ # concatenate anything
78
+ excluded_patterns = @excluded_patterns . map do |pattern |
79
+ if File . absolute_path? ( pattern )
80
+ pattern
81
+ else
82
+ File . join ( @workspace_path , pattern )
83
+ end
84
+ end
85
+
72
86
# Remove user specified patterns
73
87
indexables . reject! do |indexable |
74
- @ excluded_patterns. any? do |pattern |
88
+ excluded_patterns . any? do |pattern |
75
89
File . fnmatch? ( pattern , indexable . full_path , File ::FNM_PATHNAME | File ::FNM_EXTGLOB )
76
90
end
77
91
end
@@ -122,7 +136,7 @@ def indexables
122
136
# When working on a gem, it will be included in the locked_gems list. Since these are the project's own files,
123
137
# we have already included and handled exclude patterns for it and should not re-include or it'll lead to
124
138
# duplicates or accidentally ignoring exclude patterns
125
- next if spec . full_gem_path == Dir . pwd
139
+ next if spec . full_gem_path == @workspace_path
126
140
127
141
indexables . concat (
128
142
spec . require_paths . flat_map do |require_path |
@@ -185,7 +199,7 @@ def initial_excluded_gems
185
199
# If the dependency is prerelease, `to_spec` may return `nil` due to a bug in older version of Bundler/RubyGems:
186
200
# https://github.com/Shopify/ruby-lsp/issues/1246
187
201
this_gem = Bundler . definition . dependencies . find do |d |
188
- d . to_spec &.full_gem_path == Dir . pwd
202
+ d . to_spec &.full_gem_path == @workspace_path
189
203
rescue Gem ::MissingSpecError
190
204
false
191
205
end
0 commit comments