ruby-lsp 0.26.5 → 0.26.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/exe/ruby-lsp-launcher +5 -1
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +3 -2
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +7 -1
- data/lib/ruby_lsp/setup_bundler.rb +16 -12
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +43 -28
- data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +1 -1
- data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +1 -1
- metadata +1 -15
- data/lib/ruby_indexer/test/class_variables_test.rb +0 -140
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +0 -790
- data/lib/ruby_indexer/test/configuration_test.rb +0 -277
- data/lib/ruby_indexer/test/constant_test.rb +0 -402
- data/lib/ruby_indexer/test/enhancements_test.rb +0 -325
- data/lib/ruby_indexer/test/global_variable_test.rb +0 -49
- data/lib/ruby_indexer/test/index_test.rb +0 -2273
- data/lib/ruby_indexer/test/instance_variables_test.rb +0 -264
- data/lib/ruby_indexer/test/method_test.rb +0 -990
- data/lib/ruby_indexer/test/prefix_tree_test.rb +0 -150
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +0 -381
- data/lib/ruby_indexer/test/reference_finder_test.rb +0 -395
- data/lib/ruby_indexer/test/test_case.rb +0 -57
- data/lib/ruby_indexer/test/uri_test.rb +0 -85
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require "test_helper"
|
|
5
|
-
|
|
6
|
-
module RubyIndexer
|
|
7
|
-
class ConfigurationTest < Minitest::Test
|
|
8
|
-
def setup
|
|
9
|
-
@config = Configuration.new
|
|
10
|
-
@workspace_path = File.expand_path(File.join("..", "..", ".."), __dir__)
|
|
11
|
-
@config.workspace_path = @workspace_path
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_load_configuration_executes_configure_block
|
|
15
|
-
@config.apply_config({ "excluded_patterns" => ["**/fixtures/**/*"] })
|
|
16
|
-
uris = @config.indexable_uris
|
|
17
|
-
|
|
18
|
-
bundle_path = Bundler.bundle_path.join("gems")
|
|
19
|
-
|
|
20
|
-
assert(uris.none? { |uri| uri.full_path.include?("test/fixtures") })
|
|
21
|
-
assert(uris.none? { |uri| uri.full_path.include?(bundle_path.join("minitest-reporters").to_s) })
|
|
22
|
-
assert(uris.none? { |uri| uri.full_path.include?(bundle_path.join("ansi").to_s) })
|
|
23
|
-
assert(uris.any? { |uri| uri.full_path.include?(bundle_path.join("prism").to_s) })
|
|
24
|
-
assert(uris.none? { |uri| uri.full_path == __FILE__ })
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_indexable_uris_have_expanded_full_paths
|
|
28
|
-
@config.apply_config({ "included_patterns" => ["**/*.rb"] })
|
|
29
|
-
uris = @config.indexable_uris
|
|
30
|
-
|
|
31
|
-
# All paths should be expanded
|
|
32
|
-
assert(uris.all? { |uri| File.absolute_path?(uri.full_path) })
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_indexable_uris_only_includes_gem_require_paths
|
|
36
|
-
uris = @config.indexable_uris
|
|
37
|
-
|
|
38
|
-
Bundler.locked_gems.specs.each do |lazy_spec|
|
|
39
|
-
next if lazy_spec.name == "ruby-lsp"
|
|
40
|
-
|
|
41
|
-
spec = Gem::Specification.find_by_name(lazy_spec.name)
|
|
42
|
-
|
|
43
|
-
test_uris = uris.select do |uri|
|
|
44
|
-
File.fnmatch?(File.join(spec.full_gem_path, "test/**/*"), uri.full_path, File::Constants::FNM_PATHNAME)
|
|
45
|
-
end
|
|
46
|
-
assert_empty(test_uris)
|
|
47
|
-
rescue Gem::MissingSpecError
|
|
48
|
-
# Transitive dependencies might be missing when running tests on Windows
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def test_indexable_uris_does_not_include_default_gem_path_when_in_bundle
|
|
53
|
-
uris = @config.indexable_uris
|
|
54
|
-
assert(uris.none? { |uri| uri.full_path.start_with?("#{RbConfig::CONFIG["rubylibdir"]}/psych") })
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_indexable_uris_includes_default_gems
|
|
58
|
-
paths = @config.indexable_uris.map(&:full_path)
|
|
59
|
-
|
|
60
|
-
assert_includes(paths, "#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb")
|
|
61
|
-
assert_includes(paths, "#{RbConfig::CONFIG["rubylibdir"]}/ipaddr.rb")
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_indexable_uris_includes_project_files
|
|
65
|
-
paths = @config.indexable_uris.map(&:full_path)
|
|
66
|
-
|
|
67
|
-
Dir.glob("#{Dir.pwd}/lib/**/*.rb").each do |path|
|
|
68
|
-
next if path.end_with?("_test.rb")
|
|
69
|
-
|
|
70
|
-
assert_includes(paths, path)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def test_indexable_uris_avoids_duplicates_if_bundle_path_is_inside_project
|
|
75
|
-
Bundler.settings.temporary(path: "vendor/bundle") do
|
|
76
|
-
config = Configuration.new
|
|
77
|
-
|
|
78
|
-
assert_includes(config.instance_variable_get(:@excluded_patterns), "vendor/bundle/**/*.rb")
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_indexable_uris_does_not_include_gems_own_installed_files
|
|
83
|
-
uris = @config.indexable_uris
|
|
84
|
-
uris_inside_bundled_lsp = uris.select do |uri|
|
|
85
|
-
uri.full_path.start_with?(Bundler.bundle_path.join("gems", "ruby-lsp").to_s)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
assert_empty(
|
|
89
|
-
uris_inside_bundled_lsp,
|
|
90
|
-
"Indexable URIs should not include files from the gem currently being worked on. " \
|
|
91
|
-
"Included: #{uris_inside_bundled_lsp.map(&:full_path)}",
|
|
92
|
-
)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def test_indexable_uris_does_not_include_non_ruby_files_inside_rubylibdir
|
|
96
|
-
path = Pathname.new(RbConfig::CONFIG["rubylibdir"]).join("extra_file.txt").to_s
|
|
97
|
-
FileUtils.touch(path)
|
|
98
|
-
|
|
99
|
-
begin
|
|
100
|
-
uris = @config.indexable_uris
|
|
101
|
-
assert(uris.none? { |uri| uri.full_path == path })
|
|
102
|
-
ensure
|
|
103
|
-
FileUtils.rm(path)
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def test_paths_are_unique
|
|
108
|
-
uris = @config.indexable_uris
|
|
109
|
-
assert_equal(uris.uniq.length, uris.length)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def test_configuration_raises_for_unknown_keys
|
|
113
|
-
assert_raises(ArgumentError) do
|
|
114
|
-
@config.apply_config({ "unknown_config" => 123 })
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def test_magic_comments_regex
|
|
119
|
-
regex = @config.magic_comment_regex
|
|
120
|
-
|
|
121
|
-
[
|
|
122
|
-
"# frozen_string_literal:",
|
|
123
|
-
"# typed:",
|
|
124
|
-
"# compiled:",
|
|
125
|
-
"# encoding:",
|
|
126
|
-
"# shareable_constant_value:",
|
|
127
|
-
"# warn_indent:",
|
|
128
|
-
"# rubocop:",
|
|
129
|
-
"# nodoc:",
|
|
130
|
-
"# doc:",
|
|
131
|
-
"# coding:",
|
|
132
|
-
"# warn_past_scope:",
|
|
133
|
-
].each do |comment|
|
|
134
|
-
assert_match(regex, comment)
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def test_indexable_uris_respect_given_workspace_path
|
|
139
|
-
Dir.mktmpdir do |dir|
|
|
140
|
-
FileUtils.mkdir(File.join(dir, "ignore"))
|
|
141
|
-
FileUtils.touch(File.join(dir, "ignore", "file0.rb"))
|
|
142
|
-
FileUtils.touch(File.join(dir, "file1.rb"))
|
|
143
|
-
FileUtils.touch(File.join(dir, "file2.rb"))
|
|
144
|
-
|
|
145
|
-
@config.apply_config({ "excluded_patterns" => ["ignore/**/*.rb"] })
|
|
146
|
-
@config.workspace_path = dir
|
|
147
|
-
|
|
148
|
-
uris = @config.indexable_uris
|
|
149
|
-
assert(uris.none? { |uri| uri.full_path.start_with?(File.join(dir, "ignore")) })
|
|
150
|
-
|
|
151
|
-
# The regular default gem path is ~/.rubies/3.4.1/lib/ruby/3.4.0
|
|
152
|
-
# The alternative default gem path is ~/.rubies/3.4.1/lib/ruby/gems/3.4.0
|
|
153
|
-
# Here part_1 contains ~/.rubies/3.4.1/lib/ruby/ and part_2 contains 3.4.0, so that we can turn it into the
|
|
154
|
-
# alternative path
|
|
155
|
-
part_1, part_2 = Pathname.new(RbConfig::CONFIG["rubylibdir"]).split
|
|
156
|
-
other_default_gem_dir = part_1.join("gems").join(part_2).to_s
|
|
157
|
-
|
|
158
|
-
# After switching the workspace path, all indexable URIs will be found in one of these places:
|
|
159
|
-
# - The new workspace path
|
|
160
|
-
# - The Ruby LSP's own code (because Bundler is requiring the dependency from source)
|
|
161
|
-
# - Bundled gems
|
|
162
|
-
# - Default gems
|
|
163
|
-
# - Other default gem directory
|
|
164
|
-
assert(
|
|
165
|
-
uris.all? do |u|
|
|
166
|
-
u.full_path.start_with?(dir) ||
|
|
167
|
-
u.full_path.start_with?(File.join(Dir.pwd, "lib")) ||
|
|
168
|
-
u.full_path.start_with?(Bundler.bundle_path.to_s) ||
|
|
169
|
-
u.full_path.start_with?(RbConfig::CONFIG["rubylibdir"]) ||
|
|
170
|
-
u.full_path.start_with?(other_default_gem_dir)
|
|
171
|
-
end,
|
|
172
|
-
)
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def test_includes_top_level_files
|
|
177
|
-
Dir.mktmpdir do |dir|
|
|
178
|
-
FileUtils.touch(File.join(dir, "find_me.rb"))
|
|
179
|
-
@config.workspace_path = dir
|
|
180
|
-
|
|
181
|
-
uris = @config.indexable_uris
|
|
182
|
-
assert(uris.find { |u| File.basename(u.full_path) == "find_me.rb" })
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def test_transitive_dependencies_for_non_dev_gems_are_not_excluded
|
|
187
|
-
Dir.mktmpdir do |dir|
|
|
188
|
-
Dir.chdir(dir) do
|
|
189
|
-
# Both IRB and debug depend on reline. Since IRB is in the default group, reline should not be excluded
|
|
190
|
-
File.write(File.join(dir, "Gemfile"), <<~RUBY)
|
|
191
|
-
source "https://rubygems.org"
|
|
192
|
-
gem "irb"
|
|
193
|
-
gem "ruby-lsp", path: "#{Bundler.root}"
|
|
194
|
-
|
|
195
|
-
group :development do
|
|
196
|
-
gem "debug"
|
|
197
|
-
end
|
|
198
|
-
RUBY
|
|
199
|
-
|
|
200
|
-
Bundler.with_unbundled_env do
|
|
201
|
-
capture_subprocess_io do
|
|
202
|
-
system("bundle install")
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
stdout, _stderr = capture_subprocess_io do
|
|
206
|
-
script = [
|
|
207
|
-
"require \"ruby_lsp/internal\"",
|
|
208
|
-
"print RubyIndexer::Configuration.new.instance_variable_get(:@excluded_gems).join(\",\")",
|
|
209
|
-
].join(";")
|
|
210
|
-
system("bundle exec ruby -e '#{script}'")
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
excluded_gems = stdout.split(",")
|
|
214
|
-
assert_includes(excluded_gems, "debug")
|
|
215
|
-
refute_includes(excluded_gems, "reline")
|
|
216
|
-
refute_includes(excluded_gems, "irb")
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
def test_does_not_fail_if_there_are_missing_specs_due_to_platform_constraints
|
|
223
|
-
Dir.mktmpdir do |dir|
|
|
224
|
-
Dir.chdir(dir) do
|
|
225
|
-
File.write(File.join(dir, "Gemfile"), <<~RUBY)
|
|
226
|
-
source "https://rubygems.org"
|
|
227
|
-
gem "ruby-lsp", path: "#{Bundler.root}"
|
|
228
|
-
|
|
229
|
-
platforms :windows do
|
|
230
|
-
gem "tzinfo"
|
|
231
|
-
gem "tzinfo-data"
|
|
232
|
-
end
|
|
233
|
-
RUBY
|
|
234
|
-
|
|
235
|
-
Bundler.with_unbundled_env do
|
|
236
|
-
capture_subprocess_io do
|
|
237
|
-
system("bundle install")
|
|
238
|
-
|
|
239
|
-
script = [
|
|
240
|
-
"require \"ruby_lsp/internal\"",
|
|
241
|
-
"RubyIndexer::Configuration.new.indexable_uris",
|
|
242
|
-
].join(";")
|
|
243
|
-
|
|
244
|
-
assert(system("bundle exec ruby -e '#{script}'"))
|
|
245
|
-
end
|
|
246
|
-
end
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
def test_indexables_include_non_test_files_in_test_directories
|
|
252
|
-
# In order to linearize test parent classes and accurately detect the framework being used, then intermediate
|
|
253
|
-
# parent classes _must_ also be indexed. Otherwise, we have no way of linearizing the rest of the ancestors to
|
|
254
|
-
# determine what the test class ultimately inherits from.
|
|
255
|
-
#
|
|
256
|
-
# Therefore, we need to ensure that test files are excluded, but non test files inside test directories have to be
|
|
257
|
-
# indexed
|
|
258
|
-
FileUtils.touch("test/test_case.rb")
|
|
259
|
-
|
|
260
|
-
uris = @config.indexable_uris
|
|
261
|
-
project_paths = uris.filter_map do |uri|
|
|
262
|
-
path = uri.full_path
|
|
263
|
-
next if path.start_with?(Bundler.bundle_path.to_s) || path.start_with?(RbConfig::CONFIG["rubylibdir"])
|
|
264
|
-
|
|
265
|
-
Pathname.new(path).relative_path_from(Dir.pwd).to_s
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
begin
|
|
269
|
-
assert_includes(project_paths, "test/requests/support/expectations_test_runner.rb")
|
|
270
|
-
assert_includes(project_paths, "test/test_helper.rb")
|
|
271
|
-
assert_includes(project_paths, "test/test_case.rb")
|
|
272
|
-
ensure
|
|
273
|
-
FileUtils.rm("test/test_case.rb")
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
end
|
|
277
|
-
end
|
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
# typed: true
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require_relative "test_case"
|
|
5
|
-
|
|
6
|
-
module RubyIndexer
|
|
7
|
-
class ConstantTest < TestCase
|
|
8
|
-
def test_constant_writes
|
|
9
|
-
index(<<~RUBY)
|
|
10
|
-
FOO = 1
|
|
11
|
-
|
|
12
|
-
class ::Bar
|
|
13
|
-
FOO = 2
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
BAR = 3 if condition
|
|
17
|
-
RUBY
|
|
18
|
-
|
|
19
|
-
assert_entry("FOO", Entry::Constant, "/fake/path/foo.rb:0-0:0-7")
|
|
20
|
-
assert_entry("Bar::FOO", Entry::Constant, "/fake/path/foo.rb:3-2:3-9")
|
|
21
|
-
assert_entry("BAR", Entry::Constant, "/fake/path/foo.rb:6-0:6-7")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_constant_with_multibyte_characters
|
|
25
|
-
index(<<~RUBY)
|
|
26
|
-
CONST_💎 = "Ruby"
|
|
27
|
-
RUBY
|
|
28
|
-
|
|
29
|
-
assert_entry("CONST_💎", Entry::Constant, "/fake/path/foo.rb:0-0:0-16")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_constant_or_writes
|
|
33
|
-
index(<<~RUBY)
|
|
34
|
-
FOO ||= 1
|
|
35
|
-
|
|
36
|
-
class ::Bar
|
|
37
|
-
FOO ||= 2
|
|
38
|
-
end
|
|
39
|
-
RUBY
|
|
40
|
-
|
|
41
|
-
assert_entry("FOO", Entry::Constant, "/fake/path/foo.rb:0-0:0-9")
|
|
42
|
-
assert_entry("Bar::FOO", Entry::Constant, "/fake/path/foo.rb:3-2:3-11")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_constant_path_writes
|
|
46
|
-
index(<<~RUBY)
|
|
47
|
-
class A
|
|
48
|
-
FOO = 1
|
|
49
|
-
::BAR = 1
|
|
50
|
-
|
|
51
|
-
module B
|
|
52
|
-
FOO = 1
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
A::BAZ = 1
|
|
57
|
-
RUBY
|
|
58
|
-
|
|
59
|
-
assert_entry("A::FOO", Entry::Constant, "/fake/path/foo.rb:1-2:1-9")
|
|
60
|
-
assert_entry("BAR", Entry::Constant, "/fake/path/foo.rb:2-2:2-11")
|
|
61
|
-
assert_entry("A::B::FOO", Entry::Constant, "/fake/path/foo.rb:5-4:5-11")
|
|
62
|
-
assert_entry("A::BAZ", Entry::Constant, "/fake/path/foo.rb:9-0:9-10")
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_constant_path_or_writes
|
|
66
|
-
index(<<~RUBY)
|
|
67
|
-
class A
|
|
68
|
-
FOO ||= 1
|
|
69
|
-
::BAR ||= 1
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
A::BAZ ||= 1
|
|
73
|
-
RUBY
|
|
74
|
-
|
|
75
|
-
assert_entry("A::FOO", Entry::Constant, "/fake/path/foo.rb:1-2:1-11")
|
|
76
|
-
assert_entry("BAR", Entry::Constant, "/fake/path/foo.rb:2-2:2-13")
|
|
77
|
-
assert_entry("A::BAZ", Entry::Constant, "/fake/path/foo.rb:5-0:5-12")
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_comments_for_constants
|
|
81
|
-
index(<<~RUBY)
|
|
82
|
-
# FOO comment
|
|
83
|
-
FOO = 1
|
|
84
|
-
|
|
85
|
-
class A
|
|
86
|
-
# A::FOO comment
|
|
87
|
-
FOO = 1
|
|
88
|
-
|
|
89
|
-
# ::BAR comment
|
|
90
|
-
::BAR = 1
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# A::BAZ comment
|
|
94
|
-
A::BAZ = 1
|
|
95
|
-
RUBY
|
|
96
|
-
|
|
97
|
-
foo = @index["FOO"]&.first #: as !nil
|
|
98
|
-
assert_equal("FOO comment", foo.comments)
|
|
99
|
-
|
|
100
|
-
a_foo = @index["A::FOO"]&.first #: as !nil
|
|
101
|
-
assert_equal("A::FOO comment", a_foo.comments)
|
|
102
|
-
|
|
103
|
-
bar = @index["BAR"]&.first #: as !nil
|
|
104
|
-
assert_equal("::BAR comment", bar.comments)
|
|
105
|
-
|
|
106
|
-
a_baz = @index["A::BAZ"]&.first #: as !nil
|
|
107
|
-
assert_equal("A::BAZ comment", a_baz.comments)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def test_variable_path_constants_are_ignored
|
|
111
|
-
index(<<~RUBY)
|
|
112
|
-
var::FOO = 1
|
|
113
|
-
self.class::FOO = 1
|
|
114
|
-
RUBY
|
|
115
|
-
|
|
116
|
-
assert_no_indexed_entries
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def test_private_constant_indexing
|
|
120
|
-
index(<<~RUBY)
|
|
121
|
-
class A
|
|
122
|
-
B = 1
|
|
123
|
-
private_constant(:B)
|
|
124
|
-
|
|
125
|
-
C = 2
|
|
126
|
-
private_constant("C")
|
|
127
|
-
|
|
128
|
-
D = 1
|
|
129
|
-
end
|
|
130
|
-
RUBY
|
|
131
|
-
|
|
132
|
-
b_const = @index["A::B"]&.first #: as !nil
|
|
133
|
-
assert_predicate(b_const, :private?)
|
|
134
|
-
|
|
135
|
-
c_const = @index["A::C"]&.first #: as !nil
|
|
136
|
-
assert_predicate(c_const, :private?)
|
|
137
|
-
|
|
138
|
-
d_const = @index["A::D"]&.first #: as !nil
|
|
139
|
-
assert_predicate(d_const, :public?)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def test_marking_constants_as_private_reopening_namespaces
|
|
143
|
-
index(<<~RUBY)
|
|
144
|
-
module A
|
|
145
|
-
module B
|
|
146
|
-
CONST_A = 1
|
|
147
|
-
private_constant(:CONST_A)
|
|
148
|
-
|
|
149
|
-
CONST_B = 2
|
|
150
|
-
CONST_C = 3
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
module B
|
|
154
|
-
private_constant(:CONST_B)
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
module A
|
|
159
|
-
module B
|
|
160
|
-
private_constant(:CONST_C)
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
RUBY
|
|
164
|
-
|
|
165
|
-
a_const = @index["A::B::CONST_A"]&.first #: as !nil
|
|
166
|
-
assert_predicate(a_const, :private?)
|
|
167
|
-
|
|
168
|
-
b_const = @index["A::B::CONST_B"]&.first #: as !nil
|
|
169
|
-
assert_predicate(b_const, :private?)
|
|
170
|
-
|
|
171
|
-
c_const = @index["A::B::CONST_C"]&.first #: as !nil
|
|
172
|
-
assert_predicate(c_const, :private?)
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def test_marking_constants_as_private_with_receiver
|
|
176
|
-
index(<<~RUBY)
|
|
177
|
-
module A
|
|
178
|
-
module B
|
|
179
|
-
CONST_A = 1
|
|
180
|
-
CONST_B = 2
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
B.private_constant(:CONST_A)
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
A::B.private_constant(:CONST_B)
|
|
187
|
-
RUBY
|
|
188
|
-
|
|
189
|
-
a_const = @index["A::B::CONST_A"]&.first #: as !nil
|
|
190
|
-
assert_predicate(a_const, :private?)
|
|
191
|
-
|
|
192
|
-
b_const = @index["A::B::CONST_B"]&.first #: as !nil
|
|
193
|
-
assert_predicate(b_const, :private?)
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def test_indexing_constant_aliases
|
|
197
|
-
index(<<~RUBY)
|
|
198
|
-
module A
|
|
199
|
-
module B
|
|
200
|
-
module C
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
FIRST = B::C
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
SECOND = A::FIRST
|
|
208
|
-
RUBY
|
|
209
|
-
|
|
210
|
-
unresolve_entry = @index["A::FIRST"]&.first #: as Entry::UnresolvedConstantAlias
|
|
211
|
-
assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry)
|
|
212
|
-
assert_equal(["A"], unresolve_entry.nesting)
|
|
213
|
-
assert_equal("B::C", unresolve_entry.target)
|
|
214
|
-
|
|
215
|
-
resolved_entry = @index.resolve("A::FIRST", [])&.first #: as Entry::ConstantAlias
|
|
216
|
-
assert_instance_of(Entry::ConstantAlias, resolved_entry)
|
|
217
|
-
assert_equal("A::B::C", resolved_entry.target)
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def test_aliasing_namespaces
|
|
221
|
-
index(<<~RUBY)
|
|
222
|
-
module A
|
|
223
|
-
module B
|
|
224
|
-
module C
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
ALIAS = B
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
module Other
|
|
232
|
-
ONE_MORE = A::ALIAS
|
|
233
|
-
end
|
|
234
|
-
RUBY
|
|
235
|
-
|
|
236
|
-
unresolve_entry = @index["A::ALIAS"]&.first #: as Entry::UnresolvedConstantAlias
|
|
237
|
-
assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry)
|
|
238
|
-
assert_equal(["A"], unresolve_entry.nesting)
|
|
239
|
-
assert_equal("B", unresolve_entry.target)
|
|
240
|
-
|
|
241
|
-
resolved_entry = @index.resolve("ALIAS", ["A"])&.first #: as Entry::ConstantAlias
|
|
242
|
-
assert_instance_of(Entry::ConstantAlias, resolved_entry)
|
|
243
|
-
assert_equal("A::B", resolved_entry.target)
|
|
244
|
-
|
|
245
|
-
resolved_entry = @index.resolve("ALIAS::C", ["A"])&.first #: as Entry::Module
|
|
246
|
-
assert_instance_of(Entry::Module, resolved_entry)
|
|
247
|
-
assert_equal("A::B::C", resolved_entry.name)
|
|
248
|
-
|
|
249
|
-
unresolve_entry = @index["Other::ONE_MORE"]&.first #: as Entry::UnresolvedConstantAlias
|
|
250
|
-
assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry)
|
|
251
|
-
assert_equal(["Other"], unresolve_entry.nesting)
|
|
252
|
-
assert_equal("A::ALIAS", unresolve_entry.target)
|
|
253
|
-
|
|
254
|
-
resolved_entry = @index.resolve("Other::ONE_MORE::C", [])&.first
|
|
255
|
-
assert_instance_of(Entry::Module, resolved_entry)
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
def test_indexing_same_line_constant_aliases
|
|
259
|
-
index(<<~RUBY)
|
|
260
|
-
module A
|
|
261
|
-
B = C = 1
|
|
262
|
-
D = E ||= 1
|
|
263
|
-
F = G::H &&= 1
|
|
264
|
-
I::J = K::L = M = 1
|
|
265
|
-
end
|
|
266
|
-
RUBY
|
|
267
|
-
|
|
268
|
-
# B and C
|
|
269
|
-
unresolve_entry = @index["A::B"]&.first #: as Entry::UnresolvedConstantAlias
|
|
270
|
-
assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry)
|
|
271
|
-
assert_equal(["A"], unresolve_entry.nesting)
|
|
272
|
-
assert_equal("C", unresolve_entry.target)
|
|
273
|
-
|
|
274
|
-
resolved_entry = @index.resolve("A::B", [])&.first #: as Entry::ConstantAlias
|
|
275
|
-
assert_instance_of(Entry::ConstantAlias, resolved_entry)
|
|
276
|
-
assert_equal("A::C", resolved_entry.target)
|
|
277
|
-
|
|
278
|
-
constant = @index["A::C"]&.first #: as Entry::Constant
|
|
279
|
-
assert_instance_of(Entry::Constant, constant)
|
|
280
|
-
|
|
281
|
-
# D and E
|
|
282
|
-
unresolve_entry = @index["A::D"]&.first #: as Entry::UnresolvedConstantAlias
|
|
283
|
-
assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry)
|
|
284
|
-
assert_equal(["A"], unresolve_entry.nesting)
|
|
285
|
-
assert_equal("E", unresolve_entry.target)
|
|
286
|
-
|
|
287
|
-
resolved_entry = @index.resolve("A::D", [])&.first #: as Entry::ConstantAlias
|
|
288
|
-
assert_instance_of(Entry::ConstantAlias, resolved_entry)
|
|
289
|
-
assert_equal("A::E", resolved_entry.target)
|
|
290
|
-
|
|
291
|
-
# F and G::H
|
|
292
|
-
unresolve_entry = @index["A::F"]&.first #: as Entry::UnresolvedConstantAlias
|
|
293
|
-
assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry)
|
|
294
|
-
assert_equal(["A"], unresolve_entry.nesting)
|
|
295
|
-
assert_equal("G::H", unresolve_entry.target)
|
|
296
|
-
|
|
297
|
-
resolved_entry = @index.resolve("A::F", [])&.first #: as Entry::ConstantAlias
|
|
298
|
-
assert_instance_of(Entry::ConstantAlias, resolved_entry)
|
|
299
|
-
assert_equal("A::G::H", resolved_entry.target)
|
|
300
|
-
|
|
301
|
-
# I::J, K::L and M
|
|
302
|
-
unresolve_entry = @index["A::I::J"]&.first #: as Entry::UnresolvedConstantAlias
|
|
303
|
-
assert_instance_of(Entry::UnresolvedConstantAlias, unresolve_entry)
|
|
304
|
-
assert_equal(["A"], unresolve_entry.nesting)
|
|
305
|
-
assert_equal("K::L", unresolve_entry.target)
|
|
306
|
-
|
|
307
|
-
resolved_entry = @index.resolve("A::I::J", [])&.first #: as Entry::ConstantAlias
|
|
308
|
-
assert_instance_of(Entry::ConstantAlias, resolved_entry)
|
|
309
|
-
assert_equal("A::K::L", resolved_entry.target)
|
|
310
|
-
|
|
311
|
-
# When we are resolving A::I::J, we invoke `resolve("K::L", ["A"])`, which recursively resolves A::K::L too.
|
|
312
|
-
# Therefore, both A::I::J and A::K::L point to A::M by the end of the previous resolve invocation
|
|
313
|
-
resolved_entry = @index["A::K::L"]&.first #: as Entry::ConstantAlias
|
|
314
|
-
assert_instance_of(Entry::ConstantAlias, resolved_entry)
|
|
315
|
-
assert_equal("A::M", resolved_entry.target)
|
|
316
|
-
|
|
317
|
-
constant = @index["A::M"]&.first
|
|
318
|
-
assert_instance_of(Entry::Constant, constant)
|
|
319
|
-
end
|
|
320
|
-
|
|
321
|
-
def test_indexing_or_and_operator_nodes
|
|
322
|
-
index(<<~RUBY)
|
|
323
|
-
A ||= 1
|
|
324
|
-
B &&= 2
|
|
325
|
-
C &= 3
|
|
326
|
-
D::E ||= 4
|
|
327
|
-
F::G &&= 5
|
|
328
|
-
H::I &= 6
|
|
329
|
-
RUBY
|
|
330
|
-
|
|
331
|
-
assert_entry("A", Entry::Constant, "/fake/path/foo.rb:0-0:0-7")
|
|
332
|
-
assert_entry("B", Entry::Constant, "/fake/path/foo.rb:1-0:1-7")
|
|
333
|
-
assert_entry("C", Entry::Constant, "/fake/path/foo.rb:2-0:2-6")
|
|
334
|
-
assert_entry("D::E", Entry::Constant, "/fake/path/foo.rb:3-0:3-10")
|
|
335
|
-
assert_entry("F::G", Entry::Constant, "/fake/path/foo.rb:4-0:4-10")
|
|
336
|
-
assert_entry("H::I", Entry::Constant, "/fake/path/foo.rb:5-0:5-9")
|
|
337
|
-
end
|
|
338
|
-
|
|
339
|
-
def test_indexing_constant_targets
|
|
340
|
-
index(<<~RUBY)
|
|
341
|
-
module A
|
|
342
|
-
B, C = [1, Y]
|
|
343
|
-
D::E, F::G = [Z, 4]
|
|
344
|
-
H, I::J = [5, B]
|
|
345
|
-
K, L = C
|
|
346
|
-
end
|
|
347
|
-
|
|
348
|
-
module Real
|
|
349
|
-
Z = 1
|
|
350
|
-
Y = 2
|
|
351
|
-
end
|
|
352
|
-
RUBY
|
|
353
|
-
|
|
354
|
-
assert_entry("A::B", Entry::Constant, "/fake/path/foo.rb:1-2:1-3")
|
|
355
|
-
assert_entry("A::C", Entry::UnresolvedConstantAlias, "/fake/path/foo.rb:1-5:1-6")
|
|
356
|
-
assert_entry("A::D::E", Entry::UnresolvedConstantAlias, "/fake/path/foo.rb:2-2:2-6")
|
|
357
|
-
assert_entry("A::F::G", Entry::Constant, "/fake/path/foo.rb:2-8:2-12")
|
|
358
|
-
assert_entry("A::H", Entry::Constant, "/fake/path/foo.rb:3-2:3-3")
|
|
359
|
-
assert_entry("A::I::J", Entry::UnresolvedConstantAlias, "/fake/path/foo.rb:3-5:3-9")
|
|
360
|
-
assert_entry("A::K", Entry::Constant, "/fake/path/foo.rb:4-2:4-3")
|
|
361
|
-
assert_entry("A::L", Entry::Constant, "/fake/path/foo.rb:4-5:4-6")
|
|
362
|
-
end
|
|
363
|
-
|
|
364
|
-
def test_indexing_constant_targets_with_splats
|
|
365
|
-
index(<<~RUBY)
|
|
366
|
-
A, *, B = baz
|
|
367
|
-
C, = bar
|
|
368
|
-
(D, E) = baz
|
|
369
|
-
F, G = *baz, qux
|
|
370
|
-
H, I = [baz, *qux]
|
|
371
|
-
J, L = [*something, String]
|
|
372
|
-
M = [String]
|
|
373
|
-
RUBY
|
|
374
|
-
|
|
375
|
-
assert_entry("A", Entry::Constant, "/fake/path/foo.rb:0-0:0-1")
|
|
376
|
-
assert_entry("B", Entry::Constant, "/fake/path/foo.rb:0-6:0-7")
|
|
377
|
-
assert_entry("D", Entry::Constant, "/fake/path/foo.rb:2-1:2-2")
|
|
378
|
-
assert_entry("E", Entry::Constant, "/fake/path/foo.rb:2-4:2-5")
|
|
379
|
-
assert_entry("F", Entry::Constant, "/fake/path/foo.rb:3-0:3-1")
|
|
380
|
-
assert_entry("G", Entry::Constant, "/fake/path/foo.rb:3-3:3-4")
|
|
381
|
-
assert_entry("H", Entry::Constant, "/fake/path/foo.rb:4-0:4-1")
|
|
382
|
-
assert_entry("I", Entry::Constant, "/fake/path/foo.rb:4-3:4-4")
|
|
383
|
-
assert_entry("J", Entry::Constant, "/fake/path/foo.rb:5-0:5-1")
|
|
384
|
-
assert_entry("L", Entry::Constant, "/fake/path/foo.rb:5-3:5-4")
|
|
385
|
-
assert_entry("M", Entry::Constant, "/fake/path/foo.rb:6-0:6-12")
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
def test_indexing_destructuring_an_array
|
|
389
|
-
index(<<~RUBY)
|
|
390
|
-
Baz = [1, 2]
|
|
391
|
-
Foo, Bar = Baz
|
|
392
|
-
This, That = foo, bar
|
|
393
|
-
RUBY
|
|
394
|
-
|
|
395
|
-
assert_entry("Baz", Entry::Constant, "/fake/path/foo.rb:0-0:0-12")
|
|
396
|
-
assert_entry("Foo", Entry::Constant, "/fake/path/foo.rb:1-0:1-3")
|
|
397
|
-
assert_entry("Bar", Entry::Constant, "/fake/path/foo.rb:1-5:1-8")
|
|
398
|
-
assert_entry("This", Entry::Constant, "/fake/path/foo.rb:2-0:2-4")
|
|
399
|
-
assert_entry("That", Entry::Constant, "/fake/path/foo.rb:2-6:2-10")
|
|
400
|
-
end
|
|
401
|
-
end
|
|
402
|
-
end
|