class SyntaxTree::LanguageServer::InlayHints

github.com/microsoft/language-server-protocol/issues/956.
information, see the spec here:
This class provides inlay hints for the language server. For more

def initialize

def initialize
  @stack = []
  @hints = []
end

def parentheses(location)

def parentheses(location)
  hints << Hint.new(
    line: location.start_line - 1,
    character: location.start_column,
    label: "₍"
  )
  hints << Hint.new(
    line: location.end_line - 1,
    character: location.end_column,
    label: "₎"
  )
end

def visit(node)

def visit(node)
  stack << node
  result = super
  stack.pop
  result
end

def visit_assign(node)


end
def foo(a = ₍b = c₎)

becomes

end
def foo(a = b = c)

values of parameters. For example,
Adds parentheses around assignments contained within the default
def visit_assign(node)
  parentheses(node.location) if stack[-2].is_a?(Params)
  super
end

def visit_binary(node)


a + ₍b * c₎

becomes

a + b * c

subexpression will be evaluated first. For example,
Adds parentheses around binary expressions to make it clear which
def visit_binary(node)
  case stack[-2]
  when Assign, OpAssign
    parentheses(node.location)
  when Binary
    parentheses(node.location) if stack[-2].operator != node.operator
  end
  super
end

def visit_if_op(node)


a ? b : ₍c ? d : e₎

becomes

a ? b : c ? d : e

evaluated first. For example,
expressions where it could be confusing which subexpression will get
Adds parentheses around ternary operators contained within certain
def visit_if_op(node)
  case stack[-2]
  when Assign, Binary, IfOp, OpAssign
    parentheses(node.location)
  end
  super
end

def visit_rescue(node)


end
rescue StandardError
begin

becomes

end
rescue
begin

For example,
Adds the implicitly rescued StandardError into a bare rescue clause.
def visit_rescue(node)
  if node.exception.nil?
    hints << Hint.new(
      line: node.location.start_line - 1,
      character: node.location.start_column + "rescue".length,
      label: " StandardError"
    )
  end
  super
end

def visit_unary(node)


₍-a₎ + b

becomes

-a + b

contained within Binary nodes. For example,
Adds parentheses around unary statements using the - operator that are
def visit_unary(node)
  if stack[-2].is_a?(Binary) && (node.operator == "-")
    parentheses(node.location)
  end
  super
end