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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13d481f6982b619853ac364ffa223ddb6c010ea68cd57248c759786119f991a7
4
- data.tar.gz: 3ee49b870ff3d1ffe12bca06c1d0c80ec41e815fe056f476b91f2bb766293196
3
+ metadata.gz: cc7f5e2e4baad0d0471e6aba98df29bd5d8bb3db7c4a8fc3557581572a30865b
4
+ data.tar.gz: 76083326596e81461fc7cf9664421d4089555d9a3b1a2f8706e2884522379611
5
5
  SHA512:
6
- metadata.gz: e1e0ad0ae158c7659b253f1062693f82cd1691babf12e65237521d005f9c4ce148b53e2905dfa1d1029082133e4852ef0f8c9a46e6917d6860342cf602c0fc64
7
- data.tar.gz: 0d4ad3d30a9652e3536129f0f4733e5b7efb8ccefb699333e83f18a47e4259c2917b7f4507806aa79f4de15b0e7a73f5cf4961fafe86be88cb6c3c97a00a2d6f
6
+ metadata.gz: 47a6281011618bc51cd198c5dad586608d97c64ed05a4146d8549739332d22d70669f24fd9a59e1508c6b1ec6d631387949d589ab97241adf296fd0c2ec5ca22
7
+ data.tar.gz: dbca4f6a5c7e0777e93a98f3c6f0f14b4a15210cadcad1c8489f16319e636fe92ee5de19a295389fb3cdec7b73c37bd86510aa7de0b3dd8537f8033766cbd45c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.24.3
4
+
5
+ * _Further_ _further_ _further_ improve `--lsp` server to ignore files correctly
6
+
3
7
  ## 1.24.2
4
8
 
5
9
  * _Further_ _further_ improve `--lsp` server to always respond to requests
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- standard (1.24.2)
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.24.1)
44
- parser (>= 3.1.1.0)
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)
@@ -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
@@ -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]
@@ -9,15 +9,11 @@ module Standard
9
9
  SEV = Proto::Constant::DiagnosticSeverity
10
10
 
11
11
  class Server
12
- def self.start(standardizer)
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
- @template_options = config
9
- @runner = Standard::Runners::Rubocop.new
6
+ def initialize(config, logger)
7
+ @config = config
8
+ @logger = logger
9
+ @rubocop_runner = Standard::Runners::Rubocop.new
10
10
  end
11
11
 
12
- def format(text)
13
- run_standard(text, format: true)
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 = run_standard(text, format: false)
18
- JSON.parse(results, symbolize_names: true).dig(:files, 0, :offenses)
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
- BASENAME = ["source", ".rb"].freeze
24
- def run_standard(text, format:)
25
- Tempfile.open(BASENAME) do |temp|
26
- temp.write(text)
27
- temp.flush
28
- stdout = capture_rubocop_stdout(make_config(temp.path, format))
29
- format ? File.read(temp.path) : stdout
30
- end
31
- end
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"]], parallel: true, todo_file: nil, todo_ignore_files: [], format: "json"}
54
+ {stdin: text, autocorrect: false, formatters: [["json"]], format: "json"}
39
55
  end
40
- Standard::Config.new(@template_options.runner, [file], o, @template_options.rubocop_config_store)
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
- @runner.call(config)
62
+ @rubocop_runner.call(config)
47
63
  redir.string
48
64
  ensure
49
65
  $stdout = STDOUT
@@ -4,8 +4,7 @@ module Standard
4
4
  module Runners
5
5
  class Lsp
6
6
  def call(config)
7
- standardizer = Standard::Lsp::Standardizer.new(config)
8
- Standard::Lsp::Server.start(standardizer)
7
+ Standard::Lsp::Server.new(config).start
9
8
  end
10
9
  end
11
10
  end
@@ -1,3 +1,3 @@
1
1
  module Standard
2
- VERSION = Gem::Version.new("1.24.2")
2
+ VERSION = Gem::Version.new("1.24.3")
3
3
  end
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.2
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-10 00:00:00.000000000 Z
11
+ date: 2023-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop