aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitermayer Reis <mitermayer.reis@gmail.com>2017-09-25 22:34:58 -0700
committerGitHub <noreply@github.com>2017-09-25 22:34:58 -0700
commitade5eb14442a4d78206683eb850353945e8feaed (patch)
treee6aed0297f9dab77814b9d7f4829c2c39e066853
parent9cc6c741d11fe5ac700f333a88881c9123f83f54 (diff)
parentc880bd037e5768c4b4aaecee7a23df2a41c7c9ff (diff)
downloadvim-prettier-0.1.2.tar.xz
Merge pull request #57 from prettier/issue/56-allow-option-to-set-prettier-cli-path0.1.2
issue/56 - Allowing user path overwrite configuration
-rw-r--r--README.md13
-rw-r--r--autoload/prettier.vim6
-rw-r--r--doc/prettier.txt11
-rw-r--r--plugin/prettier.vim3
4 files changed, 27 insertions, 6 deletions
diff --git a/README.md b/README.md
index 7c09fae..cff5c8b 100644
--- a/README.md
+++ b/README.md
@@ -29,9 +29,10 @@ When installed via vim-plug, a default prettier executable is installed inside v
vim-prettier executable resolution:
-1. Traverse parents and search for Prettier installation inside `node_modules`
-2. Look for a global prettier installation
-3. Use locally installed vim-prettier prettier executable
+1. Look for user defined prettier cli path from vim configuration file
+2. Traverse parents and search for Prettier installation inside `node_modules`
+3. Look for a global prettier installation
+4. Use locally installed vim-prettier prettier executable
### USAGE
@@ -91,6 +92,12 @@ Disable auto formatting of files that have "@format" tag
let g:prettier#autoformat = 0
```
+Set the prettier CLI executable path
+
+```vim
+let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
+```
+
The command `:Prettier` by default is synchronous but can also be forced async
```vim
diff --git a/autoload/prettier.vim b/autoload/prettier.vim
index 8ad30dc..c217a58 100644
--- a/autoload/prettier.vim
+++ b/autoload/prettier.vim
@@ -218,11 +218,17 @@ function! s:Get_Prettier_Exec_Args(config) abort
endfunction
" By default we will search for the following
+" => user defined prettier cli path from vim configuration file
" => locally installed prettier inside node_modules on any parent folder
" => globally installed prettier
" => vim-prettier prettier installation
" => if all fails suggest install
function! s:Get_Prettier_Exec() abort
+ let l:user_defined_exec_path = fnamemodify(g:prettier#exec_cmd_path, ':p')
+ if executable(l:user_defined_exec_path)
+ return l:user_defined_exec_path
+ endif
+
let l:local_exec = s:Get_Prettier_Local_Exec()
if executable(l:local_exec)
return l:local_exec
diff --git a/doc/prettier.txt b/doc/prettier.txt
index 083c0df..82b601e 100644
--- a/doc/prettier.txt
+++ b/doc/prettier.txt
@@ -24,9 +24,10 @@ When installed via vim-plug, a default prettier executable is installed inside
vim-prettier executable resolution:
-1. Traverse parents and search for Prettier installation inside `node_modules`
-2. Look for a global prettier installation
-3. Use locally installed vim-prettier prettier executable
+1. Look for user defined prettier cli path from vim configuration file
+2. Traverse parents and search for Prettier installation inside `node_modules`
+3. Look for a global prettier installation
+4. Use locally installed vim-prettier prettier executable
==============================================================================
INSTALL *vim-prettier-install*
@@ -81,6 +82,10 @@ Disable auto formatting of files that have "@format" tag
>
let g:prettier#autoformat = 0
<
+Set the prettier CLI executable path
+>
+ let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
+<
The command `:Prettier` by default is synchronous but can also be forced async
>
let g:prettier#exec_cmd_async = 1
diff --git a/plugin/prettier.vim b/plugin/prettier.vim
index 343ffcd..7837370 100644
--- a/plugin/prettier.vim
+++ b/plugin/prettier.vim
@@ -20,6 +20,9 @@ let g:loaded_prettier = 1
" autoformating enabled by default upon saving
let g:prettier#autoformat = get(g:, 'prettier#autoformat', 1)
+" path to prettier cli
+let g:prettier#exec_cmd_path = get(g:, 'prettier#exec_cmd_path', 0)
+
" calling :Prettier by default runs synchronous
let g:prettier#exec_cmd_async = get(g:, 'prettier#exec_cmd_async', 0)