ruby-lsp-rubyfmt-formatter 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Rakefile +4 -1
- data/lib/ruby_lsp/rubyfmt_formatter/addon.rb +25 -2
- data/lib/ruby_lsp/rubyfmt_formatter/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e580a05f58e3543801587b5098c5389df062b05e516180e48ea97751427533f8
|
|
4
|
+
data.tar.gz: 71f7ea4463e475f05eefa8ad3d85c1a3d0d175d80beed5e766a593b4ca71201e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 031142cf02cfed40ccdf601e7c08fd71f7583821c93bef22fdbaeebbe4f4b94716b7273511e1f1eff6671bf61837b7d65feebf8114f1e1dcb2b035dcb7d1d6a1
|
|
7
|
+
data.tar.gz: f82456554a6232aced596eab50b4e07b00e3c11096e28fd16c89f1465053e39aafeaca81f803b2b333a36bb0841769f3fd286857b1ba3d841ab0adc670c70a82
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "ruby_lsp/internal"
|
|
4
4
|
require "open3"
|
|
5
|
+
require "uri"
|
|
5
6
|
|
|
6
7
|
module RubyLsp
|
|
7
8
|
module RubyfmtFormatter
|
|
@@ -28,7 +29,7 @@ module RubyLsp
|
|
|
28
29
|
|
|
29
30
|
def run_formatting(uri, document)
|
|
30
31
|
source = document.source
|
|
31
|
-
command = build_command
|
|
32
|
+
command = build_command(uri)
|
|
32
33
|
|
|
33
34
|
stdout, stderr, status = Open3.capture3(*command, stdin_data: source)
|
|
34
35
|
|
|
@@ -47,10 +48,15 @@ module RubyLsp
|
|
|
47
48
|
# rubyfmt doesn't emit diagnostics
|
|
48
49
|
end
|
|
49
50
|
|
|
50
|
-
private def build_command
|
|
51
|
+
private def build_command(uri)
|
|
51
52
|
path = rubyfmt_executable
|
|
52
53
|
args = additional_args
|
|
53
54
|
|
|
55
|
+
if uri && supports_stdin_filepath?
|
|
56
|
+
file_path = URI(uri.to_s).path
|
|
57
|
+
args += ["--stdin-filepath", file_path] if file_path
|
|
58
|
+
end
|
|
59
|
+
|
|
54
60
|
[path] + args
|
|
55
61
|
end
|
|
56
62
|
|
|
@@ -66,6 +72,23 @@ module RubyLsp
|
|
|
66
72
|
args_string.split
|
|
67
73
|
end
|
|
68
74
|
|
|
75
|
+
private def supports_stdin_filepath?
|
|
76
|
+
Gem::Version.new(rubyfmt_version) >= Gem::Version.new("0.13.0")
|
|
77
|
+
rescue ArgumentError
|
|
78
|
+
false
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
private def rubyfmt_version
|
|
82
|
+
@rubyfmt_version ||= begin
|
|
83
|
+
stdout, _stderr, status = Open3.capture3(rubyfmt_executable, "--version")
|
|
84
|
+
if status.success? && (match = stdout.match(/(\d+\.\d+\.\d+)/))
|
|
85
|
+
match[1]
|
|
86
|
+
else
|
|
87
|
+
"0.0.0"
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
69
92
|
private def settings
|
|
70
93
|
addon_settings = @global_state.settings_for_addon("rubyfmt")
|
|
71
94
|
addon_settings&.transform_keys!(&:to_sym)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-lsp-rubyfmt-formatter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Reese Williams
|
|
@@ -42,6 +42,7 @@ licenses:
|
|
|
42
42
|
metadata:
|
|
43
43
|
homepage_uri: https://github.com/reese/ruby-lsp-rubyfmt-formatter
|
|
44
44
|
source_code_uri: https://github.com/reese/ruby-lsp-rubyfmt-formatter
|
|
45
|
+
rubygems_mfa_required: 'true'
|
|
45
46
|
rdoc_options: []
|
|
46
47
|
require_paths:
|
|
47
48
|
- lib
|
|
@@ -56,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
56
57
|
- !ruby/object:Gem::Version
|
|
57
58
|
version: '0'
|
|
58
59
|
requirements: []
|
|
59
|
-
rubygems_version: 4.0.
|
|
60
|
+
rubygems_version: 4.0.6
|
|
60
61
|
specification_version: 4
|
|
61
62
|
summary: A Ruby LSP add-on for formatting with `rubyfmt`.
|
|
62
63
|
test_files: []
|