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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de59c33976acd6f570c9f4812248e905b8fc8b3ca2c61f5bc1a6acb82d903ee7
4
- data.tar.gz: 4af340c2c6c89bdd5c19e152a26e94614ac83e7770387564f936276fc063a5c4
3
+ metadata.gz: 764e9fc1c28866c816e63128566630c67a64de01806866564321f79d24f8b6a0
4
+ data.tar.gz: 6fe1eec7178a026983f631c66e82c764994d86f4c4eb9336d6df947808547c31
5
5
  SHA512:
6
- metadata.gz: 7cb778276e436791c288856e37f36e00ff22293f507368bb0170a3ccf8f0b289ca2f652a15f9eb5b24d28c8a70f3e18fe8732da3590045b252cc9c193a293a8f
7
- data.tar.gz: d68688323dd99d361f11fbb7ce070e66b31e5492ef90f7829d536215fb0439e2efa0ffb9bc67df81f410e451c89b3bd149ea629d836b55181cf2debae6aed353
6
+ metadata.gz: d2f731dae661bd512c8531918d8f69e977b2acc992f683678761fa1cb9d88b5454cae9b7e3abdbb5d273b42c0a36f8842084369ccfd6e1a0143760d26bf52cf7
7
+ data.tar.gz: b824829e84e030748ef6808e3acd7b84744d7127baf6afa23e7904825cd7d0d4ade4f89ce34f5f9f91d1e053b8635f4a109e0a7e3150913556828415450d2b85
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-lsp (0.1.4)
4
+ rubocop-lsp (0.1.5)
5
5
  language_server-protocol (>= 3.16)
6
6
  rubocop (>= 1.0)
7
7
 
@@ -26,8 +26,8 @@ module Rubocop
26
26
  end
27
27
 
28
28
  on("textDocument/didChange") do |request|
29
- uri = request[:params][:textDocument][:uri]
30
- text = request[:params][:contentChanges][0][:text]
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[:params][:textDocument][:uri]
40
- text = request[:params][:textDocument][:text]
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[:params][:textDocument][:uri]
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[:params][:textDocument][:uri]
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[:params][:textDocument][:uri]
65
- range = request[:params][:range]
66
- line_range = Range.new(range[:start][:line], range[:end][:line])
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::Formatter::BaseFormatter
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
- config_store = ::RuboCop::ConfigStore.new
18
- options, paths = ::RuboCop::Options.new.parse(["--stderr", "--auto-correct"])
19
- # config_store.options_config = options[:config] if options[:config]
20
- options[:stdin] = text
21
- paths << file
22
- runner = ::RuboCop::Runner.new(options, config_store)
23
- runner.send(:formatter_set).clear.push(self)
24
- runner.run(paths)
25
- @formatted_text = options[:stdin]
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 :cop_name, :message, :start, :end, :replacements, :diagnostic_response
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
- @cop_name = offense.cop_name
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
- private
39
+ def cop_name
40
+ @cop_name ||= badge.to_s
41
+ end
21
42
 
22
- def diagnostic_from_offense(offense)
23
- Interface::Diagnostic.new(
24
- message: offense.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: @start,
28
- end: @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
 
@@ -55,7 +55,7 @@ module Model
55
55
 
56
56
  Interface::CodeAction.new(
57
57
  title: title,
58
- kind: "rubocop.fix",
58
+ kind: kind,
59
59
  edit: Interface::WorkspaceEdit.new(
60
60
  document_changes: [
61
61
  Interface::TextDocumentEdit.new(
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Lsp
5
- VERSION = "0.1.4"
5
+ VERSION = "0.1.5"
6
6
  end
7
7
  end
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
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-07-26 00:00:00.000000000 Z
11
+ date: 2021-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop