@@ -62,7 +62,11 @@ pub(super) fn hints(
62
62
match_ast ! {
63
63
match expr {
64
64
ast:: BlockExpr ( x) => x. stmt_list( ) . and_then( |x| x. r_curly_token( ) ) . map( |x| x. text_range( ) ) . unwrap_or_else( || expr. text_range( ) ) ,
65
- _ => expr. text_range( ) ,
65
+ // make the inlay hint appear after the semicolon if there is
66
+ _ => {
67
+ let nearest_semicolon = nearest_token_after_node( expr, syntax:: SyntaxKind :: SEMICOLON ) ;
68
+ nearest_semicolon. map( |x| x. text_range( ) ) . unwrap_or_else( || expr. text_range( ) )
69
+ } ,
66
70
}
67
71
}
68
72
}
@@ -95,7 +99,7 @@ pub(super) fn hints(
95
99
label. append_str ( ")" ) ;
96
100
acc. push ( InlayHint {
97
101
range,
98
- position : InlayHintPosition :: Before ,
102
+ position : InlayHintPosition :: After ,
99
103
pad_left : true ,
100
104
pad_right : true ,
101
105
kind : InlayKind :: Drop ,
@@ -109,6 +113,16 @@ pub(super) fn hints(
109
113
Some ( ( ) )
110
114
}
111
115
116
+ fn nearest_token_after_node (
117
+ node : & syntax:: SyntaxNode ,
118
+ token_type : syntax:: SyntaxKind ,
119
+ ) -> Option < syntax:: SyntaxToken > {
120
+ node. siblings_with_tokens ( syntax:: Direction :: Next )
121
+ . filter_map ( |it| it. as_token ( ) . map ( |it| it. clone ( ) ) )
122
+ . filter ( |it| it. kind ( ) == token_type)
123
+ . next ( )
124
+ }
125
+
112
126
#[ cfg( test) ]
113
127
mod tests {
114
128
use crate :: {
@@ -129,7 +143,7 @@ mod tests {
129
143
let x = X;
130
144
if 2 == 5 {
131
145
return;
132
- //^^^^^ ^ drop(x)
146
+ // ^ drop(x)
133
147
}
134
148
}
135
149
//^ drop(x)
@@ -176,7 +190,7 @@ mod tests {
176
190
let x = X;
177
191
let t_opt = Some(2);
178
192
let t = t_opt?;
179
- //^^^^^ ^ drop(x)
193
+ // ^ drop(x)
180
194
Some(())
181
195
}
182
196
//^ drop(x)
0 commit comments