From 2f5b382087f131c0ab967600b2d9ce2f3201e653 Mon Sep 17 00:00:00 2001 From: mitermayer Date: Sun, 17 Sep 2017 23:38:58 -0700 Subject: feature: Adding more commands This includes more commands to interact with the prettier CLI from within vim itself --- README.md | 24 ++++++++++++++++++++++++ autoload/prettier.vim | 21 +++++++++++++++++++++ doc/prettier.txt | 16 ++++++++++++++++ plugin/prettier.vim | 16 ++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/README.md b/README.md index 7581820..39a4db6 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,30 @@ If your are on vim 8+ you can also trigger async formatting by: :PrettierAsync ``` +You can check what is the `vim-prettier` plugin version by: + +```vim +:PrettierVersion +``` + +You can send commands to the resolved `prettier` cli by: + +``` +:PrettierCli +``` + +You can check what is the resolved `prettier` cli path by: + +```vim +:PrettierCliPath +``` + +You can check what is the resolved `prettier` cli version by: + +```vim +:PrettierCliVersion +``` + ### Configuration Change the mapping to run from the default of `p` diff --git a/autoload/prettier.vim b/autoload/prettier.vim index 7d6eb08..79b4611 100644 --- a/autoload/prettier.vim +++ b/autoload/prettier.vim @@ -2,6 +2,27 @@ let s:root_dir = fnamemodify(resolve(expand(':p')), ':h') let s:prettier_job_running = 0 let s:prettier_quickfix_open = 0 +function! prettier#PrettierCliPath() abort + let l:execCmd = s:Get_Prettier_Exec() + + if l:execCmd != -1 + echom l:execCmd + else + call s:Suggest_Install_Prettier() + endif +endfunction + +function! prettier#PrettierCli(user_input) abort + let l:execCmd = s:Get_Prettier_Exec() + + if l:execCmd != -1 + let l:out = system(l:execCmd. ' ' . a:user_input) + echom l:out + else + call s:Suggest_Install_Prettier() + endif +endfunction + function! prettier#Prettier(...) abort let l:execCmd = s:Get_Prettier_Exec() let l:async = a:0 > 0 ? a:1 : 0 diff --git a/doc/prettier.txt b/doc/prettier.txt index 38fad26..a10f310 100644 --- a/doc/prettier.txt +++ b/doc/prettier.txt @@ -58,6 +58,22 @@ If your are on vim 8+ you can also trigger async formatting by: > :PrettierAsync < +You can check what is the `vim-prettier` plugin version by: +> + :PrettierVersion +< +You can send commands to the resolved `prettier` cli by: +> + :PrettierCli +< +You can check what is the resolved `prettier` cli path by: +> + :PrettierCliPath +< +You can check what is the resolved `prettier` cli version by: +> + :PrettierCliVersion +< ============================================================================== CONFIGURATION *vim-prettier-configuration* diff --git a/plugin/prettier.vim b/plugin/prettier.vim index 7688063..c985f7d 100644 --- a/plugin/prettier.vim +++ b/plugin/prettier.vim @@ -63,9 +63,25 @@ command! -nargs=? -range=% Prettier call prettier#Prettier(g:prettier#exec_cmd_a " prettier async command! -nargs=? -range=% PrettierAsync call prettier#Prettier(1, , ) +" prints vim-prettier version +command! -nargs=? -range=% PrettierVersion echom "0.1.0" + +" call prettier cli +command! -nargs=? -range=% PrettierCli call prettier#PrettierCli() + +" call prettier cli to get its version +command! -nargs=? -range=% PrettierCliVersion call prettier#PrettierCli('--version') + +" prints prettier resolved cli path +command! -nargs=? -range=% PrettierCliPath call prettier#PrettierCliPath() + " map command if !hasmapto('(Prettier)') && maparg('p', 'n') ==# '' nmap p (Prettier) endif nnoremap (Prettier) :Prettier nnoremap (PrettierAsync) :PrettierAsync +nnoremap (PrettierVersion) :PrettierVersion +nnoremap (PrettierCli) :PrettierCli +nnoremap (PrettierCliVersion) :PrettierCliVersion +nnoremap (PrettierCliPath) :PrettierCliPath -- cgit v1.3