@@ -25,14 +25,15 @@ interface InlayHint {
2525 label: string,
2626}
2727```
28- --]]
28+ --]]
2929
3030local inlay_hints = {}
3131
32- local inlay_hints_ns = vim .api .nvim_create_namespace (' lsp_extensions.inlay_hints' )
32+ local inlay_hints_ns = vim .api .nvim_create_namespace (" lsp_extensions.inlay_hints" )
3333
3434inlay_hints .request = function (opts , bufnr )
35- vim .lsp .buf_request (bufnr or 0 , ' rust-analyzer/inlayHints' , inlay_hints .get_params (), inlay_hints .get_callback (opts ))
35+ vim .lsp .buf_request (bufnr or 0 , " rust-analyzer/inlayHints" , inlay_hints .get_params (),
36+ inlay_hints .get_callback (opts ))
3637
3738 -- TODO: At some point, rust probably adds this?
3839 -- vim.lsp.buf_request(bufnr or 0, 'experimental/inlayHints', inlay_hints.get_params(), inlay_hints.get_callback(opts))
@@ -45,10 +46,10 @@ inlay_hints.get_callback = function(opts)
4546 local prefix = opts .prefix or " > "
4647 local aligned = opts .aligned or false
4748
49+ local enabled = opts .enabled or {" ChainingHint" }
50+
4851 local only_current_line = opts .only_current_line
49- if only_current_line == nil then
50- only_current_line = false
51- end
52+ if only_current_line == nil then only_current_line = false end
5253
5354 return function (err , _ , result , _ , bufnr )
5455 -- I'm pretty sure this only happens for unsupported items.
@@ -66,13 +67,26 @@ inlay_hints.get_callback = function(opts)
6667
6768 local longest_line = - 1
6869
70+ -- Check if something is in the list
71+ -- in_list({"ChainingHint"})("ChainingHint")
72+ local in_list = function (list )
73+ return function (item )
74+ for _ , f in ipairs (list ) do
75+ if f == item then return true end
76+ end
77+
78+ return false
79+ end
80+ end
81+
6982 for _ , hint in ipairs (result ) do
7083 local finish = hint .range [" end" ].line
71- if not hint_store [finish ] or hint .kind == " ChainingHint " then
84+ if not hint_store [finish ] and in_list ( enabled )( hint .kind ) then
7285 hint_store [finish ] = hint
7386
7487 if aligned then
75- longest_line = math.max (longest_line , # vim .api .nvim_buf_get_lines (bufnr , finish , finish + 1 , false )[1 ])
88+ longest_line = math.max (longest_line ,
89+ # vim .api .nvim_buf_get_lines (bufnr , finish , finish + 1 , false )[1 ])
7690 end
7791 end
7892 end
@@ -82,10 +96,9 @@ inlay_hints.get_callback = function(opts)
8296
8397 -- Check for any existing / more important virtual text on the line.
8498 -- TODO: Figure out how stackable virtual text works? What happens if there is more than one??
85- local existing_virt_text = vim .api .nvim_buf_get_extmarks (bufnr , inlay_hints_ns , {end_line , 0 }, {end_line , 0 }, {})
86- if not vim .tbl_isempty (existing_virt_text ) then
87- return
88- end
99+ local existing_virt_text = vim .api .nvim_buf_get_extmarks (bufnr , inlay_hints_ns , {end_line , 0 },
100+ {end_line , 0 }, {})
101+ if not vim .tbl_isempty (existing_virt_text ) then return end
89102
90103 local text
91104 if aligned then
@@ -94,7 +107,7 @@ inlay_hints.get_callback = function(opts)
94107 else
95108 text = prefix .. hint .label
96109 end
97- vim .api .nvim_buf_set_virtual_text (bufnr , inlay_hints_ns , end_line , { { text , highlight } }, {})
110+ vim .api .nvim_buf_set_virtual_text (bufnr , inlay_hints_ns , end_line , {{ text , highlight } }, {})
98111 end
99112
100113 if only_current_line then
@@ -106,22 +119,17 @@ inlay_hints.get_callback = function(opts)
106119 display_virt_text (hint )
107120 end
108121 else
109- for _ , hint in pairs (hint_store ) do
110- display_virt_text (hint )
111- end
122+ for _ , hint in pairs (hint_store ) do display_virt_text (hint ) end
112123 end
113124 end
114125end
115126
116127inlay_hints .get_params = function ()
117- return {
118- textDocument = vim .lsp .util .make_text_document_params ()
119- }
128+ return {textDocument = vim .lsp .util .make_text_document_params ()}
120129end
121130
122131inlay_hints .clear = function ()
123132 vim .api .nvim_buf_clear_namespace (0 , inlay_hints_ns , 0 , - 1 )
124133end
125134
126-
127135return inlay_hints
0 commit comments