mirror of https://github.com/amix/vimrc.git
parent
d8db85c663
commit
2b653aa950
@ -0,0 +1,46 @@ |
||||
" Author: Horacio Sanson <https://github.com/hsanson> |
||||
" Description: Support ansible language server https://github.com/ansible/ansible-language-server/ |
||||
|
||||
call ale#Set('ansible_language_server_executable', 'ansible-language-server') |
||||
call ale#Set('ansible_language_server_config', {}) |
||||
|
||||
function! ale_linters#ansible#ansible_language_server#Executable(buffer) abort |
||||
return ale#Var(a:buffer, 'ansible_language_server_executable') |
||||
endfunction |
||||
|
||||
function! ale_linters#ansible#ansible_language_server#GetCommand(buffer) abort |
||||
let l:executable = ale_linters#ansible#ansible_language_server#Executable(a:buffer) |
||||
|
||||
return ale#Escape(l:executable) . ' --stdio' |
||||
endfunction |
||||
|
||||
function! ale_linters#ansible#ansible_language_server#FindProjectRoot(buffer) abort |
||||
let l:dir = fnamemodify( |
||||
\ ale#path#FindNearestFile(a:buffer, 'ansible.cfg'), |
||||
\ ':h' |
||||
\) |
||||
|
||||
if l:dir isnot# '.' && isdirectory(l:dir) |
||||
return l:dir |
||||
endif |
||||
|
||||
let l:dir = fnamemodify( |
||||
\ ale#path#FindNearestDirectory(a:buffer, '.git'), |
||||
\ ':h:h' |
||||
\) |
||||
|
||||
if l:dir isnot# '.' && isdirectory(l:dir) |
||||
return l:dir |
||||
endif |
||||
|
||||
return '' |
||||
endfunction |
||||
|
||||
call ale#linter#Define('ansible', { |
||||
\ 'name': 'ansible-language-server', |
||||
\ 'lsp': 'stdio', |
||||
\ 'executable': function('ale_linters#ansible#ansible_language_server#Executable'), |
||||
\ 'command': function('ale_linters#ansible#ansible_language_server#GetCommand'), |
||||
\ 'project_root': function('ale_linters#ansible#ansible_language_server#FindProjectRoot'), |
||||
\ 'lsp_config': {b -> ale#Var(b, 'ansible_language_server_config')} |
||||
\}) |
@ -0,0 +1,72 @@ |
||||
" Author: Carl Smedstad <carl.smedstad at protonmail dot com> |
||||
" Description: sqlfluff for SQL files |
||||
|
||||
let g:ale_sql_sqlfluff_executable = |
||||
\ get(g:, 'ale_sql_sqlfluff_executable', 'sqlfluff') |
||||
|
||||
let g:ale_sql_sqlfluff_options = |
||||
\ get(g:, 'ale_sql_sqlfluff_options', '') |
||||
|
||||
function! ale_linters#sql#sqlfluff#Executable(buffer) abort |
||||
return ale#Var(a:buffer, 'sql_sqlfluff_executable') |
||||
endfunction |
||||
|
||||
function! ale_linters#sql#sqlfluff#Command(buffer) abort |
||||
let l:executable = ale_linters#sql#sqlfluff#Executable(a:buffer) |
||||
let l:options = ale#Var(a:buffer, 'sql_sqlfluff_options') |
||||
|
||||
let l:cmd = |
||||
\ ale#Escape(l:executable) |
||||
\ . ' lint' |
||||
|
||||
let l:config_file = ale#path#FindNearestFile(a:buffer, '.sqlfluff') |
||||
|
||||
if !empty(l:config_file) |
||||
let l:cmd .= ' --config ' . ale#Escape(l:config_file) |
||||
else |
||||
let l:cmd .= ' --dialect ansi' |
||||
endif |
||||
|
||||
let l:cmd .= |
||||
\ ' --format json ' |
||||
\ . l:options |
||||
\ . ' %t' |
||||
|
||||
return l:cmd |
||||
endfunction |
||||
|
||||
function! ale_linters#sql#sqlfluff#Handle(buffer, lines) abort |
||||
let l:output = [] |
||||
let l:json_lines = ale#util#FuzzyJSONDecode(a:lines, []) |
||||
|
||||
if empty(l:json_lines) |
||||
return l:output |
||||
endif |
||||
|
||||
let l:json = l:json_lines[0] |
||||
|
||||
" if there's no warning, 'result' is `null`. |
||||
if empty(get(l:json, 'violations')) |
||||
return l:output |
||||
endif |
||||
|
||||
for l:violation in get(l:json, 'violations', []) |
||||
call add(l:output, { |
||||
\ 'filename': l:json.filepath, |
||||
\ 'lnum': l:violation.line_no, |
||||
\ 'col': l:violation.line_pos, |
||||
\ 'text': l:violation.description, |
||||
\ 'code': l:violation.code, |
||||
\ 'type': 'W', |
||||
\}) |
||||
endfor |
||||
|
||||
return l:output |
||||
endfunction |
||||
|
||||
call ale#linter#Define('sql', { |
||||
\ 'name': 'sqlfluff', |
||||
\ 'executable': function('ale_linters#sql#sqlfluff#Executable'), |
||||
\ 'command': function('ale_linters#sql#sqlfluff#Command'), |
||||
\ 'callback': 'ale_linters#sql#sqlfluff#Handle', |
||||
\}) |
@ -0,0 +1,25 @@ |
||||
" Author: Carl Smedstad <carl.smedstad at protonmail dot com> |
||||
" Description: Fixing SQL files with sqlfluff |
||||
|
||||
call ale#Set('sql_sqlfluff_executable', 'sqlfluff') |
||||
|
||||
function! ale#fixers#sqlfluff#Fix(buffer) abort |
||||
let l:executable = ale#Var(a:buffer, 'sql_sqlfluff_executable') |
||||
|
||||
let l:cmd = |
||||
\ ale#Escape(l:executable) |
||||
\ . ' fix --force' |
||||
|
||||
let l:config_file = ale#path#FindNearestFile(a:buffer, '.sqlfluff') |
||||
|
||||
if !empty(l:config_file) |
||||
let l:cmd .= ' --config ' . ale#Escape(l:config_file) |
||||
else |
||||
let l:cmd .= ' --dialect ansi' |
||||
endif |
||||
|
||||
return { |
||||
\ 'command': l:cmd . ' %t > /dev/null', |
||||
\ 'read_temporary_file': 1, |
||||
\} |
||||
endfunction |
@ -1,13 +1,73 @@ |
||||
if exists("b:did_indent") |
||||
finish |
||||
" Only load this indent file when no other was loaded. |
||||
if exists('b:did_indent') |
||||
finish |
||||
endif |
||||
let b:did_indent = 1 |
||||
|
||||
setlocal indentexpr= |
||||
setlocal indentexpr=GetNginxIndent() |
||||
|
||||
" cindent actually works for nginx' simple file structure |
||||
setlocal cindent |
||||
" Just make sure that the comments are not reset as defs would be. |
||||
setlocal cinkeys-=0# |
||||
setlocal indentkeys=0{,0},0#,!^F,o,O |
||||
|
||||
let b:undo_indent = "setl cin< cink< inde<" |
||||
let b:undo_indent = 'setl inde< indk<' |
||||
|
||||
" Only define the function once. |
||||
if exists('*GetNginxIndent') |
||||
finish |
||||
endif |
||||
|
||||
function! GetNginxIndent() abort |
||||
let plnum = s:PrevNotAsBlank(v:lnum - 1) |
||||
|
||||
" Hit the start of the file, use zero indent. |
||||
if plnum == 0 |
||||
return 0 |
||||
endif |
||||
|
||||
let ind = indent(plnum) |
||||
|
||||
" Add a 'shiftwidth' after '{' |
||||
if s:AsEndWith(getline(plnum), '{') |
||||
let ind = ind + shiftwidth() |
||||
end |
||||
|
||||
" Subtract a 'shiftwidth' on '}' |
||||
" This is the part that requires 'indentkeys'. |
||||
if getline(v:lnum) =~ '^\s*}' |
||||
let ind = ind - shiftwidth() |
||||
endif |
||||
|
||||
let pplnum = s:PrevNotAsBlank(plnum - 1) |
||||
|
||||
if s:IsLineContinuation(plnum) |
||||
if !s:IsLineContinuation(pplnum) |
||||
let ind = ind + shiftwidth() |
||||
end |
||||
else |
||||
if s:IsLineContinuation(pplnum) |
||||
let ind = ind - shiftwidth() |
||||
end |
||||
endif |
||||
|
||||
return ind |
||||
endfunction |
||||
|
||||
" Find the first line at or above {lnum} that is non-blank and not a comment. |
||||
function! s:PrevNotAsBlank(lnum) abort |
||||
let lnum = prevnonblank(a:lnum) |
||||
while lnum > 0 |
||||
if getline(lnum) !~ '^\s*#' |
||||
break |
||||
endif |
||||
let lnum = prevnonblank(lnum - 1) |
||||
endwhile |
||||
return lnum |
||||
endfunction |
||||
|
||||
" Check whether {line} ends with {pat}, ignoring trailing comments. |
||||
function! s:AsEndWith(line, pat) abort |
||||
return a:line =~ a:pat . '\m\s*\%(#.*\)\?$' |
||||
endfunction |
||||
|
||||
function! s:IsLineContinuation(lnum) abort |
||||
return a:lnum > 0 && !s:AsEndWith(getline(a:lnum), '[;{}]') |
||||
endfunction |
||||
|
@ -0,0 +1,116 @@ |
||||
Given markdown; |
||||
# a |
||||
|
||||
## b |
||||
|
||||
### c |
||||
|
||||
#### d |
||||
|
||||
##### e |
||||
|
||||
Execute (HeaderIncrease without forbidden level): |
||||
:HeaderIncrease |
||||
|
||||
Expect (increase level of all headers): |
||||
## a |
||||
|
||||
### b |
||||
|
||||
#### c |
||||
|
||||
##### d |
||||
|
||||
###### e |
||||
|
||||
Given markdown; |
||||
# a |
||||
|
||||
###### b |
||||
|
||||
Execute (HeaderIncrease with forbidden level): |
||||
:HeaderIncrease |
||||
|
||||
Expect (no changes): |
||||
# a |
||||
|
||||
###### b |
||||
|
||||
Given markdown; |
||||
## a |
||||
|
||||
### b |
||||
|
||||
#### c |
||||
|
||||
##### d |
||||
|
||||
###### e |
||||
|
||||
Execute (HeaderDecrease without forbidden level): |
||||
:HeaderDecrease |
||||
|
||||
Expect (decrease level of all headers): |
||||
# a |
||||
|
||||
## b |
||||
|
||||
### c |
||||
|
||||
#### d |
||||
|
||||
##### e |
||||
|
||||
Given markdown; |
||||
# a |
||||
|
||||
## b |
||||
|
||||
### c |
||||
|
||||
#### d |
||||
|
||||
##### e |
||||
|
||||
###### f |
||||
|
||||
Execute (HeaderDecrease with forbidden level): |
||||
:HeaderDecrease |
||||
|
||||
Expect (no changes): |
||||
# a |
||||
|
||||
## b |
||||
|
||||
### c |
||||
|
||||
#### d |
||||
|
||||
##### e |
||||
|
||||
###### f |
||||
|
||||
Given markdown; |
||||
a |
||||
= |
||||
|
||||
b |
||||
- |
||||
|
||||
Execute (HeaderIncrease with setext headers): |
||||
:HeaderIncrease |
||||
|
||||
Expect (convert to atx headers): |
||||
## a |
||||
|
||||
### b |
||||
|
||||
Given markdown; |
||||
a |
||||
- |
||||
|
||||
Execute (HeaderDecrease with setext headers): |
||||
:HeaderDecrease |
||||
|
||||
Expect (convert to atx headers): |
||||
# a |
@ -0,0 +1,48 @@ |
||||
Given markdown; |
||||
# a |
||||
|
||||
a |
||||
= |
||||
|
||||
## b |
||||
|
||||
b |
||||
- |
||||
|
||||
Execute (SetexToAtx): |
||||
:SetexToAtx |
||||
|
||||
Expect (convert setex-style headings to atx): |
||||
# a |
||||
|
||||
# a |
||||
|
||||
## b |
||||
|
||||
## b |
||||
|
||||
Given markdown; |
||||
a |
||||
= |
||||
|
||||
b |
||||
= |
||||
|
||||
c |
||||
- |
||||
|
||||
d |
||||
- |
||||
|
||||
Execute (SetexToAtx with range): |
||||
:1,8SetexToAtx |
||||
|
||||
Expect (only convert setex headings in original range): |
||||
# a |
||||
|
||||
# b |
||||
|
||||
## c |
||||
|
||||
d |
||||
- |
Loading…
Reference in new issue