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

Javascript/React auto completion and auto import #366

Open
andreicorpo opened this issue Apr 17, 2021 · 1 comment
Open

Javascript/React auto completion and auto import #366

andreicorpo opened this issue Apr 17, 2021 · 1 comment

Comments

@andreicorpo
Copy link

Hello, I just can't figure out how to setup this plugin for javascript and react.

This is my config:

vim.o.completeopt = "menuone,noselect"
vim.o.shortmess = vim.o.shortmess .. "c"
vim.g.completion_enable_snippet = 'vim-vsnip'
vim.g.completion_matching_strategy_list = {'exact', 'substring', 'fuzzy'}
vim.g.completion_matching_ignore_case = 1
vim.g.completion_auto_change_source = 1

local t = function(str)
    return vim.api.nvim_replace_termcodes(str, true, true, true)
end

-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
    if vim.fn.pumvisible() == 1 then
        return t "<C-n>"
    elseif vim.fn.call("vsnip#available", {1}) == 1 then
        return t "<Plug>(vsnip-expand-or-jump)"
    else
        return t "<Tab>"
    end
end
_G.s_tab_complete = function()
    if vim.fn.pumvisible() == 1 then
        return t "<C-p>"
    elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
        return t "<Plug>(vsnip-jump-prev)"
    else
        return t "<S-Tab>"
    end
end

vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})

-- Chain completion list
vim.g.completion_chain_complete_list = {
    default = {
        default = {{complete_items = {'lsp', 'snippet', 'buffers'}}, {mode = '<c-p>'}, {mode = '<c-n>'}},
        comment = {},
        string = {{complete_items = {'path'}}}
    }
}

Buffers and snippet support is working, but LSP doesn't seem to work for javascript/react. Although it is working for lua.

I am using to autocommand to setup completion.

@ranjithshegde
Copy link
Contributor

what autocmd are you using to setup completion?
do you have something like the following

au BufEnter * lua require'completion'.on_attach()
or do you have it per filetype? or in an on_attach(client,bufnr) funtion?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants