1
+ local api = vim .api
1
2
local configs = require ' lspconfig.configs'
2
3
local windows = require ' lspconfig.ui.windows'
3
4
local util = require ' lspconfig.util'
@@ -52,7 +53,7 @@ local function make_config_info(config, bufnr)
52
53
config_info .cmd_is_executable = ' NA'
53
54
end
54
55
55
- local buffer_dir = vim . api .nvim_buf_call (bufnr , function ()
56
+ local buffer_dir = api .nvim_buf_call (bufnr , function ()
56
57
return vim .fn .expand ' %:p:h'
57
58
end )
58
59
local root_dir = config .get_root_dir (buffer_dir )
@@ -150,7 +151,12 @@ return function()
150
151
local buf_clients = vim .lsp .buf_get_clients ()
151
152
local clients = vim .lsp .get_active_clients ()
152
153
local buffer_filetype = vim .bo .filetype
153
- local original_bufnr = vim .api .nvim_get_current_buf ()
154
+ local original_bufnr = api .nvim_get_current_buf ()
155
+
156
+ windows .default_options .wrap = true
157
+ windows .default_options .breakindent = true
158
+ windows .default_options .breakindentopt = ' shift:25'
159
+ windows .default_options .showbreak = ' NONE'
154
160
155
161
local win_info = windows .percentage_range_window (0.8 , 0.7 )
156
162
local bufnr , win_id = win_info .bufnr , win_info .win_id
@@ -169,6 +175,9 @@ return function()
169
175
end
170
176
end
171
177
178
+ -- insert the tips at the top of window
179
+ table.insert (buf_lines , ' Use [q] or [Esc] to quit the window' )
180
+
172
181
local header = {
173
182
' ' ,
174
183
' Language client log: ' .. (vim .lsp .get_log_path ()),
@@ -216,22 +225,39 @@ return function()
216
225
217
226
local matching_config_header = {
218
227
' ' ,
219
- ' Configured servers list: ' .. table.concat (vim . tbl_keys ( configs ), ' , ' ),
228
+ ' Configured servers list: ' .. table.concat (util . available_servers ( ), ' , ' ),
220
229
}
230
+
221
231
vim .list_extend (buf_lines , matching_config_header )
222
232
223
233
local fmt_buf_lines = indent_lines (buf_lines , ' ' )
224
234
225
235
fmt_buf_lines = vim .lsp .util ._trim (fmt_buf_lines , {})
226
236
227
- vim . api .nvim_buf_set_lines (bufnr , 0 , - 1 , true , fmt_buf_lines )
228
- vim . api .nvim_buf_set_option (bufnr , ' modifiable' , false )
229
- vim . api .nvim_buf_set_option (bufnr , ' filetype' , ' lspinfo' )
237
+ api .nvim_buf_set_lines (bufnr , 0 , - 1 , true , fmt_buf_lines )
238
+ api .nvim_buf_set_option (bufnr , ' modifiable' , false )
239
+ api .nvim_buf_set_option (bufnr , ' filetype' , ' lspinfo' )
230
240
231
- vim .api .nvim_buf_set_keymap (bufnr , ' n' , ' <esc>' , ' <cmd>bd<CR>' , { noremap = true })
232
- vim .api .nvim_command (
233
- string.format (' autocmd BufHidden,BufLeave <buffer> ++once lua pcall(vim.api.nvim_win_close, %d, true)' , win_id )
234
- )
241
+ local augroup = api .nvim_create_augroup (' lspinfo' , { clear = false })
242
+
243
+ local function close ()
244
+ api .nvim_clear_autocmds { group = augroup , buffer = bufnr }
245
+ if api .nvim_buf_is_valid (bufnr ) then
246
+ api .nvim_buf_delete (bufnr , { force = true })
247
+ end
248
+ if api .nvim_win_is_valid (win_id ) then
249
+ api .nvim_win_close (win_id , true )
250
+ end
251
+ end
252
+
253
+ vim .keymap .set (' n' , ' <ESC>' , close , { buffer = bufnr , nowait = true })
254
+ vim .keymap .set (' n' , ' q' , close , { buffer = bufnr , nowait = true })
255
+ api .nvim_create_autocmd ({ ' BufDelete' , ' BufLeave' , ' BufHidden' }, {
256
+ once = true ,
257
+ buffer = bufnr ,
258
+ callback = close ,
259
+ group = augroup ,
260
+ })
235
261
236
262
vim .fn .matchadd (
237
263
' Error' ,
@@ -246,12 +272,14 @@ return function()
246
272
vim .cmd ' let m=matchadd("string", "true")'
247
273
vim .cmd ' let m=matchadd("error", "false")'
248
274
for _ , config in pairs (configs ) do
249
- vim .fn .matchadd (' Title ' , ' \\ %(Client\\ |Config\\ ):.*\\ zs' .. config .name .. ' \\ ze' )
250
- vim .fn .matchadd (' Visual ' , ' list:.*\\ zs' .. config .name .. ' \\ ze' )
275
+ vim .fn .matchadd (' LspInfoTitle ' , ' \\ %(Client\\ |Config\\ ):.*\\ zs' .. config .name .. ' \\ ze' )
276
+ vim .fn .matchadd (' LspInfoList ' , ' list:.*\\ zs' .. config .name .. ' \\ ze' )
251
277
if config .filetypes then
252
278
for _ , ft in pairs (config .filetypes ) do
253
- vim .fn .matchadd (' Type ' , ' \\ %(filetypes\\ |filetype\\ ):.*\\ zs' .. ft .. ' \\ ze' )
279
+ vim .fn .matchadd (' LspInfoFiletype ' , ' \\ %(filetypes\\ |filetype\\ ):.*\\ zs' .. ft .. ' \\ ze' )
254
280
end
255
281
end
256
282
end
283
+
284
+ api .nvim_buf_add_highlight (bufnr , 0 , ' LspInfoTip' , 0 , 0 , - 1 )
257
285
end
0 commit comments