Skip to content

Commit 3aa271e

Browse files
committed
Make srb happy
1 parent 26690fe commit 3aa271e

File tree

4 files changed

+51
-70
lines changed

4 files changed

+51
-70
lines changed

lib/ruby_indexer/lib/ruby_indexer/entry.rb

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,36 @@ class Entry
1717
#: Symbol
1818
attr_accessor :visibility
1919

20+
#: -> String?
21+
attr_accessor :file_name
22+
23+
#: -> String?
24+
attr_accessor :file_path
25+
26+
2027
#: (String name, URI::Generic uri, Location location, String? comments) -> void
2128
def initialize(name, uri, location, comments)
2229
@name = name
2330
@uri = uri
2431
@comments = comments
2532
@visibility = :public #: Symbol
2633
@location = location
34+
@file_path = @uri.full_path #: String?
35+
@file_name = if @uri.scheme == "untitled"
36+
@uri.opaque
37+
else
38+
File.basename(
39+
@file_path, #: as !nil
40+
)
41+
end #: String?
42+
@in_dependencies = if @file_path
43+
::RubyLsp::BUNDLE_PATH &&
44+
@file_path.start_with?(
45+
::RubyLsp::BUNDLE_PATH, #: as !nil
46+
) || @file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
47+
else
48+
false
49+
end #: bool
2750
end
2851

2952
#: -> bool
@@ -48,28 +71,7 @@ def resolved?
4871

4972
#: -> bool
5073
def in_dependencies?
51-
@in_dependencies ||= file_path && (
52-
::RubyLsp::BUNDLE_PATH && file_path.start_with?(
53-
::RubyLsp::BUNDLE_PATH, #: as !nil
54-
) ||
55-
file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
56-
)
57-
end
58-
59-
#: -> String
60-
def file_name
61-
@file_name ||= if @uri.scheme == "untitled"
62-
@uri.opaque #: as !nil
63-
else
64-
File.basename(
65-
file_path, #: as !nil
66-
)
67-
end
68-
end
69-
70-
#: -> String?
71-
def file_path
72-
@file_path ||= @uri.full_path
74+
@in_dependencies
7375
end
7476

7577
#: -> String
@@ -389,7 +391,7 @@ def initialize(target, nesting, name, uri, location, comments) # rubocop:disable
389391
@nesting = nesting
390392
end
391393

392-
#: -> Bool
394+
#: -> bool
393395
def resolved?
394396
false
395397
end
@@ -414,6 +416,7 @@ def initialize(target, unresolved_alias)
414416
@unresolved_alias = unresolved_alias
415417
end
416418

419+
#: -> String?
417420
def comments
418421
@comments ||= @unresolved_alias.comments
419422
end
@@ -465,7 +468,7 @@ def initialize(new_name, old_name, owner, uri, location, comments) # rubocop:dis
465468
@owner = owner
466469
end
467470

468-
#: -> Bool
471+
#: -> bool
469472
def resolved?
470473
false
471474
end

lib/ruby_indexer/lib/ruby_indexer/index.rb

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ def fuzzy_search(query)
215215
[entries, -similarity] if similarity > ENTRY_SIMILARITY_THRESHOLD
216216
end
217217
results.sort_by!(&:last)
218-
results.flat_map do |entries, _similarity|
219-
skip_unresolved_entries(entries)
220-
end
218+
results.flat_map(&:first)
221219
end
222220

223221
#: (String? name, String receiver_name) -> Array[(Entry::Member | Entry::MethodAlias)]
@@ -731,7 +729,7 @@ def entries_for(uri, type = nil)
731729
entries&.grep(type)
732730
end
733731

734-
#: -> voide
732+
#: -> void
735733
def process_unresolved_entries
736734
@entries.values.each do |entries|
737735
entries.each do |entry|
@@ -1071,34 +1069,5 @@ def resolve_method_alias(entry, receiver_name, seen_names)
10711069
original_entries << resolved_alias
10721070
resolved_alias
10731071
end
1074-
1075-
# Attempts to resolve an entry if it is an unresolved constant or method alias.
1076-
# Returns the resolved entry, or nil if it cannot be resolved.
1077-
#: (Entry) -> Entry?
1078-
def resolve_entry(entry)
1079-
case entry
1080-
when Entry::UnresolvedConstantAlias
1081-
resolved_entry = resolve_alias(entry, [])
1082-
resolved_entry unless resolved_entry.is_a?(Entry::UnresolvedConstantAlias)
1083-
when Entry::UnresolvedMethodAlias
1084-
resolved_entry = resolve_method_alias(entry, entry.owner&.name || "", [])
1085-
resolved_entry unless resolved_entry.is_a?(Entry::UnresolvedMethodAlias)
1086-
else
1087-
entry
1088-
end
1089-
end
1090-
1091-
# Filters and resolves entries, skipping those that remain unresolved.
1092-
# Returns an array of successfully resolved entries.
1093-
#: (Array[Entry]) -> Array[Entry?]
1094-
def skip_unresolved_entries(entries)
1095-
entries.filter_map do |entry|
1096-
resolved_entry = resolve_entry(entry)
1097-
1098-
next unless resolved_entry
1099-
1100-
resolved_entry
1101-
end
1102-
end
11031072
end
11041073
end

lib/ruby_indexer/lib/ruby_indexer/uri.rb

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ def from_unix_path(path:, fragment: nil, scheme: "file", load_path_entry: nil)
5252
uri
5353
end
5454

55-
if Gem.win_platform?
56-
alias_method :from_path, :from_win_path
57-
else
58-
alias_method :from_path, :from_unix_path
59-
end
55+
alias_method :from_path, Gem.win_platform? ? :from_windows_path : :from_unix_path
6056
end
6157

6258
#: String?
@@ -70,6 +66,7 @@ def add_require_path_from_load_entry(load_path_entry)
7066
self.require_path = path.delete_prefix("#{load_path_entry}/").delete_suffix(".rb")
7167
end
7268

69+
#: -> String?
7370
# On Windows, when we're getting the file system path back from the URI, we need to remove the leading forward
7471
# slash
7572
def to_standardized_win_path
@@ -100,13 +97,7 @@ def to_standardized_unix_path
10097
PARSER.unescape(unscapped_path)
10198
end
10299

103-
104-
if Gem.win_platform?
105-
alias_method :to_standardized_path, :to_standardized_win_path
106-
else
107-
alias_method :to_standardized_path, :to_standardized_unix_path
108-
end
109-
110-
alias_method :full_path, :to_standardized_path
100+
alias_method :to_standardized_path, Gem.win_platform? ? :to_standardized_win_path : :to_standardized_unix_path
101+
alias_method :full_path, Gem.win_platform? ? :to_standardized_win_path : :to_standardized_unix_path
111102
end
112103
end

sorbet/rbi/shims/uri.rbi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ module URI
55

66
class Generic
77
PARSER = T.let(const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER, RFC2396_Parser)
8+
9+
class << self
10+
sig do
11+
params(
12+
path: String,
13+
fragment: T.nilable(String),
14+
scheme: String,
15+
load_path_entry: T.nilable(String)
16+
).returns(URI::Generic)
17+
end
18+
def from_path(path:, fragment: nil, scheme: "file", load_path_entry: nil); end
19+
end
20+
21+
sig { returns(T.nilable(String)) }
22+
def to_standardized_path; end
23+
24+
sig { returns(T.nilable(String)) }
25+
def full_path; end
826
end
927

1028
class File

0 commit comments

Comments
 (0)