mirror of
https://github.com/amix/vimrc
synced 2025-07-10 03:25:00 +08:00
Use syntastic instead of pyflakes (supports a ton of more languages)
This commit is contained in:
@ -0,0 +1,40 @@
|
||||
if exists("g:loaded_syntastic_notifier_autoloclist")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_notifier_autoloclist = 1
|
||||
|
||||
if !exists("g:syntastic_auto_loc_list")
|
||||
let g:syntastic_auto_loc_list = 2
|
||||
endif
|
||||
|
||||
let g:SyntasticAutoloclistNotifier = {}
|
||||
|
||||
" Public methods {{{1
|
||||
"
|
||||
function! g:SyntasticAutoloclistNotifier.New()
|
||||
let newObj = copy(self)
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticAutoloclistNotifier.refresh(loclist)
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'autoloclist: refresh')
|
||||
call g:SyntasticAutoloclistNotifier.AutoToggle(a:loclist)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticAutoloclistNotifier.AutoToggle(loclist)
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'autoloclist: toggle')
|
||||
if !a:loclist.isEmpty()
|
||||
if g:syntastic_auto_loc_list == 1
|
||||
call a:loclist.show()
|
||||
endif
|
||||
else
|
||||
if g:syntastic_auto_loc_list > 0
|
||||
|
||||
"TODO: this will close the loc list window if one was opened by
|
||||
"something other than syntastic
|
||||
lclose
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
68
sources_non_forked/syntastic/plugin/syntastic/balloons.vim
Normal file
68
sources_non_forked/syntastic/plugin/syntastic/balloons.vim
Normal file
@ -0,0 +1,68 @@
|
||||
if exists("g:loaded_syntastic_notifier_balloons")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_notifier_balloons = 1
|
||||
|
||||
if !exists("g:syntastic_enable_balloons")
|
||||
let g:syntastic_enable_balloons = 1
|
||||
endif
|
||||
|
||||
if !has('balloon_eval')
|
||||
let g:syntastic_enable_balloons = 0
|
||||
endif
|
||||
|
||||
let g:SyntasticBalloonsNotifier = {}
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticBalloonsNotifier.New()
|
||||
let newObj = copy(self)
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticBalloonsNotifier.enabled()
|
||||
return
|
||||
\ has('balloon_eval') &&
|
||||
\ (exists('b:syntastic_enable_balloons') ? b:syntastic_enable_balloons : g:syntastic_enable_balloons)
|
||||
endfunction
|
||||
|
||||
" Update the error balloons
|
||||
function! g:SyntasticBalloonsNotifier.refresh(loclist)
|
||||
let b:syntastic_balloons = {}
|
||||
if self.enabled() && !a:loclist.isEmpty()
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'balloons: refresh')
|
||||
let buf = bufnr('')
|
||||
let issues = filter(a:loclist.copyRaw(), 'v:val["bufnr"] == buf')
|
||||
if !empty(issues)
|
||||
for i in issues
|
||||
if has_key(b:syntastic_balloons, i['lnum'])
|
||||
let b:syntastic_balloons[i['lnum']] .= "\n" . i['text']
|
||||
else
|
||||
let b:syntastic_balloons[i['lnum']] = i['text']
|
||||
endif
|
||||
endfor
|
||||
set beval bexpr=SyntasticBalloonsExprNotifier()
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Reset the error balloons
|
||||
" @vimlint(EVL103, 1, a:loclist)
|
||||
function! g:SyntasticBalloonsNotifier.reset(loclist)
|
||||
if has('balloon_eval')
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'balloons: reset')
|
||||
set nobeval
|
||||
endif
|
||||
endfunction
|
||||
" @vimlint(EVL103, 0, a:loclist)
|
||||
|
||||
" Private functions {{{1
|
||||
|
||||
function! SyntasticBalloonsExprNotifier()
|
||||
if !exists('b:syntastic_balloons')
|
||||
return ''
|
||||
endif
|
||||
return get(b:syntastic_balloons, v:beval_lnum, '')
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
144
sources_non_forked/syntastic/plugin/syntastic/checker.vim
Normal file
144
sources_non_forked/syntastic/plugin/syntastic/checker.vim
Normal file
@ -0,0 +1,144 @@
|
||||
if exists("g:loaded_syntastic_checker")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_checker = 1
|
||||
|
||||
let g:SyntasticChecker = {}
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticChecker.New(args)
|
||||
let newObj = copy(self)
|
||||
|
||||
let newObj._filetype = a:args['filetype']
|
||||
let newObj._name = a:args['name']
|
||||
let newObj._exec = get(a:args, 'exec', newObj._name)
|
||||
|
||||
if has_key(a:args, 'redirect')
|
||||
let [filetype, name] = split(a:args['redirect'], '/')
|
||||
let prefix = 'SyntaxCheckers_' . filetype . '_' . name . '_'
|
||||
else
|
||||
let prefix = 'SyntaxCheckers_' . newObj._filetype . '_' . newObj._name . '_'
|
||||
endif
|
||||
|
||||
let newObj._locListFunc = function(prefix . 'GetLocList')
|
||||
|
||||
if exists('*' . prefix . 'IsAvailable')
|
||||
let newObj._isAvailableFunc = function(prefix . 'IsAvailable')
|
||||
else
|
||||
let newObj._isAvailableFunc = function('SyntasticCheckerIsAvailableDefault')
|
||||
endif
|
||||
|
||||
if exists('*' . prefix . 'GetHighlightRegex')
|
||||
let newObj._highlightRegexFunc = function(prefix . 'GetHighlightRegex')
|
||||
endif
|
||||
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker.getFiletype()
|
||||
return self._filetype
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker.getName()
|
||||
return self._name
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker.getExec()
|
||||
if exists('g:syntastic_' . self._filetype . '_' . self._name . '_exec')
|
||||
return expand(g:syntastic_{self._filetype}_{self._name}_exec)
|
||||
endif
|
||||
|
||||
return self._exec
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker.getExecEscaped()
|
||||
return syntastic#util#shescape(self.getExec())
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker.getLocListRaw()
|
||||
let name = self._filetype . '/' . self._name
|
||||
try
|
||||
let list = self._locListFunc()
|
||||
call syntastic#log#debug(g:SyntasticDebugTrace, 'getLocList: checker ' . name . ' returned ' . v:shell_error)
|
||||
catch /\m\C^Syntastic: checker error$/
|
||||
let list = []
|
||||
call syntastic#log#error('checker ' . name . ' returned abnormal status ' . v:shell_error)
|
||||
endtry
|
||||
call self._populateHighlightRegexes(list)
|
||||
call syntastic#log#debug(g:SyntasticDebugLoclist, name . ' raw:', list)
|
||||
call self._quietMessages(list)
|
||||
return list
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker.getLocList()
|
||||
return g:SyntasticLoclist.New(self.getLocListRaw())
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker.makeprgBuild(opts)
|
||||
let setting = 'g:syntastic_' . self._filetype . '_' . self._name . '_'
|
||||
|
||||
let parts = []
|
||||
call extend(parts, self._getOpt(a:opts, setting, 'exe', self.getExecEscaped()))
|
||||
call extend(parts, self._getOpt(a:opts, setting, 'args', ''))
|
||||
call extend(parts, self._getOpt(a:opts, setting, 'fname', syntastic#util#shexpand('%')))
|
||||
call extend(parts, self._getOpt(a:opts, setting, 'post_args', ''))
|
||||
call extend(parts, self._getOpt(a:opts, setting, 'tail', ''))
|
||||
|
||||
return join(parts)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker.isAvailable()
|
||||
return self._isAvailableFunc()
|
||||
endfunction
|
||||
|
||||
" Private methods {{{1
|
||||
|
||||
function! g:SyntasticChecker._quietMessages(errors)
|
||||
let filter = 'g:syntastic_' . self._filetype . '_' . self._name . '_quiet_messages'
|
||||
if exists(filter) && type({filter}) == type({}) && !empty({filter})
|
||||
call syntastic#util#dictFilter(a:errors, {filter})
|
||||
call syntastic#log#debug(g:SyntasticDebugLoclist, 'filtered by ' . filter . ':', a:errors)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker._populateHighlightRegexes(errors)
|
||||
if has_key(self, '_highlightRegexFunc')
|
||||
for e in a:errors
|
||||
if e['valid']
|
||||
let term = self._highlightRegexFunc(e)
|
||||
if len(term) > 0
|
||||
let e['hl'] = term
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker._getOpt(opts, setting, name, default)
|
||||
let sname = a:setting . a:name
|
||||
let ret = []
|
||||
call extend( ret, self._shescape(get(a:opts, a:name . '_before', '')) )
|
||||
call extend( ret, self._shescape(exists(sname) ? {sname} : get(a:opts, a:name, a:default)) )
|
||||
call extend( ret, self._shescape(get(a:opts, a:name . '_after', '')) )
|
||||
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticChecker._shescape(opt)
|
||||
if type(a:opt) == type('') && a:opt != ''
|
||||
return [a:opt]
|
||||
elseif type(a:opt) == type([])
|
||||
return map(copy(a:opt), 'syntastic#util#shescape(v:val)')
|
||||
endif
|
||||
|
||||
return []
|
||||
endfunction
|
||||
|
||||
" Non-method functions {{{1
|
||||
|
||||
function! SyntasticCheckerIsAvailableDefault() dict
|
||||
return executable(self.getExec())
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
67
sources_non_forked/syntastic/plugin/syntastic/cursor.vim
Normal file
67
sources_non_forked/syntastic/plugin/syntastic/cursor.vim
Normal file
@ -0,0 +1,67 @@
|
||||
if exists("g:loaded_syntastic_notifier_cursor")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_notifier_cursor = 1
|
||||
|
||||
if !exists('g:syntastic_echo_current_error')
|
||||
let g:syntastic_echo_current_error = 1
|
||||
endif
|
||||
|
||||
let g:SyntasticCursorNotifier = {}
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticCursorNotifier.New()
|
||||
let newObj = copy(self)
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticCursorNotifier.enabled()
|
||||
return exists('b:syntastic_echo_current_error') ? b:syntastic_echo_current_error : g:syntastic_echo_current_error
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticCursorNotifier.refresh(loclist)
|
||||
if self.enabled() && !a:loclist.isEmpty()
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'cursor: refresh')
|
||||
let b:syntastic_messages = copy(a:loclist.messages(bufnr('')))
|
||||
let b:oldLine = -1
|
||||
autocmd! syntastic CursorMoved
|
||||
autocmd syntastic CursorMoved * call g:SyntasticRefreshCursor()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" @vimlint(EVL103, 1, a:loclist)
|
||||
function! g:SyntasticCursorNotifier.reset(loclist)
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'cursor: reset')
|
||||
autocmd! syntastic CursorMoved
|
||||
unlet! b:syntastic_messages
|
||||
let b:oldLine = -1
|
||||
endfunction
|
||||
" @vimlint(EVL103, 0, a:loclist)
|
||||
|
||||
" Private methods {{{1
|
||||
|
||||
" The following defensive nonsense is needed because of the nature of autocmd
|
||||
function! g:SyntasticRefreshCursor()
|
||||
if !exists('b:syntastic_messages') || empty(b:syntastic_messages)
|
||||
" file not checked
|
||||
return
|
||||
endif
|
||||
|
||||
if !exists('b:oldLine')
|
||||
let b:oldLine = -1
|
||||
endif
|
||||
let l = line('.')
|
||||
if l == b:oldLine
|
||||
return
|
||||
endif
|
||||
let b:oldLine = l
|
||||
|
||||
if has_key(b:syntastic_messages, l)
|
||||
call syntastic#util#wideMsg(b:syntastic_messages[l])
|
||||
else
|
||||
echo
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
@ -0,0 +1,95 @@
|
||||
if exists("g:loaded_syntastic_notifier_highlighting")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_notifier_highlighting = 1
|
||||
|
||||
" Highlighting requires getmatches introduced in 7.1.040
|
||||
let s:has_highlighting = v:version > 701 || (v:version == 701 && has('patch040'))
|
||||
|
||||
if !exists("g:syntastic_enable_highlighting")
|
||||
let g:syntastic_enable_highlighting = 1
|
||||
endif
|
||||
|
||||
let g:SyntasticHighlightingNotifier = {}
|
||||
|
||||
let s:setup_done = 0
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticHighlightingNotifier.New()
|
||||
let newObj = copy(self)
|
||||
|
||||
if !s:setup_done
|
||||
call self._setup()
|
||||
let s:setup_done = 1
|
||||
endif
|
||||
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticHighlightingNotifier.enabled()
|
||||
return
|
||||
\ s:has_highlighting &&
|
||||
\ (exists('b:syntastic_enable_highlighting') ? b:syntastic_enable_highlighting : g:syntastic_enable_highlighting)
|
||||
endfunction
|
||||
|
||||
" Sets error highlights in the cuirrent window
|
||||
function! g:SyntasticHighlightingNotifier.refresh(loclist)
|
||||
if self.enabled()
|
||||
call self.reset(a:loclist)
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'highlighting: refresh')
|
||||
let buf = bufnr('')
|
||||
let issues = filter(a:loclist.copyRaw(), 'v:val["bufnr"] == buf')
|
||||
for item in issues
|
||||
let group = item['type'] ==? 'E' ? 'SyntasticError' : 'SyntasticWarning'
|
||||
|
||||
" The function `Syntastic_{filetype}_{checker}_GetHighlightRegex` is
|
||||
" used to override default highlighting.
|
||||
if has_key(item, 'hl')
|
||||
call matchadd(group, '\%' . item['lnum'] . 'l' . item['hl'])
|
||||
elseif get(item, 'col', 0)
|
||||
if get(item, 'vcol', 0)
|
||||
let lastcol = virtcol([item['lnum'], '$'])
|
||||
let coltype = 'v'
|
||||
else
|
||||
let lastcol = col([item['lnum'], '$'])
|
||||
let coltype = 'c'
|
||||
endif
|
||||
let lcol = min([lastcol, item['col']])
|
||||
|
||||
call matchadd(group, '\%' . item['lnum'] . 'l\%' . lcol . coltype)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Remove all error highlights from the window
|
||||
" @vimlint(EVL103, 1, a:loclist)
|
||||
function! g:SyntasticHighlightingNotifier.reset(loclist)
|
||||
if s:has_highlighting
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'highlighting: reset')
|
||||
for match in getmatches()
|
||||
if stridx(match['group'], 'Syntastic') == 0
|
||||
call matchdelete(match['id'])
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
" @vimlint(EVL103, 0, a:loclist)
|
||||
|
||||
" Private methods {{{1
|
||||
|
||||
" One time setup: define our own highlighting
|
||||
function! g:SyntasticHighlightingNotifier._setup()
|
||||
if s:has_highlighting
|
||||
if !hlexists('SyntasticError')
|
||||
highlight link SyntasticError SpellBad
|
||||
|
||||
endif
|
||||
if !hlexists('SyntasticWarning')
|
||||
highlight link SyntasticWarning SpellCap
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
238
sources_non_forked/syntastic/plugin/syntastic/loclist.vim
Normal file
238
sources_non_forked/syntastic/plugin/syntastic/loclist.vim
Normal file
@ -0,0 +1,238 @@
|
||||
if exists("g:loaded_syntastic_loclist")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_loclist = 1
|
||||
|
||||
let g:SyntasticLoclist = {}
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticLoclist.New(rawLoclist)
|
||||
let newObj = copy(self)
|
||||
|
||||
let llist = filter(copy(a:rawLoclist), 'v:val["valid"] == 1')
|
||||
|
||||
for e in llist
|
||||
if get(e, 'type', '') == ''
|
||||
let e['type'] = 'E'
|
||||
endif
|
||||
endfor
|
||||
|
||||
let newObj._rawLoclist = llist
|
||||
let newObj._name = ''
|
||||
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.current()
|
||||
if !exists("b:syntastic_loclist")
|
||||
let b:syntastic_loclist = g:SyntasticLoclist.New([])
|
||||
endif
|
||||
return b:syntastic_loclist
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.extend(other)
|
||||
let list = self.copyRaw()
|
||||
call extend(list, a:other.copyRaw())
|
||||
return g:SyntasticLoclist.New(list)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.isEmpty()
|
||||
return empty(self._rawLoclist)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.copyRaw()
|
||||
return copy(self._rawLoclist)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.getRaw()
|
||||
return self._rawLoclist
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.getStatuslineFlag()
|
||||
if !exists("self._stl_format")
|
||||
let self._stl_format = ''
|
||||
endif
|
||||
if !exists("self._stl_flag")
|
||||
let self._stl_flag = ''
|
||||
endif
|
||||
|
||||
if g:syntastic_stl_format !=# self._stl_format
|
||||
let self._stl_format = g:syntastic_stl_format
|
||||
|
||||
if !empty(self._rawLoclist)
|
||||
let errors = self.errors()
|
||||
let warnings = self.warnings()
|
||||
|
||||
let num_errors = len(errors)
|
||||
let num_warnings = len(warnings)
|
||||
let num_issues = len(self._rawLoclist)
|
||||
|
||||
let output = self._stl_format
|
||||
|
||||
"hide stuff wrapped in %E(...) unless there are errors
|
||||
let output = substitute(output, '\m\C%E{\([^}]*\)}', num_errors ? '\1' : '' , 'g')
|
||||
|
||||
"hide stuff wrapped in %W(...) unless there are warnings
|
||||
let output = substitute(output, '\m\C%W{\([^}]*\)}', num_warnings ? '\1' : '' , 'g')
|
||||
|
||||
"hide stuff wrapped in %B(...) unless there are both errors and warnings
|
||||
let output = substitute(output, '\m\C%B{\([^}]*\)}', (num_warnings && num_errors) ? '\1' : '' , 'g')
|
||||
|
||||
"sub in the total errors/warnings/both
|
||||
let output = substitute(output, '\m\C%w', num_warnings, 'g')
|
||||
let output = substitute(output, '\m\C%e', num_errors, 'g')
|
||||
let output = substitute(output, '\m\C%t', num_issues, 'g')
|
||||
|
||||
"first error/warning line num
|
||||
let output = substitute(output, '\m\C%F', num_issues ? self._rawLoclist[0]['lnum'] : '', 'g')
|
||||
|
||||
"first error line num
|
||||
let output = substitute(output, '\m\C%fe', num_errors ? errors[0]['lnum'] : '', 'g')
|
||||
|
||||
"first warning line num
|
||||
let output = substitute(output, '\m\C%fw', num_warnings ? warnings[0]['lnum'] : '', 'g')
|
||||
|
||||
let self._stl_flag = output
|
||||
else
|
||||
let self._stl_flag = ''
|
||||
endif
|
||||
endif
|
||||
|
||||
return self._stl_flag
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.getFirstIssue()
|
||||
return get(self._rawLoclist, 0, {})
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.getName()
|
||||
return len(self._name)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.setName(name)
|
||||
let self._name = a:name
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.decorate(name, filetype)
|
||||
for e in self._rawLoclist
|
||||
let e['text'] .= ' [' . a:filetype . '/' . a:name . ']'
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.quietMessages(filters)
|
||||
call syntastic#util#dictFilter(self._rawLoclist, a:filters)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.errors()
|
||||
if !exists("self._cachedErrors")
|
||||
let self._cachedErrors = self.filter({'type': "E"})
|
||||
endif
|
||||
return self._cachedErrors
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.warnings()
|
||||
if !exists("self._cachedWarnings")
|
||||
let self._cachedWarnings = self.filter({'type': "W"})
|
||||
endif
|
||||
return self._cachedWarnings
|
||||
endfunction
|
||||
|
||||
" Legacy function. Syntastic no longer calls it, but we keep it
|
||||
" around because other plugins (f.i. powerline) depend on it.
|
||||
function! g:SyntasticLoclist.hasErrorsOrWarningsToDisplay()
|
||||
return !self.isEmpty()
|
||||
endfunction
|
||||
|
||||
" cache used by EchoCurrentError()
|
||||
function! g:SyntasticLoclist.messages(buf)
|
||||
if !exists("self._cachedMessages")
|
||||
let self._cachedMessages = {}
|
||||
let errors = self.errors() + self.warnings()
|
||||
|
||||
for e in errors
|
||||
let b = e['bufnr']
|
||||
let l = e['lnum']
|
||||
|
||||
if !has_key(self._cachedMessages, b)
|
||||
let self._cachedMessages[b] = {}
|
||||
endif
|
||||
|
||||
if !has_key(self._cachedMessages[b], l)
|
||||
let self._cachedMessages[b][l] = e['text']
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
return get(self._cachedMessages, a:buf, {})
|
||||
endfunction
|
||||
|
||||
"Filter the list and return new native loclist
|
||||
"e.g.
|
||||
" .filter({'bufnr': 10, 'type': 'e'})
|
||||
"
|
||||
"would return all errors for buffer 10.
|
||||
"
|
||||
"Note that all comparisons are done with ==?
|
||||
function! g:SyntasticLoclist.filter(filters)
|
||||
let conditions = values(map(copy(a:filters), 's:translate(v:key, v:val)'))
|
||||
let filter = len(conditions) == 1 ?
|
||||
\ conditions[0] : join(map(conditions, '"(" . v:val . ")"'), ' && ')
|
||||
return filter(copy(self._rawLoclist), filter)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticLoclist.setloclist()
|
||||
if !exists('w:syntastic_loclist_set')
|
||||
let w:syntastic_loclist_set = 0
|
||||
endif
|
||||
let replace = g:syntastic_reuse_loc_lists && w:syntastic_loclist_set
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'loclist: setloclist ' . (replace ? '(replace)' : '(new)'))
|
||||
call setloclist(0, self.getRaw(), replace ? 'r' : ' ')
|
||||
let w:syntastic_loclist_set = 1
|
||||
endfunction
|
||||
|
||||
"display the cached errors for this buf in the location list
|
||||
function! g:SyntasticLoclist.show()
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'loclist: show')
|
||||
call self.setloclist()
|
||||
|
||||
if !self.isEmpty()
|
||||
let num = winnr()
|
||||
execute "lopen " . g:syntastic_loc_list_height
|
||||
if num != winnr()
|
||||
wincmd p
|
||||
endif
|
||||
|
||||
" try to find the loclist window and set w:quickfix_title
|
||||
let errors = getloclist(0)
|
||||
for buf in tabpagebuflist()
|
||||
if buflisted(buf) && bufloaded(buf) && getbufvar(buf, '&buftype') ==# 'quickfix'
|
||||
let win = bufwinnr(buf)
|
||||
let title = getwinvar(win, 'quickfix_title')
|
||||
|
||||
" TODO: try to make sure we actually own this window; sadly,
|
||||
" errors == getloclist(0) is the only somewhat safe way to
|
||||
" achieve that
|
||||
if strpart(title, 0, 16) ==# ':SyntasticCheck ' ||
|
||||
\ ( (title == '' || title ==# ':setloclist()') && errors == getloclist(0) )
|
||||
call setwinvar(win, 'quickfix_title', ':SyntasticCheck ' . self._name)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Non-method functions {{{1
|
||||
|
||||
function! g:SyntasticLoclistHide()
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'loclist: hide')
|
||||
silent! lclose
|
||||
endfunction
|
||||
|
||||
" Private functions {{{1
|
||||
|
||||
function! s:translate(key, val)
|
||||
return 'get(v:val, ' . string(a:key) . ', "") ==? ' . string(a:val)
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
75
sources_non_forked/syntastic/plugin/syntastic/modemap.vim
Normal file
75
sources_non_forked/syntastic/plugin/syntastic/modemap.vim
Normal file
@ -0,0 +1,75 @@
|
||||
if exists("g:loaded_syntastic_modemap")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_modemap = 1
|
||||
|
||||
let g:SyntasticModeMap = {}
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticModeMap.Instance()
|
||||
if !exists('s:SyntasticModeMapInstance')
|
||||
let s:SyntasticModeMapInstance = copy(self)
|
||||
call s:SyntasticModeMapInstance.synch()
|
||||
endif
|
||||
|
||||
return s:SyntasticModeMapInstance
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticModeMap.synch()
|
||||
if exists('g:syntastic_mode_map')
|
||||
let self._mode = get(g:syntastic_mode_map, 'mode', 'active')
|
||||
let self._activeFiletypes = get(g:syntastic_mode_map, 'active_filetypes', [])
|
||||
let self._passiveFiletypes = get(g:syntastic_mode_map, 'passive_filetypes', [])
|
||||
else
|
||||
let self._mode = 'active'
|
||||
let self._activeFiletypes = []
|
||||
let self._passiveFiletypes = []
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticModeMap.allowsAutoChecking(filetype)
|
||||
let fts = split(a:filetype, '\m\.')
|
||||
|
||||
if self.isPassive()
|
||||
return self._isOneFiletypeActive(fts)
|
||||
else
|
||||
return self._noFiletypesArePassive(fts)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticModeMap.isPassive()
|
||||
return self._mode ==# 'passive'
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticModeMap.toggleMode()
|
||||
call self.synch()
|
||||
|
||||
if self._mode ==# 'active'
|
||||
let self._mode = 'passive'
|
||||
else
|
||||
let self._mode = 'active'
|
||||
endif
|
||||
|
||||
"XXX Changing a global variable. Tsk, tsk...
|
||||
if !exists('g:syntastic_mode_map')
|
||||
let g:syntastic_mode_map = {}
|
||||
endif
|
||||
let g:syntastic_mode_map['mode'] = self._mode
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticModeMap.echoMode()
|
||||
echo "Syntastic: " . self._mode . " mode enabled"
|
||||
endfunction
|
||||
|
||||
" Private methods {{{1
|
||||
|
||||
function! g:SyntasticModeMap._isOneFiletypeActive(filetypes)
|
||||
return !empty(filter(copy(a:filetypes), 'index(self._activeFiletypes, v:val) != -1'))
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticModeMap._noFiletypesArePassive(filetypes)
|
||||
return empty(filter(copy(a:filetypes), 'index(self._passiveFiletypes, v:val) != -1'))
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
57
sources_non_forked/syntastic/plugin/syntastic/notifiers.vim
Normal file
57
sources_non_forked/syntastic/plugin/syntastic/notifiers.vim
Normal file
@ -0,0 +1,57 @@
|
||||
if exists("g:loaded_syntastic_notifiers")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_notifiers = 1
|
||||
|
||||
let g:SyntasticNotifiers = {}
|
||||
|
||||
let s:notifier_types = ['signs', 'balloons', 'highlighting', 'cursor', 'autoloclist']
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticNotifiers.Instance()
|
||||
if !exists('s:SyntasticNotifiersInstance')
|
||||
let s:SyntasticNotifiersInstance = copy(self)
|
||||
call s:SyntasticNotifiersInstance._initNotifiers()
|
||||
endif
|
||||
|
||||
return s:SyntasticNotifiersInstance
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticNotifiers.refresh(loclist)
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'notifiers: refresh')
|
||||
for type in self._enabled_types
|
||||
let class = substitute(type, '\m.*', 'Syntastic\u&Notifier', '')
|
||||
if !has_key(g:{class}, 'enabled') || self._notifier[type].enabled()
|
||||
call self._notifier[type].refresh(a:loclist)
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticNotifiers.reset(loclist)
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'notifiers: reset')
|
||||
for type in self._enabled_types
|
||||
let class = substitute(type, '\m.*', 'Syntastic\u&Notifier', '')
|
||||
|
||||
" reset notifiers regardless if they are enabled or not, since
|
||||
" the user might have disabled them since the last refresh();
|
||||
" notifiers MUST be prepared to deal with reset() when disabled
|
||||
if has_key(g:{class}, 'reset')
|
||||
call self._notifier[type].reset(a:loclist)
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" Private methods {{{1
|
||||
|
||||
function! g:SyntasticNotifiers._initNotifiers()
|
||||
let self._notifier = {}
|
||||
for type in s:notifier_types
|
||||
let class = substitute(type, '\m.*', 'Syntastic\u&Notifier', '')
|
||||
let self._notifier[type] = g:{class}.New()
|
||||
endfor
|
||||
|
||||
let self._enabled_types = copy(s:notifier_types)
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
282
sources_non_forked/syntastic/plugin/syntastic/registry.vim
Normal file
282
sources_non_forked/syntastic/plugin/syntastic/registry.vim
Normal file
@ -0,0 +1,282 @@
|
||||
if exists("g:loaded_syntastic_registry")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_registry = 1
|
||||
|
||||
let s:defaultCheckers = {
|
||||
\ 'actionscript':['mxmlc'],
|
||||
\ 'ada': ['gcc'],
|
||||
\ 'applescript': ['osacompile'],
|
||||
\ 'asciidoc': ['asciidoc'],
|
||||
\ 'asm': ['gcc'],
|
||||
\ 'bemhtml': ['bemhtmllint'],
|
||||
\ 'c': ['gcc'],
|
||||
\ 'chef': ['foodcritic'],
|
||||
\ 'co': ['coco'],
|
||||
\ 'cobol': ['cobc'],
|
||||
\ 'coffee': ['coffee', 'coffeelint'],
|
||||
\ 'coq': ['coqtop'],
|
||||
\ 'cpp': ['gcc'],
|
||||
\ 'cs': ['mcs'],
|
||||
\ 'css': ['csslint', 'phpcs'],
|
||||
\ 'cucumber': ['cucumber'],
|
||||
\ 'cuda': ['nvcc'],
|
||||
\ 'd': ['dmd'],
|
||||
\ 'dart': ['dartanalyzer'],
|
||||
\ 'docbk': ['xmllint'],
|
||||
\ 'dustjs': ['swiffer'],
|
||||
\ 'elixir': ['elixir'],
|
||||
\ 'erlang': ['escript'],
|
||||
\ 'eruby': ['ruby'],
|
||||
\ 'fortran': ['gfortran'],
|
||||
\ 'glsl': ['cgc'],
|
||||
\ 'go': ['go'],
|
||||
\ 'haml': ['haml'],
|
||||
\ 'handlebars': ['handlebars'],
|
||||
\ 'haskell': ['ghc_mod', 'hdevtools', 'hlint'],
|
||||
\ 'haxe': ['haxe'],
|
||||
\ 'hss': ['hss'],
|
||||
\ 'html': ['tidy'],
|
||||
\ 'java': ['javac'],
|
||||
\ 'javascript': ['jshint', 'jslint'],
|
||||
\ 'json': ['jsonlint', 'jsonval'],
|
||||
\ 'less': ['lessc'],
|
||||
\ 'lex': ['flex'],
|
||||
\ 'limbo': ['limbo'],
|
||||
\ 'lisp': ['clisp'],
|
||||
\ 'llvm': ['llvm'],
|
||||
\ 'lua': ['luac'],
|
||||
\ 'matlab': ['mlint'],
|
||||
\ 'nasm': ['nasm'],
|
||||
\ 'nroff': ['mandoc'],
|
||||
\ 'objc': ['gcc'],
|
||||
\ 'objcpp': ['gcc'],
|
||||
\ 'ocaml': ['camlp4o'],
|
||||
\ 'perl': ['perl', 'perlcritic'],
|
||||
\ 'php': ['php', 'phpcs', 'phpmd'],
|
||||
\ 'po': ['msgfmt'],
|
||||
\ 'pod': ['podchecker'],
|
||||
\ 'puppet': ['puppet', 'puppetlint'],
|
||||
\ 'python': ['python', 'flake8', 'pylint'],
|
||||
\ 'racket': ['racket'],
|
||||
\ 'rst': ['rst2pseudoxml'],
|
||||
\ 'ruby': ['mri'],
|
||||
\ 'rust': ['rustc'],
|
||||
\ 'sass': ['sass'],
|
||||
\ 'scala': ['fsc', 'scalac'],
|
||||
\ 'scss': ['sass', 'scss_lint'],
|
||||
\ 'sh': ['sh', 'shellcheck'],
|
||||
\ 'slim': ['slimrb'],
|
||||
\ 'tcl': ['nagelfar'],
|
||||
\ 'tex': ['lacheck', 'chktex'],
|
||||
\ 'texinfo': ['makeinfo'],
|
||||
\ 'text': ['atdtool'],
|
||||
\ 'twig': ['twiglint'],
|
||||
\ 'typescript': ['tsc'],
|
||||
\ 'vala': ['valac'],
|
||||
\ 'verilog': ['verilator'],
|
||||
\ 'vhdl': ['ghdl'],
|
||||
\ 'vim': ['vimlint'],
|
||||
\ 'xhtml': ['tidy'],
|
||||
\ 'xml': ['xmllint'],
|
||||
\ 'xslt': ['xmllint'],
|
||||
\ 'yacc': ['bison'],
|
||||
\ 'yaml': ['jsyaml'],
|
||||
\ 'z80': ['z80syntaxchecker'],
|
||||
\ 'zpt': ['zptlint'],
|
||||
\ 'zsh': ['zsh', 'shellcheck']
|
||||
\ }
|
||||
|
||||
let s:defaultFiletypeMap = {
|
||||
\ 'gentoo-metadata': 'xml',
|
||||
\ 'lhaskell': 'haskell',
|
||||
\ 'litcoffee': 'coffee'
|
||||
\ }
|
||||
|
||||
let g:SyntasticRegistry = {}
|
||||
|
||||
" TODO: Handling of filetype aliases: all public methods take aliases as
|
||||
" parameters, all private methods take normalized filetypes. Public methods
|
||||
" are thus supposed to normalize filetypes before calling private methods.
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticRegistry.Instance()
|
||||
if !exists('s:SyntasticRegistryInstance')
|
||||
let s:SyntasticRegistryInstance = copy(self)
|
||||
let s:SyntasticRegistryInstance._checkerMap = {}
|
||||
let s:SyntasticRegistryInstance._cachedCheckersFor = {}
|
||||
endif
|
||||
|
||||
return s:SyntasticRegistryInstance
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.CreateAndRegisterChecker(args)
|
||||
let checker = g:SyntasticChecker.New(a:args)
|
||||
let registry = g:SyntasticRegistry.Instance()
|
||||
call registry._registerChecker(checker)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.checkable(ftalias)
|
||||
return !empty(self.getActiveCheckers(a:ftalias))
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.getActiveCheckers(ftalias)
|
||||
let filetype = s:SyntasticRegistryNormaliseFiletype(a:ftalias)
|
||||
let checkers = self.availableCheckersFor(a:ftalias)
|
||||
|
||||
if self._userHasFiletypeSettings(filetype)
|
||||
return self._filterCheckersByUserSettings(checkers, filetype)
|
||||
endif
|
||||
|
||||
if has_key(s:defaultCheckers, filetype)
|
||||
return self._filterCheckersByDefaultSettings(checkers, filetype)
|
||||
endif
|
||||
|
||||
return checkers[0:0]
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.getCheckers(ftalias, list)
|
||||
return self._filterCheckersByName(self.availableCheckersFor(a:ftalias), a:list)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.availableCheckersFor(ftalias)
|
||||
if !has_key(self._cachedCheckersFor, a:ftalias)
|
||||
let filetype = s:SyntasticRegistryNormaliseFiletype(a:ftalias)
|
||||
let checkers = self._allCheckersFor(filetype)
|
||||
let self._cachedCheckersFor[a:ftalias] = self._filterCheckersByAvailability(checkers)
|
||||
endif
|
||||
|
||||
return self._cachedCheckersFor[a:ftalias]
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.knownFiletypes()
|
||||
let types = keys(s:defaultCheckers)
|
||||
call extend(types, keys(s:defaultFiletypeMap))
|
||||
if exists('g:syntastic_filetype_map')
|
||||
call extend(types, keys(g:syntastic_filetype_map))
|
||||
endif
|
||||
if exists('g:syntastic_extra_filetypes') && type(g:syntastic_extra_filetypes) == type([])
|
||||
call extend(types, g:syntastic_extra_filetypes)
|
||||
endif
|
||||
return syntastic#util#unique(types)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry.echoInfoFor(ftalias_list)
|
||||
echomsg "Syntastic info for filetype: " . join(a:ftalias_list, '.')
|
||||
|
||||
let available = []
|
||||
let active = []
|
||||
for ftalias in a:ftalias_list
|
||||
call extend(available, self.availableCheckersFor(ftalias))
|
||||
call extend(active, self.getActiveCheckers(ftalias))
|
||||
endfor
|
||||
|
||||
echomsg "Available checker(s): " . join(syntastic#util#unique(map(available, "v:val.getName()")))
|
||||
echomsg "Currently enabled checker(s): " . join(syntastic#util#unique(map(active, "v:val.getName()")))
|
||||
endfunction
|
||||
|
||||
" Private methods {{{1
|
||||
|
||||
function! g:SyntasticRegistry._registerChecker(checker) abort
|
||||
let ft = a:checker.getFiletype()
|
||||
|
||||
if !has_key(self._checkerMap, ft)
|
||||
let self._checkerMap[ft] = []
|
||||
endif
|
||||
|
||||
call self._validateUniqueName(a:checker)
|
||||
|
||||
call add(self._checkerMap[ft], a:checker)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry._allCheckersFor(filetype)
|
||||
call self._loadCheckers(a:filetype)
|
||||
if empty(self._checkerMap[a:filetype])
|
||||
return []
|
||||
endif
|
||||
|
||||
return self._checkerMap[a:filetype]
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry._filterCheckersByDefaultSettings(checkers, filetype)
|
||||
if has_key(s:defaultCheckers, a:filetype)
|
||||
return self._filterCheckersByName(a:checkers, s:defaultCheckers[a:filetype])
|
||||
endif
|
||||
|
||||
return a:checkers
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry._filterCheckersByUserSettings(checkers, filetype)
|
||||
if exists("b:syntastic_checkers")
|
||||
let whitelist = b:syntastic_checkers
|
||||
else
|
||||
let whitelist = g:syntastic_{a:filetype}_checkers
|
||||
endif
|
||||
return self._filterCheckersByName(a:checkers, whitelist)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry._filterCheckersByName(checkers, list)
|
||||
let checkers_by_name = {}
|
||||
for c in a:checkers
|
||||
let checkers_by_name[c.getName()] = c
|
||||
endfor
|
||||
|
||||
let filtered = []
|
||||
for name in a:list
|
||||
if has_key(checkers_by_name, name)
|
||||
call add(filtered, checkers_by_name[name])
|
||||
endif
|
||||
endfor
|
||||
|
||||
return filtered
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry._filterCheckersByAvailability(checkers)
|
||||
return filter(copy(a:checkers), "v:val.isAvailable()")
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry._loadCheckers(filetype)
|
||||
if self._haveLoadedCheckers(a:filetype)
|
||||
return
|
||||
endif
|
||||
|
||||
execute "runtime! syntax_checkers/" . a:filetype . "/*.vim"
|
||||
|
||||
if !has_key(self._checkerMap, a:filetype)
|
||||
let self._checkerMap[a:filetype] = []
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry._haveLoadedCheckers(filetype)
|
||||
return has_key(self._checkerMap, a:filetype)
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry._userHasFiletypeSettings(filetype)
|
||||
if exists("g:syntastic_" . a:filetype . "_checker") && !exists("g:syntastic_" . a:filetype . "_checkers")
|
||||
let g:syntastic_{a:filetype}_checkers = [g:syntastic_{a:filetype}_checker]
|
||||
call syntastic#log#deprecationWarn("variable g:syntastic_" . a:filetype . "_checker is deprecated")
|
||||
endif
|
||||
return exists("b:syntastic_checkers") || exists("g:syntastic_" . a:filetype . "_checkers")
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticRegistry._validateUniqueName(checker) abort
|
||||
for checker in self._allCheckersFor(a:checker.getFiletype())
|
||||
if checker.getName() ==# a:checker.getName()
|
||||
throw "Syntastic: Duplicate syntax checker name for: " . a:checker.getName()
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" Private functions {{{1
|
||||
|
||||
"resolve filetype aliases, and replace - with _ otherwise we cant name
|
||||
"syntax checker functions legally for filetypes like "gentoo-metadata"
|
||||
function! s:SyntasticRegistryNormaliseFiletype(ftalias)
|
||||
let ft = get(s:defaultFiletypeMap, a:ftalias, a:ftalias)
|
||||
let ft = get(g:syntastic_filetype_map, ft, ft)
|
||||
let ft = substitute(ft, '\m-', '_', 'g')
|
||||
return ft
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
148
sources_non_forked/syntastic/plugin/syntastic/signs.vim
Normal file
148
sources_non_forked/syntastic/plugin/syntastic/signs.vim
Normal file
@ -0,0 +1,148 @@
|
||||
if exists("g:loaded_syntastic_notifier_signs")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_syntastic_notifier_signs = 1
|
||||
|
||||
if !exists("g:syntastic_enable_signs")
|
||||
let g:syntastic_enable_signs = 1
|
||||
endif
|
||||
|
||||
if !exists("g:syntastic_error_symbol")
|
||||
let g:syntastic_error_symbol = '>>'
|
||||
endif
|
||||
|
||||
if !exists("g:syntastic_warning_symbol")
|
||||
let g:syntastic_warning_symbol = '>>'
|
||||
endif
|
||||
|
||||
if !exists("g:syntastic_style_error_symbol")
|
||||
let g:syntastic_style_error_symbol = 'S>'
|
||||
endif
|
||||
|
||||
if !exists("g:syntastic_style_warning_symbol")
|
||||
let g:syntastic_style_warning_symbol = 'S>'
|
||||
endif
|
||||
|
||||
|
||||
" start counting sign ids at 5000, start here to hopefully avoid conflicting
|
||||
" with any other code that places signs (not sure if this precaution is
|
||||
" actually needed)
|
||||
let s:first_sign_id = 5000
|
||||
let s:next_sign_id = s:first_sign_id
|
||||
|
||||
let g:SyntasticSignsNotifier = {}
|
||||
|
||||
let s:setup_done = 0
|
||||
|
||||
" Public methods {{{1
|
||||
|
||||
function! g:SyntasticSignsNotifier.New()
|
||||
let newObj = copy(self)
|
||||
|
||||
if !s:setup_done
|
||||
call self._setup()
|
||||
let s:setup_done = 1
|
||||
endif
|
||||
|
||||
return newObj
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticSignsNotifier.enabled()
|
||||
return
|
||||
\ has('signs') &&
|
||||
\ exists('b:syntastic_enable_signs') ? b:syntastic_enable_signs : g:syntastic_enable_signs
|
||||
endfunction
|
||||
|
||||
function! g:SyntasticSignsNotifier.refresh(loclist)
|
||||
call syntastic#log#debug(g:SyntasticDebugNotifications, 'signs: refresh')
|
||||
let old_signs = copy(self._bufSignIds())
|
||||
if self.enabled()
|
||||
call self._signErrors(a:loclist)
|
||||
endif
|
||||
call self._removeSigns(old_signs)
|
||||
let s:first_sign_id = s:next_sign_id
|
||||
endfunction
|
||||
|
||||
" Private methods {{{1
|
||||
|
||||
" One time setup: define our own sign types and highlighting
|
||||
function! g:SyntasticSignsNotifier._setup()
|
||||
if has('signs')
|
||||
if !hlexists('SyntasticErrorSign')
|
||||
highlight link SyntasticErrorSign error
|
||||
endif
|
||||
if !hlexists('SyntasticWarningSign')
|
||||
highlight link SyntasticWarningSign todo
|
||||
endif
|
||||
if !hlexists('SyntasticStyleErrorSign')
|
||||
highlight link SyntasticStyleErrorSign SyntasticErrorSign
|
||||
endif
|
||||
if !hlexists('SyntasticStyleWarningSign')
|
||||
highlight link SyntasticStyleWarningSign SyntasticWarningSign
|
||||
endif
|
||||
if !hlexists('SyntasticStyleErrorLine')
|
||||
highlight link SyntasticStyleErrorLine SyntasticErrorLine
|
||||
endif
|
||||
if !hlexists('SyntasticStyleWarningLine')
|
||||
highlight link SyntasticStyleWarningLine SyntasticWarningLine
|
||||
endif
|
||||
|
||||
" define the signs used to display syntax and style errors/warns
|
||||
exe 'sign define SyntasticError text=' . g:syntastic_error_symbol .
|
||||
\ ' texthl=SyntasticErrorSign linehl=SyntasticErrorLine'
|
||||
exe 'sign define SyntasticWarning text=' . g:syntastic_warning_symbol .
|
||||
\ ' texthl=SyntasticWarningSign linehl=SyntasticWarningLine'
|
||||
exe 'sign define SyntasticStyleError text=' . g:syntastic_style_error_symbol .
|
||||
\ ' texthl=SyntasticStyleErrorSign linehl=SyntasticStyleErrorLine'
|
||||
exe 'sign define SyntasticStyleWarning text=' . g:syntastic_style_warning_symbol .
|
||||
\ ' texthl=SyntasticStyleWarningSign linehl=SyntasticStyleWarningLine'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Place signs by all syntax errors in the buffer
|
||||
function! g:SyntasticSignsNotifier._signErrors(loclist)
|
||||
let loclist = a:loclist
|
||||
if !loclist.isEmpty()
|
||||
|
||||
" errors some first, so that they are not masked by warnings
|
||||
let buf = bufnr('')
|
||||
let issues = copy(loclist.errors())
|
||||
call extend(issues, loclist.warnings())
|
||||
call filter(issues, 'v:val["bufnr"] == buf')
|
||||
let seen = {}
|
||||
|
||||
for i in issues
|
||||
if !has_key(seen, i['lnum'])
|
||||
let seen[i['lnum']] = 1
|
||||
|
||||
let sign_severity = i['type'] ==? 'W' ? 'Warning' : 'Error'
|
||||
let sign_subtype = get(i, 'subtype', '')
|
||||
let sign_type = 'Syntastic' . sign_subtype . sign_severity
|
||||
|
||||
execute "sign place " . s:next_sign_id . " line=" . i['lnum'] . " name=" . sign_type . " buffer=" . i['bufnr']
|
||||
call add(self._bufSignIds(), s:next_sign_id)
|
||||
let s:next_sign_id += 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Remove the signs with the given ids from this buffer
|
||||
function! g:SyntasticSignsNotifier._removeSigns(ids)
|
||||
if has('signs')
|
||||
for i in a:ids
|
||||
execute "sign unplace " . i
|
||||
call remove(self._bufSignIds(), index(self._bufSignIds(), i))
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Get all the ids of the SyntaxError signs in the buffer
|
||||
function! g:SyntasticSignsNotifier._bufSignIds()
|
||||
if !exists("b:syntastic_sign_ids")
|
||||
let b:syntastic_sign_ids = []
|
||||
endif
|
||||
return b:syntastic_sign_ids
|
||||
endfunction
|
||||
|
||||
" vim: set sw=4 sts=4 et fdm=marker:
|
Reference in New Issue
Block a user