From a4d442896a9ff1f83ee3db965d81b659ebc977d5 Mon Sep 17 00:00:00 2001 From: glepnir Date: Sun, 31 Mar 2024 19:09:38 +0800 Subject: [PATCH] handle file path better in definition --- lua/lspsaga/definition.lua | 3 +++ lua/lspsaga/util.lua | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lua/lspsaga/definition.lua b/lua/lspsaga/definition.lua index 7b90b2703..276b907bf 100644 --- a/lua/lspsaga/definition.lua +++ b/lua/lspsaga/definition.lua @@ -117,6 +117,9 @@ end function def:create_win(bufnr, root_dir) local fname = api.nvim_buf_get_name(bufnr) fname = util.path_sub(fname, 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 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), diff --git a/lua/lspsaga/util.lua b/lua/lspsaga/util.lua index 16394455d..d5f40ba10 100644 --- a/lua/lspsaga/util.lua +++ b/lua/lspsaga/util.lua @@ -206,4 +206,14 @@ function M.nvim_ten() return vim.version().minor >= 10 end +---sub c/ cpp header file path when in macos +---@return string +function M.sub_mac_c_header(fname) + local pos = fname:find('./usr/include') + if not pos then + return fname + end + return fname:sub(pos + 1) +end + return M