ruby-lsp 0.3.1 → 0.3.2

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: 9762389a7b7979afb57d6e6d2cf0d65b0b0a0b31f5a1fdd7045311c33a0c21d6
4
- data.tar.gz: 35cc2318946e650ee311129955d3674c7e693a87d25c5cc2f29c5a55e479d880
3
+ metadata.gz: 3e09a85000549c0b7b7dd2886b49d44ca2e32b830616a4af7181a2d7952f948f
4
+ data.tar.gz: f19b017ebffce3a090d9fe9c39c94cb0dad75a7a74856c099443839524d513f3
5
5
  SHA512:
6
- metadata.gz: 4735e18c297c992727d0a151ed7948cf6d4ea32b01fe411ed0774efdda7cdc0cf6533f5d71ad288aad9e6e717149932744376fdceda9fa4cd039b560934a9b47
7
- data.tar.gz: bd6e0c9a81a373c509f2f96b480543657a8d241a6e58ea25ec21c62ac60094f299af1c5f85d1555ad6ca1908c325e46569119271d4c6b7117f33f9919cf40bca
6
+ metadata.gz: e0b75fa95c43a4a15a46e3cd663b5dd637c9288497116b356eb69dc3f831cfdbb3e167c1c578b68feee715e85c72d26c7d63236e3250552ddbf0f2db334e8f46
7
+ data.tar.gz: c80518dba77375f07f9944f0401f6836ca69bba60ba6723677e33e366104dd69b70832e8ce76c05312b47c3a032a5308711505e88be2ce69f3f837bec2db3c21
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.2]
10
+
11
+ - Make the diagnostic request parallel (https://github.com/Shopify/ruby-lsp/pull/293)
12
+ - Improve worker stability (https://github.com/Shopify/ruby-lsp/pull/295)
13
+
9
14
  ## [0.3.1]
10
15
 
11
16
  - Resolve TODO for LSP v3.17 (https://github.com/Shopify/ruby-lsp/pull/268)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -7,8 +7,6 @@ module RubyLsp
7
7
  class Queue
8
8
  extend T::Sig
9
9
 
10
- class Cancelled < StandardError; end
11
-
12
10
  class Result < T::Struct
13
11
  const :response, T.untyped # rubocop:disable Sorbet/ForbidUntypedStructProps
14
12
  const :error, T.nilable(Exception)
@@ -40,8 +38,6 @@ module RubyLsp
40
38
  @job_queue = T.let(Thread::Queue.new, Thread::Queue)
41
39
  # The jobs hash is just a way of keeping a handle to jobs based on the request ID, so we can cancel them
42
40
  @jobs = T.let({}, T::Hash[T.any(String, Integer), Job])
43
- # The current job is a handle to cancel jobs that are currently being processed
44
- @current_job = T.let(nil, T.nilable(Job))
45
41
  @mutex = T.let(Mutex.new, Mutex)
46
42
  @worker = T.let(new_worker, Thread)
47
43
 
@@ -65,11 +61,6 @@ module RubyLsp
65
61
  @mutex.synchronize do
66
62
  # Cancel the job if it's still in the queue
67
63
  @jobs[id]&.cancel
68
-
69
- # Cancel the job if we're in the middle of processing it
70
- if @current_job&.request&.dig(:id) == id
71
- @worker.raise(Cancelled)
72
- end
73
64
  end
74
65
  end
75
66
 
@@ -92,8 +83,6 @@ module RubyLsp
92
83
 
93
84
  request_time = Benchmark.realtime do
94
85
  response = T.must(@handlers[request[:method]]).action.call(request)
95
- rescue Cancelled
96
- raise
97
86
  rescue StandardError, LoadError => e
98
87
  error = e
99
88
  end
@@ -109,25 +98,27 @@ module RubyLsp
109
98
  ).void
110
99
  end
111
100
  def finalize_request(result, request)
112
- error = result.error
113
- if error
114
- T.must(@handlers[request[:method]]).error_handler&.call(error, request)
115
-
116
- @writer.write(
117
- id: request[:id],
118
- error: {
119
- code: LanguageServer::Protocol::Constant::ErrorCodes::INTERNAL_ERROR,
120
- message: result.error.inspect,
121
- data: request.to_json,
122
- },
123
- )
124
- elsif result.response != Handler::VOID
125
- @writer.write(id: request[:id], result: result.response)
126
- end
101
+ @mutex.synchronize do
102
+ error = result.error
103
+ if error
104
+ T.must(@handlers[request[:method]]).error_handler&.call(error, request)
105
+
106
+ @writer.write(
107
+ id: request[:id],
108
+ error: {
109
+ code: LanguageServer::Protocol::Constant::ErrorCodes::INTERNAL_ERROR,
110
+ message: result.error.inspect,
111
+ data: request.to_json,
112
+ },
113
+ )
114
+ elsif result.response != Handler::VOID
115
+ @writer.write(id: request[:id], result: result.response)
116
+ end
127
117
 
128
- request_time = result.request_time
129
- if request_time
130
- @writer.write(method: "telemetry/event", params: telemetry_params(request, request_time, result.error))
118
+ request_time = result.request_time
119
+ if request_time
120
+ @writer.write(method: "telemetry/event", params: telemetry_params(request, request_time, result.error))
121
+ end
131
122
  end
132
123
  end
133
124
 
@@ -139,28 +130,20 @@ module RubyLsp
139
130
  # Thread::Queue#pop is thread safe and will wait until an item is available
140
131
  loop do
141
132
  job = T.let(@job_queue.pop, T.nilable(Job))
142
- break if job.nil?
143
-
144
133
  # The only time when the job is nil is when the queue is closed and we can then terminate the thread
134
+ break if job.nil?
145
135
 
146
136
  request = job.request
147
- @mutex.synchronize do
148
- @jobs.delete(request[:id])
149
- @current_job = job
150
- end
151
-
152
- next if job.cancelled
137
+ @mutex.synchronize { @jobs.delete(request[:id]) }
153
138
 
154
- result = execute(request)
155
- rescue Cancelled
156
- # We need to return nil to the client even if the request was cancelled
157
- result = Queue::Result.new(response: nil, error: nil, request_time: nil)
158
- ensure
159
- @mutex.synchronize { @current_job = nil }
139
+ result = if job.cancelled
140
+ # We need to return nil to the client even if the request was cancelled
141
+ Queue::Result.new(response: nil, error: nil, request_time: nil)
142
+ else
143
+ execute(request)
144
+ end
160
145
 
161
- # If there's request, it means the worker was cancelled while waiting to pop from the queue or immediately
162
- # after
163
- finalize_request(result, request) unless result.nil? || request.nil?
146
+ finalize_request(result, request)
164
147
  end
165
148
  end
166
149
  end
@@ -14,6 +14,8 @@ module RubyLsp
14
14
  class RuboCopRunner < RuboCop::Runner
15
15
  extend T::Sig
16
16
 
17
+ class ConfigurationError < StandardError; end
18
+
17
19
  sig { returns(T::Array[RuboCop::Cop::Offense]) }
18
20
  attr_reader :offenses
19
21
 
@@ -50,6 +52,8 @@ module RubyLsp
50
52
  super([path])
51
53
  rescue RuboCop::Runner::InfiniteCorrectionLoop => error
52
54
  raise Formatting::Error, error.message
55
+ rescue RuboCop::ValidationError => error
56
+ raise ConfigurationError, error.message
53
57
  end
54
58
 
55
59
  sig { returns(String) }
@@ -191,7 +191,7 @@ module RubyLsp
191
191
  Handler::VOID
192
192
  end
193
193
 
194
- on("textDocument/diagnostic") do |request|
194
+ on("textDocument/diagnostic", parallel: true) do |request|
195
195
  uri = request.dig(:params, :textDocument, :uri)
196
196
  response = store.cache_fetch(uri, :diagnostics) do |document|
197
197
  Requests::Diagnostics.new(uri, document).run
@@ -199,9 +199,7 @@ module RubyLsp
199
199
 
200
200
  { kind: "full", items: response.map(&:to_lsp_diagnostic) } if response
201
201
  end.on_error do |error|
202
- if error.is_a?(RuboCop::ValidationError)
203
- show_message(Constant::MessageType::ERROR, "Error in RuboCop configuration file: #{error.message}")
204
- end
202
+ show_message(Constant::MessageType::ERROR, "Error running diagnostics: #{error.message}")
205
203
  end
206
204
 
207
205
  on("shutdown") { shutdown }
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.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-06 00:00:00.000000000 Z
11
+ date: 2022-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol