Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/ruby_lsp/ruby-lsp-rubyfmt/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# frozen_string_literal: true

require "open3"
require "singleton"

module RubyLsp
module RubyLspRubyfmt
Expand All @@ -10,11 +11,11 @@ def name
"Ruby Fmt Formatter"
end

def activate
def activate(global_state, message_queue)
# The first argument is an identifier users can pick to select this formatter. To use this formatter, users must
# have rubyLsp.formatter configured to "rubyfmt"
# The second argument is a singleton instance that implements the `FormatterRunner` interface (see below)
RubyLsp::Requests::Formatting.register_formatter("rubyfmt", RubyFmtFormatterRunner.instance)
global_state.register_formatter("rubyfmt", RubyFmtFormatterRunner.instance)
end

def deactivate
Expand All @@ -26,7 +27,7 @@ class RubyFmtFormatterRunner
# Make it a singleton class
include Singleton
# If using Sorbet to develop the addon, then include this interface to make sure the class is properly implemented
include RubyLsp::Requests::Support::FormatterRunner
include RubyLsp::Requests::Support::Formatter

# Use the initialize method to perform any sort of ahead of time work.
# For example, reading configurations for yourformatter since they are unlikely to change between requests
Expand All @@ -36,7 +37,7 @@ def initialize
# The main part of the interface is implementing the run method.
# It receives the URI and the document being formatted.
# IMPORTANT: This method must return the formatted document source without mutating the original one in document
def run(uri, document)
def run_formatting(uri, document)
output, _status = Open3.capture2("rubyfmt", stdin_data: document.source)
output
end
Expand Down
2 changes: 1 addition & 1 deletion test/ruby/lsp/rubyfmt_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Foo; def foo
end
RUBY

output = RubyLspRubyfmt::RubyFmtFormatterRunner.instance.run("", doc)
output = RubyLspRubyfmt::RubyFmtFormatterRunner.instance.run_formatting("", doc)

assert_equal(<<~RUBY, output)
class Foo
Expand Down