Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created May 14, 2024 18:21
Show Gist options
  • Save isaacs/b0787faa2a477d18eab60547969c85f3 to your computer and use it in GitHub Desktop.
Save isaacs/b0787faa2a477d18eab60547969c85f3 to your computer and use it in GitHub Desktop.
let g:coc_global_extensions = ['coc-tsserver', 'coc-json']
" Add CoC Prettier if prettier is installed
" if isdirectory('./node_modules') && isdirectory('./node_modules/prettier')
" let g:coc_global_extensions += ['coc-prettier']
" endif
nmap <leader>gn <Plug>(coc-diagnostic-prev)
nmap <leader>gm <Plug>(coc-diagnostic-next)
nmap <leader>gd <Plug>(coc-definition)
nmap <leader>gy <Plug>(coc-type-definition)
nmap <leader>gi <Plug>(coc-implementation)
nmap <leader>gr <Plug>(coc-references)
function! ToggleCocDoc()
if coc#float#has_float()
call coc#float#close_all()
else
if CocAction('hasProvider', 'hover')
call CocActionAsync('definitionHover')
endif
endif
endfunction
nmap <leader>, :call ToggleCocDoc()<CR>
nmap <leader>f :%!npx prettier --stdin-filepath %<CR>:syntax sync fromstart<CR>
autocmd FileType typescript nmap <leader>f :call CocAction('runCommand', 'editor.action.organizeImport')<CR>:%!npx prettier --stdin-filepath %<CR>:syntax sync fromstart<CR>
autocmd FileType typescriptreact nmap <leader>f :call CocAction('runCommand', 'editor.action.organizeImport')<CR>:%!npx prettier --stdin-filepath %<CR>:syntax sync fromstart<CR>
" tab autocompletes if menu showing, otherwise it's just tab
inoremap <silent><expr> <tab> pumvisible() ? coc#_select_confirm() : "<TAB>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment