ruby-lsp 0.23.15 → 0.26.9
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 +17 -14
- data/exe/ruby-lsp-check +0 -4
- data/exe/ruby-lsp-launcher +41 -14
- data/exe/ruby-lsp-test-exec +6 -0
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +0 -1
- data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +0 -1
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +4 -3
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +42 -20
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +1 -7
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +49 -62
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +84 -74
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +6 -9
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +9 -14
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +12 -8
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +4 -4
- data/lib/ruby_lsp/addon.rb +44 -15
- data/lib/ruby_lsp/base_server.rb +56 -37
- data/lib/ruby_lsp/client_capabilities.rb +6 -1
- data/lib/ruby_lsp/document.rb +174 -62
- data/lib/ruby_lsp/erb_document.rb +10 -8
- data/lib/ruby_lsp/global_state.rb +86 -33
- data/lib/ruby_lsp/internal.rb +6 -3
- data/lib/ruby_lsp/listeners/completion.rb +22 -11
- data/lib/ruby_lsp/listeners/definition.rb +41 -21
- data/lib/ruby_lsp/listeners/document_highlight.rb +26 -1
- data/lib/ruby_lsp/listeners/document_link.rb +64 -28
- data/lib/ruby_lsp/listeners/hover.rb +27 -16
- data/lib/ruby_lsp/listeners/inlay_hints.rb +5 -3
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +2 -2
- data/lib/ruby_lsp/listeners/signature_help.rb +2 -2
- data/lib/ruby_lsp/listeners/spec_style.rb +155 -79
- data/lib/ruby_lsp/listeners/test_discovery.rb +39 -21
- data/lib/ruby_lsp/listeners/test_style.rb +75 -35
- data/lib/ruby_lsp/rbs_document.rb +3 -6
- data/lib/ruby_lsp/requests/code_action_resolve.rb +83 -58
- data/lib/ruby_lsp/requests/code_actions.rb +20 -5
- data/lib/ruby_lsp/requests/code_lens.rb +27 -6
- data/lib/ruby_lsp/requests/completion.rb +3 -3
- data/lib/ruby_lsp/requests/completion_resolve.rb +8 -6
- data/lib/ruby_lsp/requests/definition.rb +4 -7
- data/lib/ruby_lsp/requests/discover_tests.rb +2 -2
- data/lib/ruby_lsp/requests/document_highlight.rb +2 -2
- data/lib/ruby_lsp/requests/document_link.rb +1 -1
- data/lib/ruby_lsp/requests/folding_ranges.rb +1 -1
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +64 -12
- data/lib/ruby_lsp/requests/hover.rb +3 -6
- data/lib/ruby_lsp/requests/inlay_hints.rb +4 -4
- data/lib/ruby_lsp/requests/on_type_formatting.rb +1 -1
- data/lib/ruby_lsp/requests/prepare_rename.rb +1 -1
- data/lib/ruby_lsp/requests/references.rb +10 -21
- data/lib/ruby_lsp/requests/rename.rb +9 -10
- data/lib/ruby_lsp/requests/request.rb +8 -8
- data/lib/ruby_lsp/requests/selection_ranges.rb +2 -2
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +1 -1
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +2 -2
- data/lib/ruby_lsp/requests/signature_help.rb +2 -2
- data/lib/ruby_lsp/requests/support/annotation.rb +1 -1
- data/lib/ruby_lsp/requests/support/common.rb +9 -12
- data/lib/ruby_lsp/requests/support/formatter.rb +16 -15
- data/lib/ruby_lsp/requests/support/package_url.rb +414 -0
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +7 -1
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +2 -2
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +13 -3
- data/lib/ruby_lsp/requests/support/source_uri.rb +7 -4
- data/lib/ruby_lsp/requests/support/test_item.rb +7 -1
- data/lib/ruby_lsp/requests/workspace_symbol.rb +20 -12
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +1 -4
- data/lib/ruby_lsp/response_builders/document_symbol.rb +2 -3
- data/lib/ruby_lsp/response_builders/hover.rb +1 -4
- data/lib/ruby_lsp/response_builders/response_builder.rb +6 -7
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +4 -5
- data/lib/ruby_lsp/response_builders/signature_help.rb +1 -2
- data/lib/ruby_lsp/response_builders/test_collection.rb +29 -3
- data/lib/ruby_lsp/ruby_document.rb +14 -42
- data/lib/ruby_lsp/scripts/compose_bundle.rb +3 -3
- data/lib/ruby_lsp/scripts/compose_bundle_windows.rb +3 -1
- data/lib/ruby_lsp/server.rb +173 -130
- data/lib/ruby_lsp/setup_bundler.rb +114 -47
- data/lib/ruby_lsp/static_docs.rb +1 -0
- data/lib/ruby_lsp/store.rb +6 -16
- data/lib/ruby_lsp/test_helper.rb +1 -4
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +121 -17
- data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +65 -25
- data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +16 -18
- data/lib/ruby_lsp/utils.rb +102 -13
- data/static_docs/break.md +103 -0
- metadata +8 -33
- data/lib/ruby_indexer/test/class_variables_test.rb +0 -140
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +0 -770
- data/lib/ruby_indexer/test/configuration_test.rb +0 -280
- 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 -2190
- data/lib/ruby_indexer/test/instance_variables_test.rb +0 -240
- data/lib/ruby_indexer/test/method_test.rb +0 -973
- data/lib/ruby_indexer/test/prefix_tree_test.rb +0 -150
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +0 -380
- data/lib/ruby_indexer/test/reference_finder_test.rb +0 -330
- data/lib/ruby_indexer/test/test_case.rb +0 -51
- data/lib/ruby_indexer/test/uri_test.rb +0 -85
- data/lib/ruby_lsp/load_sorbet.rb +0 -62
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b12b079fa54de3410e0d0ab2db9bf2241c6413c3c61d3ead21d4bbcc9b4e7d6
|
|
4
|
+
data.tar.gz: dede13048ef29f79079271c7d20d505160f8fe24d495863e08be96c95207c6bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 922edf8dadc38fa037d2c157c8e0b9bbbd3c759931ac6cda3070b615a3039597028672e8632507e80689f6a8f6cc793e7a1006a49bba28d72489f541e75f2fc3
|
|
7
|
+
data.tar.gz: 046d2d369c16a743f71750a9a6dfed945d8e21b43bb58ad357ce1098fd731dc4e7060ffebcc96e1b78a43a3b2571ac9e31d94dc6c25c380478cb54a979c0f461
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.26.9
|
data/exe/ruby-lsp
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
require "optparse"
|
|
5
5
|
|
|
6
|
-
original_args = ARGV.dup
|
|
7
6
|
options = {}
|
|
8
7
|
parser = OptionParser.new do |opts|
|
|
9
8
|
opts.banner = "Usage: ruby-lsp [options]"
|
|
@@ -22,13 +21,6 @@ parser = OptionParser.new do |opts|
|
|
|
22
21
|
options[:time_index] = true
|
|
23
22
|
end
|
|
24
23
|
|
|
25
|
-
opts.on(
|
|
26
|
-
"--branch [BRANCH]",
|
|
27
|
-
"Launch the Ruby LSP using the specified branch rather than the release version",
|
|
28
|
-
) do |branch|
|
|
29
|
-
options[:branch] = branch
|
|
30
|
-
end
|
|
31
|
-
|
|
32
24
|
opts.on("--doctor", "Run troubleshooting steps") do
|
|
33
25
|
options[:doctor] = true
|
|
34
26
|
end
|
|
@@ -37,6 +29,10 @@ parser = OptionParser.new do |opts|
|
|
|
37
29
|
options[:launcher] = true
|
|
38
30
|
end
|
|
39
31
|
|
|
32
|
+
opts.on("--beta", "Use pre-release server gems") do
|
|
33
|
+
options[:beta] = true
|
|
34
|
+
end
|
|
35
|
+
|
|
40
36
|
opts.on("-h", "--help", "Print this help") do
|
|
41
37
|
puts opts.help
|
|
42
38
|
puts
|
|
@@ -46,7 +42,7 @@ parser = OptionParser.new do |opts|
|
|
|
46
42
|
end
|
|
47
43
|
|
|
48
44
|
begin
|
|
49
|
-
parser.parse
|
|
45
|
+
parser.parse(ARGV)
|
|
50
46
|
rescue OptionParser::InvalidOption => e
|
|
51
47
|
warn(e)
|
|
52
48
|
warn("")
|
|
@@ -66,6 +62,7 @@ if ENV["BUNDLE_GEMFILE"].nil?
|
|
|
66
62
|
if options[:launcher]
|
|
67
63
|
flags = []
|
|
68
64
|
flags << "--debug" if options[:debug]
|
|
65
|
+
flags << "--beta" if options[:beta]
|
|
69
66
|
exit exec(Gem.ruby, File.expand_path("ruby-lsp-launcher", __dir__), *flags)
|
|
70
67
|
end
|
|
71
68
|
|
|
@@ -85,16 +82,20 @@ if ENV["BUNDLE_GEMFILE"].nil?
|
|
|
85
82
|
base_command << " _#{env["BUNDLER_VERSION"]}_"
|
|
86
83
|
end
|
|
87
84
|
|
|
88
|
-
exit exec(env, "#{base_command} exec ruby-lsp #{
|
|
85
|
+
exit exec(env, "#{base_command} exec ruby-lsp #{ARGV.join(" ")}".strip)
|
|
89
86
|
end
|
|
90
87
|
|
|
88
|
+
$stdin.sync = true
|
|
89
|
+
$stdout.sync = true
|
|
90
|
+
$stderr.sync = true
|
|
91
|
+
$stdin.binmode
|
|
92
|
+
$stdout.binmode
|
|
93
|
+
$stderr.binmode
|
|
94
|
+
|
|
91
95
|
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
|
|
92
96
|
|
|
93
|
-
require "ruby_lsp/load_sorbet"
|
|
94
97
|
require "ruby_lsp/internal"
|
|
95
98
|
|
|
96
|
-
T::Utils.run_all_sig_blocks
|
|
97
|
-
|
|
98
99
|
if options[:debug]
|
|
99
100
|
if ["x64-mingw-ucrt", "x64-mingw32"].include?(RUBY_PLATFORM)
|
|
100
101
|
$stderr.puts "Debugging is not supported on Windows"
|
|
@@ -147,8 +148,10 @@ if options[:doctor]
|
|
|
147
148
|
return
|
|
148
149
|
end
|
|
149
150
|
|
|
151
|
+
server = RubyLsp::Server.new
|
|
152
|
+
|
|
150
153
|
# Ensure all output goes out stderr by default to allow puts/p/pp to work
|
|
151
154
|
# without specifying output device.
|
|
152
155
|
$> = $stderr
|
|
153
156
|
|
|
154
|
-
|
|
157
|
+
server.start
|
data/exe/ruby-lsp-check
CHANGED
|
@@ -3,13 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
# This executable checks if all automatic LSP requests run successfully on every Ruby file under the current directory
|
|
5
5
|
|
|
6
|
-
require "ruby_lsp/load_sorbet"
|
|
7
|
-
|
|
8
6
|
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
|
|
9
7
|
require "ruby_lsp/internal"
|
|
10
8
|
|
|
11
|
-
T::Utils.run_all_sig_blocks
|
|
12
|
-
|
|
13
9
|
files = Dir.glob("#{Dir.pwd}/**/*.rb")
|
|
14
10
|
|
|
15
11
|
puts "Verifying that all automatic LSP requests execute successfully. This may take a while..."
|
data/exe/ruby-lsp-launcher
CHANGED
|
@@ -6,6 +6,13 @@
|
|
|
6
6
|
# composed bundle
|
|
7
7
|
# !!!!!!!
|
|
8
8
|
|
|
9
|
+
$stdin.sync = true
|
|
10
|
+
$stdout.sync = true
|
|
11
|
+
$stderr.sync = true
|
|
12
|
+
$stdin.binmode
|
|
13
|
+
$stdout.binmode
|
|
14
|
+
$stderr.binmode
|
|
15
|
+
|
|
9
16
|
setup_error = nil
|
|
10
17
|
install_error = nil
|
|
11
18
|
reboot = false
|
|
@@ -13,6 +20,10 @@ reboot = false
|
|
|
13
20
|
workspace_uri = ARGV.first
|
|
14
21
|
raw_initialize_path = File.join(".ruby-lsp", "raw_initialize")
|
|
15
22
|
|
|
23
|
+
# Extract CLI options that affect bundle composition (e.g. --beta) from the arguments passed by the server
|
|
24
|
+
cli_options = {}
|
|
25
|
+
cli_options[:beta] = true if ARGV.include?("--beta")
|
|
26
|
+
|
|
16
27
|
raw_initialize = if workspace_uri && !workspace_uri.start_with?("--")
|
|
17
28
|
# If there's an argument without `--`, then it's the server asking to compose the bundle and passing to this
|
|
18
29
|
# executable the workspace URI. We can't require gems at this point, so we built a fake initialize request manually
|
|
@@ -28,7 +39,6 @@ else
|
|
|
28
39
|
# Read the initialize request before even starting the server. We need to do this to figure out the workspace URI.
|
|
29
40
|
# Editors are not required to spawn the language server process on the same directory as the workspace URI, so we need
|
|
30
41
|
# to ensure that we're setting up the bundle in the right place
|
|
31
|
-
$stdin.binmode
|
|
32
42
|
headers = $stdin.gets("\r\n\r\n")
|
|
33
43
|
content_length = headers[/Content-Length: (\d+)/i, 1].to_i
|
|
34
44
|
$stdin.read(content_length)
|
|
@@ -43,16 +53,20 @@ pid = if Gem.win_platform?
|
|
|
43
53
|
["-I", File.expand_path(path)]
|
|
44
54
|
end
|
|
45
55
|
|
|
56
|
+
cli_flags = []
|
|
57
|
+
cli_flags << "--beta" if cli_options[:beta]
|
|
58
|
+
|
|
46
59
|
Process.spawn(
|
|
47
60
|
Gem.ruby,
|
|
48
61
|
*load_path,
|
|
49
62
|
File.expand_path("../lib/ruby_lsp/scripts/compose_bundle_windows.rb", __dir__),
|
|
50
63
|
raw_initialize,
|
|
64
|
+
*cli_flags,
|
|
51
65
|
)
|
|
52
66
|
else
|
|
53
67
|
fork do
|
|
54
68
|
require_relative "../lib/ruby_lsp/scripts/compose_bundle"
|
|
55
|
-
compose(raw_initialize)
|
|
69
|
+
compose(raw_initialize, **cli_options)
|
|
56
70
|
end
|
|
57
71
|
end
|
|
58
72
|
|
|
@@ -83,23 +97,33 @@ begin
|
|
|
83
97
|
# This Marshal load can only happen after requiring Bundler because it will load a custom error class from Bundler
|
|
84
98
|
# itself. If we try to load before requiring, the class will not be defined and loading will fail
|
|
85
99
|
error_path = File.join(".ruby-lsp", "install_error")
|
|
86
|
-
install_error =
|
|
87
|
-
Marshal.load(File.read(error_path))
|
|
100
|
+
install_error = begin
|
|
101
|
+
Marshal.load(File.read(error_path)) if File.exist?(error_path)
|
|
102
|
+
rescue ArgumentError
|
|
103
|
+
# The class we tried to load is not defined. This might happen when the user upgrades Bundler and new error
|
|
104
|
+
# classes are introduced or removed
|
|
105
|
+
File.delete(error_path)
|
|
106
|
+
nil
|
|
88
107
|
end
|
|
89
108
|
|
|
90
109
|
Bundler.setup
|
|
91
110
|
$stderr.puts("Composed Bundle set up successfully")
|
|
92
111
|
end
|
|
93
|
-
rescue Bundler::GemNotFound, Bundler::GitError
|
|
112
|
+
rescue Bundler::GemNotFound, Bundler::GitError => e
|
|
94
113
|
# Sometimes, we successfully set up the bundle, but users either change their Gemfile or uninstall gems from an
|
|
95
114
|
# external process. If there's no install error, but the gem is still not found, then we need to attempt to start from
|
|
96
115
|
# scratch
|
|
97
116
|
unless install_error || ARGV.include?("--retry")
|
|
98
117
|
$stderr.puts("Initial bundle compose succeeded, but Bundler.setup failed. Trying to restart from scratch...")
|
|
99
118
|
File.write(raw_initialize_path, raw_initialize)
|
|
100
|
-
|
|
119
|
+
|
|
120
|
+
Bundler.with_unbundled_env do
|
|
121
|
+
exec(Gem.ruby, __FILE__, *ARGV, "--retry")
|
|
122
|
+
end
|
|
101
123
|
end
|
|
102
124
|
|
|
125
|
+
setup_error = e
|
|
126
|
+
$stderr.puts("Failed to set up composed Bundle\n#{e.full_message}")
|
|
103
127
|
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
|
|
104
128
|
rescue StandardError => e
|
|
105
129
|
setup_error = e
|
|
@@ -120,11 +144,8 @@ end
|
|
|
120
144
|
# Now that the bundle is set up, we can begin actually launching the server. Note that `Bundler.setup` will have already
|
|
121
145
|
# configured the load path using the version of the Ruby LSP present in the composed bundle. Do not push any Ruby LSP
|
|
122
146
|
# paths into the load path manually or we may end up requiring the wrong version of the gem
|
|
123
|
-
require "ruby_lsp/load_sorbet"
|
|
124
147
|
require "ruby_lsp/internal"
|
|
125
148
|
|
|
126
|
-
T::Utils.run_all_sig_blocks
|
|
127
|
-
|
|
128
149
|
if ARGV.include?("--debug")
|
|
129
150
|
if ["x64-mingw-ucrt", "x64-mingw32"].include?(RUBY_PLATFORM)
|
|
130
151
|
$stderr.puts "Debugging is not supported on Windows"
|
|
@@ -138,22 +159,28 @@ if ARGV.include?("--debug")
|
|
|
138
159
|
end
|
|
139
160
|
end
|
|
140
161
|
|
|
141
|
-
# Ensure all output goes out stderr by default to allow puts/p/pp to work without specifying output device.
|
|
142
|
-
$> = $stderr
|
|
143
|
-
|
|
144
162
|
initialize_request = JSON.parse(raw_initialize, symbolize_names: true) if raw_initialize
|
|
145
163
|
|
|
146
164
|
begin
|
|
147
|
-
RubyLsp::Server.new(
|
|
165
|
+
server = RubyLsp::Server.new(
|
|
148
166
|
install_error: install_error,
|
|
149
167
|
setup_error: setup_error,
|
|
150
168
|
initialize_request: initialize_request,
|
|
151
|
-
)
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# Ensure all output goes out stderr by default to allow puts/p/pp to work without specifying output device.
|
|
172
|
+
$> = $stderr
|
|
173
|
+
|
|
174
|
+
server.start
|
|
152
175
|
rescue ArgumentError
|
|
153
176
|
# If the launcher is booting an outdated version of the server, then the initializer doesn't accept a keyword splat
|
|
154
177
|
# and we already read the initialize request from the stdin pipe. In this case, we need to process the initialize
|
|
155
178
|
# request manually and then start the main loop
|
|
156
179
|
server = RubyLsp::Server.new
|
|
180
|
+
|
|
181
|
+
# Ensure all output goes out stderr by default to allow puts/p/pp to work without specifying output device.
|
|
182
|
+
$> = $stderr
|
|
183
|
+
|
|
157
184
|
server.process_message(initialize_request)
|
|
158
185
|
server.start
|
|
159
186
|
end
|
|
@@ -66,7 +66,7 @@ module RubyIndexer
|
|
|
66
66
|
flags = File::FNM_PATHNAME | File::FNM_EXTGLOB
|
|
67
67
|
|
|
68
68
|
uris = @included_patterns.flat_map do |pattern|
|
|
69
|
-
load_path_entry =
|
|
69
|
+
load_path_entry = nil #: String?
|
|
70
70
|
|
|
71
71
|
Dir.glob(File.join(@workspace_path, pattern), flags).map! do |path|
|
|
72
72
|
# All entries for the same pattern match the same $LOAD_PATH entry. Since searching the $LOAD_PATH for every
|
|
@@ -227,7 +227,7 @@ module RubyIndexer
|
|
|
227
227
|
others.uniq!
|
|
228
228
|
others.map!(&:name)
|
|
229
229
|
|
|
230
|
-
excluded.
|
|
230
|
+
transitive_excluded = excluded.each_with_object([]) do |dependency, acc|
|
|
231
231
|
next unless dependency.runtime?
|
|
232
232
|
|
|
233
233
|
spec = dependency.to_spec
|
|
@@ -236,7 +236,7 @@ module RubyIndexer
|
|
|
236
236
|
spec.dependencies.each do |transitive_dependency|
|
|
237
237
|
next if others.include?(transitive_dependency.name)
|
|
238
238
|
|
|
239
|
-
|
|
239
|
+
acc << transitive_dependency
|
|
240
240
|
end
|
|
241
241
|
rescue Gem::MissingSpecError
|
|
242
242
|
# If a gem is scoped only to some specific platform, then its dependencies may not be installed either, but they
|
|
@@ -244,6 +244,7 @@ module RubyIndexer
|
|
|
244
244
|
# just ignore if they're missing
|
|
245
245
|
end
|
|
246
246
|
|
|
247
|
+
excluded.concat(transitive_excluded)
|
|
247
248
|
excluded.uniq!
|
|
248
249
|
excluded.map(&:name)
|
|
249
250
|
rescue Bundler::GemfileNotFound
|
|
@@ -9,7 +9,7 @@ module RubyIndexer
|
|
|
9
9
|
#: Array[String]
|
|
10
10
|
attr_reader :indexing_errors
|
|
11
11
|
|
|
12
|
-
#: (Index index, Prism::Dispatcher dispatcher, Prism::ParseResult parse_result, URI::Generic uri, ?collect_comments: bool) -> void
|
|
12
|
+
#: (Index index, Prism::Dispatcher dispatcher, Prism::ParseLexResult | Prism::ParseResult parse_result, URI::Generic uri, ?collect_comments: bool) -> void
|
|
13
13
|
def initialize(index, dispatcher, parse_result, uri, collect_comments: false)
|
|
14
14
|
@index = index
|
|
15
15
|
@uri = uri
|
|
@@ -132,7 +132,7 @@ module RubyIndexer
|
|
|
132
132
|
name = (expression.is_a?(Prism::SelfNode) ? "<Class:#{last_name_in_stack}>" : "<Class:#{expression.slice}>")
|
|
133
133
|
real_nesting = Index.actual_nesting(@stack, name)
|
|
134
134
|
|
|
135
|
-
existing_entries =
|
|
135
|
+
existing_entries = @index[real_nesting.join("::")] #: as Array[Entry::SingletonClass]?
|
|
136
136
|
|
|
137
137
|
if existing_entries
|
|
138
138
|
entry = existing_entries.first #: as !nil
|
|
@@ -143,6 +143,7 @@ module RubyIndexer
|
|
|
143
143
|
)
|
|
144
144
|
else
|
|
145
145
|
entry = Entry::SingletonClass.new(
|
|
146
|
+
@index.configuration,
|
|
146
147
|
real_nesting,
|
|
147
148
|
@uri,
|
|
148
149
|
Location.from_prism_location(node.location, @code_units_cache),
|
|
@@ -260,16 +261,19 @@ module RubyIndexer
|
|
|
260
261
|
handle_attribute(node, reader: false, writer: true)
|
|
261
262
|
when :attr_accessor
|
|
262
263
|
handle_attribute(node, reader: true, writer: true)
|
|
264
|
+
when :attr
|
|
265
|
+
has_writer = node.arguments&.arguments&.last&.is_a?(Prism::TrueNode) || false
|
|
266
|
+
handle_attribute(node, reader: true, writer: has_writer)
|
|
263
267
|
when :alias_method
|
|
264
268
|
handle_alias_method(node)
|
|
265
269
|
when :include, :prepend, :extend
|
|
266
270
|
handle_module_operation(node, message)
|
|
267
271
|
when :public
|
|
268
|
-
handle_visibility_change(node,
|
|
272
|
+
handle_visibility_change(node, :public)
|
|
269
273
|
when :protected
|
|
270
|
-
handle_visibility_change(node,
|
|
274
|
+
handle_visibility_change(node, :protected)
|
|
271
275
|
when :private
|
|
272
|
-
handle_visibility_change(node,
|
|
276
|
+
handle_visibility_change(node, :private)
|
|
273
277
|
when :module_function
|
|
274
278
|
handle_module_function(node)
|
|
275
279
|
when :private_class_method
|
|
@@ -323,6 +327,7 @@ module RubyIndexer
|
|
|
323
327
|
signatures = [Entry::Signature.new(list_params(node.parameters))]
|
|
324
328
|
|
|
325
329
|
@index.add(Entry::Method.new(
|
|
330
|
+
@index.configuration,
|
|
326
331
|
method_name,
|
|
327
332
|
@uri,
|
|
328
333
|
location,
|
|
@@ -337,13 +342,14 @@ module RubyIndexer
|
|
|
337
342
|
singleton = @index.existing_or_new_singleton_class(owner.name)
|
|
338
343
|
|
|
339
344
|
@index.add(Entry::Method.new(
|
|
345
|
+
@index.configuration,
|
|
340
346
|
method_name,
|
|
341
347
|
@uri,
|
|
342
348
|
location,
|
|
343
349
|
name_location,
|
|
344
350
|
comments,
|
|
345
351
|
signatures,
|
|
346
|
-
|
|
352
|
+
:public,
|
|
347
353
|
singleton,
|
|
348
354
|
))
|
|
349
355
|
end
|
|
@@ -351,6 +357,7 @@ module RubyIndexer
|
|
|
351
357
|
singleton = @index.existing_or_new_singleton_class(owner.name)
|
|
352
358
|
|
|
353
359
|
@index.add(Entry::Method.new(
|
|
360
|
+
@index.configuration,
|
|
354
361
|
method_name,
|
|
355
362
|
@uri,
|
|
356
363
|
Location.from_prism_location(node.location, @code_units_cache),
|
|
@@ -430,6 +437,7 @@ module RubyIndexer
|
|
|
430
437
|
comments = collect_comments(node)
|
|
431
438
|
@index.add(
|
|
432
439
|
Entry::UnresolvedMethodAlias.new(
|
|
440
|
+
@index.configuration,
|
|
433
441
|
method_name,
|
|
434
442
|
node.old_name.slice,
|
|
435
443
|
@owner_stack.last,
|
|
@@ -465,11 +473,12 @@ module RubyIndexer
|
|
|
465
473
|
handle_class_variable(node, node.name_loc)
|
|
466
474
|
end
|
|
467
475
|
|
|
468
|
-
#: (String name, Prism::Location node_location, Array[Entry::Signature] signatures, ?visibility:
|
|
469
|
-
def add_method(name, node_location, signatures, visibility:
|
|
476
|
+
#: (String name, Prism::Location node_location, Array[Entry::Signature] signatures, ?visibility: Symbol, ?comments: String?) -> void
|
|
477
|
+
def add_method(name, node_location, signatures, visibility: :public, comments: nil)
|
|
470
478
|
location = Location.from_prism_location(node_location, @code_units_cache)
|
|
471
479
|
|
|
472
480
|
@index.add(Entry::Method.new(
|
|
481
|
+
@index.configuration,
|
|
473
482
|
name,
|
|
474
483
|
@uri,
|
|
475
484
|
location,
|
|
@@ -487,6 +496,7 @@ module RubyIndexer
|
|
|
487
496
|
name_loc = Location.from_prism_location(name_location, @code_units_cache)
|
|
488
497
|
|
|
489
498
|
entry = Entry::Module.new(
|
|
499
|
+
@index.configuration,
|
|
490
500
|
Index.actual_nesting(@stack, name),
|
|
491
501
|
@uri,
|
|
492
502
|
location,
|
|
@@ -501,6 +511,7 @@ module RubyIndexer
|
|
|
501
511
|
def add_class(name_or_nesting, full_location, name_location, parent_class_name: nil, comments: nil)
|
|
502
512
|
nesting = name_or_nesting.is_a?(Array) ? name_or_nesting : Index.actual_nesting(@stack, name_or_nesting)
|
|
503
513
|
entry = Entry::Class.new(
|
|
514
|
+
@index.configuration,
|
|
504
515
|
nesting,
|
|
505
516
|
@uri,
|
|
506
517
|
Location.from_prism_location(full_location, @code_units_cache),
|
|
@@ -545,6 +556,7 @@ module RubyIndexer
|
|
|
545
556
|
comments = collect_comments(node)
|
|
546
557
|
|
|
547
558
|
@index.add(Entry::GlobalVariable.new(
|
|
559
|
+
@index.configuration,
|
|
548
560
|
name,
|
|
549
561
|
@uri,
|
|
550
562
|
Location.from_prism_location(loc, @code_units_cache),
|
|
@@ -569,6 +581,7 @@ module RubyIndexer
|
|
|
569
581
|
end
|
|
570
582
|
|
|
571
583
|
@index.add(Entry::ClassVariable.new(
|
|
584
|
+
@index.configuration,
|
|
572
585
|
name,
|
|
573
586
|
@uri,
|
|
574
587
|
Location.from_prism_location(loc, @code_units_cache),
|
|
@@ -591,6 +604,7 @@ module RubyIndexer
|
|
|
591
604
|
end
|
|
592
605
|
|
|
593
606
|
@index.add(Entry::InstanceVariable.new(
|
|
607
|
+
@index.configuration,
|
|
594
608
|
name,
|
|
595
609
|
@uri,
|
|
596
610
|
Location.from_prism_location(loc, @code_units_cache),
|
|
@@ -621,7 +635,7 @@ module RubyIndexer
|
|
|
621
635
|
# The private_constant method does not resolve the constant name. It always points to a constant that needs to
|
|
622
636
|
# exist in the current namespace
|
|
623
637
|
entries = @index[fully_qualify_name(name)]
|
|
624
|
-
entries&.each { |entry| entry.visibility =
|
|
638
|
+
entries&.each { |entry| entry.visibility = :private }
|
|
625
639
|
end
|
|
626
640
|
|
|
627
641
|
#: (Prism::CallNode node) -> void
|
|
@@ -653,6 +667,7 @@ module RubyIndexer
|
|
|
653
667
|
comments = collect_comments(node)
|
|
654
668
|
@index.add(
|
|
655
669
|
Entry::UnresolvedMethodAlias.new(
|
|
670
|
+
@index.configuration,
|
|
656
671
|
new_name_value,
|
|
657
672
|
old_name_value,
|
|
658
673
|
@owner_stack.last,
|
|
@@ -672,6 +687,7 @@ module RubyIndexer
|
|
|
672
687
|
case value
|
|
673
688
|
when Prism::ConstantReadNode, Prism::ConstantPathNode
|
|
674
689
|
Entry::UnresolvedConstantAlias.new(
|
|
690
|
+
@index.configuration,
|
|
675
691
|
value.slice,
|
|
676
692
|
@stack.dup,
|
|
677
693
|
name,
|
|
@@ -685,6 +701,7 @@ module RubyIndexer
|
|
|
685
701
|
# If the right hand side is another constant assignment, we need to visit it because that constant has to be
|
|
686
702
|
# indexed too
|
|
687
703
|
Entry::UnresolvedConstantAlias.new(
|
|
704
|
+
@index.configuration,
|
|
688
705
|
value.name.to_s,
|
|
689
706
|
@stack.dup,
|
|
690
707
|
name,
|
|
@@ -696,6 +713,7 @@ module RubyIndexer
|
|
|
696
713
|
Prism::ConstantPathAndWriteNode
|
|
697
714
|
|
|
698
715
|
Entry::UnresolvedConstantAlias.new(
|
|
716
|
+
@index.configuration,
|
|
699
717
|
value.target.slice,
|
|
700
718
|
@stack.dup,
|
|
701
719
|
name,
|
|
@@ -705,6 +723,7 @@ module RubyIndexer
|
|
|
705
723
|
)
|
|
706
724
|
else
|
|
707
725
|
Entry::Constant.new(
|
|
726
|
+
@index.configuration,
|
|
708
727
|
name,
|
|
709
728
|
@uri,
|
|
710
729
|
Location.from_prism_location(node.location, @code_units_cache),
|
|
@@ -726,6 +745,9 @@ module RubyIndexer
|
|
|
726
745
|
comment = @comments_by_line[line]
|
|
727
746
|
break unless comment
|
|
728
747
|
|
|
748
|
+
# a trailing comment from a previous line is not a comment for this node
|
|
749
|
+
break if comment.trailing?
|
|
750
|
+
|
|
729
751
|
comment_content = comment.location.slice
|
|
730
752
|
|
|
731
753
|
# invalid encodings would raise an "invalid byte sequence" exception
|
|
@@ -779,6 +801,7 @@ module RubyIndexer
|
|
|
779
801
|
|
|
780
802
|
if reader
|
|
781
803
|
@index.add(Entry::Accessor.new(
|
|
804
|
+
@index.configuration,
|
|
782
805
|
name,
|
|
783
806
|
@uri,
|
|
784
807
|
Location.from_prism_location(loc, @code_units_cache),
|
|
@@ -791,6 +814,7 @@ module RubyIndexer
|
|
|
791
814
|
next unless writer
|
|
792
815
|
|
|
793
816
|
@index.add(Entry::Accessor.new(
|
|
817
|
+
@index.configuration,
|
|
794
818
|
"#{name}=",
|
|
795
819
|
@uri,
|
|
796
820
|
Location.from_prism_location(loc, @code_units_cache),
|
|
@@ -868,18 +892,19 @@ module RubyIndexer
|
|
|
868
892
|
entry_owner_name = entry.owner&.name
|
|
869
893
|
next unless entry_owner_name
|
|
870
894
|
|
|
871
|
-
entry.visibility =
|
|
895
|
+
entry.visibility = :private
|
|
872
896
|
|
|
873
897
|
singleton = @index.existing_or_new_singleton_class(entry_owner_name)
|
|
874
898
|
location = Location.from_prism_location(argument.location, @code_units_cache)
|
|
875
899
|
@index.add(Entry::Method.new(
|
|
900
|
+
@index.configuration,
|
|
876
901
|
method_name,
|
|
877
902
|
@uri,
|
|
878
903
|
location,
|
|
879
904
|
location,
|
|
880
905
|
collect_comments(node)&.concat(entry.comments),
|
|
881
906
|
entry.signatures,
|
|
882
|
-
|
|
907
|
+
:public,
|
|
883
908
|
singleton,
|
|
884
909
|
))
|
|
885
910
|
end
|
|
@@ -894,7 +919,7 @@ module RubyIndexer
|
|
|
894
919
|
# If we're passing a method definition directly to `private_class_method`, push a new private scope. That will be
|
|
895
920
|
# applied when the indexer finds the method definition and then popped on `call_node_leave`
|
|
896
921
|
if arguments.first.is_a?(Prism::DefNode)
|
|
897
|
-
@visibility_stack.push(VisibilityScope.new(visibility:
|
|
922
|
+
@visibility_stack.push(VisibilityScope.new(visibility: :private))
|
|
898
923
|
return
|
|
899
924
|
end
|
|
900
925
|
|
|
@@ -903,10 +928,9 @@ module RubyIndexer
|
|
|
903
928
|
|
|
904
929
|
# private_class_method accepts strings, symbols or arrays of strings and symbols as arguments. Here we build a
|
|
905
930
|
# single list of all of the method names that have to be made private
|
|
906
|
-
arrays, others =
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
)
|
|
931
|
+
arrays, others = arguments.partition do |argument|
|
|
932
|
+
argument.is_a?(Prism::ArrayNode)
|
|
933
|
+
end #: as [Array[Prism::ArrayNode], Array[Prism::Node]]
|
|
910
934
|
arrays.each { |array| others.concat(array.elements) }
|
|
911
935
|
|
|
912
936
|
names = others.filter_map do |argument|
|
|
@@ -922,9 +946,7 @@ module RubyIndexer
|
|
|
922
946
|
entries = @index.resolve_method(name, @index.existing_or_new_singleton_class(owner_name).name)
|
|
923
947
|
next unless entries
|
|
924
948
|
|
|
925
|
-
entries.each
|
|
926
|
-
entry.visibility = Entry::Visibility::PRIVATE
|
|
927
|
-
end
|
|
949
|
+
entries.each { |entry| entry.visibility = :private }
|
|
928
950
|
end
|
|
929
951
|
end
|
|
930
952
|
|
|
@@ -1038,7 +1060,7 @@ module RubyIndexer
|
|
|
1038
1060
|
name.split("::").last
|
|
1039
1061
|
end
|
|
1040
1062
|
|
|
1041
|
-
#: (Prism::CallNode,
|
|
1063
|
+
#: (Prism::CallNode, Symbol) -> void
|
|
1042
1064
|
def handle_visibility_change(node, visibility)
|
|
1043
1065
|
owner = @owner_stack.last
|
|
1044
1066
|
return unless owner
|
|
@@ -2,17 +2,11 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
module RubyIndexer
|
|
5
|
+
# @abstract
|
|
5
6
|
class Enhancement
|
|
6
|
-
extend T::Sig
|
|
7
|
-
extend T::Helpers
|
|
8
|
-
|
|
9
|
-
abstract!
|
|
10
|
-
|
|
11
7
|
@enhancements = [] #: Array[Class[Enhancement]]
|
|
12
8
|
|
|
13
9
|
class << self
|
|
14
|
-
extend T::Sig
|
|
15
|
-
|
|
16
10
|
#: (Class[Enhancement] child) -> void
|
|
17
11
|
def inherited(child)
|
|
18
12
|
@enhancements << child
|