Merge branch 'dev' into thesis

nvim: fix lua LSP name change
        shorten statusline filenames
This commit is contained in:
David JULIEN 2023-02-13 14:58:31 +01:00
commit 378f6b528b
No known key found for this signature in database
GPG Key ID: 1DD6B2BA6DD78810
4 changed files with 168 additions and 121 deletions

View File

@ -24,5 +24,21 @@ return {
"echasnovski/mini.pairs",
version = "*",
config = function() require("mini.pairs").setup() end,
},
{
"echasnovski/mini.indentscope",
version = "*",
opts = function()
local plugin = require("mini.indentscope")
return {
draw = {
animation = plugin.gen_animation.none()
}
}
end,
config = function(_, opts)
require("mini.indentscope").setup(opts)
end,
}
}

View File

@ -9,7 +9,7 @@ _G.lsp_root_dir = vim.fn.stdpath("data") .. "/mason/bin"
local servers = {
"clangd",
"rust_analyzer",
"sumneko_lua",
"lua_ls",
"texlab",
}

View File

@ -98,6 +98,29 @@ local function get_mode_color(m)
return color[m]
end
-- from https://github.com/nvim-lualine/lualine.nvim/blob/master/lua/lualine/components/filename.lua
local function shorten_path(path, max_len)
local sep = '/'
local len = #path
if len <= max_len then
return path
end
local segments = vim.split(path, sep)
for idx = 1, #segments - 1 do
if len <= max_len then
break
end
local segment = segments[idx]
local shortened = segment:sub(1, vim.startswith(segment, '.') and 2 or 1)
segments[idx] = shortened
len = len - (#segment - #shortened)
end
return table.concat(segments, sep)
end
-- from https://github.com/nvim-lua/lsp-status.nvim/blob/master/lua/lsp-status/diagnostics.lua
local function get_lsp_diagnostics()
local result = {}
@ -138,14 +161,16 @@ end
end
local function statusline_focused()
local file = vim.fn.expand("%:p:~")
local diagnostics = get_lsp_diagnostics()
local mode = vim.fn.mode()
local mg = get_mode(mode)
local accent_color = get_mode_color(mg)
local winwidth = vim.fn.winwidth(0)
local left = table.concat {
gen_section(accent_color, { get_mode_display_name(mg) }),
gen_section("%#Middle#", {"%f"}),
gen_section("%#Middle#", { shorten_path(file, winwidth / 3) }),
gen_section("%#Bottom#", { "%m", "%r" }),
gen_section(
"%#Alert#",
@ -190,8 +215,14 @@ return table.concat {
end
local function statusline_not_focused()
local bufnr = vim.fn.winbufnr(vim.g.statusline_winid)
local file = vim.fn.expand("#" .. bufnr .. ":p:~")
local winwidth = vim.fn.winwidth(0)
return table.concat {
gen_section("%#StatuslineNF#", {"%f", "%m"}),
gen_section("%#StatuslineNF#", {
shorten_path(file, winwidth / 3),
"%m"
}),
"%=",
gen_section("%#StatuslineNF#", { "%03.p%%" }),
gen_section("%#StatuslineNF#", { "-%03.c-" })