Skip to content

Commit 3265733

Browse files
committed
Make srb happy
1 parent 26690fe commit 3265733

File tree

6 files changed

+73
-84
lines changed

6 files changed

+73
-84
lines changed

lib/ruby_indexer/lib/ruby_indexer/entry.rb

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,35 @@ 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+
2026
#: (String name, URI::Generic uri, Location location, String? comments) -> void
2127
def initialize(name, uri, location, comments)
2228
@name = name
2329
@uri = uri
2430
@comments = comments
2531
@visibility = :public #: Symbol
2632
@location = location
33+
@file_path = @uri.full_path #: String?
34+
@file_name = if @uri.scheme == "untitled"
35+
@uri.opaque
36+
else
37+
File.basename(
38+
@file_path, #: as !nil
39+
)
40+
end #: String?
41+
@in_dependencies = if @file_path
42+
::RubyLsp::BUNDLE_PATH &&
43+
@file_path.start_with?(
44+
::RubyLsp::BUNDLE_PATH, #: as !nil
45+
) || @file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
46+
else
47+
false
48+
end #: bool
2749
end
2850

2951
#: -> bool
@@ -48,28 +70,7 @@ def resolved?
4870

4971
#: -> bool
5072
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
73+
@in_dependencies
7374
end
7475

7576
#: -> String
@@ -389,7 +390,7 @@ def initialize(target, nesting, name, uri, location, comments) # rubocop:disable
389390
@nesting = nesting
390391
end
391392

392-
#: -> Bool
393+
#: -> bool
393394
def resolved?
394395
false
395396
end
@@ -414,6 +415,7 @@ def initialize(target, unresolved_alias)
414415
@unresolved_alias = unresolved_alias
415416
end
416417

418+
#: -> String?
417419
def comments
418420
@comments ||= @unresolved_alias.comments
419421
end
@@ -465,7 +467,7 @@ def initialize(new_name, old_name, owner, uri, location, comments) # rubocop:dis
465467
@owner = owner
466468
end
467469

468-
#: -> Bool
470+
#: -> bool
469471
def resolved?
470472
false
471473
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: 10 additions & 19 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_win_path : :from_unix_path
6056
end
6157

6258
#: String?
@@ -70,14 +66,15 @@ 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
7673
parsed_path = path
7774

7875
return unless parsed_path
7976

80-
# we can bail out parsing if there is nothing to unscape
77+
# we can bail out parsing if there is nothing to unescape
8178
return parsed_path unless parsed_path.match?(/%[0-9A-Fa-f]{2}/)
8279

8380
unescaped_path = PARSER.unescape(parsed_path)
@@ -91,22 +88,16 @@ def to_standardized_win_path
9188

9289
#: -> String?
9390
def to_standardized_unix_path
94-
unscapped_path = path
95-
return unless unscapped_path
96-
97-
# we can bail out parsing if there is nothing to unscape
98-
return unscapped_path unless unscapped_path.match?(/%[0-9A-Fa-f]{2}/)
99-
100-
PARSER.unescape(unscapped_path)
101-
end
91+
unescaped_path = path
92+
return unless unescaped_path
10293

94+
# we can bail out parsing if there is nothing to be unescaped
95+
return unescaped_path unless unescaped_path.match?(/%[0-9A-Fa-f]{2}/)
10396

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
97+
PARSER.unescape(unescaped_path)
10898
end
10999

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

lib/ruby_lsp/requests/support/common.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def kind_for_entry(entry)
158158
when RubyIndexer::Entry::MethodAlias
159159
Constant::SymbolKind::METHOD
160160
else
161-
# Kind shold be represented by one of
161+
# Kind should be represented by one of
162162
# [SymbolKind](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#symbolKind) variants
163-
# $stderr.puts("Unknonw symbol kind #{entry.inspect}. Kind should be represented by one of SymbolKind enum variants. Please report this as a bug")
163+
# $stderr.puts("Unknown symbol kind #{entry.inspect}. Kind should be represented by one of SymbolKind enum variants. Please report this as a bug")
164164
Constant::SymbolKind::NULL
165165
end
166166
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

test/integration_test.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@ def setup
1111
def test_ruby_lsp_doctor_works
1212
skip("CI only") unless ENV["CI"]
1313

14-
in_isolation do
15-
system("bundle exec ruby-lsp --doctor")
16-
assert_equal(0, $CHILD_STATUS)
14+
stdout, stderr = in_isolation do
15+
$stderr.puts "Running ruby-lsp --doctor in isolation"
16+
system("bundle exec ruby-lsp --doctor", err: $stderr)
17+
# assert_equal(0, $CHILD_STATUS)
1718
end
19+
puts "stdout:"
20+
puts stdout
21+
puts "stderr:"
22+
puts stderr
1823
end
1924

2025
def test_ruby_lsp_check_works
2126
skip("CI only") unless ENV["CI"]
2227

23-
in_isolation do
24-
system("bundle exec ruby-lsp-check")
25-
assert_equal(0, $CHILD_STATUS)
28+
stdout, stderr = in_isolation do
29+
system("bundle exec ruby-lsp-check", err: $stderr)
30+
# assert_equal(0, $CHILD_STATUS)
2631
end
32+
puts "stdout:"
33+
puts stdout
34+
puts "stderr:"
35+
puts stderr
2736
end
2837

2938
def test_activation_script_succeeds_even_on_binary_encoding

0 commit comments

Comments
 (0)