rubocop-lsp 0.1.1 → 0.1.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: 3c17a7ea5c41b994245f6f8d3231d64bd14debc7d694383f2e847f0ccef92d82
4
- data.tar.gz: c1b2f65bfd943cc815ac35196660296f11e89bdfd6945f605014c813c7244489
3
+ metadata.gz: 2e39f6df6dfef436bd3d67d745e2b300e9eead65c37ddeb8d28e05ac916d6ce5
4
+ data.tar.gz: d537d77e74bef4a92db2a71a05fd4e1b8c4832f4ca40a9a524b94433e9a1f204
5
5
  SHA512:
6
- metadata.gz: ffacb6a3e97dd4d3d70e8c36daf9a6d3864b1a732ea09fa5bb6f92cba96ea7cb4ac15d8e384fd82b839dea513af5de15da072289cbad99e90d80f9bb81298a3f
7
- data.tar.gz: 6d37b9ee07feda017345dd717c26c158d8cafe154d2b3c61b89d460d1edcc092cebfeb7fe68d1167e7036d097de9a41347b3208e19a438c355327037739ef4ca
6
+ metadata.gz: 5de228c6fa093e2835e58686a6452d04971d5808a84ed15b2cae42a2ccbecc126e0ca115695b0c82075d455b2cf59778d35a3b6ca5cc44d8ba0f5c2e09fbb6b5
7
+ data.tar.gz: 33eeba13254dc0ee9617ef1b1d8f559da3a91ac3e9c9daeafc528fe38bdafab90975260ed7b04a8a4d22771b097c381574ef0398d3219aa48fd125bd47319423
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-lsp (0.1.1)
4
+ rubocop-lsp (0.1.2)
5
5
  language_server-protocol (>= 3.16)
6
6
  rubocop (>= 1.0)
7
7
 
@@ -22,8 +22,9 @@ module Rubocop
22
22
  capabilities: Interface::ServerCapabilities.new(
23
23
  text_document_sync: Interface::TextDocumentSyncOptions.new(
24
24
  change: Constant::TextDocumentSyncKind::FULL,
25
- open_close: true
25
+ open_close: true,
26
26
  ),
27
+ document_formatting_provider: true,
27
28
  code_action_provider: true
28
29
  ),
29
30
  )
@@ -62,6 +63,16 @@ module Rubocop
62
63
  nil
63
64
  end
64
65
 
66
+ on("textDocument/formatting") do |request|
67
+ uri = request[:params][:textDocument][:uri]
68
+ file = CGI.unescape(URI.parse(uri).path)
69
+
70
+ collector = DiagnosticCollector.new(file: file, text: File.binread(file))
71
+ collector.run
72
+
73
+ collector.text_edits_from_formatting
74
+ end
75
+
65
76
  on("textDocument/codeAction") do |request|
66
77
  uri = request[:params][:textDocument][:uri]
67
78
  range = request[:params][:range]
@@ -4,21 +4,25 @@ class DiagnosticCollector < RuboCop::Formatter::BaseFormatter
4
4
  Interface = LanguageServer::Protocol::Interface
5
5
  Constant = LanguageServer::Protocol::Constant
6
6
 
7
- attr_reader :diagnostics
7
+ attr_reader :file, :text, :formatted_text, :diagnostics
8
8
 
9
- def initialize
9
+ def initialize(file:, text:)
10
10
  super({}, nil)
11
+ @file = file
12
+ @text = text
13
+ @formatted_text = nil
11
14
  end
12
15
 
13
- def run(file:, text:)
16
+ def run
14
17
  config_store = ::RuboCop::ConfigStore.new
15
- options, paths = ::RuboCop::Options.new.parse(["--stderr"])
18
+ options, paths = ::RuboCop::Options.new.parse(["--stderr", "--auto-correct"])
16
19
  # config_store.options_config = options[:config] if options[:config]
17
20
  options[:stdin] = text
18
21
  paths << file
19
22
  runner = ::RuboCop::Runner.new(options, config_store)
20
23
  runner.send(:formatter_set).clear.push(self)
21
24
  runner.run(paths)
25
+ @formatted_text = options[:stdin]
22
26
  end
23
27
 
24
28
  def file_finished(_file, offenses)
@@ -27,6 +31,20 @@ class DiagnosticCollector < RuboCop::Formatter::BaseFormatter
27
31
  end
28
32
  end
29
33
 
34
+ def formatting_text_edits
35
+ return unless formatted_text
36
+
37
+ [
38
+ Interface::TextEdit.new(
39
+ range: Interface::Range.new(
40
+ start: Interface::Position.new(line: 0, character: 0),
41
+ end: Interface::Position.new(line: text.size, character: text.size)
42
+ ),
43
+ new_text: formatted_text
44
+ ),
45
+ ]
46
+ end
47
+
30
48
  private
31
49
 
32
50
  def diagnostic_from_offense(offense)
@@ -35,7 +35,6 @@ module DiagnosticStore
35
35
 
36
36
  unless actions.empty?
37
37
  actions << code_action_from_diagnostics(uri, line_diagnostics, title: "Autocorrect all offenses on line")
38
- actions << code_action_from_diagnostics(uri, file_diagnostics, title: "Autocorrect all offenses in file")
39
38
  end
40
39
 
41
40
  actions
@@ -65,8 +65,8 @@ class Handler
65
65
 
66
66
  def collect_diagnostics(uri:, text:)
67
67
  file = CGI.unescape(URI.parse(uri).path)
68
- collector = DiagnosticCollector.new
69
- collector.run(file: file, text: text)
68
+ collector = DiagnosticCollector.new(file: file, text: text)
69
+ collector.run
70
70
  DiagnosticStore.set_diagnostics_for(uri, collector.diagnostics)
71
71
  end
72
72
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Lsp
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-lsp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify