-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathinlay_hints.rb
79 lines (72 loc) · 2.28 KB
/
inlay_hints.rb
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
77
78
79
# typed: strict
# frozen_string_literal: true
require "ruby_lsp/listeners/inlay_hints"
module RubyLsp
module Requests
# 
#
# [Inlay hints](https://microsoft.github.io/language-server-protocol/specification#textDocument_inlayHint)
# are labels added directly in the code that explicitly show the user something that might
# otherwise just be implied.
#
# # Configuration
#
# To enable rescue hints, set `rubyLsp.featuresConfiguration.inlayHint.implicitRescue` to `true`.
#
# To enable hash value hints, set `rubyLsp.featuresConfiguration.inlayHint.implicitHashValue` to `true`.
#
# To enable all hints, set `rubyLsp.featuresConfiguration.inlayHint.enableAll` to `true`.
#
# # Example
#
# ```ruby
# begin
# puts "do something that might raise"
# rescue # Label "StandardError" goes here as a bare rescue implies rescuing StandardError
# puts "handle some rescue"
# end
# ```
#
# # Example
#
# ```ruby
# var = "foo"
# {
# var: var, # Label "var" goes here in cases where the value is omitted
# a: "hello",
# }
# ```
class InlayHints < Request
extend T::Sig
class << self
extend T::Sig
sig { returns(Interface::InlayHintOptions) }
def provider
Interface::InlayHintOptions.new(resolve_provider: false)
end
end
sig do
params(
document: T.any(RubyDocument, ERBDocument),
range: T::Hash[Symbol, T.untyped],
hints_configuration: RequestConfig,
dispatcher: Prism::Dispatcher,
).void
end
def initialize(document, range, hints_configuration, dispatcher)
super()
start_line = range.dig(:start, :line)
end_line = range.dig(:end, :line)
@response_builder = T.let(
ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint].new,
ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint],
)
Listeners::InlayHints.new(@response_builder, start_line..end_line, hints_configuration, dispatcher)
end
sig { override.returns(T::Array[Interface::InlayHint]) }
def perform
@response_builder.response
end
end
end
end