ruby-lsp 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a8db1decbd8a8d3a05226ececbd13ba54aa2a0b5e727fd9a752ccda5b52322d
4
- data.tar.gz: 4f49ca2d80313dcd41e0410a1583ddc3f0c913305b4c3347611181a752561265
3
+ metadata.gz: 59e3f670a003f565c001d00333a727d8cf4080eb274d4ebdf248bc0ad76b9c16
4
+ data.tar.gz: 5010473614d96f47ba10a267844448d6b5985b469cdfec752489be268ba95510
5
5
  SHA512:
6
- metadata.gz: 510bd7ef4da254c79da9af3437403ffe70a054718e9b0a33efc52b1bb49f93cf9c951729e6528ad4cbcf7d383fa7904835f8e0496482611c3891c3ed12ba784c
7
- data.tar.gz: 2df5df95106e85a37c834c4ff77a5a19609e1946326ca86828292abb4440787b0eb8f38c9fd8f6f3cd2eb5460e8c27d0c41bb1c025d317f01502ab21afad4161
6
+ metadata.gz: '0853a29d497f7befc9bcbbd0387c3e456293728788b0067b91026f4c61c5013240284adc913471b5c015184b19752ecac5e958ab021f301e41c24ce55ed876e2'
7
+ data.tar.gz: c2ee016b997013590cad9c575b1461d50f833d3fc06a7b22aa953aa73d6163feb5d821fe443c4ba20b0ac25cf686f32ed26c34348016408f6118f45261cce8a9
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.6
@@ -96,8 +96,9 @@ module RubyLsp
96
96
  end
97
97
 
98
98
  @tree = SyntaxTree.parse(@parsable_source)
99
- rescue SyntaxTree::Parser::ParseError
100
- # If we can't parse the source even after emptying the edits, then just fallback to the previous source
99
+ rescue StandardError
100
+ # Trying to maintain a parsable source when there are syntax errors is a best effort. If we fail to apply edits or
101
+ # parse, just ignore it
101
102
  end
102
103
 
103
104
  sig { params(source: String, range: RangeShape, text: String).void }
@@ -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.6
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-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol
@@ -44,14 +44,20 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 3.6.3
47
+ version: 4.0.2
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 5.0.0
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
55
  - - ">="
53
56
  - !ruby/object:Gem::Version
54
- version: 3.6.3
57
+ version: 4.0.2
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 5.0.0
55
61
  description: An opinionated language server for Ruby
56
62
  email:
57
63
  - ruby@shopify.com