Class: LanguageServer::Protocol::Interface::FormattingOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/language_server/protocol/interface/formatting_options.rb

Overview

Value-object describing what options formatting should use.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tab_size:, insert_spaces:, trim_trailing_whitespace: nil, insert_final_newline: nil, trim_final_newlines: nil) ⇒ FormattingOptions

Returns a new instance of FormattingOptions.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/language_server/protocol/interface/formatting_options.rb', line 8

def initialize(tab_size:, insert_spaces:, trim_trailing_whitespace: nil, insert_final_newline: nil, trim_final_newlines: nil)
  @attributes = {}

  @attributes[:tabSize] = tab_size
  @attributes[:insertSpaces] = insert_spaces
  @attributes[:trimTrailingWhitespace] = trim_trailing_whitespace if trim_trailing_whitespace
  @attributes[:insertFinalNewline] = insert_final_newline if insert_final_newline
  @attributes[:trimFinalNewlines] = trim_final_newlines if trim_final_newlines

  @attributes.freeze
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



60
61
62
# File 'lib/language_server/protocol/interface/formatting_options.rb', line 60

def attributes
  @attributes
end

Instance Method Details

#insert_final_newlineboolean

Insert a newline character at the end of the file if one does not exist.

Returns:

  • (boolean)


48
49
50
# File 'lib/language_server/protocol/interface/formatting_options.rb', line 48

def insert_final_newline
  attributes.fetch(:insertFinalNewline)
end

#insert_spacesboolean

Prefer spaces over tabs.

Returns:

  • (boolean)


32
33
34
# File 'lib/language_server/protocol/interface/formatting_options.rb', line 32

def insert_spaces
  attributes.fetch(:insertSpaces)
end

#tab_sizenumber

Size of a tab in spaces.

Returns:

  • (number)


24
25
26
# File 'lib/language_server/protocol/interface/formatting_options.rb', line 24

def tab_size
  attributes.fetch(:tabSize)
end

#to_hashObject



62
63
64
# File 'lib/language_server/protocol/interface/formatting_options.rb', line 62

def to_hash
  attributes
end

#to_json(*args) ⇒ Object



66
67
68
# File 'lib/language_server/protocol/interface/formatting_options.rb', line 66

def to_json(*args)
  to_hash.to_json(*args)
end

#trim_final_newlinesboolean

Trim all newlines after the final newline at the end of the file.

Returns:

  • (boolean)


56
57
58
# File 'lib/language_server/protocol/interface/formatting_options.rb', line 56

def trim_final_newlines
  attributes.fetch(:trimFinalNewlines)
end

#trim_trailing_whitespaceboolean

Trim trailing whitespace on a line.

Returns:

  • (boolean)


40
41
42
# File 'lib/language_server/protocol/interface/formatting_options.rb', line 40

def trim_trailing_whitespace
  attributes.fetch(:trimTrailingWhitespace)
end