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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rubocop/lsp/cli.rb +12 -1
- data/lib/rubocop/lsp/diagnostic_collector.rb +22 -4
- data/lib/rubocop/lsp/diagnostic_store.rb +0 -1
- data/lib/rubocop/lsp/handler.rb +2 -2
- data/lib/rubocop/lsp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e39f6df6dfef436bd3d67d745e2b300e9eead65c37ddeb8d28e05ac916d6ce5
|
4
|
+
data.tar.gz: d537d77e74bef4a92db2a71a05fd4e1b8c4832f4ca40a9a524b94433e9a1f204
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5de228c6fa093e2835e58686a6452d04971d5808a84ed15b2cae42a2ccbecc126e0ca115695b0c82075d455b2cf59778d35a3b6ca5cc44d8ba0f5c2e09fbb6b5
|
7
|
+
data.tar.gz: 33eeba13254dc0ee9617ef1b1d8f559da3a91ac3e9c9daeafc528fe38bdafab90975260ed7b04a8a4d22771b097c381574ef0398d3219aa48fd125bd47319423
|
data/Gemfile.lock
CHANGED
data/lib/rubocop/lsp/cli.rb
CHANGED
@@ -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
|
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
|
data/lib/rubocop/lsp/handler.rb
CHANGED
@@ -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
|
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
|
data/lib/rubocop/lsp/version.rb
CHANGED