ruby-lsp 0.3.4 → 0.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a8db1decbd8a8d3a05226ececbd13ba54aa2a0b5e727fd9a752ccda5b52322d
4
- data.tar.gz: 4f49ca2d80313dcd41e0410a1583ddc3f0c913305b4c3347611181a752561265
3
+ metadata.gz: 37a06a9c8be918e5c5a22986e68e378fc767f5c5becc46f79baa78d4b00c8c08
4
+ data.tar.gz: 4a79a4a39aaf59c49bddd6420e526246e31ade2a944ab314328f0a30da7661c2
5
5
  SHA512:
6
- metadata.gz: 510bd7ef4da254c79da9af3437403ffe70a054718e9b0a33efc52b1bb49f93cf9c951729e6528ad4cbcf7d383fa7904835f8e0496482611c3891c3ed12ba784c
7
- data.tar.gz: 2df5df95106e85a37c834c4ff77a5a19609e1946326ca86828292abb4440787b0eb8f38c9fd8f6f3cd2eb5460e8c27d0c41bb1c025d317f01502ab21afad4161
6
+ metadata.gz: 698eaf5cf5d213f6a1ffce60e40f1a4e89d599132e1940699f3a98eb5de7b4141cb442338f97c3a35850a0ed239a52a8d27edaf8a59e7a1f169373a8c2fd9fa1
7
+ data.tar.gz: d5668dfd0c88482fbb6fab215b1782a2fcfc384504a485b8047fd28a99bb3b958de9bde80ecd213b30ae369bfb50d521c60d361e631d06e398f4efb5731e3158
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -27,11 +27,14 @@ module RubyLsp
27
27
 
28
28
  sig { params(document: Document, position: Document::PositionShape).void }
29
29
  def initialize(document, position)
30
+ super(document)
31
+
30
32
  @highlights = T.let([], T::Array[LanguageServer::Protocol::Interface::DocumentHighlight])
31
33
  position = Document::Scanner.new(document.source).find_position(position)
32
- @target = T.let(find(T.must(document.tree), position), T.nilable(Support::HighlightTarget))
33
34
 
34
- super(document)
35
+ return unless document.parsed?
36
+
37
+ @target = T.let(find(T.must(document.tree), position), T.nilable(Support::HighlightTarget))
35
38
  end
36
39
 
37
40
  sig { override.returns(T.all(T::Array[LanguageServer::Protocol::Interface::DocumentHighlight], Object)) }
@@ -31,7 +31,7 @@ module RubyLsp
31
31
  class << self
32
32
  extend T::Sig
33
33
 
34
- sig { returns(T::Hash[String, T::Array[String]]) }
34
+ sig { returns(T::Hash[String, T::Hash[String, T::Hash[String, String]]]) }
35
35
  def gem_paths
36
36
  @gem_paths ||= T.let(begin
37
37
  lookup = {}
@@ -61,7 +61,7 @@ module RubyLsp
61
61
  end
62
62
 
63
63
  lookup
64
- end, T.nilable(T::Hash[String, T::Array[String]]))
64
+ end, T.nilable(T::Hash[String, T::Hash[String, T::Hash[String, String]]]))
65
65
  end
66
66
  end
67
67
 
@@ -88,7 +88,7 @@ module RubyLsp
88
88
  return unless match
89
89
 
90
90
  uri = T.cast(URI(match[0]), URI::Source)
91
- gem_version = resolve_version(uri)
91
+ gem_version = T.must(resolve_version(uri))
92
92
  file_path = self.class.gem_paths.dig(uri.gem_name, gem_version, uri.path)
93
93
  return if file_path.nil?
94
94
 
@@ -1,8 +1,6 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "ruby_lsp/requests/support/rails_document_client"
5
-
6
4
  module RubyLsp
7
5
  module Requests
8
6
  # ![Hover demo](../../misc/rails_document_link_hover.gif)
@@ -20,6 +20,7 @@ module RubyLsp
20
20
  # ```
21
21
  class SemanticHighlighting < BaseRequest
