-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add convenience on_attach function and default statusline module
- Loading branch information
1 parent
e0af53b
commit 8fb7cc4
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
vim.g.indicator_errors = '' | ||
vim.g.indicator_warnings = '' | ||
vim.g.indicator_info = '🛈' | ||
vim.g.indicator_hint = '❗' | ||
vim.g.indicator_ok = '' | ||
vim.g.spinner_frames = { '⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷' } | ||
|
||
local diagnostics = require('lsp-status/diagnostics') | ||
local messages = require('lsp-status/messaging').messages | ||
local aliases = { | ||
pyls_ms = 'MPLS', | ||
} | ||
|
||
local function statusline_lsp() | ||
if #vim.lsp.buf_get_clients() == 0 then | ||
return '' | ||
end | ||
|
||
local buf_diagnostics = diagnostics() | ||
local buf_messages = messages() | ||
local only_hint = true | ||
local some_diagnostics = false | ||
local status_parts = {} | ||
if buf_diagnostics.errors and buf_diagnostics.errors > 0 then | ||
table.insert(status_parts, vim.g.indicator_errors .. ' ' .. buf_diagnostics.errors) | ||
only_hint = false | ||
some_diagnostics = true | ||
end | ||
|
||
if buf_diagnostics.warnings and buf_diagnostics.warnings > 0 then | ||
table.insert(status_parts, vim.g.indicator_warnings .. ' ' .. buf_diagnostics.warnings) | ||
only_hint = false | ||
some_diagnostics = true | ||
end | ||
|
||
if buf_diagnostics.info and buf_diagnostics.info > 0 then | ||
table.insert(status_parts, vim.g.indicator_info .. ' ' .. buf_diagnostics.info) | ||
only_hint = false | ||
some_diagnostics = true | ||
end | ||
|
||
if buf_diagnostics.hints and buf_diagnostics.hints > 0 then | ||
table.insert(status_parts, vim.g.indicator_hint .. ' ' .. buf_diagnostics.hints) | ||
some_diagnostics = true | ||
end | ||
|
||
local msgs = {} | ||
for _, msg in ipairs(buf_messages) do | ||
local name = aliases[msg.name] or msg.name | ||
local client_name = '[' .. name .. ']' | ||
if msg.progress then | ||
local contents = msg.title | ||
if msg.message then | ||
contents = contents .. ' ' .. msg.message | ||
end | ||
|
||
if msg.percentage then | ||
contents = contents .. ' (' .. msg.percentage .. ')' | ||
end | ||
|
||
if msg.spinner then | ||
contents = vim.g.spinner_frames[(msg.spinner % #vim.g.spinner_frames) + 1] .. ' ' .. contents | ||
end | ||
|
||
table.insert(msgs, client_name .. ' ' .. contents) | ||
else | ||
table.insert(msgs, client_name .. ' ' .. msg.content) | ||
end | ||
end | ||
|
||
local base_status = vim.trim(table.concat(status_parts, ' ') .. ' ' .. table.concat(msgs, ' ')) | ||
local symbol = ' 🇻' .. ((some_diagnostics and only_hint) and '' or ' ') | ||
local current_function = vim.b.lsp_current_function | ||
if current_function and current_function ~= '' then | ||
symbol = symbol .. '(' .. current_function .. ') ' | ||
end | ||
|
||
if base_status ~= '' then | ||
return symbol .. base_status .. ' ' | ||
end | ||
|
||
return symbol .. vim.g.indicator_ok .. ' ' | ||
end | ||
|
||
return statusline_lsp |