ruby-lsp-rubyfmt-formatter 0.1.0
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 +7 -0
- data/.vscode/settings.json +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +7 -0
- data/lib/ruby_lsp/rubyfmt_formatter/addon.rb +75 -0
- data/lib/ruby_lsp/rubyfmt_formatter/version.rb +7 -0
- metadata +61 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ed5cb1b1289eb0b163a41623c2747754ec8c8c26aeb98221290445be1bd5a767
|
|
4
|
+
data.tar.gz: 68244f3c075f5286267cf0e7f525a0385227f0ae57ae15135a50f20202f9d15a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a6d7d26044b7cf7f9430fabf3e727276d1d4ad1f8f97d2d3cc921db60f5e8b2da948b88aed97d0aa52bcdb514eb4dd1810af12ffeb246f8c2b19aa3059fb4657
|
|
7
|
+
data.tar.gz: 3a5b50120bfe500ad94737055ec8ba86e6f7872eda1a5861ec400fe797a626662a257ddb6659d3a626c0a40ecbe1524bcd75a31d9f7dc9d9661eca3ba56efa4e
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Reese Williams
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# `ruby-lsp-rubyfmt-formatter`
|
|
2
|
+
|
|
3
|
+
A [Ruby LSP](https://github.com/Shopify/ruby-lsp) add-on that provides formatting support using [rubyfmt](https://github.com/fables-tales/rubyfmt).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this gem to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bundle add ruby-lsp-rubyfmt-formatter
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install it directly:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
gem install ruby-lsp-rubyfmt-formatter
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Once installed, configure your VSCode settings to use rubyfmt as the formatter:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"[ruby]": {
|
|
26
|
+
"editor.defaultFormatter": "Shopify.ruby-lsp",
|
|
27
|
+
"editor.formatOnSave": true
|
|
28
|
+
},
|
|
29
|
+
"rubyLsp.formatter": "rubyfmt"
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
By default, the extension uses the `rubyfmt` in your PATH, or see the configuration options below for passing a specific path.
|
|
34
|
+
|
|
35
|
+
For instructions on installing `rubyfmt` itself, see [the docs](https://github.com/fables-tales/rubyfmt?tab=readme-ov-file#how-do-i-use-it).
|
|
36
|
+
|
|
37
|
+
### Configuration Options
|
|
38
|
+
|
|
39
|
+
You can customize the rubyfmt behavior via `rubyLsp.addonSettings` in your VSCode settings:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"rubyLsp.formatter": "rubyfmt",
|
|
44
|
+
"rubyLsp.addonSettings": {
|
|
45
|
+
"rubyfmt": {
|
|
46
|
+
"rubyfmtPath": "/custom/path/to/rubyfmt",
|
|
47
|
+
"rubyfmtArgs": "--include-gitignored"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Available Options
|
|
54
|
+
|
|
55
|
+
| Option | Type | Default | Description |
|
|
56
|
+
| ------------- | ------ | ----------- | ----------------------------------------------------- |
|
|
57
|
+
| `rubyfmtPath` | String | `"rubyfmt"` | Path to the rubyfmt executable. Uses PATH by default. |
|
|
58
|
+
| `rubyfmtArgs` | String | `""` | Additional arguments to pass to rubyfmt. |
|
|
59
|
+
|
|
60
|
+
## Contributing
|
|
61
|
+
|
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/reese/ruby-lsp-rubyfmt-formatter.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ruby_lsp/internal"
|
|
4
|
+
require "open3"
|
|
5
|
+
|
|
6
|
+
module RubyLsp
|
|
7
|
+
module RubyfmtFormatter
|
|
8
|
+
class Addon < ::RubyLsp::Addon
|
|
9
|
+
def activate(global_state, message_queue)
|
|
10
|
+
@message_queue = message_queue
|
|
11
|
+
global_state.register_formatter("rubyfmt", Formatter.new(global_state))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def deactivate
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def name
|
|
18
|
+
"rubyfmt Formatter"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Formatter
|
|
23
|
+
include RubyLsp::Requests::Support::Formatter
|
|
24
|
+
|
|
25
|
+
def initialize(global_state)
|
|
26
|
+
@global_state = global_state
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def run_formatting(uri, document)
|
|
30
|
+
source = document.source
|
|
31
|
+
command = build_command
|
|
32
|
+
|
|
33
|
+
stdout, stderr, status = Open3.capture3(*command, stdin_data: source)
|
|
34
|
+
|
|
35
|
+
unless status.success?
|
|
36
|
+
raise StandardError, "`rubyfmt` failed: #{stderr}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
stdout
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def run_range_formatting(_uri, _source, _base_indentation)
|
|
43
|
+
# rubyfmt doesn't support range formatting
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def run_diagnostic(_uri, _document)
|
|
47
|
+
# rubyfmt doesn't emit diagnostics
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private def build_command
|
|
51
|
+
path = rubyfmt_executable
|
|
52
|
+
args = additional_args
|
|
53
|
+
|
|
54
|
+
[path] + args
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private def rubyfmt_executable
|
|
58
|
+
# Fall back to PATH if nothing is provided
|
|
59
|
+
settings.fetch("rubyfmtPath", "rubyfmt")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private def additional_args
|
|
63
|
+
args_string = settings.fetch("rubyfmtArgs", "")
|
|
64
|
+
return [] if args_string.empty?
|
|
65
|
+
|
|
66
|
+
args_string.split
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private def settings
|
|
70
|
+
addon_settings = @global_state.settings_for_addon("rubyfmt")
|
|
71
|
+
addon_settings || {}
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby-lsp-rubyfmt-formatter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Reese Williams
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: ruby-lsp
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.17.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.17.0
|
|
26
|
+
email:
|
|
27
|
+
- reese@reesew.com
|
|
28
|
+
executables: []
|
|
29
|
+
extensions: []
|
|
30
|
+
extra_rdoc_files: []
|
|
31
|
+
files:
|
|
32
|
+
- ".vscode/settings.json"
|
|
33
|
+
- LICENSE.txt
|
|
34
|
+
- README.md
|
|
35
|
+
- Rakefile
|
|
36
|
+
- lib/ruby_lsp/rubyfmt_formatter/addon.rb
|
|
37
|
+
- lib/ruby_lsp/rubyfmt_formatter/version.rb
|
|
38
|
+
homepage: https://github.com/reese/ruby-lsp-rubyfmt-formatter
|
|
39
|
+
licenses:
|
|
40
|
+
- MIT
|
|
41
|
+
metadata:
|
|
42
|
+
homepage_uri: https://github.com/reese/ruby-lsp-rubyfmt-formatter
|
|
43
|
+
source_code_uri: https://github.com/reese/ruby-lsp-rubyfmt-formatter
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 3.0.0
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 4.0.3
|
|
59
|
+
specification_version: 4
|
|
60
|
+
summary: A Ruby LSP add-on for formatting with `rubyfmt`.
|
|
61
|
+
test_files: []
|