module Steep module Server module LSPFormatter include Services class CommentBuilder def initialize @array = [] end def self.build builder = CommentBuilder.new yield builder builder.to_s end def to_s unless @array.empty? @array.join("\n\n----\n\n") else "" end end def <<(string) if string s = string.rstrip.gsub(/^[ \t]*)-->\n/, "").gsub(/\A([ \t]*\n)+/, "") unless @array.include?(s) @array << s end end end def push s = "" yield s self << s end end module_function def format_hover_content(content) case content when HoverProvider::Ruby::VariableContent "`#{content.name}`: `#{content.type.to_s}`" when HoverProvider::Ruby::MethodCallContent CommentBuilder.build do |builder| call = content.method_call builder.push do |s| case call when TypeInference::MethodCall::Special mt = call.actual_method_type.with( type: call.actual_method_type.type.with(return_type: call.return_type) ) s << <<-EOM **💡 Custom typing rule applies** ```rbs #{mt.to_s} ``` EOM when TypeInference::MethodCall::Typed mt = call.actual_method_type.with( type: call.actual_method_type.type.with(return_type: call.return_type) ) s << "```rbs\n#{mt.to_s}\n```\n\n" when TypeInference::MethodCall::Error s << "```rbs\n( ??? ) -> #{call.return_type.to_s}\n```\n\n" end s << to_list(call.method_decls) do |decl| "`#{decl.method_name}`" end end call.method_decls.each do |decl| if comment = decl.method_def.comment builder << < 1 builder << to_list(content.definition.method_types) {|type| "`#{type.to_s}`" } end end when HoverProvider::Ruby::ConstantContent CommentBuilder.build do |builder| if decl = content.class_or_module? builder << <