mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins
This commit is contained in:
@ -16,12 +16,16 @@ endfunction
|
||||
|
||||
function! ale_linters#python#jedils#GetCommand(buffer) abort
|
||||
let l:executable = ale_linters#python#jedils#GetExecutable(a:buffer)
|
||||
|
||||
let l:exec_args = l:executable =~? 'pipenv$'
|
||||
\ ? ' run jedi-language-server'
|
||||
\ : ''
|
||||
let l:env_string = ''
|
||||
|
||||
return ale#Escape(l:executable) . l:exec_args
|
||||
if ale#Var(a:buffer, 'python_auto_virtualenv')
|
||||
let l:env_string = ale#python#AutoVirtualenvEnvString(a:buffer)
|
||||
endif
|
||||
|
||||
return l:env_string . ale#Escape(l:executable) . l:exec_args
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('python', {
|
||||
|
86
sources_non_forked/ale/ale_linters/python/pycln.vim
Normal file
86
sources_non_forked/ale/ale_linters/python/pycln.vim
Normal file
@ -0,0 +1,86 @@
|
||||
" Author: Yining <zhang.yining@gmail.com>
|
||||
" Description: pycln as linter for python files
|
||||
|
||||
call ale#Set('python_pycln_executable', 'pycln')
|
||||
call ale#Set('python_pycln_options', '')
|
||||
call ale#Set('python_pycln_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('python_pycln_change_directory', 1)
|
||||
call ale#Set('python_pycln_auto_pipenv', 0)
|
||||
call ale#Set('python_pycln_auto_poetry', 0)
|
||||
call ale#Set('python_pycln_config_file', '')
|
||||
|
||||
function! ale_linters#python#pycln#GetExecutable(buffer) abort
|
||||
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pycln_auto_pipenv'))
|
||||
\ && ale#python#PipenvPresent(a:buffer)
|
||||
return 'pipenv'
|
||||
endif
|
||||
|
||||
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pycln_auto_poetry'))
|
||||
\ && ale#python#PoetryPresent(a:buffer)
|
||||
return 'poetry'
|
||||
endif
|
||||
|
||||
return ale#python#FindExecutable(a:buffer, 'python_pycln', ['pycln'])
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#pycln#GetCwd(buffer) abort
|
||||
if ale#Var(a:buffer, 'python_pycln_change_directory')
|
||||
" Run from project root if found, else from buffer dir.
|
||||
let l:project_root = ale#python#FindProjectRoot(a:buffer)
|
||||
|
||||
return !empty(l:project_root) ? l:project_root : '%s:h'
|
||||
endif
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#pycln#GetCommand(buffer, version) abort
|
||||
let l:executable = ale_linters#python#pycln#GetExecutable(a:buffer)
|
||||
let l:exec_args = l:executable =~? 'pipenv\|poetry$'
|
||||
\ ? ' run pycln'
|
||||
\ : ''
|
||||
|
||||
let l:options = ale#Var(a:buffer, 'python_pycln_options')
|
||||
let l:config_file = ale#Var(a:buffer, 'python_pycln_config_file')
|
||||
let l:config_file = l:options !~# '\v(^| )--config ' && !empty(l:config_file)
|
||||
\ ? ale#Escape(ale#path#Simplify(l:config_file))
|
||||
\ : ''
|
||||
|
||||
" NOTE: pycln version `1.3.0` supports liniting input from stdin
|
||||
return ale#Escape(l:executable) . l:exec_args
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'python_pycln_options'))
|
||||
\ . (empty(l:config_file) ? '' : ' --config ' . l:config_file)
|
||||
\ . ' --check'
|
||||
\ . (ale#semver#GTE(a:version, [1, 3, 0]) ? ' -' : ' %s')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#pycln#Handle(buffer, lines) abort
|
||||
" Example: tmp/test.py:3:0 'import os' would be removed!
|
||||
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+):? (.+)$'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'col': l:match[2] + 0,
|
||||
\ 'text': l:match[3],
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('python', {
|
||||
\ 'name': 'pycln',
|
||||
\ 'executable': function('ale_linters#python#pycln#GetExecutable'),
|
||||
\ 'cwd': function('ale_linters#python#pycln#GetCwd'),
|
||||
\ 'command': {buffer -> ale#semver#RunWithVersionCheck(
|
||||
\ buffer,
|
||||
\ ale_linters#python#pycln#GetExecutable(buffer),
|
||||
\ '%e --version',
|
||||
\ function('ale_linters#python#pycln#GetCommand'),
|
||||
\ )},
|
||||
\ 'callback': 'ale_linters#python#pycln#Handle',
|
||||
\ 'output_stream': 'both',
|
||||
\ 'read_buffer': 1,
|
||||
\})
|
@ -22,20 +22,38 @@ function! ale_linters#python#pylsp#GetExecutable(buffer) abort
|
||||
return ale#python#FindExecutable(a:buffer, 'python_pylsp', ['pylsp'])
|
||||
endfunction
|
||||
|
||||
" Force the cwd of the server to be the same as the project root to
|
||||
" fix issues with treating local files matching first or third party library
|
||||
" names being imported incorrectly.
|
||||
function! ale_linters#python#pylsp#GetCwd(buffer) abort
|
||||
let l:fake_linter = {
|
||||
\ 'name': 'pylsp',
|
||||
\ 'project_root': function('ale#python#FindProjectRoot'),
|
||||
\}
|
||||
let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, l:fake_linter)
|
||||
|
||||
return !empty(l:root) ? l:root : v:null
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#pylsp#GetCommand(buffer) abort
|
||||
let l:executable = ale_linters#python#pylsp#GetExecutable(a:buffer)
|
||||
|
||||
let l:exec_args = l:executable =~? 'pipenv\|poetry$'
|
||||
\ ? ' run pylsp'
|
||||
\ : ''
|
||||
let l:env_string = ''
|
||||
|
||||
return ale#Escape(l:executable) . l:exec_args . ale#Pad(ale#Var(a:buffer, 'python_pylsp_options'))
|
||||
if ale#Var(a:buffer, 'python_auto_virtualenv')
|
||||
let l:env_string = ale#python#AutoVirtualenvEnvString(a:buffer)
|
||||
endif
|
||||
|
||||
return l:env_string . ale#Escape(l:executable) . l:exec_args . ale#Pad(ale#Var(a:buffer, 'python_pylsp_options'))
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('python', {
|
||||
\ 'name': 'pylsp',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': function('ale_linters#python#pylsp#GetExecutable'),
|
||||
\ 'cwd': function('ale_linters#python#pylsp#GetCwd'),
|
||||
\ 'command': function('ale_linters#python#pylsp#GetCommand'),
|
||||
\ 'project_root': function('ale#python#FindProjectRoot'),
|
||||
\ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
|
||||
|
@ -1,5 +1,21 @@
|
||||
call ale#Set('python_pyright_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('python_pyright_executable', 'pyright-langserver')
|
||||
call ale#Set('python_pyright_config', {})
|
||||
call ale#Set('python_pyright_auto_pipenv', 0)
|
||||
call ale#Set('python_pyright_auto_poetry', 0)
|
||||
|
||||
" Force the cwd of the server to be the same as the project root to
|
||||
" fix issues with treating local files matching first or third party library
|
||||
" names being imported incorrectly.
|
||||
function! ale_linters#python#pyright#GetCwd(buffer) abort
|
||||
let l:fake_linter = {
|
||||
\ 'name': 'pyright',
|
||||
\ 'project_root': function('ale#python#FindProjectRoot'),
|
||||
\}
|
||||
let l:root = ale#lsp_linter#FindProjectRoot(a:buffer, l:fake_linter)
|
||||
|
||||
return !empty(l:root) ? l:root : v:null
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#pyright#GetConfig(buffer) abort
|
||||
let l:config = deepcopy(ale#Var(a:buffer, 'python_pyright_config'))
|
||||
@ -32,11 +48,40 @@ function! ale_linters#python#pyright#GetConfig(buffer) abort
|
||||
return l:config
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#pyright#GetExecutable(buffer) abort
|
||||
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pyright_auto_pipenv'))
|
||||
\ && ale#python#PipenvPresent(a:buffer)
|
||||
return 'pipenv'
|
||||
endif
|
||||
|
||||
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pyright_auto_poetry'))
|
||||
\ && ale#python#PoetryPresent(a:buffer)
|
||||
return 'poetry'
|
||||
endif
|
||||
|
||||
return ale#python#FindExecutable(a:buffer, 'python_pyright', ['pyright-langserver'])
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#pyright#GetCommand(buffer) abort
|
||||
let l:executable = ale_linters#python#pyright#GetExecutable(a:buffer)
|
||||
let l:exec_args = l:executable =~? 'pipenv\|poetry$'
|
||||
\ ? ' run pyright'
|
||||
\ : ''
|
||||
let l:env_string = ''
|
||||
|
||||
if ale#Var(a:buffer, 'python_auto_virtualenv')
|
||||
let l:env_string = ale#python#AutoVirtualenvEnvString(a:buffer)
|
||||
endif
|
||||
|
||||
return l:env_string . ale#Escape(l:executable) . l:exec_args . ' --stdio'
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('python', {
|
||||
\ 'name': 'pyright',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': {b -> ale#Var(b, 'python_pyright_executable')},
|
||||
\ 'command': '%e --stdio',
|
||||
\ 'cwd': function('ale_linters#python#pyright#GetCwd'),
|
||||
\ 'executable': function('ale_linters#python#pyright#GetExecutable'),
|
||||
\ 'command': function('ale_linters#python#pyright#GetCommand'),
|
||||
\ 'project_root': function('ale#python#FindProjectRoot'),
|
||||
\ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
|
||||
\ 'lsp_config': function('ale_linters#python#pyright#GetConfig'),
|
||||
|
73
sources_non_forked/ale/ale_linters/python/refurb.vim
Normal file
73
sources_non_forked/ale/ale_linters/python/refurb.vim
Normal file
@ -0,0 +1,73 @@
|
||||
" Author: Yining <zhang.yining@gmail.com>
|
||||
" Description: refurb as linter for python files
|
||||
|
||||
call ale#Set('python_refurb_executable', 'refurb')
|
||||
call ale#Set('python_refurb_options', '')
|
||||
call ale#Set('python_refurb_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('python_refurb_change_directory', 1)
|
||||
call ale#Set('python_refurb_auto_pipenv', 0)
|
||||
call ale#Set('python_refurb_auto_poetry', 0)
|
||||
|
||||
function! ale_linters#python#refurb#GetExecutable(buffer) abort
|
||||
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_refurb_auto_pipenv'))
|
||||
\ && ale#python#PipenvPresent(a:buffer)
|
||||
return 'pipenv'
|
||||
endif
|
||||
|
||||
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_refurb_auto_poetry'))
|
||||
\ && ale#python#PoetryPresent(a:buffer)
|
||||
return 'poetry'
|
||||
endif
|
||||
|
||||
return ale#python#FindExecutable(a:buffer, 'python_refurb', ['refurb'])
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#refurb#GetCwd(buffer) abort
|
||||
if ale#Var(a:buffer, 'python_refurb_change_directory')
|
||||
" Run from project root if found, else from buffer dir.
|
||||
let l:project_root = ale#python#FindProjectRoot(a:buffer)
|
||||
|
||||
return !empty(l:project_root) ? l:project_root : '%s:h'
|
||||
endif
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#refurb#GetCommand(buffer) abort
|
||||
let l:executable = ale_linters#python#refurb#GetExecutable(a:buffer)
|
||||
let l:exec_args = l:executable =~? 'pipenv\|poetry$'
|
||||
\ ? ' run refurb'
|
||||
\ : ''
|
||||
|
||||
return ale#Escape(l:executable) . l:exec_args
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'python_refurb_options'))
|
||||
\ . ' %s'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#refurb#Handle(buffer, lines) abort
|
||||
"Example: path/to/file.py:3:17 [FURB109]: Replace `in [x, y, z]` with `in (x, y, z)`
|
||||
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+)?:?\s*\[FURB(\d+)\]:\s*(.+)$'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'col': l:match[2] + 0,
|
||||
\ 'code': l:match[3] + 0,
|
||||
\ 'text': l:match[4],
|
||||
\ 'type': 'W',
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('python', {
|
||||
\ 'name': 'refurb',
|
||||
\ 'executable': function('ale_linters#python#refurb#GetExecutable'),
|
||||
\ 'cwd': function('ale_linters#python#refurb#GetCwd'),
|
||||
\ 'command': function('ale_linters#python#refurb#GetCommand'),
|
||||
\ 'callback': 'ale_linters#python#refurb#Handle',
|
||||
\ 'output_stream': 'both',
|
||||
\ 'read_buffer': 0,
|
||||
\})
|
@ -49,7 +49,7 @@ function! ale_linters#python#ruff#GetCommand(buffer, version) abort
|
||||
return ale#Escape(l:executable) . l:exec_args
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'python_ruff_options'))
|
||||
\ . ' --format text'
|
||||
\ . (ale#semver#GTE(a:version, [0, 0, 69]) ? ' -' : ' %s')
|
||||
\ . (ale#semver#GTE(a:version, [0, 0, 69]) ? ' --stdin-filename %s -' : ' %s')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#python#ruff#Handle(buffer, lines) abort
|
||||
|
Reference in New Issue
Block a user