@@ -69,34 +69,27 @@ pub fn extract_library_paths(settings: &serde_json::Value) -> Option<Vec<Library
6969
7070/// Extract the inlay hint type from LSP settings.
7171///
72- /// The type is determined by checking which option is enabled:
73- /// - If `masm.inlayHints.disassembly` is true or unset, returns `Disassembly` (default)
74- /// - Else if `masm.inlayHints.description` is true, returns `Description`
75- /// - If both are explicitly false, returns `None`
76- ///
7772/// Expects settings in the format:
7873/// ```json
79- /// { "masm": { "inlayHints": { "description ": true, "disassembly": false } } }
74+ /// { "masm": { "inlayHints": { "type ": "disassembly" } } }
8075/// ```
76+ ///
77+ /// Valid values for `type`:
78+ /// - `"disassembly"` - Show pseudocode disassembly (default)
79+ /// - `"description"` - Show instruction descriptions
80+ /// - `"none"` - Disable inlay hints
8181pub fn extract_inlay_hint_type ( settings : & serde_json:: Value ) -> Option < InlayHintType > {
82- let hints = settings. get ( "masm" ) . and_then ( |v| v. get ( "inlayHints" ) ) ?;
83-
84- let description = hints
85- . get ( "description" )
86- . and_then ( |v| v. as_bool ( ) ) ;
87- let disassembly = hints
88- . get ( "disassembly" )
89- . and_then ( |v| v. as_bool ( ) ) ;
82+ let hint_type = settings
83+ . get ( "masm" )
84+ . and_then ( |v| v. get ( "inlayHints" ) )
85+ . and_then ( |v| v. get ( "type" ) )
86+ . and_then ( |v| v. as_str ( ) ) ?;
9087
91- match ( description, disassembly) {
92- // Disassembly takes priority if enabled (or default if nothing set)
93- ( _, Some ( true ) ) | ( None , None ) => Some ( InlayHintType :: Disassembly ) ,
94- // Description enabled, disassembly not set or disabled
95- ( Some ( true ) , _) => Some ( InlayHintType :: Description ) ,
96- // Both explicitly disabled
97- ( Some ( false ) , Some ( false ) ) | ( Some ( false ) , None ) => Some ( InlayHintType :: None ) ,
98- // Disassembly explicitly disabled but description not set - use description
99- ( None , Some ( false ) ) => Some ( InlayHintType :: Description ) ,
88+ match hint_type. to_lowercase ( ) . as_str ( ) {
89+ "disassembly" => Some ( InlayHintType :: Disassembly ) ,
90+ "description" => Some ( InlayHintType :: Description ) ,
91+ "none" | "disabled" | "off" => Some ( InlayHintType :: None ) ,
92+ _ => None ,
10093 }
10194}
10295
@@ -191,11 +184,11 @@ mod tests {
191184 }
192185
193186 #[ test]
194- fn extract_inlay_hint_type_disassembly_enabled ( ) {
187+ fn extract_inlay_hint_type_disassembly ( ) {
195188 let settings = json ! ( {
196189 "masm" : {
197190 "inlayHints" : {
198- "disassembly " : true
191+ "type " : "disassembly"
199192 }
200193 }
201194 } ) ;
@@ -206,11 +199,11 @@ mod tests {
206199 }
207200
208201 #[ test]
209- fn extract_inlay_hint_type_description_enabled ( ) {
202+ fn extract_inlay_hint_type_description ( ) {
210203 let settings = json ! ( {
211204 "masm" : {
212205 "inlayHints" : {
213- "description " : true
206+ "type " : "description"
214207 }
215208 }
216209 } ) ;
@@ -221,28 +214,26 @@ mod tests {
221214 }
222215
223216 #[ test]
224- fn extract_inlay_hint_type_disassembly_takes_priority ( ) {
217+ fn extract_inlay_hint_type_none ( ) {
225218 let settings = json ! ( {
226219 "masm" : {
227220 "inlayHints" : {
228- "description" : true ,
229- "disassembly" : true
221+ "type" : "none"
230222 }
231223 }
232224 } ) ;
233225 assert_eq ! (
234226 extract_inlay_hint_type( & settings) ,
235- Some ( InlayHintType :: Disassembly )
227+ Some ( InlayHintType :: None )
236228 ) ;
237229 }
238230
239231 #[ test]
240- fn extract_inlay_hint_type_both_disabled ( ) {
232+ fn extract_inlay_hint_type_disabled_alias ( ) {
241233 let settings = json ! ( {
242234 "masm" : {
243235 "inlayHints" : {
244- "description" : false ,
245- "disassembly" : false
236+ "type" : "disabled"
246237 }
247238 }
248239 } ) ;
@@ -253,17 +244,17 @@ mod tests {
253244 }
254245
255246 #[ test]
256- fn extract_inlay_hint_type_description_disabled_only ( ) {
247+ fn extract_inlay_hint_type_case_insensitive ( ) {
257248 let settings = json ! ( {
258249 "masm" : {
259250 "inlayHints" : {
260- "description " : false
251+ "type " : "DISASSEMBLY"
261252 }
262253 }
263254 } ) ;
264255 assert_eq ! (
265256 extract_inlay_hint_type( & settings) ,
266- Some ( InlayHintType :: None )
257+ Some ( InlayHintType :: Disassembly )
267258 ) ;
268259 }
269260
@@ -274,15 +265,24 @@ mod tests {
274265 }
275266
276267 #[ test]
277- fn extract_inlay_hint_type_empty_hints_defaults_disassembly ( ) {
268+ fn extract_inlay_hint_type_invalid_value_returns_none ( ) {
269+ let settings = json ! ( {
270+ "masm" : {
271+ "inlayHints" : {
272+ "type" : "invalid"
273+ }
274+ }
275+ } ) ;
276+ assert_eq ! ( extract_inlay_hint_type( & settings) , None ) ;
277+ }
278+
279+ #[ test]
280+ fn extract_inlay_hint_type_empty_hints_returns_none ( ) {
278281 let settings = json ! ( {
279282 "masm" : {
280283 "inlayHints" : { }
281284 }
282285 } ) ;
283- assert_eq ! (
284- extract_inlay_hint_type( & settings) ,
285- Some ( InlayHintType :: Disassembly )
286- ) ;
286+ assert_eq ! ( extract_inlay_hint_type( & settings) , None ) ;
287287 }
288288}
0 commit comments