Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

opt.get_option in on_attach() returns nil for unset options #402

@brainplot

Description

@brainplot

When I try to active completion-nvim in my init.lua with the on_attach function, I get a bunch of errors.

Error running config for completion-nvim: ...ite/pack/packer/start/completion-nvim/lua/completion.lua:251: bad argument #1 to 'ipairs' (table expected, got nil)

If we look at the offending line:

M.on_attach = function(option)
-- setup completion_option tables
opt.set_option_table(option)
local disable_filetypes = opt.get_option("disable_filetypes")
local ft = vim.bo.filetype
for _, disable_ft in ipairs(disable_filetypes) do
if ft == disable_ft then
return
end
end

disable_filetypes which is returned by get_options is nil the moment ipairs is called. I tried to manually edit the file and add disable_filetypes = disable_filetypes or {} at line 250 but I got basically the same error elsewhere.

Error running config for completion-nvim: ...ite/pack/packer/start/completion-nvim/lua/completion.lua:266: bad argument #1 to 'len' (string expected, got nil)

which is basically the same error.

if string.len(opt.get_option('confirm_key')) ~= 0 then
api.nvim_buf_set_keymap(0, 'i', opt.get_option('confirm_key'),
'pumvisible() ? complete_info()["selected"] != "-1" ? "\\<Plug>(completion_confirm_completion)" :'..
' "\\<c-e>\\<CR>" : "\\<CR>"',
{silent=false, noremap=false, expr=true})
end

string.len() is getting nil as its argument.

My testing minimal init.lua

require('completion').on_attach()

(literally my one-line init.lua created in a temporary home directory)

Expected behavior
I expect not to get errors when I call on_attach. Perhaps get_options should handle missing options better (?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions