mhartington / nvim-typescript

Typescript tooling for Neovim
615 stars 76 forks source link

Autoimport suggestions as you type #125

Closed bloadvenro closed 4 years ago

bloadvenro commented 6 years ago

Problems summary

Suppose we are able to import Component from React or add from lodash. We have to know exact identifier name to perform :TSImport.

Expected

It would be great to see Component in suggestions when we wrote only part of name (e.g. Compo). Such behavior is supported in VSCode.

Environment Information

Provide a minimal vim rc with less than 50 lines (Required!)

" Your minimal init.vim
call plug#begin('~/.config/nvim/plugged')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'mhartington/nvim-typescript'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'christoomey/vim-tmux-navigator'
Plug 'tomasiser/vim-code-dark'
Plug 'tpope/vim-commentary'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'jiangmiao/auto-pairs'
Plug 'mattn/emmet-vim'
Plug 'tpope/vim-surround'
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-repeat'
Plug 'leafgarland/typescript-vim'
Plug 'prettier/vim-prettier', { 'do': 'yarn install' }
Plug 'w0rp/ale'
call plug#end()

syntax on
set noswapfile
set ignorecase "Case-insensitive search.
set history=200 "By default is 20 or 50.
set exrc "Enable per project configuration.
set number " Show line numbers.
set mouse=a "Activate mouse inside vim. It is better to have such feature I think.
set cursorline "Highlight current line.
highlight Cursorline term=none cterm=none
call matchadd('ColorColumn', '\%81v', 120) "Ruler.
highlight ColorColumn ctermbg=magenta "Ruler style.
set splitright "Open new buffer on the right of the current buffer.
set splitbelow "Open new buffer below the current buffer.
colorscheme codedark 
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent
set cindent

let g:airline_theme='codedark'
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|.git\|tmp\' " Ingone specific folders by CtrlP plugin.
let g:deoplete#enable_at_startup = 1
let g:prettier#exec_cmd_async = 1
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue PrettierAsync
let g:ale_completion_enabled = 0
let g:ale_sign_column_always = 1
let g:nvim_typescript#max_completion_detail=100

The reproduce ways from neovim starting

  1. Init npm project, add tsconfig.json, npm i react @types/react lodash @types/lodash
  2. Start typing some name you want to autoimport

Screen shot (if possible)

Neovim: image

VSCode: image

mhartington commented 6 years ago

Going to mark this as a nice to have. I've never really liked import as your types setups (I'm lame I guess). If someone is up to making a PR for this, I'd happily accept it!

chemzqm commented 6 years ago

This feature requires implementation of completion resolve and handle the codeActions from tsserver response on complete done, it would be much easier if completion manager could provide this kind of feature, instead of handled be completion provider.

hdayi commented 5 years ago

I really would like to have this feature.

insidewhy commented 5 years ago

This is basically the feature that made me move from neovim to VS Code for typescript. Adding imports for angular/react typescript projects manually is an incredible amount of effort that I just can't be bothered with.

VSCodeVim is such a pain but its inadequacies still waste a lot less time than having to manually import.

SnowCone161803 commented 4 years ago

This is basically the feature that made me move from neovim to VS Code for typescript. Adding imports for angular/react typescript projects manually is an incredible amount of effort that I just can't be bothered with.

VSCodeVim is such a pain but its inadequacies still waste a lot less time than having to manually import.

Have you seen that you can get the import by moving the cursor onto the missing type doing :TSGetCodeFix?

insidewhy commented 4 years ago

@SnowCone161803 I'm using neovim-coc now, with that you just highlight the completion and press enter.

SnowCone161803 commented 4 years ago

@ohjames wicked, thanks! 😀