rubocop-lsp 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rubocop/lsp/cli.rb +12 -9
- data/lib/rubocop/lsp/diagnostic_collector.rb +24 -11
- data/lib/rubocop/lsp/model/diagnostic.rb +45 -9
- data/lib/rubocop/lsp/model/diagnostic_collection.rb +1 -1
- data/lib/rubocop/lsp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 764e9fc1c28866c816e63128566630c67a64de01806866564321f79d24f8b6a0
|
4
|
+
data.tar.gz: 6fe1eec7178a026983f631c66e82c764994d86f4c4eb9336d6df947808547c31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2f731dae661bd512c8531918d8f69e977b2acc992f683678761fa1cb9d88b5454cae9b7e3abdbb5d273b42c0a36f8842084369ccfd6e1a0143760d26bf52cf7
|
7
|
+
data.tar.gz: b824829e84e030748ef6808e3acd7b84744d7127baf6afa23e7904825cd7d0d4ade4f89ce34f5f9f91d1e053b8635f4a109e0a7e3150913556828415450d2b85
|
data/Gemfile.lock
CHANGED
data/lib/rubocop/lsp/cli.rb
CHANGED
@@ -26,8 +26,8 @@ module Rubocop
|
|
26
26
|
end
|
27
27
|
|
28
28
|
on("textDocument/didChange") do |request|
|
29
|
-
uri = request
|
30
|
-
text = request
|
29
|
+
uri = request.dig(:params, :textDocument, :uri)
|
30
|
+
text = request.dig(:params, :contentChanges, 0, :text)
|
31
31
|
|
32
32
|
collector = collect_diagnostics(uri: uri, text: text)
|
33
33
|
send_diagnostics(collector)
|
@@ -36,8 +36,8 @@ module Rubocop
|
|
36
36
|
end
|
37
37
|
|
38
38
|
on("textDocument/didOpen") do |request|
|
39
|
-
uri = request
|
40
|
-
text = request
|
39
|
+
uri = request.dig(:params, :textDocument, :uri)
|
40
|
+
text = request.dig(:params, :textDocument, :text)
|
41
41
|
|
42
42
|
collector = collect_diagnostics(uri: uri, text: text)
|
43
43
|
send_diagnostics(collector)
|
@@ -46,7 +46,7 @@ module Rubocop
|
|
46
46
|
end
|
47
47
|
|
48
48
|
on("textDocument/didClose") do |request|
|
49
|
-
uri = request
|
49
|
+
uri = request.dig(:params, :textDocument, :uri)
|
50
50
|
|
51
51
|
clear_diagnostics(uri: uri)
|
52
52
|
|
@@ -54,16 +54,19 @@ module Rubocop
|
|
54
54
|
end
|
55
55
|
|
56
56
|
on("textDocument/formatting") do |request|
|
57
|
-
uri = request
|
57
|
+
uri = request.dig(:params, :textDocument, :uri)
|
58
58
|
|
59
59
|
collector = collect_diagnostics(uri: uri, text: store.text_for(uri))
|
60
60
|
send_text_edits(collector)
|
61
61
|
end
|
62
62
|
|
63
63
|
on("textDocument/codeAction") do |request|
|
64
|
-
uri = request
|
65
|
-
range = request
|
66
|
-
|
64
|
+
uri = request.dig(:params, :textDocument, :uri)
|
65
|
+
range = request.dig(:params, :range)
|
66
|
+
start_line = range.dig(:start, :line)
|
67
|
+
end_line = range.dig(:end, :line)
|
68
|
+
|
69
|
+
line_range = Range.new(start_line, end_line)
|
67
70
|
|
68
71
|
send_code_actions(uri, line_range)
|
69
72
|
end
|
@@ -2,27 +2,40 @@
|
|
2
2
|
|
3
3
|
require "rubocop/lsp/model/diagnostic_collection"
|
4
4
|
|
5
|
-
class DiagnosticCollector < RuboCop::
|
5
|
+
class DiagnosticCollector < RuboCop::Runner
|
6
|
+
RUBOCOP_FLAGS = [
|
7
|
+
"--stderr", # Print any output to stderr so that our stdout does not get polluted
|
8
|
+
"--format",
|
9
|
+
"quiet", # Supress any progress output by setting the formatter to `quiet`
|
10
|
+
"--auto-correct", # Apply the autocorrects on the supplied buffer
|
11
|
+
]
|
12
|
+
|
6
13
|
attr_reader :uri, :file, :text, :formatted_text, :diagnostics
|
7
14
|
|
8
15
|
def initialize(uri:, text:)
|
9
|
-
super({}, nil)
|
10
16
|
@uri = uri
|
11
17
|
@file = CGI.unescape(URI.parse(uri).path)
|
12
18
|
@text = text
|
13
19
|
@formatted_text = nil
|
20
|
+
|
21
|
+
super(
|
22
|
+
::RuboCop::Options.new.parse(RUBOCOP_FLAGS).first,
|
23
|
+
::RuboCop::ConfigStore.new
|
24
|
+
)
|
14
25
|
end
|
15
26
|
|
16
27
|
def run
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
options[:stdin] = text
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
# Send text via "stdin".
|
29
|
+
# RuboCop reads all of stdin into the "stdin" option, when `--stdin`
|
30
|
+
# flag is supplied
|
31
|
+
@options[:stdin] = text
|
32
|
+
|
33
|
+
# Invoke the actual run method with just this file in `paths`
|
34
|
+
super([file])
|
35
|
+
|
36
|
+
# RuboCop applies autocorrections to the "stdin" option,
|
37
|
+
# so read that into the formatted text attribute
|
38
|
+
@formatted_text = @options[:stdin]
|
26
39
|
end
|
27
40
|
|
28
41
|
def file_finished(_file, offenses)
|
@@ -2,34 +2,70 @@
|
|
2
2
|
|
3
3
|
module Model
|
4
4
|
class Diagnostic
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :badge, :message, :start, :end, :replacements
|
6
|
+
|
7
|
+
DOCS_URLS = {
|
8
|
+
"Bundler": "https://docs.rubocop.org/rubocop/cops_bundler.html#%{anchor}",
|
9
|
+
"Gemspec": "https://docs.rubocop.org/rubocop/cops_gemspec.html#%{anchor}",
|
10
|
+
"Layout": "https://docs.rubocop.org/rubocop/cops_layout.html#%{anchor}",
|
11
|
+
"Lint": "https://docs.rubocop.org/rubocop/cops_lint.html#%{anchor}",
|
12
|
+
"Metrics": "https://docs.rubocop.org/rubocop/cops_metrics.html#%{anchor}",
|
13
|
+
"Migration": "https://docs.rubocop.org/rubocop/cops_migration.html#%{anchor}",
|
14
|
+
"Naming": "https://docs.rubocop.org/rubocop/cops_naming.html#%{anchor}",
|
15
|
+
"Security": "https://docs.rubocop.org/rubocop/cops_security.html#%{anchor}",
|
16
|
+
"Style": "https://docs.rubocop.org/rubocop/cops_style.html#%{anchor}",
|
17
|
+
"Minitest": "https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#%{anchor}",
|
18
|
+
"Performance": "https://docs.rubocop.org/rubocop-performance/cops_performance.html#%{anchor}",
|
19
|
+
"Rails": "https://docs.rubocop.org/rubocop-rails/cops_rails.html#%{anchor}",
|
20
|
+
"RSpec": "https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#%{anchor}",
|
21
|
+
"RSpec/Capybara": "https://docs.rubocop.org/rubocop-rspec/cops_rspec/capybara.html#%{anchor}",
|
22
|
+
"RSpec/FactoryBot": "https://docs.rubocop.org/rubocop-rspec/cops_rspec/factorybot.html#%{anchor}",
|
23
|
+
"RSpec/Rails": "https://docs.rubocop.org/rubocop-rspec/cops_rspec/rails.html#%{anchor}",
|
24
|
+
"Sorbet": "https://github.com/Shopify/rubocop-sorbet/blob/master/manual/cops_sorbet.md#%{anchor}",
|
25
|
+
}
|
6
26
|
|
7
27
|
def initialize(offense)
|
8
|
-
@
|
28
|
+
@badge = RuboCop::Cop::Badge.parse(offense.cop_name)
|
9
29
|
@message = offense.message
|
10
30
|
@start = Interface::Position.new(line: offense.line - 1, character: offense.column)
|
11
31
|
@end = Interface::Position.new(line: offense.last_line - 1, character: offense.last_column)
|
12
32
|
@replacements = replacements_from_offense(offense)
|
13
|
-
@diagnostic_response = diagnostic_from_offense(offense)
|
14
33
|
end
|
15
34
|
|
16
35
|
def correctable?
|
17
36
|
!!@replacements
|
18
37
|
end
|
19
38
|
|
20
|
-
|
39
|
+
def cop_name
|
40
|
+
@cop_name ||= badge.to_s
|
41
|
+
end
|
21
42
|
|
22
|
-
def
|
23
|
-
Interface::Diagnostic.new(
|
24
|
-
message:
|
43
|
+
def diagnostic_response
|
44
|
+
@diagnostic_response ||= Interface::Diagnostic.new(
|
45
|
+
message: message,
|
46
|
+
"source": "RuboCop",
|
47
|
+
code: cop_name,
|
48
|
+
code_description: Interface::CodeDescription.new(
|
49
|
+
href: doc_url
|
50
|
+
),
|
25
51
|
severity: Constant::DiagnosticSeverity::INFORMATION,
|
26
52
|
range: Interface::Range.new(
|
27
|
-
start:
|
28
|
-
end:
|
53
|
+
start: start,
|
54
|
+
end: self.end
|
29
55
|
)
|
30
56
|
)
|
31
57
|
end
|
32
58
|
|
59
|
+
private
|
60
|
+
|
61
|
+
def doc_url
|
62
|
+
@doc_url ||= begin
|
63
|
+
anchor = cop_name.downcase.gsub(%r{/}, "")
|
64
|
+
|
65
|
+
format(DOCS_URLS[badge.department], anchor: anchor)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
33
69
|
def replacements_from_offense(offense)
|
34
70
|
return unless offense.correctable?
|
35
71
|
|
data/lib/rubocop/lsp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-lsp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|