ruby-lsp 0.23.1 → 0.23.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/exe/ruby-lsp-launcher +15 -9
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +89 -58
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +21 -10
- data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +36 -0
- data/lib/ruby_indexer/ruby_indexer.rb +1 -0
- data/lib/ruby_indexer/test/index_test.rb +2 -1
- data/lib/ruby_indexer/test/instance_variables_test.rb +20 -0
- data/lib/ruby_indexer/test/method_test.rb +86 -8
- data/lib/ruby_lsp/base_server.rb +9 -15
- data/lib/ruby_lsp/document.rb +62 -9
- data/lib/ruby_lsp/erb_document.rb +5 -3
- data/lib/ruby_lsp/global_state.rb +9 -0
- data/lib/ruby_lsp/listeners/definition.rb +7 -2
- data/lib/ruby_lsp/rbs_document.rb +2 -2
- data/lib/ruby_lsp/requests/code_action_resolve.rb +2 -6
- data/lib/ruby_lsp/requests/completion.rb +2 -1
- data/lib/ruby_lsp/requests/definition.rb +1 -1
- data/lib/ruby_lsp/requests/document_highlight.rb +1 -1
- data/lib/ruby_lsp/requests/hover.rb +1 -1
- data/lib/ruby_lsp/requests/prepare_rename.rb +1 -1
- data/lib/ruby_lsp/requests/references.rb +1 -1
- data/lib/ruby_lsp/requests/rename.rb +3 -3
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +1 -4
- data/lib/ruby_lsp/requests/signature_help.rb +1 -1
- data/lib/ruby_lsp/requests/workspace_symbol.rb +2 -2
- data/lib/ruby_lsp/ruby_document.rb +75 -6
- data/lib/ruby_lsp/server.rb +68 -48
- data/lib/ruby_lsp/store.rb +7 -7
- data/lib/ruby_lsp/type_inferrer.rb +39 -17
- data/lib/ruby_lsp/utils.rb +43 -0
- metadata +3 -2
data/lib/ruby_lsp/store.rb
CHANGED
@@ -13,8 +13,9 @@ module RubyLsp
|
|
13
13
|
sig { returns(String) }
|
14
14
|
attr_accessor :client_name
|
15
15
|
|
16
|
-
sig { void }
|
17
|
-
def initialize
|
16
|
+
sig { params(global_state: GlobalState).void }
|
17
|
+
def initialize(global_state)
|
18
|
+
@global_state = global_state
|
18
19
|
@state = T.let({}, T::Hash[String, Document[T.untyped]])
|
19
20
|
@features_configuration = T.let(
|
20
21
|
{
|
@@ -61,17 +62,16 @@ module RubyLsp
|
|
61
62
|
source: String,
|
62
63
|
version: Integer,
|
63
64
|
language_id: Document::LanguageId,
|
64
|
-
encoding: Encoding,
|
65
65
|
).returns(Document[T.untyped])
|
66
66
|
end
|
67
|
-
def set(uri:, source:, version:, language_id
|
67
|
+
def set(uri:, source:, version:, language_id:)
|
68
68
|
@state[uri.to_s] = case language_id
|
69
69
|
when Document::LanguageId::ERB
|
70
|
-
ERBDocument.new(source: source, version: version, uri: uri,
|
70
|
+
ERBDocument.new(source: source, version: version, uri: uri, global_state: @global_state)
|
71
71
|
when Document::LanguageId::RBS
|
72
|
-
RBSDocument.new(source: source, version: version, uri: uri,
|
72
|
+
RBSDocument.new(source: source, version: version, uri: uri, global_state: @global_state)
|
73
73
|
else
|
74
|
-
RubyDocument.new(source: source, version: version, uri: uri,
|
74
|
+
RubyDocument.new(source: source, version: version, uri: uri, global_state: @global_state)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -91,29 +91,45 @@ module RubyLsp
|
|
91
91
|
return Type.new("#{last}::<Class:#{last}>") if parts.empty?
|
92
92
|
|
93
93
|
Type.new("#{parts.join("::")}::#{last}::<Class:#{last}>")
|
94
|
-
|
94
|
+
when Prism::CallNode
|
95
|
+
raw_receiver = receiver.message
|
95
96
|
|
96
|
-
raw_receiver
|
97
|
-
receiver
|
98
|
-
|
99
|
-
receiver
|
100
|
-
end
|
97
|
+
if raw_receiver == "new"
|
98
|
+
# When invoking `new`, we recursively infer the type of the receiver to get the class type its being invoked
|
99
|
+
# on and then return the attached version of that type, since it's being instantiated.
|
100
|
+
type = infer_receiver_for_call_node(receiver, node_context)
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
name = entries&.first&.name
|
112
|
-
GuessedType.new(name) if name
|
102
|
+
return unless type
|
103
|
+
|
104
|
+
# If the method `new` was overridden, then we cannot assume that it will return a new instance of the class
|
105
|
+
new_method = @index.resolve_method("new", type.name)&.first
|
106
|
+
return if new_method && new_method.owner&.name != "Class"
|
107
|
+
|
108
|
+
type.attached
|
109
|
+
elsif raw_receiver
|
110
|
+
guess_type(raw_receiver, node_context.nesting)
|
113
111
|
end
|
112
|
+
else
|
113
|
+
guess_type(receiver.slice, node_context.nesting)
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
sig { params(raw_receiver: String, nesting: T::Array[String]).returns(T.nilable(GuessedType)) }
|
118
|
+
def guess_type(raw_receiver, nesting)
|
119
|
+
guessed_name = raw_receiver
|
120
|
+
.delete_prefix("@")
|
121
|
+
.delete_prefix("@@")
|
122
|
+
.split("_")
|
123
|
+
.map(&:capitalize)
|
124
|
+
.join
|
125
|
+
|
126
|
+
entries = @index.resolve(guessed_name, nesting) || @index.first_unqualified_const(guessed_name)
|
127
|
+
name = entries&.first&.name
|
128
|
+
return unless name
|
129
|
+
|
130
|
+
GuessedType.new(name)
|
131
|
+
end
|
132
|
+
|
117
133
|
sig { params(node_context: NodeContext).returns(Type) }
|
118
134
|
def self_receiver_handling(node_context)
|
119
135
|
nesting = node_context.nesting
|
@@ -176,6 +192,12 @@ module RubyLsp
|
|
176
192
|
def initialize(name)
|
177
193
|
@name = name
|
178
194
|
end
|
195
|
+
|
196
|
+
# Returns the attached version of this type by removing the `<Class:...>` part from its name
|
197
|
+
sig { returns(Type) }
|
198
|
+
def attached
|
199
|
+
Type.new(T.must(@name.split("::")[..-2]).join("::"))
|
200
|
+
end
|
179
201
|
end
|
180
202
|
|
181
203
|
# A type that was guessed based on the receiver raw name
|
data/lib/ruby_lsp/utils.rb
CHANGED
@@ -142,6 +142,20 @@ module RubyLsp
|
|
142
142
|
),
|
143
143
|
)
|
144
144
|
end
|
145
|
+
|
146
|
+
sig do
|
147
|
+
params(
|
148
|
+
uri: String,
|
149
|
+
diagnostics: T::Array[Interface::Diagnostic],
|
150
|
+
version: T.nilable(Integer),
|
151
|
+
).returns(Notification)
|
152
|
+
end
|
153
|
+
def publish_diagnostics(uri, diagnostics, version: nil)
|
154
|
+
new(
|
155
|
+
method: "textDocument/publishDiagnostics",
|
156
|
+
params: Interface::PublishDiagnosticsParams.new(uri: uri, diagnostics: diagnostics, version: version),
|
157
|
+
)
|
158
|
+
end
|
145
159
|
end
|
146
160
|
|
147
161
|
extend T::Sig
|
@@ -155,6 +169,35 @@ module RubyLsp
|
|
155
169
|
class Request < Message
|
156
170
|
extend T::Sig
|
157
171
|
|
172
|
+
class << self
|
173
|
+
extend T::Sig
|
174
|
+
|
175
|
+
sig { params(id: Integer, pattern: T.any(Interface::RelativePattern, String), kind: Integer).returns(Request) }
|
176
|
+
def register_watched_files(
|
177
|
+
id,
|
178
|
+
pattern,
|
179
|
+
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE
|
180
|
+
)
|
181
|
+
new(
|
182
|
+
id: id,
|
183
|
+
method: "client/registerCapability",
|
184
|
+
params: Interface::RegistrationParams.new(
|
185
|
+
registrations: [
|
186
|
+
Interface::Registration.new(
|
187
|
+
id: "workspace/didChangeWatchedFiles",
|
188
|
+
method: "workspace/didChangeWatchedFiles",
|
189
|
+
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
|
190
|
+
watchers: [
|
191
|
+
Interface::FileSystemWatcher.new(glob_pattern: pattern, kind: kind),
|
192
|
+
],
|
193
|
+
),
|
194
|
+
),
|
195
|
+
],
|
196
|
+
),
|
197
|
+
)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
158
201
|
sig { params(id: T.any(Integer, String), method: String, params: Object).void }
|
159
202
|
def initialize(id:, method:, params:)
|
160
203
|
@id = id
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lsp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.23.
|
4
|
+
version: 0.23.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-01-
|
10
|
+
date: 2025-01-09 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: language_server-protocol
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb
|
107
107
|
- lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb
|
108
108
|
- lib/ruby_indexer/lib/ruby_indexer/uri.rb
|
109
|
+
- lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb
|
109
110
|
- lib/ruby_indexer/ruby_indexer.rb
|
110
111
|
- lib/ruby_indexer/test/class_variables_test.rb
|
111
112
|
- lib/ruby_indexer/test/classes_and_modules_test.rb
|