feat: detect ghostty config files by canonical path
Problem: enabled() only checked for the 'ghostty' filetype, but many users have ghostty config files detected as 'config' or with no filetype set. These users got no completions. Solution: check canonical ghostty config directories ($XDG_CONFIG_HOME/ghostty, ~/.config/ghostty, /etc/ghostty) when the filetype is 'config' or empty, resolving symlinks to handle indirect paths.
This commit is contained in:
parent
dfbae31684
commit
7d95afba81
2 changed files with 60 additions and 1 deletions
|
|
@ -10,9 +10,31 @@ function M.new()
|
|||
return setmetatable({}, { __index = M })
|
||||
end
|
||||
|
||||
local ghostty_config_dirs = {
|
||||
vim.fn.expand('$XDG_CONFIG_HOME/ghostty'),
|
||||
vim.fn.expand('$HOME/.config/ghostty'),
|
||||
'/etc/ghostty',
|
||||
}
|
||||
|
||||
---@return boolean
|
||||
function M.enabled()
|
||||
return vim.bo.filetype == 'ghostty'
|
||||
if vim.bo.filetype == 'ghostty' then
|
||||
return true
|
||||
end
|
||||
if vim.bo.filetype ~= 'config' and vim.bo.filetype ~= '' then
|
||||
return false
|
||||
end
|
||||
local path = vim.api.nvim_buf_get_name(0)
|
||||
if path == '' then
|
||||
return false
|
||||
end
|
||||
local real = vim.uv.fs_realpath(path) or path
|
||||
for _, dir in ipairs(ghostty_config_dirs) do
|
||||
if real:find(dir, 1, true) == 1 then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---@return blink.cmp.CompletionItem[]
|
||||
|
|
|
|||
|
|
@ -98,6 +98,43 @@ describe('blink-cmp-ghostty', function()
|
|||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('returns true for config filetype in ghostty config dir', function()
|
||||
local source = require('blink-cmp-ghostty')
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_set_option_value('filetype', 'config', { buf = bufnr })
|
||||
local config_path = vim.fn.expand('$HOME/.config/ghostty/config')
|
||||
vim.api.nvim_buf_set_name(bufnr, config_path)
|
||||
local original_realpath = vim.uv.fs_realpath
|
||||
vim.uv.fs_realpath = function(p)
|
||||
if p == config_path then
|
||||
return config_path
|
||||
end
|
||||
return original_realpath(p)
|
||||
end
|
||||
assert.is_true(source.enabled())
|
||||
vim.uv.fs_realpath = original_realpath
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('returns false for config filetype outside ghostty dir', function()
|
||||
local source = require('blink-cmp-ghostty')
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_set_current_buf(bufnr)
|
||||
vim.api.nvim_set_option_value('filetype', 'config', { buf = bufnr })
|
||||
vim.api.nvim_buf_set_name(bufnr, '/tmp/some-other/config')
|
||||
local original_realpath = vim.uv.fs_realpath
|
||||
vim.uv.fs_realpath = function(p)
|
||||
if p == '/tmp/some-other/config' then
|
||||
return '/tmp/some-other/config'
|
||||
end
|
||||
return original_realpath(p)
|
||||
end
|
||||
assert.is_false(source.enabled())
|
||||
vim.uv.fs_realpath = original_realpath
|
||||
helpers.delete_buffer(bufnr)
|
||||
end)
|
||||
|
||||
it('returns false for other filetypes', function()
|
||||
local bufnr = helpers.create_buffer({}, 'lua')
|
||||
local source = require('blink-cmp-ghostty')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue