Skip to content

Commit

Permalink
handle file path better in definition
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Mar 31, 2024
1 parent 2f951f8 commit a4d4428
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lua/lspsaga/definition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 10 additions & 0 deletions lua/lspsaga/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a4d4428

Please sign in to comment.