diff options
| author | mitermayer <mitermayer.reis@gmail.com> | 2018-05-02 16:55:44 -0700 |
|---|---|---|
| committer | mitermayer <mitermayer.reis@gmail.com> | 2018-05-02 17:02:01 -0700 |
| commit | a9326e2596c56b7717562b9dc7f749c7c5faf7b4 (patch) | |
| tree | 10054fdb03ca67682a4109fc831b526811325faf | |
| parent | a324f7194c33ff8061a2e5a07a0f8543059c9407 (diff) | |
| download | vim-prettier-a9326e2596c56b7717562b9dc7f749c7c5faf7b4.tar.xz | |
Starting refactoring methods out to components
- This is the first commit on refactoring methods outs on self contained
components, this will help on unit testing and maintainability
| -rw-r--r-- | autoload/prettier.vim | 6 | ||||
| -rw-r--r-- | autoload/prettier/logging/error.vim | 12 |
2 files changed, 15 insertions, 3 deletions
diff --git a/autoload/prettier.vim b/autoload/prettier.vim index 7cf9cca..71f21d6 100644 --- a/autoload/prettier.vim +++ b/autoload/prettier.vim @@ -204,7 +204,7 @@ function! s:Prettier_Job_Close(channel, startSelection, endSelection, bufferName silent exec 'sp '. escape(bufname(bufnr(a:bufferName)), ' \') call s:Prettier_Format_And_Save(l:out, a:startSelection, a:endSelection) catch - echohl WarningMsg | echom 'Prettier: failed to parse buffer: ' . a:bufferName | echohl NONE + call prettier#logging#error#log('PARSING_ERROR', a:bufferName) finally " we should then hide this buffer again if a:bufferName == bufname('%') @@ -453,7 +453,7 @@ function! s:Traverse_Dir_Search(rootDir) abort endfunction function! s:Prettier_Parse_Error(errors) abort - echohl WarningMsg | echom 'Prettier: failed to parse buffer.' | echohl NONE + call prettier#logging#error#log('PARSING_ERROR') if g:prettier#quickfix_enabled call s:Handle_Parsing_Errors(a:errors) endif @@ -461,5 +461,5 @@ endfunction " If we can't find any prettier installing we then suggest where to get it from function! s:Suggest_Install_Prettier() abort - echohl WarningMsg | echom 'Prettier: no prettier executable installation found.' | echohl NONE + call prettier#logging#error#log('EXECUTABLE_NOT_FOUND_ERROR') endfunction diff --git a/autoload/prettier/logging/error.vim b/autoload/prettier/logging/error.vim new file mode 100644 index 0000000..48ad048 --- /dev/null +++ b/autoload/prettier/logging/error.vim @@ -0,0 +1,12 @@ +let s:PREFIX_MSG = 'Prettier: ' +let s:ERRORS = { + \ 'EXECUTABLE_NOT_FOUND_ERROR': 'no prettier executable installation found', + \ 'PARSING_ERROR': 'failed to parse buffer', + \ } +let s:DEFAULT_ERROR = get(s:, 'PARSING_ERROR') + +function! prettier#logging#error#log(...) abort + let l:error = a:0 > 0 ? a:1 : s:DEFAULT_ERROR + let l:msg = a:0 > 1 ? ': ' . a:2 : '' + echohl WarningMsg | echom s:PREFIX_MSG . get(s:ERRORS, l:error, s:DEFAULT_ERROR) . l:msg | echohl NONE +endfunction |
