8
8
use common:: Location ;
9
9
use common:: Span ;
10
10
use graphql_ir:: Argument ;
11
+ use graphql_ir:: FragmentDefinitionName ;
11
12
use graphql_ir:: FragmentSpread ;
12
13
use graphql_ir:: InlineFragment ;
14
+ use graphql_ir:: Program ;
13
15
use graphql_ir:: Visitor ;
14
16
use intern:: string_key:: StringKey ;
15
17
use lsp_types:: request:: InlayHintRequest ;
@@ -40,9 +42,10 @@ pub fn on_inlay_hint_request(
40
42
41
43
let project_name = state. extract_project_name_from_url ( & uri) ?;
42
44
let schema = state. get_schema ( & project_name) ?;
45
+ let program = state. get_program ( & project_name) ?;
43
46
let asts = state. resolve_executable_definitions ( & uri) ?;
44
47
let irs = build_ir_for_lsp ( & schema, & asts) . map_err ( |_| LSPRuntimeError :: ExpectedError ) ?;
45
- let mut visitor = InlayHintVisitor :: new ( & schema) ;
48
+ let mut visitor = InlayHintVisitor :: new ( & program , & schema) ;
46
49
for executable_definition in irs {
47
50
visitor. visit_executable_definition ( & executable_definition) ;
48
51
}
@@ -95,13 +98,15 @@ impl Hint {
95
98
}
96
99
97
100
struct InlayHintVisitor < ' a > {
101
+ program : & ' a Program ,
98
102
schema : & ' a SDLSchema ,
99
103
inlay_hints : Vec < Hint > ,
100
104
}
101
105
102
106
impl < ' a > InlayHintVisitor < ' a > {
103
- fn new ( schema : & ' a SDLSchema ) -> Self {
107
+ fn new ( program : & ' a Program , schema : & ' a SDLSchema ) -> Self {
104
108
Self {
109
+ program,
105
110
schema,
106
111
inlay_hints : vec ! [ ] ,
107
112
}
@@ -127,6 +132,29 @@ impl<'a> InlayHintVisitor<'a> {
127
132
}
128
133
}
129
134
}
135
+
136
+ fn add_fragment_argument_hints (
137
+ & mut self ,
138
+ fragment_name : FragmentDefinitionName ,
139
+ arguments : & [ Argument ] ,
140
+ ) {
141
+ if let Some ( fragment) = self . program . fragment ( fragment_name) {
142
+ for arg in arguments {
143
+ if let Some ( variable_def) = fragment
144
+ . variable_definitions
145
+ . iter ( )
146
+ . find ( |variable| variable. name . item . 0 == arg. name . item . 0 )
147
+ {
148
+ let arg_type = self . schema . get_type_string ( & variable_def. type_ ) ;
149
+ self . inlay_hints . push ( Hint {
150
+ location : arg. value . location ,
151
+ label : arg_type,
152
+ tooltip : None ,
153
+ } ) ;
154
+ }
155
+ }
156
+ }
157
+ }
130
158
}
131
159
132
160
impl Visitor for InlayHintVisitor < ' _ > {
@@ -159,8 +187,10 @@ impl Visitor for InlayHintVisitor<'_> {
159
187
& spread. fragment . location ,
160
188
Span :: new ( initial_span. start - 3 , initial_span. end ) ,
161
189
) ;
162
- self . add_alias_hint ( alias. item , adjusted_location)
190
+ self . add_alias_hint ( alias. item , adjusted_location) ;
163
191
}
192
+
193
+ self . add_fragment_argument_hints ( spread. fragment . item , & spread. arguments ) ;
164
194
}
165
195
166
196
fn visit_inline_fragment ( & mut self , fragment : & InlineFragment ) {
0 commit comments