Skip to content

Commit

Permalink
Merge pull request #11 from mluts/support-add-linters
Browse files Browse the repository at this point in the history
Add support for add-linters. Use fireplace#query to avoid callback/println
  • Loading branch information
venantius committed Mar 27, 2018
2 parents 20050f0 + a1c0957 commit 27e04b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 44 deletions.
31 changes: 19 additions & 12 deletions plugin/eastwood.vim
Expand Up @@ -18,20 +18,27 @@ function! g:EastwoodRequire()
endtry
endfunction

function! EastwoodCallback()
return "(fn [x] " .
\ " (if (= (:kind x) :lint-warning) " .
\ " (let [{:keys [line file column msg] :as x} (:warn-data x)" .
\ " warning (clojure.string/join \":\" [file line column msg])]" .
\ " (println warning))))"
endfunction
function! g:EastwoodLintNS(...) abort
let opts = a:0 ? a:1 : {}
let add_linters = exists('opts.add_linters') ? opts.add_linters : []

function! g:EastwoodLintNS()
let cmd = "(eastwood.lint/eastwood {:namespaces ['" . fireplace#ns() . "] :callback " . EastwoodCallback() . "})"
let cmd = "(->> (eastwood.lint/lint { " .
\ " :namespaces '[" . fireplace#ns() . "]" .
\ " :add-linters [" . join(map(copy(add_linters), '":" . v:val'), " ") ."]" .
\ " })" .
\ " :warnings" .
\ " (map (fn [e]" .
\ "{:text (:msg e)" .
\ " :lnum (:line e)" .
\ " :col (:column e)" .
\ " :valid true" .
\ " :bufnr " . bufnr('%') .
\ " :type \"E\"})))"
try
silent! call fireplace#session_eval(cmd)
return ''
call g:EastwoodRequire() " In case if REPL was restarted
let res=fireplace#query(cmd)
return res
catch /^Clojure:.*/
return ''
return []
endtry
endfunction
35 changes: 3 additions & 32 deletions syntax_checkers/clojure/eastwood.vim
Expand Up @@ -26,38 +26,9 @@ function! SyntaxCheckers_clojure_eastwood_IsAvailable() dict
endfunction

function! SyntaxCheckers_clojure_eastwood_GetLocList() dict
let errorformat = '%f:%l:%c: %m'

let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }

redir => eastwood_output
call g:EastwoodLintNS()
redir end
let result_array = split(eastwood_output, "\n")[1:]
let loclist = []

for message in result_array
let error = {}
let filename_idx = match(message, ":", 0, 1)
let filename = message[0 : filename_idx - 1]

let line_idx = match(message, ":", 0, 2)
let line = message[filename_idx + 1 : line_idx - 1]

let column_idx = match(message, ":", 0, 3)
let column = message[line_idx + 1 : column_idx - 1]
let msg = message[column_idx + 1 : ]

let error.text = msg
let error.lnum = line
let error.col = column
let error.valid = 1
let error.type = "E"
let error.bufnr = bufnr('%')
call add(loclist, error)
endfor

return loclist
let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
let opts = {'add_linters': exists('g:eastwood_add_linters') ? g:eastwood_add_linters : []}
return g:EastwoodLintNS(opts)
endfunction

call g:SyntasticRegistry.CreateAndRegisterChecker({
Expand Down

0 comments on commit 27e04b1

Please sign in to comment.