aboutsummaryrefslogtreecommitdiff
path: root/autoload/prettier/bridge/parser.vim
diff options
context:
space:
mode:
authormitermayer <mitermayer.reis@gmail.com>2018-05-02 21:59:24 -0700
committermitermayer <mitermayer.reis@gmail.com>2018-05-02 21:59:24 -0700
commitb36bc58f36237a7b6f87057b8877fb31ef0c3f0b (patch)
treef51decc37893d6f6e48cdaac09b6741850ac3eba /autoload/prettier/bridge/parser.vim
parentbfd9fc654c34a7ffea5dd0f98dc17472ffe2baee (diff)
downloadvim-prettier-b36bc58f36237a7b6f87057b8877fb31ef0c3f0b.tar.xz
Adding bridge handler
- Refactoring parser out into its own module in order to make it easier to test
Diffstat (limited to 'autoload/prettier/bridge/parser.vim')
-rw-r--r--autoload/prettier/bridge/parser.vim28
1 files changed, 28 insertions, 0 deletions
diff --git a/autoload/prettier/bridge/parser.vim b/autoload/prettier/bridge/parser.vim
new file mode 100644
index 0000000..eb23210
--- /dev/null
+++ b/autoload/prettier/bridge/parser.vim
@@ -0,0 +1,28 @@
+function! prettier#bridge#parser#onError(out) abort
+ let l:errors = []
+
+ for l:line in a:out
+ " matches:
+ " file.ext: SyntaxError: Unexpected token (2:8)sd
+ " stdin: SyntaxError: Unexpected token (2:8)
+ " [error] file.ext: SyntaxError: Unexpected token (2:8)
+ let l:match = matchlist(l:line, '^.*: \(.*\) (\(\d\{1,}\):\(\d\{1,}\)*)')
+ if !empty(l:match)
+ call add(l:errors, { 'bufnr': bufnr('%'),
+ \ 'text': l:match[1],
+ \ 'lnum': l:match[2],
+ \ 'col': l:match[3] })
+ endif
+ endfor
+
+ if len(l:errors)
+ let l:winnr = winnr()
+ call setqflist(l:errors, 'r')
+ botright copen
+ if !g:prettier#quickfix_auto_focus
+ " Return the cursor back to the main buffer.
+ exe l:winnr . 'wincmd w'
+ endif
+ return 1
+ endif
+endfunction