@@ -35,11 +35,49 @@ local function init(_, _config)
3535 _info = make_statusline_component (' info' )
3636end
3737
38+ local function get_lsp_progress ()
39+ local buf_messages = messages ()
40+ local msgs = {}
41+
42+ for _ , msg in ipairs (buf_messages ) do
43+ local name = aliases [msg .name ] or msg .name
44+ local client_name = ' [' .. name .. ' ]'
45+ local contents
46+ if msg .progress then
47+ contents = msg .title
48+ if msg .message then contents = contents .. ' ' .. msg .message end
49+
50+ -- this percentage format string escapes a percent sign once to show a percentage and one more
51+ -- time to prevent errors in vim statusline's because of it's treatment of % chars
52+ if msg .percentage then contents = contents .. string.format (" (%.0f%%%%)" , msg .percentage ) end
53+
54+ if msg .spinner then
55+ contents = config .spinner_frames [(msg .spinner % # config .spinner_frames ) + 1 ] .. ' ' ..
56+ contents
57+ end
58+ elseif msg .status then
59+ contents = msg .content
60+ if msg .uri then
61+ local filename = vim .uri_to_fname (msg .uri )
62+ filename = vim .fn .fnamemodify (filename , ' :~:.' )
63+ local space = math.min (60 , math.floor (0.6 * vim .fn .winwidth (0 )))
64+ if # filename > space then filename = vim .fn .pathshorten (filename ) end
65+
66+ contents = ' (' .. filename .. ' ) ' .. contents
67+ end
68+ else
69+ contents = msg .content
70+ end
71+
72+ table.insert (msgs , client_name .. ' ' .. contents )
73+ end
74+ return table.concat (msgs , config .component_separator )
75+ end
76+
3877local function get_lsp_statusline (bufnr )
3978 bufnr = bufnr or 0
4079 if # vim .lsp .buf_get_clients (bufnr ) == 0 then return ' ' end
4180 local buf_diagnostics = config .diagnostics and diagnostics (bufnr ) or nil
42- local buf_messages = messages ()
4381 local only_hint = true
4482 local some_diagnostics = false
4583 local status_parts = {}
@@ -72,40 +110,9 @@ local function get_lsp_statusline(bufnr)
72110 end
73111 end
74112
75- local msgs = {}
76- for _ , msg in ipairs (buf_messages ) do
77- local name = aliases [msg .name ] or msg .name
78- local client_name = ' [' .. name .. ' ]'
79- local contents
80- if msg .progress then
81- contents = msg .title
82- if msg .message then contents = contents .. ' ' .. msg .message end
83-
84- if msg .percentage then contents = contents .. string.format (" (%.0f%%)" , msg .percentage ) end
85-
86- if msg .spinner then
87- contents = config .spinner_frames [(msg .spinner % # config .spinner_frames ) + 1 ] .. ' ' ..
88- contents
89- end
90- elseif msg .status then
91- contents = msg .content
92- if msg .uri then
93- local filename = vim .uri_to_fname (msg .uri )
94- filename = vim .fn .fnamemodify (filename , ' :~:.' )
95- local space = math.min (60 , math.floor (0.6 * vim .fn .winwidth (0 )))
96- if # filename > space then filename = vim .fn .pathshorten (filename ) end
97-
98- contents = ' (' .. filename .. ' ) ' .. contents
99- end
100- else
101- contents = msg .content
102- end
103-
104- table.insert (msgs , client_name .. ' ' .. contents )
105- end
113+ local msgs = get_lsp_progress ()
106114
107- local base_status = vim .trim (table.concat (status_parts , config .component_separator ) .. ' ' ..
108- table.concat (msgs , config .component_separator ))
115+ local base_status = vim .trim (table.concat (status_parts , config .component_separator ) .. ' ' .. msgs )
109116 local symbol = config .status_symbol .. ((some_diagnostics and only_hint ) and ' ' or ' ' )
110117 if config .current_function then
111118 local current_function = vim .b .lsp_current_function
126133local M = {
127134 _init = init ,
128135 status = get_lsp_statusline ,
129- _get_component_functions = get_component_functions
136+ progress = get_lsp_progress ,
137+ _get_component_functions = get_component_functions ,
130138}
131139
132140return M
0 commit comments