22
22
  extend T::Sig
23
+ include SyntaxTree::WithEnvironment
23
24
 
24
25
  TOKEN_TYPES = T.let({
25
26
  namespace: 0,
@@ -172,37 +173,52 @@ module RubyLsp
172
173
  def visit_params(node)
173
174
  node.keywords.each do |keyword,|
174
175
  location = keyword.location
175
- add_token(location_without_colon(location), :variable)
176
+ add_token(location_without_colon(location), :parameter)
176
177
  end
177
178
 
178
179
  node.requireds.each do |required|
179
- add_token(required.location, :variable)
180
+ add_token(required.location, :parameter)
180
181
  end
181
182
 
182
183
  rest = node.keyword_rest
183
- return if rest.nil? || rest.is_a?(SyntaxTree::ArgsForward)
184
+ if rest && !rest.is_a?(SyntaxTree::ArgsForward)
185
+ name = rest.name
186
+ add_token(name.location, :parameter) if name
187
+ end
188
+
189
+ super
190
+ end
191
+
192
+ sig { override.params(node: SyntaxTree::Field).void }
193
+ def visit_field(node)
194
+ add_token(node.name.location, :method)
184
195
 
185
- name = rest.name
186
- add_token(name.location, :variable) if name
196
+ super
187
197
  end
188
198
 
189
199
  sig { override.params(node: SyntaxTree::VarField).void }
190
200
  def visit_var_field(node)
191
- case node.value
201
+ value = node.value
202
+
203
+ case value
192
204
  when SyntaxTree::Ident
193
- add_token(node.value.location, :variable)
205
+ type = type_for_local(value)
206
+ add_token(value.location, type)
194
207
  else
195
- visit(node.value)
208
+ visit(value)
196
209
  end
197
210
  end
198
211
 
199
212
  sig { override.params(node: SyntaxTree::VarRef).void }
200
213
  def visit_var_ref(node)
201
- case node.value
214
+ value = node.value
215
+
216
+ case value
202
217
  when SyntaxTree::Ident
203
- add_token(node.value.location, :variable)
218
+ type = type_for_local(value)
219
+ add_token(value.location, type)
204
220
  else
205
- visit(node.value)
221
+ visit(value)
206
222
  end
207
223
  end
208
224
 
@@ -263,6 +279,17 @@ module RubyLsp
263
279
  def special_method?(method_name)
264
280
  SPECIAL_RUBY_METHODS.include?(method_name)
265
281
  end
282
+
283
+ sig { params(value: SyntaxTree::Ident).returns(Symbol) }
284
+ def type_for_local(value)
285
+ local = current_environment.find_local(value.value)
286
+
287
+ if local.nil? || local.type == :variable
288
+ :variable
289
+ else
290
+ :parameter
291
+ end
292
+ end
266
293
  end
267
294
  end
268
295
  end
@@ -28,7 +28,7 @@ module RubyLsp
28
28
  params(name: String).returns(T::Array[String])
29
29
  end
30
30
  def generate_rails_document_urls(name)
31
- docs = T.must(search_index)[name]
31
+ docs = search_index&.fetch(name, nil)
32
32
 
33
33
  return [] unless docs
34
34
 
@@ -39,6 +39,7 @@ module RubyLsp
39
39
  autoload :SemanticTokenEncoder, "ruby_lsp/requests/support/semantic_token_encoder"
40
40
  autoload :SyntaxErrorDiagnostic, "ruby_lsp/requests/support/syntax_error_diagnostic"
41
41
  autoload :HighlightTarget, "ruby_lsp/requests/support/highlight_target"
42
+ autoload :RailsDocumentClient, "ruby_lsp/requests/support/rails_document_client"
42
43
  end
43
44
  end
44
45
  end
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.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-13 00:00:00.000000000 Z
11
+ date: 2022-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 3.6.3
47
+ version: 4.0.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.6.3
54
+ version: 4.0.2
55
55
  description: An opinionated language server for Ruby
56
56
  email:
57
57
  - ruby@shopify.com