How to configure coc and nvim to sort react imports correcty?
2
votes
0
answers
198
views
I use nvim daily in conjunction with coc and it has been extremely more efficient than VS code, however, something that is done in vscode and I can't configure for when I use React is the import in this order .
React ( useState, useEffect, useRef)
Dependencies ( momentjs, antd )
Built-in ( My own components as Component.tsx )
I've tried several ways, using coc-eslint, coc-prettier, coc-tsserver, but none of them really work.
I've tried using CocCommand editor.action.organizeImport but it just leaves it in alphabetical order
*My nvim config*
set nocompatible
syntax enable
set colorcolumn=80
set updatetime=500
set relativenumber
set viminfo='1000
set tabstop=2
set shiftwidth=2
set expandtab
set completeopt=noinsert,menuone,noselect
set wildmenu
set ignorecase
set autoindent
let g:fzf_preview_command = 'bat --color=always --plain {-1}'
let let g:fzf_preview_git_files_command = 'fd .'
let g:fzf_preview_filelist_command = 'rg --files --hidden --follow --no-messages -g \!"* *"'
highlight ColorColumn ctermbg=0 guibg=lightgrey
call plug#begin()
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'scrooloose/nerdtree' " NERD Tree
Plug 'Xuyuanp/nerdtree-git-plugin' " show git status in Nerd tree
Plug 'itchyny/lightline.vim' " UI
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Code {{{
Plug 'editorconfig/editorconfig-vim'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'othree/html5.vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }} " Markdown preview
"}}}
" GIT {{{
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
" }}}
call plug#end()
let mapleader=" "
" by myself
"go to
nmap gy (coc-type-definition)
nmap gi (coc-implementation)
nmap gr (coc-references)
nmap gd (coc-definition)
"search
map g :CocCommand fzf-preview.ProjectGrep
nnoremap f :CocCommand fzf-preview.GitFiles
nnoremap d :CocCommand fzf-preview.CocDefinition
nnoremap :CocCommand fzf-preview.CocDiagnostics
nnoremap :CocCommand fzf-preview.CocTypeDefinition
nnoremap :CocCommand fzf-preview.CocImplementations
"snippets
inoremap
\ coc#pum#visible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\" :
\ CheckBackspace() ? "\" :
\ coc#refresh()
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = ''
" Use for both expand and jump (make expand higher priority.)
imap (coc-snippets-expand-jump)
" Use for jump to previous placeholder, it's default of coc.nvim
let g:coc_snippet_prev = ''
"tabs & navigation
map t gt
map n :tabnew
map m :tabmove
map c :close
map :tabclose
map o :tabonly
"common
noremap l :nohl
noremap s :vsp
map w :w
map y "+y
map p "+p
map r w
"autoindent - eslint - prettier
command! -nargs=0 Prettier :call CocAction('runCommand', 'prettier.formatFile')
augroup Mygroup
autocmd!
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
autocmd BufWritePre .ts,.js,.py,.rb,*.go silent! call CocAction('runCommand', 'editor.action.organizeImport')
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
*My CocConfig*
{
"suggest.noselect": true,
"javascript.updateImportsOnFileMove": "always",
"javascript.suggestionActions.enabled": true,
"javascript.implementationsCodeLens.enabled": true,
"javascript.preferences.quoteStyle":"single",
"javascript.suggest.autoImports": true,
"tsserver.experimental.enableProjectDiagnostics": true,
"typescript.suggest.autoImports": true,
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
"typescript.preferences.importModuleSpecifier": "shortest",
"typescript.preferences.importModuleSpecifierEnding": "minimal",
"snippets.ultisnips.pythonPrompt": false,
"eslint.autoFixOnSave": true,
"eslint.filetypes":["javascript", "javascriptreact", "typescript", "typescriptreact"],
"prettier.disableSuccessMessage": true,
"coc.preferences.formatOnSaveFiletypes": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"tsserver.formatOnType": true,
"coc.preferences.formatOnType": true
}
Asked by Hudson Ribeiro
(21 rep)
Dec 12, 2023, 08:31 PM