definition: better sub filename

This commit is contained in:
glepnir 2024-06-07 19:50:44 +08:00
parent 31017128cb
commit 979079b21b
2 changed files with 12 additions and 0 deletions

View File

@ -121,6 +121,10 @@ function def:create_win(bufnr, root_dir)
if util.ismac and (vim.bo[bufnr].filetype == 'c' or vim.bo[bufnr].filetype == 'cpp') then
fname = util.sub_mac_c_header(fname)
end
if vim.bo[bufnr].filetype == 'rust' then
fname = util.sub_rust_toolchains(fname)
end
if not self.list or vim.tbl_isempty(self.list) then
local float_opt = {
width = math.floor(api.nvim_win_get_width(0) * config.definition.width),

View File

@ -235,4 +235,12 @@ function M.get_bold_num()
return num
end
function M.sub_rust_toolchains(fname)
local rustup_home = os.getenv('RUSTUP_HOME') or vim.fs.joinpath(vim.env.HOME, '.rustup')
local toolchains = vim.fs.joinpath(rustup_home, 'toolchains')
local parts = vim.split(fname, M.path_sep, { trimempty = true })
local count = #vim.split(toolchains, M.path_sep, { trimempty = true })
return vim.fs.joinpath(unpack(parts, count + 1))
end
return M