standard 1.24.2 → 1.24.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +3 -3
- data/lib/standard/lsp/logger.rb +10 -0
- data/lib/standard/lsp/routes.rb +6 -2
- data/lib/standard/lsp/server.rb +2 -6
- data/lib/standard/lsp/standardizer.rb +42 -26
- data/lib/standard/runners/lsp.rb +1 -2
- data/lib/standard/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: cc7f5e2e4baad0d0471e6aba98df29bd5d8bb3db7c4a8fc3557581572a30865b
|
4
|
+
data.tar.gz: 76083326596e81461fc7cf9664421d4089555d9a3b1a2f8706e2884522379611
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47a6281011618bc51cd198c5dad586608d97c64ed05a4146d8549739332d22d70669f24fd9a59e1508c6b1ec6d631387949d589ab97241adf296fd0c2ec5ca22
|
7
|
+
data.tar.gz: dbca4f6a5c7e0777e93a98f3c6f0f14b4a15210cadcad1c8489f16319e636fe92ee5de19a295389fb3cdec7b73c37bd86510aa7de0b3dd8537f8033766cbd45c
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
standard (1.24.
|
4
|
+
standard (1.24.3)
|
5
5
|
language_server-protocol (~> 3.17.0.2)
|
6
6
|
rubocop (= 1.44.1)
|
7
7
|
rubocop-performance (= 1.15.2)
|
@@ -40,8 +40,8 @@ GEM
|
|
40
40
|
rubocop-ast (>= 1.24.1, < 2.0)
|
41
41
|
ruby-progressbar (~> 1.7)
|
42
42
|
unicode-display_width (>= 2.4.0, < 3.0)
|
43
|
-
rubocop-ast (1.
|
44
|
-
parser (>= 3.
|
43
|
+
rubocop-ast (1.26.0)
|
44
|
+
parser (>= 3.2.1.0)
|
45
45
|
rubocop-performance (1.15.2)
|
46
46
|
rubocop (>= 1.7.0, < 2.0)
|
47
47
|
rubocop-ast (>= 0.4.0)
|
data/lib/standard/lsp/logger.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
module Standard
|
2
2
|
module Lsp
|
3
3
|
class Logger
|
4
|
+
def initialize
|
5
|
+
@puts_onces = []
|
6
|
+
end
|
7
|
+
|
4
8
|
def puts(message)
|
5
9
|
warn("[server] #{message}")
|
6
10
|
end
|
11
|
+
|
12
|
+
def puts_once(message)
|
13
|
+
return if @puts_onces.include?(message)
|
14
|
+
@puts_onces << message
|
15
|
+
puts(message)
|
16
|
+
end
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
data/lib/standard/lsp/routes.rb
CHANGED
@@ -130,13 +130,17 @@ module Standard
|
|
130
130
|
|
131
131
|
private
|
132
132
|
|
133
|
+
def uri_to_path(uri)
|
134
|
+
uri.sub(%r{^file://}, "")
|
135
|
+
end
|
136
|
+
|
133
137
|
def format_file(file_uri)
|
134
138
|
text = @text_cache[file_uri]
|
135
139
|
if text.nil?
|
136
140
|
@logger.puts "Format request arrived before text synchonized; skipping: `#{file_uri}'"
|
137
141
|
[]
|
138
142
|
else
|
139
|
-
new_text = @standardizer.format(text)
|
143
|
+
new_text = @standardizer.format(uri_to_path(file_uri), text)
|
140
144
|
if new_text == text
|
141
145
|
[]
|
142
146
|
else
|
@@ -153,7 +157,7 @@ module Standard
|
|
153
157
|
|
154
158
|
def diagnostic(file_uri, text)
|
155
159
|
@text_cache[file_uri] = text
|
156
|
-
offenses = @standardizer.offenses(text)
|
160
|
+
offenses = @standardizer.offenses(uri_to_path(file_uri), text)
|
157
161
|
|
158
162
|
lsp_diagnostics = offenses.map { |o|
|
159
163
|
code = o[:cop_name]
|
data/lib/standard/lsp/server.rb
CHANGED
@@ -9,15 +9,11 @@ module Standard
|
|
9
9
|
SEV = Proto::Constant::DiagnosticSeverity
|
10
10
|
|
11
11
|
class Server
|
12
|
-
def
|
13
|
-
new(standardizer).start
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(standardizer)
|
17
|
-
@standardizer = standardizer
|
12
|
+
def initialize(config)
|
18
13
|
@writer = Proto::Transport::Io::Writer.new($stdout)
|
19
14
|
@reader = Proto::Transport::Io::Reader.new($stdin)
|
20
15
|
@logger = Logger.new
|
16
|
+
@standardizer = Standard::Lsp::Standardizer.new(config, @logger)
|
21
17
|
@routes = Routes.new(@writer, @logger, @standardizer)
|
22
18
|
end
|
23
19
|
|
@@ -1,49 +1,65 @@
|
|
1
1
|
require_relative "../runners/rubocop"
|
2
|
-
require "tempfile"
|
3
2
|
|
4
3
|
module Standard
|
5
4
|
module Lsp
|
6
5
|
class Standardizer
|
7
|
-
def initialize(config)
|
8
|
-
@
|
9
|
-
@
|
6
|
+
def initialize(config, logger)
|
7
|
+
@config = config
|
8
|
+
@logger = logger
|
9
|
+
@rubocop_runner = Standard::Runners::Rubocop.new
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
# This abuses the --stdin option of rubocop and reads the formatted text
|
13
|
+
# from the options[:stdin] that rubocop mutates. This depends on
|
14
|
+
# parallel: false as well as the fact that rubocop doesn't otherwise dup
|
15
|
+
# or reassign that options object. Risky business!
|
16
|
+
#
|
17
|
+
# Reassigning options[:stdin] is done here:
|
18
|
+
# https://github.com/rubocop/rubocop/blob/master/lib/rubocop/cop/team.rb#L131
|
19
|
+
# Printing options[:stdin]
|
20
|
+
# https://github.com/rubocop/rubocop/blob/master/lib/rubocop/cli/command/execute_runner.rb#L95
|
21
|
+
# Setting `parallel: true` would break this here:
|
22
|
+
# https://github.com/rubocop/rubocop/blob/master/lib/rubocop/runner.rb#L72
|
23
|
+
def format(path, text)
|
24
|
+
ad_hoc_config = fork_config(path, text, format: true)
|
25
|
+
capture_rubocop_stdout(ad_hoc_config)
|
26
|
+
ad_hoc_config.rubocop_options[:stdin]
|
14
27
|
end
|
15
28
|
|
16
|
-
def offenses(text)
|
17
|
-
results =
|
18
|
-
|
29
|
+
def offenses(path, text)
|
30
|
+
results = JSON.parse(
|
31
|
+
capture_rubocop_stdout(fork_config(path, text, format: false)),
|
32
|
+
symbolize_names: true
|
33
|
+
)
|
34
|
+
if results[:files].empty?
|
35
|
+
@logger.puts_once "Ignoring file, per configuration: #{path}"
|
36
|
+
[]
|
37
|
+
else
|
38
|
+
results.dig(:files, 0, :offenses)
|
39
|
+
end
|
19
40
|
end
|
20
41
|
|
21
42
|
private
|
22
43
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
def make_config(file, format)
|
34
|
-
# Can't make frozen versions of this hash because RuboCop mutates it
|
35
|
-
o = if format
|
36
|
-
{autocorrect: true, formatters: [["Standard::Formatter", nil]], parallel: true, todo_file: nil, todo_ignore_files: [], safe_autocorrect: true}
|
44
|
+
BASE_OPTIONS = {
|
45
|
+
force_exclusion: true,
|
46
|
+
parallel: false,
|
47
|
+
todo_file: nil,
|
48
|
+
todo_ignore_files: []
|
49
|
+
}
|
50
|
+
def fork_config(path, text, format:)
|
51
|
+
options = if format
|
52
|
+
{stdin: text, autocorrect: true, formatters: [], safe_autocorrect: true}
|
37
53
|
else
|
38
|
-
{autocorrect: false, formatters: [["json"]],
|
54
|
+
{stdin: text, autocorrect: false, formatters: [["json"]], format: "json"}
|
39
55
|
end
|
40
|
-
Standard::Config.new(@
|
56
|
+
Standard::Config.new(@config.runner, [path], BASE_OPTIONS.merge(options), @config.rubocop_config_store)
|
41
57
|
end
|
42
58
|
|
43
59
|
def capture_rubocop_stdout(config)
|
44
60
|
redir = StringIO.new
|
45
61
|
$stdout = redir
|
46
|
-
@
|
62
|
+
@rubocop_runner.call(config)
|
47
63
|
redir.string
|
48
64
|
ensure
|
49
65
|
$stdout = STDOUT
|
data/lib/standard/runners/lsp.rb
CHANGED
data/lib/standard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.24.
|
4
|
+
version: 1.24.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Searls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|