Skip to content

Commit 47413c6

Browse files
committed
Make srb happy
1 parent 26690fe commit 47413c6

File tree

4 files changed

+47
-63
lines changed

4 files changed

+47
-63
lines changed

lib/ruby_indexer/lib/ruby_indexer/entry.rb

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ def initialize(name, uri, location, comments)
2424
@comments = comments
2525
@visibility = :public #: Symbol
2626
@location = location
27+
@file_path = @uri.full_path #: String?
28+
@file_name = if @uri.scheme == "untitled"
29+
@uri.opaque
30+
else
31+
File.basename(
32+
@file_path, #: as !nil
33+
)
34+
end #: String?
35+
@in_dependencies = if @file_path
36+
::RubyLsp::BUNDLE_PATH &&
37+
@file_path.start_with?(
38+
::RubyLsp::BUNDLE_PATH, #: as !nil
39+
) || @file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
40+
else
41+
false
42+
end #: bool
2743
end
2844

2945
#: -> bool
@@ -48,28 +64,17 @@ def resolved?
4864

4965
#: -> bool
5066
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-
)
67+
@in_dependencies
5768
end
5869

59-
#: -> String
70+
#: -> String?
6071
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
72+
@file_name
6873
end
6974

7075
#: -> String?
7176
def file_path
72-
@file_path ||= @uri.full_path
77+
@file_path
7378
end
7479

7580
#: -> String
@@ -389,7 +394,7 @@ def initialize(target, nesting, name, uri, location, comments) # rubocop:disable
389394
@nesting = nesting
390395
end
391396

392-
#: -> Bool
397+
#: -> bool
393398
def resolved?
394399
false
395400
end
@@ -414,6 +419,7 @@ def initialize(target, unresolved_alias)
414419
@unresolved_alias = unresolved_alias
415420
end
416421

422+
#: -> String?
417423
def comments
418424
@comments ||= @unresolved_alias.comments
419425
end
@@ -465,7 +471,7 @@ def initialize(new_name, old_name, owner, uri, location, comments) # rubocop:dis
465471
@owner = owner
466472
end
467473

468-
#: -> Bool
474+
#: -> bool
469475
def resolved?
470476
false
471477
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)