Skip to content

SQL Server field completion doesn't work #73

@Sh00Fly

Description

@Sh00Fly

Hi,
I just setup vim-dadbod-completion, and it works to complete keywords and table names, but doesn't complete field names.
If I try to type in TableName. I get the following error as soon as I hit "."

[dadbod completion] Fetching columns for table DBVersion...
Error executing lua callback: TextChangedI Autocommands for "*"..function vim_dadbod_completion#omni[103]..<SNR>80_get_table_scope_columns[13]..vim_dadbod_completion#job#run, line 2: Vim(let):E475: Invalid value for argument cmd: 'env' is not executable
stack traceback:
	[C]: in function 'vim_dadbod_completion#omni'
	...lazy/vim-dadbod-completion/lua/vim_dadbod_completion.lua:48: in function 'complete'
	...AppData/Local/nvim-data/lazy/nvim-cmp/lua/cmp/source.lua:326: in function 'complete'
	...n/AppData/Local/nvim-data/lazy/nvim-cmp/lua/cmp/core.lua:299: in function 'complete'
	...n/AppData/Local/nvim-data/lazy/nvim-cmp/lua/cmp/core.lua:169: in function 'callback'
	...n/AppData/Local/nvim-data/lazy/nvim-cmp/lua/cmp/core.lua:229: in function 'autoindent'
	...n/AppData/Local/nvim-data/lazy/nvim-cmp/lua/cmp/core.lua:161: in function 'on_change'
	...n/AppData/Local/nvim-data/lazy/nvim-cmp/lua/cmp/init.lua:346: in function 'callback'
	.../Local/nvim-data/lazy/nvim-cmp/lua/cmp/utils/autocmd.lua:49: in function 'emit'
	.../Local/nvim-data/lazy/nvim-cmp/lua/cmp/utils/autocmd.lua:23: in function <.../Local/nvim-data/lazy/nvim-cmp/lua/cmp/utils/autocmd.lua:22>

Here is my lazy.nvim config:

return {
    {
        "kristijanhusak/vim-dadbod-ui",
        dependencies = {
            { "tpope/vim-dadbod",  },
            { "kristijanhusak/vim-dadbod-completion",
                ft = { "sql", "mysql", "plsql" },
                lazy = true,
            },
        },
        cmd = {
            "DBUI",
            "DBUIToggle",
            "DBUIAddConnection",
            "DBUIFindBuffer",
        },
        init = function()
        -- Your DBUI configuration
        vim.g.db_ui_use_nerd_fonts = 1
        end,
    },
}

And here is my completion setup:

-- Autocompletion Configuration
return {
    "hrsh7th/nvim-cmp",
    dependencies = {
        { "L3MON4D3/LuaSnip",
            dependencies = {
                {  "rafamadriz/friendly-snippets", },
            },
            config = function()
                require("luasnip.loaders.from_vscode").lazy_load() -- loads friendly-snippets
                require("luasnip").config.setup({})
            end,
        },
        { "saadparwaiz1/cmp_luasnip", },
        { "hrsh7th/cmp-nvim-lsp", },
        { "onsails/lspkind.nvim", },
        { "hrsh7th/cmp-buffer", }, 
        { "hrsh7th/cmp-path", },
        { "hrsh7th/cmp-cmdline", 
            config = function()
                local cmp = require("cmp")
                cmp.setup.cmdline(":", {
                    mapping = cmp.mapping.preset.cmdline(),
                    sources = cmp.config.sources({
                        { name = "path" },
                    }, {
                        {
                            name = "cmdline",
                            option = {
                                ignore_cmds = { "Man", "!" },
                            },
                        },
                    }),
                })
                cmp.setup.cmdline("/", {
                    mapping = cmp.mapping.preset.cmdline(),
                    sources = {
                        { name = "buffer" },
                    },
                })
            end,
        },
    },
    config = function()
        local cmp = require("cmp")
        local luasnip = require("luasnip")
        local lspkind = require("lspkind")

        cmp.setup({
            completion = {
                completeopt = "menu, menuone, preview, noselect",
            },
            snippet = {
                expand = function(args)
                    luasnip.lsp_expand(args.body)
                end,
            },
            mapping = cmp.mapping.preset.insert({
                ["<C-n>"] = cmp.mapping.select_next_item(),
                ["<C-p>"] = cmp.mapping.select_prev_item(),
                ["<C-d>"] = cmp.mapping.scroll_docs(-4),
                ["<C-f>"] = cmp.mapping.scroll_docs(4),
                ["<C-S-k>"] = cmp.mapping.complete({}), 
                ["<C-e>"] = cmp.mapping.abort(),
                ["<CR>"] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
                ["<Tab>"] = cmp.mapping(function(fallback)
                    if cmp.visible() then
                        cmp.select_next_item()
                    elseif luasnip.expand_or_locally_jumpable() then
                        luasnip.expand_or_jump()
                    else
                        fallback()
                    end
                end, { "i", "s" }),
                ["<S-Tab>"] = cmp.mapping(function(fallback)
                    if cmp.visible() then
                        cmp.select_prev_item()
                    elseif luasnip.locally_jumpable(-1) then
                        luasnip.jump(-1)
                    else
                        fallback()
                    end
                end, { "i", "s" }),
            }),
            sources = cmp.config.sources({
                { name = "nvim_lsp" },
                { name = "luasnip" },
                { name = "buffer" },
                { name = "path" },
                -- { name = "cmdline" },
            }),
            formatting = {
                expandable_indicator = true,
                format = lspkind.cmp_format({
                    mode = "symbol_text",
                    menu = {
                        buffer = "[Buffer]",
                        nvim_lsp = "[LSP]",
                        luasnip = "[LuaSnip]",
                        nvim_lua = "[Lua]",
                        latex_symbols = "[Latex]",
                    },
                    maxwidth = 50,
                    ellipsis_char = "...",
                }),
            },
            -- setup vim-dadbod
            cmp.setup.filetype({ "sql" }, {
                sources = {
                    { name = "vim-dadbod-completion" },
                    { name = "buffer" },
                },
            }),
            experimental = {
                ghost_text = true,
            },
        })
    end,
}
---------------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions