1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# typed: true
# frozen_string_literal: true
require "test_helper"
require_relative "support/expectations_test_runner"
class InlayHintsExpectationsTest < ExpectationsTestRunner
expectations_tests RubyLsp::Requests::InlayHints, "inlay_hints"
def run_expectations(source)
params = @__params&.any? ? @__params : default_args
uri = URI("file://#{@_path}")
document = RubyLsp::RubyDocument.new(source: source, version: 1, uri: uri, global_state: @global_state)
dispatcher = Prism::Dispatcher.new
@global_state.apply_options({
initializationOptions: {
featuresConfiguration: {
inlayHint: { implicitRescue: true, implicitHashValue: true },
},
},
})
request = RubyLsp::Requests::InlayHints.new(@global_state, document, dispatcher)
dispatcher.dispatch(document.ast)
range = params.first
ruby_range = range.dig(:start, :line)..range.dig(:end, :line)
request.perform.select do |hint|
ruby_range.cover?(hint.position[:line])
end
end
def default_args
[{ start: { line: 0, character: 0 }, end: { line: 20, character: 20 } }]
end
def test_skip_implicit_hash_value
uri = URI("file://foo.rb")
document = RubyLsp::RubyDocument.new(uri: uri, source: <<~RUBY, version: 1, global_state: @global_state)
{bar:, baz:}
RUBY
dispatcher = Prism::Dispatcher.new
@global_state.apply_options({
initializationOptions: {
featuresConfiguration: {
inlayHint: { implicitRescue: true, implicitHashValue: false },
},
},
})
request = RubyLsp::Requests::InlayHints.new(@global_state, document, dispatcher)
dispatcher.dispatch(document.ast)
assert_empty(request.perform)
end
def test_skip_implicit_rescue
uri = URI("file://foo.rb")
document = RubyLsp::RubyDocument.new(uri: uri, source: <<~RUBY, version: 1, global_state: @global_state)
begin
rescue
end
RUBY
dispatcher = Prism::Dispatcher.new
@global_state.apply_options({
initializationOptions: {
featuresConfiguration: {
inlayHint: { implicitRescue: false, implicitHashValue: true },
},
},
})
request = RubyLsp::Requests::InlayHints.new(@global_state, document, dispatcher)
dispatcher.dispatch(document.ast)
assert_empty(request.perform)
end
end
|