ruby-lsp 0.18.1 → 0.18.2
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 +0 -7
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +105 -4
- data/lib/ruby_indexer/test/index_test.rb +68 -0
- data/lib/ruby_lsp/internal.rb +41 -2
- data/lib/ruby_lsp/listeners/completion.rb +20 -6
- data/lib/ruby_lsp/listeners/inlay_hints.rb +1 -16
- data/lib/ruby_lsp/requests/completion_resolve.rb +2 -2
- data/lib/ruby_lsp/requests/inlay_hints.rb +2 -5
- data/lib/ruby_lsp/server.rb +22 -3
- data/lib/ruby_lsp/setup_bundler.rb +3 -3
- metadata +2 -4
- data/lib/ruby_lsp/requests.rb +0 -64
- data/lib/ruby_lsp/response_builders.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d78954c10106529d35716e266769c1ddf6bf8235d7441c881aaa2f06cb757956
|
4
|
+
data.tar.gz: 14a40cc3212ce2c90ad23f099b44b0a8aa75a0cf40445b6b2a9b74048cb18794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2320f897c2895afa3cd710c10f5bc5bf238c9a53eb39a38071887cd475198fd4c6f60020d71d62405579ff3ebe5ea0bd9b1d8e02599d5107b35ca6fe17789397
|
7
|
+
data.tar.gz: 8e31ed714b473b46791dda5c3e83e68d4e0756dc2980f0e6c34b8652337278a928e104566be12a933ffae1525533b8935651c45580b07f95cab4ac732965a348
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.18.
|
1
|
+
0.18.2
|
data/exe/ruby-lsp
CHANGED
@@ -29,13 +29,6 @@ parser = OptionParser.new do |opts|
|
|
29
29
|
options[:branch] = branch
|
30
30
|
end
|
31
31
|
|
32
|
-
opts.on(
|
33
|
-
"--experimental",
|
34
|
-
"Run pre-release versions of the Ruby LSP",
|
35
|
-
) do
|
36
|
-
options[:experimental] = true
|
37
|
-
end
|
38
|
-
|
39
32
|
opts.on("--doctor", "Run troubleshooting steps") do
|
40
33
|
options[:doctor] = true
|
41
34
|
end
|
@@ -242,6 +242,64 @@ module RubyIndexer
|
|
242
242
|
completion_items.values.map!(&:first)
|
243
243
|
end
|
244
244
|
|
245
|
+
sig do
|
246
|
+
params(
|
247
|
+
name: String,
|
248
|
+
nesting: T::Array[String],
|
249
|
+
).returns(T::Array[T::Array[T.any(
|
250
|
+
Entry::Constant,
|
251
|
+
Entry::ConstantAlias,
|
252
|
+
Entry::Namespace,
|
253
|
+
Entry::UnresolvedConstantAlias,
|
254
|
+
)]])
|
255
|
+
end
|
256
|
+
def constant_completion_candidates(name, nesting)
|
257
|
+
# If we have a top level reference, then we don't need to include completions inside the current nesting
|
258
|
+
if name.start_with?("::")
|
259
|
+
return T.cast(
|
260
|
+
@entries_tree.search(name.delete_prefix("::")),
|
261
|
+
T::Array[T::Array[T.any(
|
262
|
+
Entry::Constant,
|
263
|
+
Entry::ConstantAlias,
|
264
|
+
Entry::Namespace,
|
265
|
+
Entry::UnresolvedConstantAlias,
|
266
|
+
)]],
|
267
|
+
)
|
268
|
+
end
|
269
|
+
|
270
|
+
# Otherwise, we have to include every possible constant the user might be referring to. This is essentially the
|
271
|
+
# same algorithm as resolve, but instead of returning early we concatenate all unique results
|
272
|
+
|
273
|
+
# Direct constants inside this namespace
|
274
|
+
entries = @entries_tree.search(nesting.any? ? "#{nesting.join("::")}::#{name}" : name)
|
275
|
+
|
276
|
+
# Constants defined in enclosing scopes
|
277
|
+
nesting.length.downto(1) do |i|
|
278
|
+
namespace = T.must(nesting[0...i]).join("::")
|
279
|
+
entries.concat(@entries_tree.search("#{namespace}::#{name}"))
|
280
|
+
end
|
281
|
+
|
282
|
+
# Inherited constants
|
283
|
+
if name.end_with?("::")
|
284
|
+
entries.concat(inherited_constant_completion_candidates(nil, nesting + [name]))
|
285
|
+
else
|
286
|
+
entries.concat(inherited_constant_completion_candidates(name, nesting))
|
287
|
+
end
|
288
|
+
|
289
|
+
# Top level constants
|
290
|
+
entries.concat(@entries_tree.search(name))
|
291
|
+
entries.uniq!
|
292
|
+
T.cast(
|
293
|
+
entries,
|
294
|
+
T::Array[T::Array[T.any(
|
295
|
+
Entry::Constant,
|
296
|
+
Entry::ConstantAlias,
|
297
|
+
Entry::Namespace,
|
298
|
+
Entry::UnresolvedConstantAlias,
|
299
|
+
)]],
|
300
|
+
)
|
301
|
+
end
|
302
|
+
|
245
303
|
# Resolve a constant to its declaration based on its name and the nesting where the reference was found. Parameter
|
246
304
|
# documentation:
|
247
305
|
#
|
@@ -365,12 +423,10 @@ module RubyIndexer
|
|
365
423
|
# aliases, so we have to invoke `follow_aliased_namespace` again to check until we only return a real name
|
366
424
|
sig { params(name: String, seen_names: T::Array[String]).returns(String) }
|
367
425
|
def follow_aliased_namespace(name, seen_names = [])
|
368
|
-
return name if @entries[name]
|
369
|
-
|
370
426
|
parts = name.split("::")
|
371
427
|
real_parts = []
|
372
428
|
|
373
|
-
(parts.length - 1).downto(0)
|
429
|
+
(parts.length - 1).downto(0) do |i|
|
374
430
|
current_name = T.must(parts[0..i]).join("::")
|
375
431
|
entry = @entries[current_name]&.first
|
376
432
|
|
@@ -824,7 +880,7 @@ module RubyIndexer
|
|
824
880
|
)]))
|
825
881
|
end
|
826
882
|
def lookup_enclosing_scopes(name, nesting, seen_names)
|
827
|
-
nesting.length.downto(1)
|
883
|
+
nesting.length.downto(1) do |i|
|
828
884
|
namespace = T.must(nesting[0...i]).join("::")
|
829
885
|
|
830
886
|
# If we find an entry with `full_name` directly, then we can already return it, even if it contains aliases -
|
@@ -871,6 +927,51 @@ module RubyIndexer
|
|
871
927
|
nil
|
872
928
|
end
|
873
929
|
|
930
|
+
sig do
|
931
|
+
params(
|
932
|
+
name: T.nilable(String),
|
933
|
+
nesting: T::Array[String],
|
934
|
+
).returns(T::Array[T::Array[T.any(
|
935
|
+
Entry::Namespace,
|
936
|
+
Entry::ConstantAlias,
|
937
|
+
Entry::UnresolvedConstantAlias,
|
938
|
+
Entry::Constant,
|
939
|
+
)]])
|
940
|
+
end
|
941
|
+
def inherited_constant_completion_candidates(name, nesting)
|
942
|
+
namespace_entries = if name
|
943
|
+
*nesting_parts, constant_name = build_non_redundant_full_name(name, nesting).split("::")
|
944
|
+
return [] if nesting_parts.empty?
|
945
|
+
|
946
|
+
resolve(nesting_parts.join("::"), [])
|
947
|
+
else
|
948
|
+
resolve(nesting.join("::"), [])
|
949
|
+
end
|
950
|
+
return [] unless namespace_entries
|
951
|
+
|
952
|
+
ancestors = linearized_ancestors_of(T.must(namespace_entries.first).name)
|
953
|
+
candidates = ancestors.flat_map do |ancestor_name|
|
954
|
+
@entries_tree.search("#{ancestor_name}::#{constant_name}")
|
955
|
+
end
|
956
|
+
|
957
|
+
# For candidates with the same name, we must only show the first entry in the inheritance chain, since that's the
|
958
|
+
# one the user will be referring to in completion
|
959
|
+
completion_items = candidates.each_with_object({}) do |entries, hash|
|
960
|
+
*parts, short_name = T.must(entries.first).name.split("::")
|
961
|
+
namespace_name = parts.join("::")
|
962
|
+
ancestor_index = ancestors.index(namespace_name)
|
963
|
+
existing_entry, existing_entry_index = hash[short_name]
|
964
|
+
|
965
|
+
next unless ancestor_index && (!existing_entry || ancestor_index < existing_entry_index)
|
966
|
+
|
967
|
+
hash[short_name] = [entries, ancestor_index]
|
968
|
+
end
|
969
|
+
|
970
|
+
completion_items.values.map!(&:first)
|
971
|
+
rescue NonExistingNamespaceError
|
972
|
+
[]
|
973
|
+
end
|
974
|
+
|
874
975
|
# Removes redudancy from a constant reference's full name. For example, if we find a reference to `A::B::Foo` inside
|
875
976
|
# of the ["A", "B"] nesting, then we should not concatenate the nesting with the name or else we'll end up with
|
876
977
|
# `A::B::A::B::Foo`. This method will remove any redundant parts from the final name based on the reference and the
|
@@ -1863,5 +1863,73 @@ module RubyIndexer
|
|
1863
1863
|
def test_entries_for_returns_nil_if_no_matches
|
1864
1864
|
assert_nil(@index.entries_for("non_existing_file.rb", Entry::Namespace))
|
1865
1865
|
end
|
1866
|
+
|
1867
|
+
def test_constant_completion_candidates_all_possible_constants
|
1868
|
+
index(<<~RUBY)
|
1869
|
+
XQRK = 3
|
1870
|
+
|
1871
|
+
module Bar
|
1872
|
+
XQRK = 2
|
1873
|
+
end
|
1874
|
+
|
1875
|
+
module Foo
|
1876
|
+
XQRK = 1
|
1877
|
+
end
|
1878
|
+
|
1879
|
+
module Namespace
|
1880
|
+
XQRK = 0
|
1881
|
+
|
1882
|
+
class Baz
|
1883
|
+
include Foo
|
1884
|
+
include Bar
|
1885
|
+
end
|
1886
|
+
end
|
1887
|
+
RUBY
|
1888
|
+
|
1889
|
+
result = @index.constant_completion_candidates("X", ["Namespace", "Baz"])
|
1890
|
+
|
1891
|
+
result.each do |entries|
|
1892
|
+
name = entries.first.name
|
1893
|
+
assert(entries.all? { |e| e.name == name })
|
1894
|
+
end
|
1895
|
+
|
1896
|
+
assert_equal(["Namespace::XQRK", "Bar::XQRK", "XQRK"], result.map { |entries| entries.first.name })
|
1897
|
+
|
1898
|
+
result = @index.constant_completion_candidates("::X", ["Namespace", "Baz"])
|
1899
|
+
assert_equal(["XQRK"], result.map { |entries| entries.first.name })
|
1900
|
+
end
|
1901
|
+
|
1902
|
+
def test_constant_completion_candidates_for_empty_name
|
1903
|
+
index(<<~RUBY)
|
1904
|
+
module Foo
|
1905
|
+
Bar = 1
|
1906
|
+
end
|
1907
|
+
|
1908
|
+
class Baz
|
1909
|
+
include Foo
|
1910
|
+
end
|
1911
|
+
RUBY
|
1912
|
+
|
1913
|
+
result = @index.constant_completion_candidates("Baz::", [])
|
1914
|
+
assert_includes(result.map { |entries| entries.first.name }, "Foo::Bar")
|
1915
|
+
end
|
1916
|
+
|
1917
|
+
def test_follow_alias_namespace
|
1918
|
+
index(<<~RUBY)
|
1919
|
+
module First
|
1920
|
+
module Second
|
1921
|
+
class Foo
|
1922
|
+
end
|
1923
|
+
end
|
1924
|
+
end
|
1925
|
+
|
1926
|
+
module Namespace
|
1927
|
+
Second = First::Second
|
1928
|
+
end
|
1929
|
+
RUBY
|
1930
|
+
|
1931
|
+
real_namespace = @index.follow_aliased_namespace("Namespace::Second")
|
1932
|
+
assert_equal("First::Second", real_namespace)
|
1933
|
+
end
|
1866
1934
|
end
|
1867
1935
|
end
|
data/lib/ruby_lsp/internal.rb
CHANGED
@@ -30,8 +30,6 @@ require "ruby_lsp/parameter_scope"
|
|
30
30
|
require "ruby_lsp/global_state"
|
31
31
|
require "ruby_lsp/server"
|
32
32
|
require "ruby_lsp/type_inferrer"
|
33
|
-
require "ruby_lsp/requests"
|
34
|
-
require "ruby_lsp/response_builders"
|
35
33
|
require "ruby_lsp/node_context"
|
36
34
|
require "ruby_lsp/document"
|
37
35
|
require "ruby_lsp/ruby_document"
|
@@ -39,6 +37,47 @@ require "ruby_lsp/erb_document"
|
|
39
37
|
require "ruby_lsp/rbs_document"
|
40
38
|
require "ruby_lsp/store"
|
41
39
|
require "ruby_lsp/addon"
|
40
|
+
|
41
|
+
# Response builders
|
42
|
+
require "ruby_lsp/response_builders/response_builder"
|
43
|
+
require "ruby_lsp/response_builders/collection_response_builder"
|
44
|
+
require "ruby_lsp/response_builders/document_symbol"
|
45
|
+
require "ruby_lsp/response_builders/hover"
|
46
|
+
require "ruby_lsp/response_builders/semantic_highlighting"
|
47
|
+
require "ruby_lsp/response_builders/signature_help"
|
48
|
+
|
49
|
+
# Request support
|
50
|
+
require "ruby_lsp/requests/support/rubocop_diagnostic"
|
51
|
+
require "ruby_lsp/requests/support/selection_range"
|
52
|
+
require "ruby_lsp/requests/support/annotation"
|
53
|
+
require "ruby_lsp/requests/support/sorbet"
|
54
|
+
require "ruby_lsp/requests/support/common"
|
55
|
+
require "ruby_lsp/requests/support/formatter"
|
42
56
|
require "ruby_lsp/requests/support/rubocop_runner"
|
43
57
|
require "ruby_lsp/requests/support/rubocop_formatter"
|
44
58
|
require "ruby_lsp/requests/support/syntax_tree_formatter"
|
59
|
+
|
60
|
+
# Requests
|
61
|
+
require "ruby_lsp/requests/request"
|
62
|
+
require "ruby_lsp/requests/code_action_resolve"
|
63
|
+
require "ruby_lsp/requests/code_actions"
|
64
|
+
require "ruby_lsp/requests/code_lens"
|
65
|
+
require "ruby_lsp/requests/completion_resolve"
|
66
|
+
require "ruby_lsp/requests/completion"
|
67
|
+
require "ruby_lsp/requests/definition"
|
68
|
+
require "ruby_lsp/requests/diagnostics"
|
69
|
+
require "ruby_lsp/requests/document_highlight"
|
70
|
+
require "ruby_lsp/requests/document_link"
|
71
|
+
require "ruby_lsp/requests/document_symbol"
|
72
|
+
require "ruby_lsp/requests/folding_ranges"
|
73
|
+
require "ruby_lsp/requests/formatting"
|
74
|
+
require "ruby_lsp/requests/hover"
|
75
|
+
require "ruby_lsp/requests/inlay_hints"
|
76
|
+
require "ruby_lsp/requests/on_type_formatting"
|
77
|
+
require "ruby_lsp/requests/prepare_type_hierarchy"
|
78
|
+
require "ruby_lsp/requests/selection_ranges"
|
79
|
+
require "ruby_lsp/requests/semantic_highlighting"
|
80
|
+
require "ruby_lsp/requests/show_syntax_tree"
|
81
|
+
require "ruby_lsp/requests/signature_help"
|
82
|
+
require "ruby_lsp/requests/type_hierarchy_supertypes"
|
83
|
+
require "ruby_lsp/requests/workspace_symbol"
|
@@ -104,7 +104,7 @@ module RubyLsp
|
|
104
104
|
name = constant_name(node)
|
105
105
|
return if name.nil?
|
106
106
|
|
107
|
-
candidates = @index.
|
107
|
+
candidates = @index.constant_completion_candidates(name, @node_context.nesting)
|
108
108
|
candidates.each do |entries|
|
109
109
|
complete_name = T.must(entries.first).name
|
110
110
|
@response_builder << build_entry_completion(
|
@@ -124,7 +124,13 @@ module RubyLsp
|
|
124
124
|
# no sigil, Sorbet will still provide completion for constants
|
125
125
|
return if @sorbet_level != RubyDocument::SorbetLevel::Ignore
|
126
126
|
|
127
|
-
name =
|
127
|
+
name = begin
|
128
|
+
node.full_name
|
129
|
+
rescue Prism::ConstantPathNode::MissingNodesInConstantPathError
|
130
|
+
node.slice
|
131
|
+
rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError
|
132
|
+
nil
|
133
|
+
end
|
128
134
|
return if name.nil?
|
129
135
|
|
130
136
|
constant_path_completion(name, range_from_location(node.location))
|
@@ -230,7 +236,7 @@ module RubyLsp
|
|
230
236
|
|
231
237
|
real_namespace = @index.follow_aliased_namespace(T.must(namespace_entries.first).name)
|
232
238
|
|
233
|
-
candidates = @index.
|
239
|
+
candidates = @index.constant_completion_candidates(
|
234
240
|
"#{real_namespace}::#{incomplete_name}",
|
235
241
|
top_level_reference ? [] : nesting,
|
236
242
|
)
|
@@ -240,8 +246,16 @@ module RubyLsp
|
|
240
246
|
first_entry = T.must(entries.first)
|
241
247
|
next if first_entry.private? && !first_entry.name.start_with?("#{nesting}::")
|
242
248
|
|
243
|
-
|
244
|
-
full_name = aliased_namespace
|
249
|
+
entry_name = first_entry.name
|
250
|
+
full_name = if aliased_namespace != real_namespace
|
251
|
+
constant_name = entry_name.delete_prefix("#{real_namespace}::")
|
252
|
+
aliased_namespace.empty? ? constant_name : "#{aliased_namespace}::#{constant_name}"
|
253
|
+
elsif !entry_name.start_with?(aliased_namespace)
|
254
|
+
*_, short_name = entry_name.split("::")
|
255
|
+
"#{aliased_namespace}::#{short_name}"
|
256
|
+
else
|
257
|
+
entry_name
|
258
|
+
end
|
245
259
|
|
246
260
|
@response_builder << build_entry_completion(
|
247
261
|
full_name,
|
@@ -545,7 +559,7 @@ module RubyLsp
|
|
545
559
|
sig { params(entry_name: String).returns(T::Boolean) }
|
546
560
|
def top_level?(entry_name)
|
547
561
|
nesting = @node_context.nesting
|
548
|
-
nesting.length.downto(0)
|
562
|
+
nesting.length.downto(0) do |i|
|
549
563
|
prefix = T.must(nesting[0...i]).join("::")
|
550
564
|
full_name = prefix.empty? ? entry_name : "#{prefix}::#{entry_name}"
|
551
565
|
next if full_name == entry_name
|
@@ -12,14 +12,12 @@ module RubyLsp
|
|
12
12
|
sig do
|
13
13
|
params(
|
14
14
|
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint],
|
15
|
-
range: T::Range[Integer],
|
16
15
|
hints_configuration: RequestConfig,
|
17
16
|
dispatcher: Prism::Dispatcher,
|
18
17
|
).void
|
19
18
|
end
|
20
|
-
def initialize(response_builder,
|
19
|
+
def initialize(response_builder, hints_configuration, dispatcher)
|
21
20
|
@response_builder = response_builder
|
22
|
-
@range = range
|
23
21
|
@hints_configuration = hints_configuration
|
24
22
|
|
25
23
|
dispatcher.register(self, :on_rescue_node_enter, :on_implicit_node_enter)
|
@@ -31,7 +29,6 @@ module RubyLsp
|
|
31
29
|
return unless node.exceptions.empty?
|
32
30
|
|
33
31
|
loc = node.location
|
34
|
-
return unless visible?(node, @range)
|
35
32
|
|
36
33
|
@response_builder << Interface::InlayHint.new(
|
37
34
|
position: { line: loc.start_line - 1, character: loc.start_column + RESCUE_STRING_LENGTH },
|
@@ -44,7 +41,6 @@ module RubyLsp
|
|
44
41
|
sig { params(node: Prism::ImplicitNode).void }
|
45
42
|
def on_implicit_node_enter(node)
|
46
43
|
return unless @hints_configuration.enabled?(:implicitHashValue)
|
47
|
-
return unless visible?(node, @range)
|
48
44
|
|
49
45
|
node_value = node.value
|
50
46
|
loc = node.location
|
@@ -69,17 +65,6 @@ module RubyLsp
|
|
69
65
|
tooltip: tooltip,
|
70
66
|
)
|
71
67
|
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
sig { params(node: T.nilable(Prism::Node), range: T.nilable(T::Range[Integer])).returns(T::Boolean) }
|
76
|
-
def visible?(node, range)
|
77
|
-
return true if range.nil?
|
78
|
-
return false if node.nil?
|
79
|
-
|
80
|
-
loc = node.location
|
81
|
-
range.cover?(loc.start_line - 1) && range.cover?(loc.end_line - 1)
|
82
|
-
end
|
83
68
|
end
|
84
69
|
end
|
85
70
|
end
|
@@ -46,8 +46,8 @@ module RubyLsp
|
|
46
46
|
|
47
47
|
if owner_name
|
48
48
|
entries = entries.select do |entry|
|
49
|
-
(entry.is_a?(RubyIndexer::Entry::Member) || entry.is_a?(RubyIndexer::Entry::InstanceVariable)
|
50
|
-
|
49
|
+
(entry.is_a?(RubyIndexer::Entry::Member) || entry.is_a?(RubyIndexer::Entry::InstanceVariable) ||
|
50
|
+
entry.is_a?(RubyIndexer::Entry::MethodAlias)) && entry.owner&.name == owner_name
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -23,21 +23,18 @@ module RubyLsp
|
|
23
23
|
sig do
|
24
24
|
params(
|
25
25
|
document: T.any(RubyDocument, ERBDocument),
|
26
|
-
range: T::Hash[Symbol, T.untyped],
|
27
26
|
hints_configuration: RequestConfig,
|
28
27
|
dispatcher: Prism::Dispatcher,
|
29
28
|
).void
|
30
29
|
end
|
31
|
-
def initialize(document,
|
30
|
+
def initialize(document, hints_configuration, dispatcher)
|
32
31
|
super()
|
33
|
-
start_line = range.dig(:start, :line)
|
34
|
-
end_line = range.dig(:end, :line)
|
35
32
|
|
36
33
|
@response_builder = T.let(
|
37
34
|
ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint].new,
|
38
35
|
ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint],
|
39
36
|
)
|
40
|
-
Listeners::InlayHints.new(@response_builder,
|
37
|
+
Listeners::InlayHints.new(@response_builder, hints_configuration, dispatcher)
|
41
38
|
end
|
42
39
|
|
43
40
|
sig { override.returns(T::Array[Interface::InlayHint]) }
|
data/lib/ruby_lsp/server.rb
CHANGED
@@ -411,6 +411,7 @@ module RubyLsp
|
|
411
411
|
document_symbol = Requests::DocumentSymbol.new(uri, dispatcher)
|
412
412
|
document_link = Requests::DocumentLink.new(uri, parse_result.comments, dispatcher)
|
413
413
|
code_lens = Requests::CodeLens.new(@global_state, uri, dispatcher)
|
414
|
+
inlay_hint = Requests::InlayHints.new(document, T.must(@store.features_configuration.dig(:inlayHint)), dispatcher)
|
414
415
|
dispatcher.dispatch(parse_result.value)
|
415
416
|
|
416
417
|
# Store all responses retrieve in this round of visits in the cache and then return the response for the request
|
@@ -419,6 +420,7 @@ module RubyLsp
|
|
419
420
|
document.cache_set("textDocument/documentSymbol", document_symbol.perform)
|
420
421
|
document.cache_set("textDocument/documentLink", document_link.perform)
|
421
422
|
document.cache_set("textDocument/codeLens", code_lens.perform)
|
423
|
+
document.cache_set("textDocument/inlayHint", inlay_hint.perform)
|
422
424
|
|
423
425
|
send_message(Result.new(id: message[:id], response: document.cache_get(message[:method])))
|
424
426
|
end
|
@@ -611,18 +613,35 @@ module RubyLsp
|
|
611
613
|
sig { params(message: T::Hash[Symbol, T.untyped]).void }
|
612
614
|
def text_document_inlay_hint(message)
|
613
615
|
params = message[:params]
|
616
|
+
document = @store.get(params.dig(:textDocument, :uri))
|
617
|
+
range = params.dig(:range, :start, :line)..params.dig(:range, :end, :line)
|
618
|
+
|
619
|
+
cached_response = document.cache_get("textDocument/inlayHint")
|
620
|
+
if cached_response != Document::EMPTY_CACHE
|
621
|
+
|
622
|
+
send_message(
|
623
|
+
Result.new(
|
624
|
+
id: message[:id],
|
625
|
+
response: cached_response.select { |hint| range.cover?(hint.position[:line]) },
|
626
|
+
),
|
627
|
+
)
|
628
|
+
return
|
629
|
+
end
|
630
|
+
|
614
631
|
hints_configurations = T.must(@store.features_configuration.dig(:inlayHint))
|
615
632
|
dispatcher = Prism::Dispatcher.new
|
616
|
-
document = @store.get(params.dig(:textDocument, :uri))
|
617
633
|
|
618
634
|
unless document.is_a?(RubyDocument) || document.is_a?(ERBDocument)
|
619
635
|
send_empty_response(message[:id])
|
620
636
|
return
|
621
637
|
end
|
622
638
|
|
623
|
-
request = Requests::InlayHints.new(document,
|
639
|
+
request = Requests::InlayHints.new(document, hints_configurations, dispatcher)
|
624
640
|
dispatcher.visit(document.parse_result.value)
|
625
|
-
|
641
|
+
result = request.perform
|
642
|
+
document.cache_set("textDocument/inlayHint", result)
|
643
|
+
|
644
|
+
send_message(Result.new(id: message[:id], response: result.select { |hint| range.cover?(hint.position[:line]) }))
|
626
645
|
end
|
627
646
|
|
628
647
|
sig { params(message: T::Hash[Symbol, T.untyped]).void }
|
@@ -27,7 +27,6 @@ module RubyLsp
|
|
27
27
|
def initialize(project_path, **options)
|
28
28
|
@project_path = project_path
|
29
29
|
@branch = T.let(options[:branch], T.nilable(String))
|
30
|
-
@experimental = T.let(options[:experimental], T.nilable(T::Boolean))
|
31
30
|
|
32
31
|
# Regular bundle paths
|
33
32
|
@gemfile = T.let(
|
@@ -207,7 +206,6 @@ module RubyLsp
|
|
207
206
|
command << "ruby-lsp " unless @dependencies["ruby-lsp"]
|
208
207
|
command << "debug " unless @dependencies["debug"]
|
209
208
|
command << "ruby-lsp-rails " if @rails_app && !@dependencies["ruby-lsp-rails"]
|
210
|
-
command << "--pre" if @experimental
|
211
209
|
command.delete_suffix!(" ")
|
212
210
|
command << ")"
|
213
211
|
|
@@ -255,7 +253,9 @@ module RubyLsp
|
|
255
253
|
# "vendor/bundle"`
|
256
254
|
settings.all.to_h do |e|
|
257
255
|
key = Bundler::Settings.key_for(e)
|
258
|
-
|
256
|
+
value = Array(settings[e]).join(":").tr(" ", ":")
|
257
|
+
|
258
|
+
[key, value]
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
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.18.
|
4
|
+
version: 0.18.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: language_server-protocol
|
@@ -131,7 +131,6 @@ files:
|
|
131
131
|
- lib/ruby_lsp/node_context.rb
|
132
132
|
- lib/ruby_lsp/parameter_scope.rb
|
133
133
|
- lib/ruby_lsp/rbs_document.rb
|
134
|
-
- lib/ruby_lsp/requests.rb
|
135
134
|
- lib/ruby_lsp/requests/code_action_resolve.rb
|
136
135
|
- lib/ruby_lsp/requests/code_actions.rb
|
137
136
|
- lib/ruby_lsp/requests/code_lens.rb
|
@@ -165,7 +164,6 @@ files:
|
|
165
164
|
- lib/ruby_lsp/requests/support/syntax_tree_formatter.rb
|
166
165
|
- lib/ruby_lsp/requests/type_hierarchy_supertypes.rb
|
167
166
|
- lib/ruby_lsp/requests/workspace_symbol.rb
|
168
|
-
- lib/ruby_lsp/response_builders.rb
|
169
167
|
- lib/ruby_lsp/response_builders/collection_response_builder.rb
|
170
168
|
- lib/ruby_lsp/response_builders/document_symbol.rb
|
171
169
|
- lib/ruby_lsp/response_builders/hover.rb
|
data/lib/ruby_lsp/requests.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# typed: strict
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module RubyLsp
|
5
|
-
# Supported features
|
6
|
-
#
|
7
|
-
# - [DocumentSymbol](rdoc-ref:RubyLsp::Requests::DocumentSymbol)
|
8
|
-
# - [DocumentLink](rdoc-ref:RubyLsp::Requests::DocumentLink)
|
9
|
-
# - [Hover](rdoc-ref:RubyLsp::Requests::Hover)
|
10
|
-
# - [FoldingRange](rdoc-ref:RubyLsp::Requests::FoldingRanges)
|
11
|
-
# - [SelectionRange](rdoc-ref:RubyLsp::Requests::SelectionRanges)
|
12
|
-
# - [SemanticHighlighting](rdoc-ref:RubyLsp::Requests::SemanticHighlighting)
|
13
|
-
# - [Formatting](rdoc-ref:RubyLsp::Requests::Formatting)
|
14
|
-
# - [OnTypeFormatting](rdoc-ref:RubyLsp::Requests::OnTypeFormatting)
|
15
|
-
# - [Diagnostic](rdoc-ref:RubyLsp::Requests::Diagnostics)
|
16
|
-
# - [CodeAction](rdoc-ref:RubyLsp::Requests::CodeActions)
|
17
|
-
# - [CodeActionResolve](rdoc-ref:RubyLsp::Requests::CodeActionResolve)
|
18
|
-
# - [DocumentHighlight](rdoc-ref:RubyLsp::Requests::DocumentHighlight)
|
19
|
-
# - [InlayHint](rdoc-ref:RubyLsp::Requests::InlayHints)
|
20
|
-
# - [Completion](rdoc-ref:RubyLsp::Requests::Completion)
|
21
|
-
# - [CompletionResolve](rdoc-ref:RubyLsp::Requests::CompletionResolve)
|
22
|
-
# - [CodeLens](rdoc-ref:RubyLsp::Requests::CodeLens)
|
23
|
-
# - [Definition](rdoc-ref:RubyLsp::Requests::Definition)
|
24
|
-
# - [ShowSyntaxTree](rdoc-ref:RubyLsp::Requests::ShowSyntaxTree)
|
25
|
-
# - [WorkspaceSymbol](rdoc-ref:RubyLsp::Requests::WorkspaceSymbol)
|
26
|
-
# - [SignatureHelp](rdoc-ref:RubyLsp::Requests::SignatureHelp)
|
27
|
-
|
28
|
-
module Requests
|
29
|
-
autoload :Request, "ruby_lsp/requests/request"
|
30
|
-
autoload :DocumentSymbol, "ruby_lsp/requests/document_symbol"
|
31
|
-
autoload :DocumentLink, "ruby_lsp/requests/document_link"
|
32
|
-
autoload :Hover, "ruby_lsp/requests/hover"
|
33
|
-
autoload :FoldingRanges, "ruby_lsp/requests/folding_ranges"
|
34
|
-
autoload :SelectionRanges, "ruby_lsp/requests/selection_ranges"
|
35
|
-
autoload :SemanticHighlighting, "ruby_lsp/requests/semantic_highlighting"
|
36
|
-
autoload :Formatting, "ruby_lsp/requests/formatting"
|
37
|
-
autoload :OnTypeFormatting, "ruby_lsp/requests/on_type_formatting"
|
38
|
-
autoload :Diagnostics, "ruby_lsp/requests/diagnostics"
|
39
|
-
autoload :CodeActions, "ruby_lsp/requests/code_actions"
|
40
|
-
autoload :CodeActionResolve, "ruby_lsp/requests/code_action_resolve"
|
41
|
-
autoload :DocumentHighlight, "ruby_lsp/requests/document_highlight"
|
42
|
-
autoload :InlayHints, "ruby_lsp/requests/inlay_hints"
|
43
|
-
autoload :Completion, "ruby_lsp/requests/completion"
|
44
|
-
autoload :CompletionResolve, "ruby_lsp/requests/completion_resolve"
|
45
|
-
autoload :CodeLens, "ruby_lsp/requests/code_lens"
|
46
|
-
autoload :Definition, "ruby_lsp/requests/definition"
|
47
|
-
autoload :ShowSyntaxTree, "ruby_lsp/requests/show_syntax_tree"
|
48
|
-
autoload :WorkspaceSymbol, "ruby_lsp/requests/workspace_symbol"
|
49
|
-
autoload :SignatureHelp, "ruby_lsp/requests/signature_help"
|
50
|
-
autoload :PrepareTypeHierarchy, "ruby_lsp/requests/prepare_type_hierarchy"
|
51
|
-
autoload :TypeHierarchySupertypes, "ruby_lsp/requests/type_hierarchy_supertypes"
|
52
|
-
|
53
|
-
# :nodoc:
|
54
|
-
module Support
|
55
|
-
autoload :RuboCopDiagnostic, "ruby_lsp/requests/support/rubocop_diagnostic"
|
56
|
-
autoload :SelectionRange, "ruby_lsp/requests/support/selection_range"
|
57
|
-
autoload :Annotation, "ruby_lsp/requests/support/annotation"
|
58
|
-
autoload :Sorbet, "ruby_lsp/requests/support/sorbet"
|
59
|
-
autoload :RailsDocumentClient, "ruby_lsp/requests/support/rails_document_client"
|
60
|
-
autoload :Common, "ruby_lsp/requests/support/common"
|
61
|
-
autoload :Formatter, "ruby_lsp/requests/support/formatter"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# typed: strict
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module RubyLsp
|
5
|
-
module ResponseBuilders
|
6
|
-
autoload :CollectionResponseBuilder, "ruby_lsp/response_builders/collection_response_builder"
|
7
|
-
autoload :DocumentSymbol, "ruby_lsp/response_builders/document_symbol"
|
8
|
-
autoload :Hover, "ruby_lsp/response_builders/hover"
|
9
|
-
autoload :ResponseBuilder, "ruby_lsp/response_builders/response_builder"
|
10
|
-
autoload :SemanticHighlighting, "ruby_lsp/response_builders/semantic_highlighting"
|
11
|
-
autoload :SignatureHelp, "ruby_lsp/response_builders/signature_help"
|
12
|
-
end
|
13
|
-
end
|