Skip to content

Commit 979079b

Browse files
committed
definition: better sub filename
1 parent 3101712 commit 979079b

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lua/lspsaga/definition.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ function def:create_win(bufnr, root_dir)
121121
if util.ismac and (vim.bo[bufnr].filetype == 'c' or vim.bo[bufnr].filetype == 'cpp') then
122122
fname = util.sub_mac_c_header(fname)
123123
end
124+
if vim.bo[bufnr].filetype == 'rust' then
125+
fname = util.sub_rust_toolchains(fname)
126+
end
127+
124128
if not self.list or vim.tbl_isempty(self.list) then
125129
local float_opt = {
126130
width = math.floor(api.nvim_win_get_width(0) * config.definition.width),

lua/lspsaga/util.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,12 @@ function M.get_bold_num()
235235
return num
236236
end
237237

238+
function M.sub_rust_toolchains(fname)
239+
local rustup_home = os.getenv('RUSTUP_HOME') or vim.fs.joinpath(vim.env.HOME, '.rustup')
240+
local toolchains = vim.fs.joinpath(rustup_home, 'toolchains')
241+
local parts = vim.split(fname, M.path_sep, { trimempty = true })
242+
local count = #vim.split(toolchains, M.path_sep, { trimempty = true })
243+
return vim.fs.joinpath(unpack(parts, count + 1))
244+
end
245+
238246
return M

0 commit comments

Comments
 (0)