summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/definition.vim4
-rw-r--r--autoload/ale/engine.vim16
-rw-r--r--autoload/ale/fix.vim4
-rw-r--r--autoload/ale/fix/registry.vim16
-rw-r--r--autoload/ale/fixers/elm_format.vim (renamed from autoload/ale/fixers/format.vim)6
-rw-r--r--autoload/ale/fixers/mix_format.vim15
-rw-r--r--autoload/ale/fixers/rufo.vim20
-rw-r--r--autoload/ale/handlers/flawfinder.vim47
-rw-r--r--autoload/ale/handlers/gawk.vim25
-rw-r--r--autoload/ale/handlers/gcc.vim2
-rw-r--r--autoload/ale/handlers/go.vim25
-rw-r--r--autoload/ale/handlers/redpen.vim24
-rw-r--r--autoload/ale/handlers/textlint.vim19
-rw-r--r--autoload/ale/lsp.vim14
-rw-r--r--autoload/ale/lsp/reset.vim25
-rw-r--r--autoload/ale/path.vim4
16 files changed, 245 insertions, 21 deletions
diff --git a/autoload/ale/definition.vim b/autoload/ale/definition.vim
index b20c01a0..521cd0b1 100644
--- a/autoload/ale/definition.vim
+++ b/autoload/ale/definition.vim
@@ -19,6 +19,10 @@ function! ale#definition#Execute(expr) abort
execute a:expr
endfunction
+function! ale#definition#ClearLSPData() abort
+ let s:go_to_definition_map = {}
+endfunction
+
function! ale#definition#Open(options, filename, line, column) abort
if a:options.open_in_tab
call ale#definition#Execute('tabedit ' . fnameescape(a:filename))
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index 6ccc3a34..dd871c36 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -76,6 +76,11 @@ function! ale#engine#InitBufferInfo(buffer) abort
return 0
endfunction
+" Clear LSP linter data for the linting engine.
+function! ale#engine#ClearLSPData() abort
+ let s:lsp_linter_map = {}
+endfunction
+
" This function is documented and part of the public API.
"
" Return 1 if ALE is busy checking a given buffer
@@ -144,7 +149,7 @@ function! s:GatherOutput(job_id, line) abort
endif
endfunction
-function! s:HandleLoclist(linter_name, buffer, loclist) abort
+function! ale#engine#HandleLoclist(linter_name, buffer, loclist) abort
let l:info = get(g:ale_buffer_info, a:buffer, {})
if empty(l:info)
@@ -223,7 +228,7 @@ function! s:HandleExit(job_id, exit_code) abort
let l:loclist = ale#util#GetFunction(l:linter.callback)(l:buffer, l:output)
- call s:HandleLoclist(l:linter.name, l:buffer, l:loclist)
+ call ale#engine#HandleLoclist(l:linter.name, l:buffer, l:loclist)
endfunction
function! s:HandleLSPDiagnostics(conn_id, response) abort
@@ -237,7 +242,7 @@ function! s:HandleLSPDiagnostics(conn_id, response) abort
let l:loclist = ale#lsp#response#ReadDiagnostics(a:response)
- call s:HandleLoclist(l:linter_name, l:buffer, l:loclist)
+ call ale#engine#HandleLoclist(l:linter_name, l:buffer, l:loclist)
endfunction
function! s:HandleTSServerDiagnostics(response, error_type) abort
@@ -262,7 +267,7 @@ function! s:HandleTSServerDiagnostics(response, error_type) abort
let l:loclist = get(l:info, 'semantic_loclist', [])
\ + get(l:info, 'syntax_loclist', [])
- call s:HandleLoclist('tsserver', l:buffer, l:loclist)
+ call ale#engine#HandleLoclist('tsserver', l:buffer, l:loclist)
endfunction
function! s:HandleLSPErrorMessage(error_message) abort
@@ -361,9 +366,6 @@ function! s:RemapItemTypes(type_map, loclist) abort
endfor
endfunction
-" Save the temporary directory so we can figure out if files are in it.
-let s:temp_dir = fnamemodify(tempname(), ':h')
-
function! ale#engine#FixLocList(buffer, linter_name, loclist) abort
let l:bufnr_map = {}
let l:new_loclist = []
diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim
index 9111db3d..398f57d0 100644
--- a/autoload/ale/fix.vim
+++ b/autoload/ale/fix.vim
@@ -54,6 +54,8 @@ function! ale#fix#ApplyQueuedFixes() abort
let l:should_lint = l:data.changes_made
endif
+ silent doautocmd <nomodeline> User ALEFixPost
+
" If ALE linting is enabled, check for problems with the file again after
" fixing problems.
if g:ale_enabled
@@ -463,6 +465,8 @@ function! ale#fix#Fix(...) abort
call ale#fix#RemoveManagedFiles(l:buffer)
call ale#fix#InitBufferData(l:buffer, l:fixing_flag)
+ silent doautocmd <nomodeline> User ALEFixPre
+
call s:RunFixer({
\ 'buffer': l:buffer,
\ 'input': g:ale_fix_buffer_data[l:buffer].lines_before,
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 3e407c52..4c0703a5 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -23,6 +23,12 @@ let s:default_registry = {
\ 'description': 'Apply prettier-standard to a file.',
\ 'aliases': ['prettier-standard'],
\ },
+\ 'elm-format': {
+\ 'function': 'ale#fixers#elm_format#Fix',
+\ 'suggested_filetypes': ['elm'],
+\ 'description': 'Apply elm-format to a file.',
+\ 'aliases': ['format'],
+\ },
\ 'eslint': {
\ 'function': 'ale#fixers#eslint#Fix',
\ 'suggested_filetypes': ['javascript', 'typescript'],
@@ -33,11 +39,6 @@ let s:default_registry = {
\ 'suggested_filetypes': ['elixir'],
\ 'description': 'Apply mix format to a file.',
\ },
-\ 'format': {
-\ 'function': 'ale#fixers#format#Fix',
-\ 'suggested_filetypes': ['elm'],
-\ 'description': 'Apply elm-format to a file.',
-\ },
\ 'isort': {
\ 'function': 'ale#fixers#isort#Fix',
\ 'suggested_filetypes': ['python'],
@@ -84,6 +85,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['ruby'],
\ 'description': 'Fix ruby files with rubocop --auto-correct.',
\ },
+\ 'rufo': {
+\ 'function': 'ale#fixers#rufo#Fix',
+\ 'suggested_filetypes': ['ruby'],
+\ 'description': 'Fix ruby files with rufo',
+\ },
\ 'standard': {
\ 'function': 'ale#fixers#standard#Fix',
\ 'suggested_filetypes': ['javascript'],
diff --git a/autoload/ale/fixers/format.vim b/autoload/ale/fixers/elm_format.vim
index be130f00..b2119d2c 100644
--- a/autoload/ale/fixers/format.vim
+++ b/autoload/ale/fixers/elm_format.vim
@@ -5,17 +5,17 @@ call ale#Set('elm_format_executable', 'elm-format')
call ale#Set('elm_format_use_global', 0)
call ale#Set('elm_format_options', '--yes')
-function! ale#fixers#format#GetExecutable(buffer) abort
+function! ale#fixers#elm_format#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'elm_format', [
\ 'node_modules/.bin/elm-format',
\])
endfunction
-function! ale#fixers#format#Fix(buffer) abort
+function! ale#fixers#elm_format#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'elm_format_options')
return {
- \ 'command': ale#Escape(ale#fixers#format#GetExecutable(a:buffer))
+ \ 'command': ale#Escape(ale#fixers#elm_format#GetExecutable(a:buffer))
\ . ' %t'
\ . (empty(l:options) ? '' : ' ' . l:options),
\ 'read_temporary_file': 1,
diff --git a/autoload/ale/fixers/mix_format.vim b/autoload/ale/fixers/mix_format.vim
index 04866408..7a091701 100644
--- a/autoload/ale/fixers/mix_format.vim
+++ b/autoload/ale/fixers/mix_format.vim
@@ -1,16 +1,25 @@
-" Author: carakan <carakan@gmail.com>
+" Author: carakan <carakan@gmail.com>, Fernando Mendes <fernando@mendes.codes>
" Description: Fixing files with elixir formatter 'mix format'.
call ale#Set('elixir_mix_executable', 'mix')
+call ale#Set('elixir_mix_format_options', '')
function! ale#fixers#mix_format#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'elixir_mix_executable')
endfunction
+function! ale#fixers#mix_format#GetCommand(buffer) abort
+ let l:executable = ale#Escape(ale#fixers#mix_format#GetExecutable(a:buffer))
+ let l:options = ale#Var(a:buffer, 'elixir_mix_format_options')
+
+ return l:executable . ' format'
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+ \ . ' %t'
+endfunction
+
function! ale#fixers#mix_format#Fix(buffer) abort
return {
- \ 'command': ale#Escape(ale#fixers#mix_format#GetExecutable(a:buffer))
- \ . ' format %t',
+ \ 'command': ale#fixers#mix_format#GetCommand(a:buffer),
\ 'read_temporary_file': 1,
\}
endfunction
diff --git a/autoload/ale/fixers/rufo.vim b/autoload/ale/fixers/rufo.vim
new file mode 100644
index 00000000..01d537a9
--- /dev/null
+++ b/autoload/ale/fixers/rufo.vim
@@ -0,0 +1,20 @@
+" Author: Fohte (Hayato Kawai) https://github.com/fohte
+" Description: Integration of Rufo with ALE.
+
+call ale#Set('ruby_rufo_executable', 'rufo')
+
+function! ale#fixers#rufo#GetCommand(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'ruby_rufo_executable')
+ let l:exec_args = l:executable =~? 'bundle$'
+ \ ? ' exec rufo'
+ \ : ''
+
+ return ale#Escape(l:executable) . l:exec_args . ' %t'
+endfunction
+
+function! ale#fixers#rufo#Fix(buffer) abort
+ return {
+ \ 'command': ale#fixers#rufo#GetCommand(a:buffer),
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
diff --git a/autoload/ale/handlers/flawfinder.vim b/autoload/ale/handlers/flawfinder.vim
new file mode 100644
index 00000000..a650d6dd
--- /dev/null
+++ b/autoload/ale/handlers/flawfinder.vim
@@ -0,0 +1,47 @@
+" Author: Christian Gibbons <cgibbons@gmu.edu>
+" Description: This file defines a handler function that should work for the
+" flawfinder format with the -CDQS flags.
+
+" Swiped this function from the GCC handler. Not sure if needed, but doesn't
+" hurt to have it.
+function! s:RemoveUnicodeQuotes(text) abort
+ let l:text = a:text
+ let l:text = substitute(l:text, '[`´‘’]', '''', 'g')
+ let l:text = substitute(l:text, '\v\\u2018([^\\]+)\\u2019', '''\1''', 'g')
+ let l:text = substitute(l:text, '[“”]', '"', 'g')
+
+ return l:text
+endfunction
+
+function! ale#handlers#flawfinder#HandleFlawfinderFormat(buffer, lines) abort
+ " Look for lines like the following.
+ "
+ " <stdin>:12:4: [2] (buffer) char:Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length.
+ " <stdin>:31:4: [1] (buffer) strncpy:Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120).
+ let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ( \[[0-5]\] [^:]+):(.+)$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ " Use severity level to determine if it should be considered a warning
+ " or error.
+ let l:severity = str2nr(matchstr(split(l:match[4])[0], '[0-5]'))
+
+ let l:item = {
+ \ 'lnum': str2nr(l:match[2]),
+ \ 'col': str2nr(l:match[3]),
+ \ 'type': (l:severity < ale#Var(a:buffer, 'c_flawfinder_error_severity'))
+ \ ? 'W' : 'E',
+ \ 'text': s:RemoveUnicodeQuotes(join(split(l:match[4])[1:]) . ': ' . l:match[5]),
+ \}
+
+ " If the filename is something like <stdin>, <nofile> or -, then
+ " this is an error for the file we checked.
+ if l:match[1] isnot# '-' && l:match[1][0] isnot# '<'
+ let l:item['filename'] = l:match[1]
+ endif
+
+ call add(l:output, l:item)
+ endfor
+
+ return l:output
+endfunction
diff --git a/autoload/ale/handlers/gawk.vim b/autoload/ale/handlers/gawk.vim
new file mode 100644
index 00000000..942bc2b2
--- /dev/null
+++ b/autoload/ale/handlers/gawk.vim
@@ -0,0 +1,25 @@
+" Author: Anthony DeDominic <adedomin@gmail.com>
+" Description: Handle output from gawk's --lint option
+
+function! ale#handlers#gawk#HandleGawkFormat(buffer, lines) abort
+ " Look for lines like the following:
+ " gawk: /tmp/v0fddXz/1/something.awk:1: ^ invalid char ''' in expression
+ let l:pattern = '^.\{-}:\(\d\+\):\s\+\(warning:\|\^\)\s*\(.*\)'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ let l:ecode = 'E'
+ if l:match[2] is? 'warning:'
+ let l:ecode = 'W'
+ endif
+ call add(l:output, {
+ \ 'lnum': l:match[1] + 0,
+ \ 'col': 0,
+ \ 'text': l:match[3],
+ \ 'code': 0,
+ \ 'type': l:ecode,
+ \})
+ endfor
+
+ return l:output
+endfunction
diff --git a/autoload/ale/handlers/gcc.vim b/autoload/ale/handlers/gcc.vim
index 7f2078a4..9ec7b110 100644
--- a/autoload/ale/handlers/gcc.vim
+++ b/autoload/ale/handlers/gcc.vim
@@ -24,7 +24,7 @@ function! ale#handlers#gcc#HandleGCCFormat(buffer, lines) abort
" <stdin>:8:5: warning: conversion lacks type at end of format [-Wformat=]
" <stdin>:10:27: error: invalid operands to binary - (have ‘int’ and ‘char *’)
" -:189:7: note: $/${} is unnecessary on arithmetic variables. [SC2004]
- let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ([^:]+): ?(.+)$'
+ let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ([^:]+): (.+)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
diff --git a/autoload/ale/handlers/go.vim b/autoload/ale/handlers/go.vim
new file mode 100644
index 00000000..224df664
--- /dev/null
+++ b/autoload/ale/handlers/go.vim
@@ -0,0 +1,25 @@
+" Author: neersighted <bjorn@neersighted.com>
+" Description: go vet for Go files
+"
+" Author: John Eikenberry <jae@zhar.net>
+" Description: updated to work with go1.10
+"
+" Author: Ben Paxton <ben@gn32.uk>
+" Description: moved to generic Golang file from govet
+
+function! ale#handlers#go#Handler(buffer, lines) abort
+ let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?:? ?(.+)$'
+ let l:output = []
+ let l:dir = expand('#' . a:buffer . ':p:h')
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:output, {
+ \ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]),
+ \ 'lnum': l:match[2] + 0,
+ \ 'col': l:match[3] + 0,
+ \ 'text': l:match[4],
+ \ 'type': 'E',
+ \})
+ endfor
+ return l:output
+endfunction
diff --git a/autoload/ale/handlers/redpen.vim b/autoload/ale/handlers/redpen.vim
index 2fb05684..c136789c 100644
--- a/autoload/ale/handlers/redpen.vim
+++ b/autoload/ale/handlers/redpen.vim
@@ -25,6 +25,30 @@ function! ale#handlers#redpen#HandleRedpenOutput(buffer, lines) abort
let l:item.lnum = l:err.lineNum
let l:item.col = l:err.sentenceStartColumnNum + 1
endif
+
+ " Adjust column number for multibyte string
+ let l:line = getline(l:item.lnum)
+ if l:line is# ''
+ let l:line = l:err.sentence
+ endif
+ let l:line = split(l:line, '\zs')
+
+ if l:item.col >= 2
+ let l:col = 0
+ for l:strlen in map(l:line[0:(l:item.col - 2)], 'strlen(v:val)')
+ let l:col = l:col + l:strlen
+ endfor
+ let l:item.col = l:col + 1
+ endif
+
+ if has_key(l:item, 'end_col')
+ let l:col = 0
+ for l:strlen in map(l:line[0:(l:item.end_col - 1)], 'strlen(v:val)')
+ let l:col = l:col + l:strlen
+ endfor
+ let l:item.end_col = l:col
+ endif
+
call add(l:output, l:item)
endfor
return l:output
diff --git a/autoload/ale/handlers/textlint.vim b/autoload/ale/handlers/textlint.vim
new file mode 100644
index 00000000..0aae57ef
--- /dev/null
+++ b/autoload/ale/handlers/textlint.vim
@@ -0,0 +1,19 @@
+" Author: tokida https://rouger.info
+" Description: Redpen, a proofreading tool (http://redpen.cc)
+
+function! ale#handlers#textlint#HandleTextlintOutput(buffer, lines) abort
+ let l:res = get(ale#util#FuzzyJSONDecode(a:lines, []), 0, {'messages': []})
+ let l:output = []
+
+ for l:err in l:res.messages
+ call add(l:output, {
+ \ 'text': l:err.message,
+ \ 'type': 'W',
+ \ 'code': l:err.ruleId,
+ \ 'lnum': l:err.line,
+ \ 'col' : l:err.column
+ \})
+ endfor
+
+ return l:output
+endfunction
diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim
index 126d6c18..8db9348f 100644
--- a/autoload/ale/lsp.vim
+++ b/autoload/ale/lsp.vim
@@ -325,6 +325,20 @@ function! ale#lsp#ConnectToAddress(address, project_root, callback) abort
return 1
endfunction
+" Stop all LSP connections, closing all jobs and channels, and removing any
+" queued messages.
+function! ale#lsp#StopAll() abort
+ for l:conn in s:connections
+ if has_key(l:conn, 'channel')
+ call ch_close(l:conn.channel)
+ else
+ call ale#job#Stop(l:conn.id)
+ endif
+ endfor
+
+ let s:connections = []
+endfunction
+
function! s:SendMessageData(conn, data) abort
if has_key(a:conn, 'executable')
call ale#job#SendRaw(a:conn.id, a:data)
diff --git a/autoload/ale/lsp/reset.vim b/autoload/ale/lsp/reset.vim
new file mode 100644
index 00000000..c206ed08
--- /dev/null
+++ b/autoload/ale/lsp/reset.vim
@@ -0,0 +1,25 @@
+" Stop all LSPs and remove all of the data for them.
+function! ale#lsp#reset#StopAllLSPs() abort
+ call ale#lsp#StopAll()
+
+ if exists('*ale#definition#ClearLSPData')
+ " Clear the mapping for connections, etc.
+ call ale#definition#ClearLSPData()
+ endif
+
+ if exists('*ale#engine#ClearLSPData')
+ " Clear the mapping for connections, etc.
+ call ale#engine#ClearLSPData()
+
+ " Remove the problems for all of the LSP linters in every buffer.
+ for l:buffer_string in keys(g:ale_buffer_info)
+ let l:buffer = str2nr(l:buffer_string)
+
+ for l:linter in ale#linter#Get(getbufvar(l:buffer, '&filetype'))
+ if !empty(l:linter.lsp)
+ call ale#engine#HandleLoclist(l:linter.name, l:buffer, [])
+ endif
+ endfor
+ endfor
+ endif
+endfunction
diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim
index 16dabf21..91832b35 100644
--- a/autoload/ale/path.vim
+++ b/autoload/ale/path.vim
@@ -84,12 +84,12 @@ function! ale#path#IsAbsolute(filename) abort
return a:filename[:0] is# '/' || a:filename[1:2] is# ':\'
endfunction
-let s:temp_dir = fnamemodify(tempname(), ':h')
+let s:temp_dir = ale#path#Simplify(fnamemodify(tempname(), ':h'))
" Given a filename, return 1 if the file represents some temporary file
" created by Vim.
function! ale#path#IsTempName(filename) abort
- return a:filename[:len(s:temp_dir) - 1] is# s:temp_dir
+ return ale#path#Simplify(a:filename)[:len(s:temp_dir) - 1] is# s:temp_dir
endfunction
" Given a base directory, which must not have a trailing slash, and a