ruby-lsp 0.23.11 → 0.23.16
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/README.md +2 -2
- data/VERSION +1 -1
- data/exe/ruby-lsp-launcher +20 -11
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
- data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +82 -116
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +123 -169
- data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -7
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +92 -202
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +116 -222
- data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +18 -19
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +22 -45
- data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +47 -61
- data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +17 -19
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
- data/lib/ruby_indexer/test/class_variables_test.rb +14 -14
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +65 -40
- data/lib/ruby_indexer/test/configuration_test.rb +48 -7
- data/lib/ruby_indexer/test/constant_test.rb +34 -34
- data/lib/ruby_indexer/test/enhancements_test.rb +1 -1
- data/lib/ruby_indexer/test/index_test.rb +139 -135
- data/lib/ruby_indexer/test/instance_variables_test.rb +37 -37
- data/lib/ruby_indexer/test/method_test.rb +143 -117
- data/lib/ruby_indexer/test/prefix_tree_test.rb +13 -13
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +65 -71
- data/lib/ruby_indexer/test/test_case.rb +2 -2
- data/lib/ruby_indexer/test/uri_test.rb +15 -2
- data/lib/ruby_lsp/addon.rb +44 -71
- data/lib/ruby_lsp/base_server.rb +29 -32
- data/lib/ruby_lsp/client_capabilities.rb +10 -12
- data/lib/ruby_lsp/document.rb +39 -45
- data/lib/ruby_lsp/erb_document.rb +36 -40
- data/lib/ruby_lsp/global_state.rb +52 -57
- data/lib/ruby_lsp/internal.rb +2 -0
- data/lib/ruby_lsp/listeners/code_lens.rb +82 -89
- data/lib/ruby_lsp/listeners/completion.rb +60 -66
- data/lib/ruby_lsp/listeners/definition.rb +38 -52
- data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
- data/lib/ruby_lsp/listeners/document_link.rb +46 -63
- data/lib/ruby_lsp/listeners/document_symbol.rb +38 -52
- data/lib/ruby_lsp/listeners/folding_ranges.rb +40 -43
- data/lib/ruby_lsp/listeners/hover.rb +83 -102
- data/lib/ruby_lsp/listeners/inlay_hints.rb +4 -11
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +54 -56
- data/lib/ruby_lsp/listeners/signature_help.rb +11 -26
- data/lib/ruby_lsp/listeners/spec_style.rb +155 -0
- data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
- data/lib/ruby_lsp/listeners/test_style.rb +160 -88
- data/lib/ruby_lsp/node_context.rb +12 -39
- data/lib/ruby_lsp/rbs_document.rb +8 -6
- data/lib/ruby_lsp/requests/code_action_resolve.rb +24 -25
- data/lib/ruby_lsp/requests/code_actions.rb +14 -26
- data/lib/ruby_lsp/requests/code_lens.rb +6 -17
- data/lib/ruby_lsp/requests/completion.rb +7 -20
- data/lib/ruby_lsp/requests/completion_resolve.rb +6 -6
- data/lib/ruby_lsp/requests/definition.rb +8 -17
- data/lib/ruby_lsp/requests/diagnostics.rb +8 -11
- data/lib/ruby_lsp/requests/discover_tests.rb +18 -5
- data/lib/ruby_lsp/requests/document_highlight.rb +5 -15
- data/lib/ruby_lsp/requests/document_link.rb +6 -17
- data/lib/ruby_lsp/requests/document_symbol.rb +5 -8
- data/lib/ruby_lsp/requests/folding_ranges.rb +7 -15
- data/lib/ruby_lsp/requests/formatting.rb +6 -9
- data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
- data/lib/ruby_lsp/requests/hover.rb +10 -20
- data/lib/ruby_lsp/requests/inlay_hints.rb +6 -17
- data/lib/ruby_lsp/requests/on_type_formatting.rb +32 -40
- data/lib/ruby_lsp/requests/prepare_rename.rb +4 -9
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +5 -15
- data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
- data/lib/ruby_lsp/requests/references.rb +8 -37
- data/lib/ruby_lsp/requests/rename.rb +19 -42
- data/lib/ruby_lsp/requests/request.rb +7 -19
- data/lib/ruby_lsp/requests/selection_ranges.rb +6 -6
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +16 -35
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +7 -8
- data/lib/ruby_lsp/requests/signature_help.rb +8 -26
- data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
- data/lib/ruby_lsp/requests/support/common.rb +16 -51
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +11 -14
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +22 -34
- data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
- data/lib/ruby_lsp/requests/support/sorbet.rb +29 -38
- data/lib/ruby_lsp/requests/support/source_uri.rb +20 -32
- data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
- data/lib/ruby_lsp/requests/support/test_item.rb +10 -14
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +5 -6
- data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -4
- data/lib/ruby_lsp/response_builders/collection_response_builder.rb +5 -5
- data/lib/ruby_lsp/response_builders/document_symbol.rb +13 -18
- data/lib/ruby_lsp/response_builders/hover.rb +11 -14
- data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +60 -88
- data/lib/ruby_lsp/response_builders/signature_help.rb +5 -6
- data/lib/ruby_lsp/response_builders/test_collection.rb +6 -10
- data/lib/ruby_lsp/ruby_document.rb +24 -62
- data/lib/ruby_lsp/scope.rb +7 -11
- data/lib/ruby_lsp/scripts/compose_bundle.rb +6 -4
- data/lib/ruby_lsp/server.rb +147 -79
- data/lib/ruby_lsp/setup_bundler.rb +65 -60
- data/lib/ruby_lsp/static_docs.rb +11 -7
- data/lib/ruby_lsp/store.rb +24 -42
- data/lib/ruby_lsp/test_helper.rb +2 -12
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +164 -0
- data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +105 -0
- data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +94 -0
- data/lib/ruby_lsp/type_inferrer.rb +13 -14
- data/lib/ruby_lsp/utils.rb +49 -83
- metadata +9 -3
@@ -4,26 +4,22 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
6
|
class Hover < ResponseBuilder
|
7
|
-
extend T::Sig
|
8
7
|
extend T::Generic
|
9
8
|
|
10
9
|
ResponseType = type_member { { fixed: String } }
|
11
10
|
|
12
|
-
|
11
|
+
#: -> void
|
13
12
|
def initialize
|
14
13
|
super
|
15
14
|
|
16
|
-
@response =
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
},
|
22
|
-
T::Hash[Symbol, String],
|
23
|
-
)
|
15
|
+
@response = {
|
16
|
+
title: +"",
|
17
|
+
links: +"",
|
18
|
+
documentation: +"",
|
19
|
+
} #: Hash[Symbol, String]
|
24
20
|
end
|
25
21
|
|
26
|
-
|
22
|
+
#: (String content, category: Symbol) -> void
|
27
23
|
def push(content, category:)
|
28
24
|
hover_content = @response[category]
|
29
25
|
if hover_content
|
@@ -31,14 +27,15 @@ module RubyLsp
|
|
31
27
|
end
|
32
28
|
end
|
33
29
|
|
34
|
-
|
30
|
+
#: -> bool
|
35
31
|
def empty?
|
36
32
|
@response.values.all?(&:empty?)
|
37
33
|
end
|
38
34
|
|
39
|
-
|
35
|
+
# @override
|
36
|
+
#: -> ResponseType
|
40
37
|
def response
|
41
|
-
result =
|
38
|
+
result = @response[:title] #: as !nil
|
42
39
|
result << "\n" << @response[:links] if @response[:links]
|
43
40
|
result << "\n" << @response[:documentation] if @response[:documentation]
|
44
41
|
|
@@ -6,68 +6,55 @@ module RubyLsp
|
|
6
6
|
class SemanticHighlighting < ResponseBuilder
|
7
7
|
class UndefinedTokenType < StandardError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
abstract: 5,
|
48
|
-
async: 6,
|
49
|
-
modification: 7,
|
50
|
-
documentation: 8,
|
51
|
-
default_library: 9,
|
52
|
-
}.freeze,
|
53
|
-
T::Hash[Symbol, Integer],
|
54
|
-
)
|
9
|
+
TOKEN_TYPES = {
|
10
|
+
namespace: 0,
|
11
|
+
type: 1,
|
12
|
+
class: 2,
|
13
|
+
enum: 3,
|
14
|
+
interface: 4,
|
15
|
+
struct: 5,
|
16
|
+
typeParameter: 6,
|
17
|
+
parameter: 7,
|
18
|
+
variable: 8,
|
19
|
+
property: 9,
|
20
|
+
enumMember: 10,
|
21
|
+
event: 11,
|
22
|
+
function: 12,
|
23
|
+
method: 13,
|
24
|
+
macro: 14,
|
25
|
+
keyword: 15,
|
26
|
+
modifier: 16,
|
27
|
+
comment: 17,
|
28
|
+
string: 18,
|
29
|
+
number: 19,
|
30
|
+
regexp: 20,
|
31
|
+
operator: 21,
|
32
|
+
decorator: 22,
|
33
|
+
}.freeze #: Hash[Symbol, Integer]
|
34
|
+
|
35
|
+
TOKEN_MODIFIERS = {
|
36
|
+
declaration: 0,
|
37
|
+
definition: 1,
|
38
|
+
readonly: 2,
|
39
|
+
static: 3,
|
40
|
+
deprecated: 4,
|
41
|
+
abstract: 5,
|
42
|
+
async: 6,
|
43
|
+
modification: 7,
|
44
|
+
documentation: 8,
|
45
|
+
default_library: 9,
|
46
|
+
}.freeze #: Hash[Symbol, Integer]
|
55
47
|
|
56
48
|
ResponseType = type_member { { fixed: Interface::SemanticTokens } }
|
57
49
|
|
58
|
-
|
59
|
-
params(code_units_cache: T.any(
|
60
|
-
T.proc.params(arg0: Integer).returns(Integer),
|
61
|
-
Prism::CodeUnitsCache,
|
62
|
-
)).void
|
63
|
-
end
|
50
|
+
#: ((^(Integer arg0) -> Integer | Prism::CodeUnitsCache) code_units_cache) -> void
|
64
51
|
def initialize(code_units_cache)
|
65
52
|
super()
|
66
53
|
@code_units_cache = code_units_cache
|
67
|
-
@stack =
|
54
|
+
@stack = [] #: Array[SemanticToken]
|
68
55
|
end
|
69
56
|
|
70
|
-
|
57
|
+
#: (Prism::Location location, Symbol type, ?Array[Symbol] modifiers) -> void
|
71
58
|
def add_token(location, type, modifiers = [])
|
72
59
|
end_code_unit = location.cached_end_code_units_offset(@code_units_cache)
|
73
60
|
length = end_code_unit - location.cached_start_code_units_offset(@code_units_cache)
|
@@ -77,13 +64,13 @@ module RubyLsp
|
|
77
64
|
start_line: location.start_line,
|
78
65
|
start_code_unit_column: location.cached_start_code_units_column(@code_units_cache),
|
79
66
|
length: length,
|
80
|
-
type:
|
67
|
+
type: TOKEN_TYPES[type], #: as !nil
|
81
68
|
modifier: modifiers_indices,
|
82
69
|
),
|
83
70
|
)
|
84
71
|
end
|
85
72
|
|
86
|
-
|
73
|
+
#: (Prism::Location location) -> bool
|
87
74
|
def last_token_matches?(location)
|
88
75
|
token = @stack.last
|
89
76
|
return false unless token
|
@@ -92,43 +79,34 @@ module RubyLsp
|
|
92
79
|
token.start_code_unit_column == location.cached_start_code_units_column(@code_units_cache)
|
93
80
|
end
|
94
81
|
|
95
|
-
|
82
|
+
#: -> SemanticToken?
|
96
83
|
def last
|
97
84
|
@stack.last
|
98
85
|
end
|
99
86
|
|
100
|
-
|
87
|
+
# @override
|
88
|
+
#: -> Array[SemanticToken]
|
101
89
|
def response
|
102
90
|
@stack
|
103
91
|
end
|
104
92
|
|
105
93
|
class SemanticToken
|
106
|
-
|
107
|
-
|
108
|
-
sig { returns(Integer) }
|
94
|
+
#: Integer
|
109
95
|
attr_reader :start_line
|
110
96
|
|
111
|
-
|
97
|
+
#: Integer
|
112
98
|
attr_reader :start_code_unit_column
|
113
99
|
|
114
|
-
|
100
|
+
#: Integer
|
115
101
|
attr_reader :length
|
116
102
|
|
117
|
-
|
103
|
+
#: Integer
|
118
104
|
attr_reader :type
|
119
105
|
|
120
|
-
|
106
|
+
#: Array[Integer]
|
121
107
|
attr_reader :modifier
|
122
108
|
|
123
|
-
|
124
|
-
params(
|
125
|
-
start_line: Integer,
|
126
|
-
start_code_unit_column: Integer,
|
127
|
-
length: Integer,
|
128
|
-
type: Integer,
|
129
|
-
modifier: T::Array[Integer],
|
130
|
-
).void
|
131
|
-
end
|
109
|
+
#: (start_line: Integer, start_code_unit_column: Integer, length: Integer, type: Integer, modifier: Array[Integer]) -> void
|
132
110
|
def initialize(start_line:, start_code_unit_column:, length:, type:, modifier:)
|
133
111
|
@start_line = start_line
|
134
112
|
@start_code_unit_column = start_code_unit_column
|
@@ -137,7 +115,7 @@ module RubyLsp
|
|
137
115
|
@modifier = modifier
|
138
116
|
end
|
139
117
|
|
140
|
-
|
118
|
+
#: (Symbol type_symbol) -> void
|
141
119
|
def replace_type(type_symbol)
|
142
120
|
type_int = TOKEN_TYPES[type_symbol]
|
143
121
|
raise UndefinedTokenType, "Undefined token type: #{type_symbol}" unless type_int
|
@@ -145,7 +123,7 @@ module RubyLsp
|
|
145
123
|
@type = type_int
|
146
124
|
end
|
147
125
|
|
148
|
-
|
126
|
+
#: (Array[Symbol] modifier_symbols) -> void
|
149
127
|
def replace_modifier(modifier_symbols)
|
150
128
|
@modifier = modifier_symbols.filter_map do |modifier_symbol|
|
151
129
|
modifier_index = TOKEN_MODIFIERS[modifier_symbol]
|
@@ -157,19 +135,13 @@ module RubyLsp
|
|
157
135
|
end
|
158
136
|
|
159
137
|
class SemanticTokenEncoder
|
160
|
-
|
161
|
-
|
162
|
-
sig { void }
|
138
|
+
#: -> void
|
163
139
|
def initialize
|
164
|
-
@current_row =
|
165
|
-
@current_column =
|
140
|
+
@current_row = 0 #: Integer
|
141
|
+
@current_column = 0 #: Integer
|
166
142
|
end
|
167
143
|
|
168
|
-
|
169
|
-
params(
|
170
|
-
tokens: T::Array[SemanticToken],
|
171
|
-
).returns(T::Array[Integer])
|
172
|
-
end
|
144
|
+
#: (Array[SemanticToken] tokens) -> Array[Integer]
|
173
145
|
def encode(tokens)
|
174
146
|
sorted_tokens = tokens.sort_by.with_index do |token, index|
|
175
147
|
# Enumerable#sort_by is not deterministic when the compared values are equal.
|
@@ -194,7 +166,7 @@ module RubyLsp
|
|
194
166
|
|
195
167
|
# For more information on how each number is calculated, read:
|
196
168
|
# https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_semanticTokens
|
197
|
-
|
169
|
+
#: (SemanticToken token) -> Array[Integer]
|
198
170
|
def compute_delta(token)
|
199
171
|
row = token.start_line - 1
|
200
172
|
column = token.start_code_unit_column
|
@@ -216,7 +188,7 @@ module RubyLsp
|
|
216
188
|
# For example, [:default_library] will be encoded as
|
217
189
|
# 0b1000000000, as :default_library is the 10th bit according
|
218
190
|
# to the token modifiers index map.
|
219
|
-
|
191
|
+
#: (Array[Integer] modifiers) -> Integer
|
220
192
|
def encode_modifiers(modifiers)
|
221
193
|
modifiers.inject(0) do |encoded_modifiers, modifier|
|
222
194
|
encoded_modifiers | (1 << modifier)
|
@@ -4,22 +4,21 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
6
|
class SignatureHelp < ResponseBuilder
|
7
|
-
extend T::Sig
|
8
|
-
|
9
7
|
ResponseType = type_member { { fixed: T.nilable(Interface::SignatureHelp) } }
|
10
8
|
|
11
|
-
|
9
|
+
#: -> void
|
12
10
|
def initialize
|
13
11
|
super
|
14
|
-
@signature_help =
|
12
|
+
@signature_help = nil #: ResponseType
|
15
13
|
end
|
16
14
|
|
17
|
-
|
15
|
+
#: (ResponseType signature_help) -> void
|
18
16
|
def replace(signature_help)
|
19
17
|
@signature_help = signature_help
|
20
18
|
end
|
21
19
|
|
22
|
-
|
20
|
+
# @override
|
21
|
+
#: -> ResponseType
|
23
22
|
def response
|
24
23
|
@signature_help
|
25
24
|
end
|
@@ -4,32 +4,28 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module ResponseBuilders
|
6
6
|
class TestCollection < ResponseBuilder
|
7
|
-
class DuplicateIdError < StandardError; end
|
8
|
-
|
9
|
-
extend T::Sig
|
10
7
|
extend T::Generic
|
11
8
|
|
12
9
|
ResponseType = type_member { { fixed: Requests::Support::TestItem } }
|
13
10
|
|
14
|
-
|
11
|
+
#: -> void
|
15
12
|
def initialize
|
16
13
|
super
|
17
|
-
@items =
|
14
|
+
@items = {} #: Hash[String, ResponseType]
|
18
15
|
end
|
19
16
|
|
20
|
-
|
17
|
+
#: (ResponseType item) -> void
|
21
18
|
def add(item)
|
22
|
-
raise DuplicateIdError, "TestItem ID is already in use" if @items.key?(item.id)
|
23
|
-
|
24
19
|
@items[item.id] = item
|
25
20
|
end
|
26
21
|
|
27
|
-
|
22
|
+
#: (String id) -> ResponseType?
|
28
23
|
def [](id)
|
29
24
|
@items[id]
|
30
25
|
end
|
31
26
|
|
32
|
-
|
27
|
+
# @override
|
28
|
+
#: -> Array[ResponseType]
|
33
29
|
def response
|
34
30
|
@items.values
|
35
31
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
class RubyDocument < Document
|
6
|
-
extend T::Sig
|
7
6
|
extend T::Generic
|
8
7
|
|
9
8
|
ParseResultType = type_member { { fixed: Prism::ParseResult } }
|
@@ -35,38 +34,15 @@ module RubyLsp
|
|
35
34
|
end
|
36
35
|
|
37
36
|
class << self
|
38
|
-
|
39
|
-
|
40
|
-
sig do
|
41
|
-
params(
|
42
|
-
node: Prism::Node,
|
43
|
-
char_position: Integer,
|
44
|
-
code_units_cache: T.any(
|
45
|
-
T.proc.params(arg0: Integer).returns(Integer),
|
46
|
-
Prism::CodeUnitsCache,
|
47
|
-
),
|
48
|
-
node_types: T::Array[T.class_of(Prism::Node)],
|
49
|
-
).returns(NodeContext)
|
50
|
-
end
|
37
|
+
#: (Prism::Node node, Integer char_position, code_units_cache: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache), ?node_types: Array[singleton(Prism::Node)]) -> NodeContext
|
51
38
|
def locate(node, char_position, code_units_cache:, node_types: [])
|
52
|
-
queue =
|
39
|
+
queue = node.child_nodes.compact #: Array[Prism::Node?]
|
53
40
|
closest = node
|
54
|
-
parent =
|
55
|
-
nesting_nodes =
|
56
|
-
[],
|
57
|
-
T::Array[T.any(
|
58
|
-
Prism::ClassNode,
|
59
|
-
Prism::ModuleNode,
|
60
|
-
Prism::SingletonClassNode,
|
61
|
-
Prism::DefNode,
|
62
|
-
Prism::BlockNode,
|
63
|
-
Prism::LambdaNode,
|
64
|
-
Prism::ProgramNode,
|
65
|
-
)],
|
66
|
-
)
|
41
|
+
parent = nil #: Prism::Node?
|
42
|
+
nesting_nodes = [] #: Array[(Prism::ClassNode | Prism::ModuleNode | Prism::SingletonClassNode | Prism::DefNode | Prism::BlockNode | Prism::LambdaNode | Prism::ProgramNode)] # rubocop:disable Layout/LineLength
|
67
43
|
|
68
44
|
nesting_nodes << node if node.is_a?(Prism::ProgramNode)
|
69
|
-
call_node =
|
45
|
+
call_node = nil #: Prism::CallNode?
|
70
46
|
|
71
47
|
until queue.empty?
|
72
48
|
candidate = queue.shift
|
@@ -77,7 +53,7 @@ module RubyLsp
|
|
77
53
|
# Add the next child_nodes to the queue to be processed. The order here is important! We want to move in the
|
78
54
|
# same order as the visiting mechanism, which means searching the child nodes before moving on to the next
|
79
55
|
# sibling
|
80
|
-
|
56
|
+
queue.unshift(*candidate.child_nodes)
|
81
57
|
|
82
58
|
# Skip if the current node doesn't cover the desired position
|
83
59
|
loc = candidate.location
|
@@ -150,24 +126,18 @@ module RubyLsp
|
|
150
126
|
end
|
151
127
|
end
|
152
128
|
|
153
|
-
|
154
|
-
returns(T.any(
|
155
|
-
T.proc.params(arg0: Integer).returns(Integer),
|
156
|
-
Prism::CodeUnitsCache,
|
157
|
-
))
|
158
|
-
end
|
129
|
+
#: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache)
|
159
130
|
attr_reader :code_units_cache
|
160
131
|
|
161
|
-
|
132
|
+
#: (source: String, version: Integer, uri: URI::Generic, global_state: GlobalState) -> void
|
162
133
|
def initialize(source:, version:, uri:, global_state:)
|
163
134
|
super
|
164
|
-
@code_units_cache =
|
165
|
-
|
166
|
-
Prism::CodeUnitsCache,
|
167
|
-
))
|
135
|
+
@code_units_cache = @parse_result
|
136
|
+
.code_units_cache(@encoding) #: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache)
|
168
137
|
end
|
169
138
|
|
170
|
-
|
139
|
+
# @override
|
140
|
+
#: -> bool
|
171
141
|
def parse!
|
172
142
|
return false unless @needs_parsing
|
173
143
|
|
@@ -177,17 +147,19 @@ module RubyLsp
|
|
177
147
|
true
|
178
148
|
end
|
179
149
|
|
180
|
-
|
150
|
+
# @override
|
151
|
+
#: -> bool
|
181
152
|
def syntax_error?
|
182
153
|
@parse_result.failure?
|
183
154
|
end
|
184
155
|
|
185
|
-
|
156
|
+
# @override
|
157
|
+
#: -> LanguageId
|
186
158
|
def language_id
|
187
159
|
LanguageId::Ruby
|
188
160
|
end
|
189
161
|
|
190
|
-
|
162
|
+
#: -> SorbetLevel
|
191
163
|
def sorbet_level
|
192
164
|
sigil = parse_result.magic_comments.find do |comment|
|
193
165
|
comment.key == "typed"
|
@@ -207,17 +179,12 @@ module RubyLsp
|
|
207
179
|
end
|
208
180
|
end
|
209
181
|
|
210
|
-
|
211
|
-
params(
|
212
|
-
range: T::Hash[Symbol, T.untyped],
|
213
|
-
node_types: T::Array[T.class_of(Prism::Node)],
|
214
|
-
).returns(T.nilable(Prism::Node))
|
215
|
-
end
|
182
|
+
#: (Hash[Symbol, untyped] range, ?node_types: Array[singleton(Prism::Node)]) -> Prism::Node?
|
216
183
|
def locate_first_within_range(range, node_types: [])
|
217
184
|
start_position, end_position = find_index_by_position(range[:start], range[:end])
|
218
185
|
|
219
186
|
desired_range = (start_position...end_position)
|
220
|
-
queue =
|
187
|
+
queue = @parse_result.value.child_nodes.compact #: Array[Prism::Node?]
|
221
188
|
|
222
189
|
until queue.empty?
|
223
190
|
candidate = queue.shift
|
@@ -228,7 +195,7 @@ module RubyLsp
|
|
228
195
|
# Add the next child_nodes to the queue to be processed. The order here is important! We want to move in the
|
229
196
|
# same order as the visiting mechanism, which means searching the child nodes before moving on to the next
|
230
197
|
# sibling
|
231
|
-
|
198
|
+
queue.unshift(*candidate.child_nodes)
|
232
199
|
|
233
200
|
# Skip if the current node doesn't cover the desired position
|
234
201
|
loc = candidate.location
|
@@ -240,12 +207,7 @@ module RubyLsp
|
|
240
207
|
end
|
241
208
|
end
|
242
209
|
|
243
|
-
|
244
|
-
params(
|
245
|
-
position: T::Hash[Symbol, T.untyped],
|
246
|
-
node_types: T::Array[T.class_of(Prism::Node)],
|
247
|
-
).returns(NodeContext)
|
248
|
-
end
|
210
|
+
#: (Hash[Symbol, untyped] position, ?node_types: Array[singleton(Prism::Node)]) -> NodeContext
|
249
211
|
def locate_node(position, node_types: [])
|
250
212
|
char_position, _ = find_index_by_position(position)
|
251
213
|
|
@@ -257,7 +219,7 @@ module RubyLsp
|
|
257
219
|
)
|
258
220
|
end
|
259
221
|
|
260
|
-
|
222
|
+
#: -> bool
|
261
223
|
def should_index?
|
262
224
|
# This method controls when we should index documents. If there's no recent edit and the document has just been
|
263
225
|
# opened, we need to index it
|
@@ -268,7 +230,7 @@ module RubyLsp
|
|
268
230
|
|
269
231
|
private
|
270
232
|
|
271
|
-
|
233
|
+
#: -> bool
|
272
234
|
def last_edit_may_change_declarations?
|
273
235
|
case @last_edit
|
274
236
|
when Delete
|
@@ -282,7 +244,7 @@ module RubyLsp
|
|
282
244
|
end
|
283
245
|
end
|
284
246
|
|
285
|
-
|
247
|
+
#: (Hash[Symbol, Integer] position) -> bool
|
286
248
|
def position_may_impact_declarations?(position)
|
287
249
|
node_context = locate_node(position)
|
288
250
|
node_at_edit = node_context.node
|
data/lib/ruby_lsp/scope.rb
CHANGED
@@ -3,26 +3,24 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
class Scope
|
6
|
-
|
7
|
-
|
8
|
-
sig { returns(T.nilable(Scope)) }
|
6
|
+
#: Scope?
|
9
7
|
attr_reader :parent
|
10
8
|
|
11
|
-
|
9
|
+
#: (?Scope? parent) -> void
|
12
10
|
def initialize(parent = nil)
|
13
11
|
@parent = parent
|
14
12
|
|
15
13
|
# A hash of name => type
|
16
|
-
@locals =
|
14
|
+
@locals = {} #: Hash[Symbol, Local]
|
17
15
|
end
|
18
16
|
|
19
17
|
# Add a new local to this scope. The types should only be `:parameter` or `:variable`
|
20
|
-
|
18
|
+
#: ((String | Symbol) name, Symbol type) -> void
|
21
19
|
def add(name, type)
|
22
20
|
@locals[name.to_sym] = Local.new(type)
|
23
21
|
end
|
24
22
|
|
25
|
-
|
23
|
+
#: ((String | Symbol) name) -> Local?
|
26
24
|
def lookup(name)
|
27
25
|
sym = name.to_sym
|
28
26
|
entry = @locals[sym]
|
@@ -33,12 +31,10 @@ module RubyLsp
|
|
33
31
|
end
|
34
32
|
|
35
33
|
class Local
|
36
|
-
|
37
|
-
|
38
|
-
sig { returns(Symbol) }
|
34
|
+
#: Symbol
|
39
35
|
attr_reader :type
|
40
36
|
|
41
|
-
|
37
|
+
#: (Symbol type) -> void
|
42
38
|
def initialize(type)
|
43
39
|
@type = type
|
44
40
|
end
|
@@ -13,8 +13,10 @@ def compose(raw_initialize)
|
|
13
13
|
workspace_path ||= Dir.pwd
|
14
14
|
|
15
15
|
env = RubyLsp::SetupBundler.new(workspace_path, launcher: true).setup!
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
|
17
|
+
File.open(File.join(".ruby-lsp", "bundle_env"), "w") do |f|
|
18
|
+
f.flock(File::LOCK_EX)
|
19
|
+
f.write(env.map { |k, v| "#{k}=#{v}" }.join("\n"))
|
20
|
+
f.flush
|
21
|
+
end
|
20
22
|
end
|