@@ -5,6 +5,11 @@ import * as ra from './lsp_ext';
5
5
import { Ctx , Disposable } from './ctx' ;
6
6
import { sendRequestWithRetry , isRustDocument , RustDocument , RustEditor , sleep } from './util' ;
7
7
8
+ interface InlayHintStyle {
9
+ decorationType : vscode . TextEditorDecorationType ;
10
+ toDecoration ( hint : ra . InlayHint , conv : lc . Protocol2CodeConverter ) : vscode . DecorationOptions ;
11
+ } ;
12
+
8
13
9
14
export function activateInlayHints ( ctx : Ctx ) {
10
15
const maybeUpdater = {
@@ -19,6 +24,7 @@ export function activateInlayHints(ctx: Ctx) {
19
24
20
25
await sleep ( 100 ) ;
21
26
if ( this . updater ) {
27
+ this . updater . updateInlayHintsStyles ( ) ;
22
28
this . updater . syncCacheAndRenderHints ( ) ;
23
29
} else {
24
30
this . updater = new HintsUpdater ( ctx ) ;
@@ -39,11 +45,7 @@ export function activateInlayHints(ctx: Ctx) {
39
45
maybeUpdater . onConfigChange ( ) . catch ( console . error ) ;
40
46
}
41
47
42
- const typeHints = createHintStyle ( "type" ) ;
43
- const paramHints = createHintStyle ( "parameter" ) ;
44
- const chainingHints = createHintStyle ( "chaining" ) ;
45
-
46
- function createHintStyle ( hintKind : "type" | "parameter" | "chaining" ) {
48
+ function createHintStyle ( ctx : Ctx , hintKind : "type" | "parameter" | "chaining" ) : InlayHintStyle {
47
49
// U+200C is a zero-width non-joiner to prevent the editor from forming a ligature
48
50
// between code and type hints
49
51
const [ pos , render ] = ( {
@@ -52,6 +54,8 @@ function createHintStyle(hintKind: "type" | "parameter" | "chaining") {
52
54
chaining : [ "after" , ( label : string ) => `\u{200c}: ${ label } ` ] ,
53
55
} as const ) [ hintKind ] ;
54
56
57
+ const smallerHints = ctx . config . inlayHints . smallerHints ;
58
+
55
59
const fg = new vscode . ThemeColor ( `rust_analyzer.inlayHints.foreground.${ hintKind } Hints` ) ;
56
60
const bg = new vscode . ThemeColor ( `rust_analyzer.inlayHints.background.${ hintKind } Hints` ) ;
57
61
return {
@@ -61,7 +65,7 @@ function createHintStyle(hintKind: "type" | "parameter" | "chaining") {
61
65
backgroundColor : bg ,
62
66
fontStyle : "normal" ,
63
67
fontWeight : "normal" ,
64
- textDecoration : ";font-size:smaller" ,
68
+ textDecoration : smallerHints ? ";font-size:smaller" : "none ",
65
69
} ,
66
70
} ) ,
67
71
toDecoration ( hint : ra . InlayHint , conv : lc . Protocol2CodeConverter ) : vscode . DecorationOptions {
@@ -76,6 +80,11 @@ function createHintStyle(hintKind: "type" | "parameter" | "chaining") {
76
80
class HintsUpdater implements Disposable {
77
81
private sourceFiles = new Map < string , RustSourceFile > ( ) ; // map Uri -> RustSourceFile
78
82
private readonly disposables : Disposable [ ] = [ ] ;
83
+ private inlayHintsStyles ! : {
84
+ typeHints : InlayHintStyle ;
85
+ paramHints : InlayHintStyle ;
86
+ chainingHints : InlayHintStyle ;
87
+ } ;
79
88
80
89
constructor ( private readonly ctx : Ctx ) {
81
90
vscode . window . onDidChangeVisibleTextEditors (
@@ -100,6 +109,7 @@ class HintsUpdater implements Disposable {
100
109
}
101
110
) ) ;
102
111
112
+ this . updateInlayHintsStyles ( ) ;
103
113
this . syncCacheAndRenderHints ( ) ;
104
114
}
105
115
@@ -114,6 +124,17 @@ class HintsUpdater implements Disposable {
114
124
this . syncCacheAndRenderHints ( ) ;
115
125
}
116
126
127
+ 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
+ } ;
136
+ }
137
+
117
138
syncCacheAndRenderHints ( ) {
118
139
this . sourceFiles . forEach ( ( file , uri ) => this . fetchHints ( file ) . then ( hints => {
119
140
if ( ! hints ) return ;
@@ -161,12 +182,14 @@ class HintsUpdater implements Disposable {
161
182
}
162
183
163
184
private renderDecorations ( editor : RustEditor , decorations : InlaysDecorations ) {
185
+ const { typeHints, paramHints, chainingHints } = this . inlayHintsStyles ;
164
186
editor . setDecorations ( typeHints . decorationType , decorations . type ) ;
165
187
editor . setDecorations ( paramHints . decorationType , decorations . param ) ;
166
188
editor . setDecorations ( chainingHints . decorationType , decorations . chaining ) ;
167
189
}
168
190
169
191
private hintsToDecorations ( hints : ra . InlayHint [ ] ) : InlaysDecorations {
192
+ const { typeHints, paramHints, chainingHints } = this . inlayHintsStyles ;
170
193
const decorations : InlaysDecorations = { type : [ ] , param : [ ] , chaining : [ ] } ;
171
194
const conv = this . ctx . client . protocol2CodeConverter ;
172
195
0 commit comments