ruby-lsp 0.17.2 → 0.17.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/VERSION +1 -1
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +56 -0
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +28 -0
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +156 -40
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +99 -0
- data/lib/ruby_indexer/ruby_indexer.rb +1 -0
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +3 -2
- data/lib/ruby_indexer/test/configuration_test.rb +1 -1
- data/lib/ruby_indexer/test/constant_test.rb +1 -1
- data/lib/ruby_indexer/test/index_test.rb +388 -56
- data/lib/ruby_indexer/test/method_test.rb +20 -0
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +42 -0
- data/lib/ruby_indexer/test/test_case.rb +7 -0
- data/lib/ruby_lsp/global_state.rb +37 -16
- data/lib/ruby_lsp/internal.rb +1 -0
- data/lib/ruby_lsp/listeners/code_lens.rb +2 -2
- data/lib/ruby_lsp/server.rb +11 -0
- metadata +26 -4
@@ -54,18 +54,19 @@ module RubyLsp
|
|
54
54
|
|
55
55
|
sig { params(options: T::Hash[Symbol, T.untyped]).void }
|
56
56
|
def apply_options(options)
|
57
|
-
|
57
|
+
direct_dependencies = gather_direct_dependencies
|
58
|
+
all_dependencies = gather_direct_and_indirect_dependencies
|
58
59
|
workspace_uri = options.dig(:workspaceFolders, 0, :uri)
|
59
60
|
@workspace_uri = URI(workspace_uri) if workspace_uri
|
60
61
|
|
61
62
|
specified_formatter = options.dig(:initializationOptions, :formatter)
|
62
63
|
@formatter = specified_formatter if specified_formatter
|
63
|
-
@formatter = detect_formatter(
|
64
|
+
@formatter = detect_formatter(direct_dependencies, all_dependencies) if @formatter == "auto"
|
64
65
|
|
65
66
|
specified_linters = options.dig(:initializationOptions, :linters)
|
66
|
-
@linters = specified_linters || detect_linters(
|
67
|
-
@test_library = detect_test_library(
|
68
|
-
@typechecker = detect_typechecker(
|
67
|
+
@linters = specified_linters || detect_linters(direct_dependencies)
|
68
|
+
@test_library = detect_test_library(direct_dependencies)
|
69
|
+
@typechecker = detect_typechecker(direct_dependencies)
|
69
70
|
|
70
71
|
encodings = options.dig(:capabilities, :general, :positionEncodings)
|
71
72
|
@encoding = if !encodings || encodings.empty?
|
@@ -103,16 +104,18 @@ module RubyLsp
|
|
103
104
|
|
104
105
|
private
|
105
106
|
|
106
|
-
sig { params(
|
107
|
-
def detect_formatter(
|
107
|
+
sig { params(direct_dependencies: T::Array[String], all_dependencies: T::Array[String]).returns(String) }
|
108
|
+
def detect_formatter(direct_dependencies, all_dependencies)
|
108
109
|
# NOTE: Intentionally no $ at end, since we want to match rubocop-shopify, etc.
|
109
|
-
if
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
110
|
+
return "rubocop" if direct_dependencies.any?(/^rubocop/)
|
111
|
+
|
112
|
+
syntax_tree_is_direct_dependency = direct_dependencies.include?("syntax_tree")
|
113
|
+
return "syntax_tree" if syntax_tree_is_direct_dependency
|
114
|
+
|
115
|
+
rubocop_is_transitive_dependency = all_dependencies.include?("rubocop")
|
116
|
+
return "rubocop" if dot_rubocop_yml_present && rubocop_is_transitive_dependency
|
117
|
+
|
118
|
+
"none"
|
116
119
|
end
|
117
120
|
|
118
121
|
# Try to detect if there are linters in the project's dependencies. For auto-detection, we always only consider a
|
@@ -132,7 +135,7 @@ module RubyLsp
|
|
132
135
|
# by ruby-lsp-rails. A Rails app doesn't need to depend on the rails gem itself, individual components like
|
133
136
|
# activestorage may be added to the gemfile so that other components aren't downloaded. Check for the presence
|
134
137
|
# of bin/rails to support these cases.
|
135
|
-
elsif
|
138
|
+
elsif bin_rails_present
|
136
139
|
"rails"
|
137
140
|
# NOTE: Intentionally ends with $ to avoid mis-matching minitest-reporters, etc. in a Rails app.
|
138
141
|
elsif dependencies.any?(/^minitest$/)
|
@@ -162,8 +165,18 @@ module RubyLsp
|
|
162
165
|
false
|
163
166
|
end
|
164
167
|
|
168
|
+
sig { returns(T::Boolean) }
|
169
|
+
def bin_rails_present
|
170
|
+
File.exist?(File.join(workspace_path, "bin/rails"))
|
171
|
+
end
|
172
|
+
|
173
|
+
sig { returns(T::Boolean) }
|
174
|
+
def dot_rubocop_yml_present
|
175
|
+
File.exist?(File.join(workspace_path, ".rubocop.yml"))
|
176
|
+
end
|
177
|
+
|
165
178
|
sig { returns(T::Array[String]) }
|
166
|
-
def
|
179
|
+
def gather_direct_dependencies
|
167
180
|
Bundler.with_original_env { Bundler.default_gemfile }
|
168
181
|
Bundler.locked_gems.dependencies.keys + gemspec_dependencies
|
169
182
|
rescue Bundler::GemfileNotFound
|
@@ -176,5 +189,13 @@ module RubyLsp
|
|
176
189
|
.grep(Bundler::Source::Gemspec)
|
177
190
|
.flat_map { _1.gemspec&.dependencies&.map(&:name) }
|
178
191
|
end
|
192
|
+
|
193
|
+
sig { returns(T::Array[String]) }
|
194
|
+
def gather_direct_and_indirect_dependencies
|
195
|
+
Bundler.with_original_env { Bundler.default_gemfile }
|
196
|
+
Bundler.locked_gems.specs.map(&:name)
|
197
|
+
rescue Bundler::GemfileNotFound
|
198
|
+
[]
|
199
|
+
end
|
179
200
|
end
|
180
201
|
end
|
data/lib/ruby_lsp/internal.rb
CHANGED
@@ -236,7 +236,7 @@ module RubyLsp
|
|
236
236
|
# so there must be something to the left of the available path.
|
237
237
|
group_stack = T.must(group_stack[last_dynamic_reference_index + 1..])
|
238
238
|
if method_name
|
239
|
-
" --name " + "/::#{Shellwords.escape(group_stack.join("::") + "#" + method_name)}$/"
|
239
|
+
" --name " + "/::#{Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)}$/"
|
240
240
|
else
|
241
241
|
# When clicking on a CodeLens for `Test`, `(#|::)` will match all tests
|
242
242
|
# that are registered on the class itself (matches after `#`) and all tests
|
@@ -245,7 +245,7 @@ module RubyLsp
|
|
245
245
|
end
|
246
246
|
elsif method_name
|
247
247
|
# We know the entire path, do an exact match
|
248
|
-
" --name " + Shellwords.escape(group_stack.join("::") + "#" + method_name)
|
248
|
+
" --name " + Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)
|
249
249
|
elsif spec_name
|
250
250
|
" --name " + "/#{Shellwords.escape(spec_name)}/"
|
251
251
|
else
|
data/lib/ruby_lsp/server.rb
CHANGED
@@ -690,6 +690,17 @@ module RubyLsp
|
|
690
690
|
|
691
691
|
sig { params(config_hash: T::Hash[String, T.untyped]).void }
|
692
692
|
def perform_initial_indexing(config_hash)
|
693
|
+
index_ruby_core
|
694
|
+
index_ruby_code(config_hash)
|
695
|
+
end
|
696
|
+
|
697
|
+
sig { void }
|
698
|
+
def index_ruby_core
|
699
|
+
RubyIndexer::RBSIndexer.new(@global_state.index).index_ruby_core
|
700
|
+
end
|
701
|
+
|
702
|
+
sig { params(config_hash: T::Hash[String, T.untyped]).void }
|
703
|
+
def index_ruby_code(config_hash)
|
693
704
|
# The begin progress invocation happens during `initialize`, so that the notification is sent before we are
|
694
705
|
# stuck indexing files
|
695
706
|
RubyIndexer.configuration.apply_config(config_hash)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lsp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.17.
|
4
|
+
version: 0.17.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: language_server-protocol
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: 0.29.0
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '0.
|
36
|
+
version: '0.31'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,27 @@ dependencies:
|
|
43
43
|
version: 0.29.0
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0.
|
46
|
+
version: '0.31'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rbs
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '4'
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '4'
|
47
67
|
- !ruby/object:Gem::Dependency
|
48
68
|
name: sorbet-runtime
|
49
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,6 +105,7 @@ files:
|
|
85
105
|
- lib/ruby_indexer/lib/ruby_indexer/indexable_path.rb
|
86
106
|
- lib/ruby_indexer/lib/ruby_indexer/location.rb
|
87
107
|
- lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb
|
108
|
+
- lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb
|
88
109
|
- lib/ruby_indexer/ruby_indexer.rb
|
89
110
|
- lib/ruby_indexer/test/classes_and_modules_test.rb
|
90
111
|
- lib/ruby_indexer/test/configuration_test.rb
|
@@ -93,6 +114,7 @@ files:
|
|
93
114
|
- lib/ruby_indexer/test/instance_variables_test.rb
|
94
115
|
- lib/ruby_indexer/test/method_test.rb
|
95
116
|
- lib/ruby_indexer/test/prefix_tree_test.rb
|
117
|
+
- lib/ruby_indexer/test/rbs_indexer_test.rb
|
96
118
|
- lib/ruby_indexer/test/test_case.rb
|
97
119
|
- lib/ruby_lsp/addon.rb
|
98
120
|
- lib/ruby_lsp/base_server.rb
|