aboutsummaryrefslogtreecommitdiff
path: root/autoload/prettier/resolver/config.vim
diff options
context:
space:
mode:
authorVictor S <victorplentz@gmail.com>2023-10-07 23:57:33 -0300
committerVictor S <victorplentz@gmail.com>2023-10-07 23:57:33 -0300
commit6dd9a0813b78158254987e5452455000aabd6b02 (patch)
treede4559399f02f3789433e477c5a54e0ee53cdeb9 /autoload/prettier/resolver/config.vim
parent6649ecfdae2169e8b76d446aa162ce705685807f (diff)
downloadvim-prettier-6dd9a0813b78158254987e5452455000aabd6b02.tar.xz
refactor: add helper functions to get CLI version
Added two helper functions to get the version of the Prettier CLI as a string. This is part of a plan to compose the CLI command from an object with flag details.
Diffstat (limited to 'autoload/prettier/resolver/config.vim')
-rw-r--r--autoload/prettier/resolver/config.vim20
1 files changed, 20 insertions, 0 deletions
diff --git a/autoload/prettier/resolver/config.vim b/autoload/prettier/resolver/config.vim
index 430d994..84dc933 100644
--- a/autoload/prettier/resolver/config.vim
+++ b/autoload/prettier/resolver/config.vim
@@ -266,3 +266,23 @@ let s:FLAGS = {
\ 'global_name': '',
\ 'mapper': function('s:Flag_stdin'),
\ 'deprecated': '2.0.0'}}
+
+" Returns the argument string with unprintable characters represented in Vim
+" internal format removed from both ends.
+function! s:Trim_internal_unprintable(text) abort
+ let l:char_patt = '\%(\%(\^\m.\)\|\%(<\x\x>\)\)\{}'
+ let l:patt_at_ends = '^' . l:char_patt . '\|' . l:char_patt . '$'
+ let l:trimmed_text = a:text->substitute(l:patt_at_ends, '', 'g')
+ return l:trimmed_text
+endfunction
+
+" Returns the version of the Prettier CLI as a string.
+function! s:Get_prettier_cli_version() abort
+ let l:output = ''
+ redir => l:output
+ silent call prettier#PrettierCli('--version')
+ redir END
+ " The shell sends the string with whitespaces at both ends.
+ let l:prettier_cli_version = s:Trim_internal_unprintable(trim(l:output))
+ return l:prettier_cli_version
+endfunction