Class: RubyLsp::Requests::Formatting
- Inherits:
-
BaseRequest
- Object
- SyntaxTree::Visitor
- BaseRequest
- RubyLsp::Requests::Formatting
- Extended by:
- T::Sig
- Defined in:
- lib/ruby_lsp/requests/formatting.rb
Overview

The [formatting](microsoft.github.io/language-server-protocol/specification#textDocument_formatting) request uses RuboCop to fix auto-correctable offenses in the document. This requires enabling format on save and registering the ruby-lsp as the Ruby formatter.
# Example
“‘ruby def say_hello puts “Hello” # –> formatting: fixes the indentation on save end “`
Instance Method Summary collapse
-
#initialize(uri, document) ⇒ Formatting
constructor
A new instance of Formatting.
- #run ⇒ Object
Methods inherited from BaseRequest
Constructor Details
#initialize(uri, document) ⇒ Formatting
Returns a new instance of Formatting.
25 26 27 28 29 |
# File 'lib/ruby_lsp/requests/formatting.rb', line 25 def initialize(uri, document) super(document) @uri = uri end |
Instance Method Details
#run ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_lsp/requests/formatting.rb', line 32 def run formatted_text = formatted_file return unless formatted_text size = @document.source.size [ LanguageServer::Protocol::Interface::TextEdit.new( range: LanguageServer::Protocol::Interface::Range.new( start: LanguageServer::Protocol::Interface::Position.new(line: 0, character: 0), end: LanguageServer::Protocol::Interface::Position.new(line: size, character: size) ), new_text: formatted_text ), ] end |