@@ -10,6 +10,12 @@ interface InlayHintStyle {
10
10
toDecoration ( hint : ra . InlayHint , conv : lc . Protocol2CodeConverter ) : vscode . DecorationOptions ;
11
11
} ;
12
12
13
+ interface InlayHintsStyles {
14
+ typeHints : InlayHintStyle ;
15
+ paramHints : InlayHintStyle ;
16
+ chainingHints : InlayHintStyle ;
17
+ }
18
+
13
19
14
20
export function activateInlayHints ( ctx : Ctx ) {
15
21
const maybeUpdater = {
@@ -45,7 +51,7 @@ export function activateInlayHints(ctx: Ctx) {
45
51
maybeUpdater . onConfigChange ( ) . catch ( console . error ) ;
46
52
}
47
53
48
- function createHintStyle ( ctx : Ctx , hintKind : "type" | "parameter" | "chaining" ) : InlayHintStyle {
54
+ function createHintStyle ( hintKind : "type" | "parameter" | "chaining" , smallerHints : boolean ) : InlayHintStyle {
49
55
// U+200C is a zero-width non-joiner to prevent the editor from forming a ligature
50
56
// between code and type hints
51
57
const [ pos , render ] = ( {
@@ -54,8 +60,6 @@ function createHintStyle(ctx: Ctx, hintKind: "type" | "parameter" | "chaining"):
54
60
chaining : [ "after" , ( label : string ) => `\u{200c}: ${ label } ` ] ,
55
61
} as const ) [ hintKind ] ;
56
62
57
- const smallerHints = ctx . config . inlayHints . smallerHints ;
58
-
59
63
const fg = new vscode . ThemeColor ( `rust_analyzer.inlayHints.foreground.${ hintKind } Hints` ) ;
60
64
const bg = new vscode . ThemeColor ( `rust_analyzer.inlayHints.background.${ hintKind } Hints` ) ;
61
65
return {
@@ -77,14 +81,23 @@ function createHintStyle(ctx: Ctx, hintKind: "type" | "parameter" | "chaining"):
77
81
} ;
78
82
}
79
83
84
+ const smallHintsStyles = {
85
+ typeHints : createHintStyle ( "type" , true ) ,
86
+ paramHints : createHintStyle ( "parameter" , true ) ,
87
+ chainingHints : createHintStyle ( "chaining" , true ) ,
88
+ } ;
89
+
90
+ const biggerHintsStyles = {
91
+ typeHints : createHintStyle ( "type" , false ) ,
92
+ paramHints : createHintStyle ( "parameter" , false ) ,
93
+ chainingHints : createHintStyle ( "chaining" , false ) ,
94
+ } ;
95
+
80
96
class HintsUpdater implements Disposable {
81
97
private sourceFiles = new Map < string , RustSourceFile > ( ) ; // map Uri -> RustSourceFile
82
98
private readonly disposables : Disposable [ ] = [ ] ;
83
- private inlayHintsStyles ! : {
84
- typeHints : InlayHintStyle ;
85
- paramHints : InlayHintStyle ;
86
- chainingHints : InlayHintStyle ;
87
- } ;
99
+ private pendingDisposeDecorations : undefined | InlayHintsStyles = undefined ;
100
+ private inlayHintsStyles ! : InlayHintsStyles ;
88
101
89
102
constructor ( private readonly ctx : Ctx ) {
90
103
vscode . window . onDidChangeVisibleTextEditors (
@@ -125,14 +138,12 @@ class HintsUpdater implements Disposable {
125
138
}
126
139
127
140
updateInlayHintsStyles ( ) {
128
- this . inlayHintsStyles ?. typeHints . decorationType . dispose ( ) ;
129
- this . inlayHintsStyles ?. paramHints . decorationType . dispose ( ) ;
130
- this . inlayHintsStyles ?. chainingHints . decorationType . dispose ( ) ;
131
- this . inlayHintsStyles = {
132
- typeHints : createHintStyle ( this . ctx , "type" ) ,
133
- paramHints : createHintStyle ( this . ctx , "parameter" ) ,
134
- chainingHints : createHintStyle ( this . ctx , "chaining" ) ,
135
- } ;
141
+ const inlayHintsStyles = this . ctx . config . inlayHints . smallerHints ? smallHintsStyles : biggerHintsStyles ;
142
+
143
+ if ( inlayHintsStyles !== this . inlayHintsStyles ) {
144
+ this . pendingDisposeDecorations = this . inlayHintsStyles ;
145
+ this . inlayHintsStyles = inlayHintsStyles ;
146
+ }
136
147
}
137
148
138
149
syncCacheAndRenderHints ( ) {
@@ -183,6 +194,12 @@ class HintsUpdater implements Disposable {
183
194
184
195
private renderDecorations ( editor : RustEditor , decorations : InlaysDecorations ) {
185
196
const { typeHints, paramHints, chainingHints } = this . inlayHintsStyles ;
197
+ if ( this . pendingDisposeDecorations !== undefined ) {
198
+ const { typeHints, paramHints, chainingHints } = this . pendingDisposeDecorations ;
199
+ editor . setDecorations ( typeHints . decorationType , [ ] ) ;
200
+ editor . setDecorations ( paramHints . decorationType , [ ] ) ;
201
+ editor . setDecorations ( chainingHints . decorationType , [ ] ) ;
202
+ }
186
203
editor . setDecorations ( typeHints . decorationType , decorations . type ) ;
187
204
editor . setDecorations ( paramHints . decorationType , decorations . param ) ;
188
205
editor . setDecorations ( chainingHints . decorationType , decorations . chaining ) ;
0 commit comments