ruby-lsp 0.23.1 → 0.23.3

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.
@@ -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:, encoding: Encoding::UTF_8)
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, encoding: encoding)
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, encoding: encoding)
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, encoding: encoding)
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
- else
94
+ when Prism::CallNode
95
+ raw_receiver = receiver.message
95
96
 
96
- raw_receiver = if receiver.is_a?(Prism::CallNode)
97
- receiver.message
98
- else
99
- receiver.slice
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
- if raw_receiver
103
- guessed_name = raw_receiver
104
- .delete_prefix("@")
105
- .delete_prefix("@@")
106
- .split("_")
107
- .map(&:capitalize)
108
- .join
109
-
110
- entries = @index.resolve(guessed_name, node_context.nesting) || @index.first_unqualified_const(guessed_name)
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
@@ -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.1
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-06 00:00:00.000000000 Z
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