mirror of
https://github.com/dense-analysis/ale.git
synced 2026-05-17 13:59:47 +08:00
Close #4971 - Add support for ty via LSP
CI / Build (push) Waiting to run
CI / Lint (push) Blocked by required conditions
CI / Lua (push) Blocked by required conditions
CI / Neovim 0.10 Linux (push) Blocked by required conditions
CI / Neovim 0.12 Linux (push) Blocked by required conditions
CI / Vim 8.2 Linux (push) Blocked by required conditions
CI / Vim 9.2 Linux (push) Blocked by required conditions
CI / Neovim 0.10 Windows (push) Waiting to run
CI / Neovim 0.12 Windows (push) Waiting to run
CI / Vim 8.2 Windows (push) Waiting to run
CI / Vim 9.2 Windows (push) Waiting to run
CI / Build (push) Waiting to run
CI / Lint (push) Blocked by required conditions
CI / Lua (push) Blocked by required conditions
CI / Neovim 0.10 Linux (push) Blocked by required conditions
CI / Neovim 0.12 Linux (push) Blocked by required conditions
CI / Vim 8.2 Linux (push) Blocked by required conditions
CI / Vim 9.2 Linux (push) Blocked by required conditions
CI / Neovim 0.10 Windows (push) Waiting to run
CI / Neovim 0.12 Windows (push) Waiting to run
CI / Vim 8.2 Windows (push) Waiting to run
CI / Vim 9.2 Windows (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
" Author: w0rp <dev@w0rp.com>
|
||||||
|
" Description: Astral's Python type checker and language server
|
||||||
|
|
||||||
|
call ale#Set('python_ty_executable', 'ty')
|
||||||
|
call ale#Set('python_ty_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
|
call ale#Set('python_ty_auto_pipenv', 0)
|
||||||
|
call ale#Set('python_ty_auto_poetry', 0)
|
||||||
|
call ale#Set('python_ty_auto_uv', 0)
|
||||||
|
call ale#Set('python_ty_config', {})
|
||||||
|
|
||||||
|
function! ale_linters#python#ty#GetExecutable(buffer) abort
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_ty_auto_pipenv'))
|
||||||
|
\ && ale#python#PipenvPresent(a:buffer)
|
||||||
|
return 'pipenv'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_ty_auto_poetry'))
|
||||||
|
\ && ale#python#PoetryPresent(a:buffer)
|
||||||
|
return 'poetry'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_ty_auto_uv'))
|
||||||
|
\ && ale#python#UvPresent(a:buffer)
|
||||||
|
return 'uv'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ale#python#FindExecutable(a:buffer, 'python_ty', ['ty'])
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Force the cwd of the server to be the same as the project root.
|
||||||
|
function! ale_linters#python#ty#GetCwd(buffer) abort
|
||||||
|
let l:fake_linter = {
|
||||||
|
\ 'name': 'ty',
|
||||||
|
\ '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#ty#GetCommand(buffer) abort
|
||||||
|
let l:executable = ale_linters#python#ty#GetExecutable(a:buffer)
|
||||||
|
let l:exec_args = [
|
||||||
|
\ ale#Escape(l:executable),
|
||||||
|
\]
|
||||||
|
\ + (l:executable =~? '\(pipenv\|poetry\|uv\)$' ? ['run', 'ty'] : [])
|
||||||
|
\ + [
|
||||||
|
\ 'server',
|
||||||
|
\]
|
||||||
|
|
||||||
|
return join(l:exec_args, ' ')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call ale#linter#Define('python', {
|
||||||
|
\ 'name': 'ty',
|
||||||
|
\ 'lsp': 'stdio',
|
||||||
|
\ 'executable': function('ale_linters#python#ty#GetExecutable'),
|
||||||
|
\ 'cwd': function('ale_linters#python#ty#GetCwd'),
|
||||||
|
\ 'command': function('ale_linters#python#ty#GetCommand'),
|
||||||
|
\ 'project_root': function('ale#python#FindProjectRoot'),
|
||||||
|
\ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
|
||||||
|
\ 'lsp_config': {b -> ale#Var(b, 'python_ty_config')},
|
||||||
|
\})
|
||||||
@@ -54,7 +54,7 @@ let s:default_ale_linters = {
|
|||||||
\ 'jsonc': ['biome'],
|
\ 'jsonc': ['biome'],
|
||||||
\ 'perl': ['perlcritic'],
|
\ 'perl': ['perlcritic'],
|
||||||
\ 'perl6': [],
|
\ 'perl6': [],
|
||||||
\ 'python': ['flake8', 'mypy', 'pylint', 'pyright', 'ruff'],
|
\ 'python': ['flake8', 'mypy', 'pylint', 'pyright', 'ruff', 'ty'],
|
||||||
\ 'rust': ['analyzer', 'cargo'],
|
\ 'rust': ['analyzer', 'cargo'],
|
||||||
\ 'spec': [],
|
\ 'spec': [],
|
||||||
\ 'text': [],
|
\ 'text': [],
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ function! ale#python#FindProjectRootIni(buffer) abort
|
|||||||
\|| filereadable(l:path . '/Pipfile.lock')
|
\|| filereadable(l:path . '/Pipfile.lock')
|
||||||
\|| filereadable(l:path . '/poetry.lock')
|
\|| filereadable(l:path . '/poetry.lock')
|
||||||
\|| filereadable(l:path . '/pyproject.toml')
|
\|| filereadable(l:path . '/pyproject.toml')
|
||||||
|
\|| filereadable(l:path . '/ty.toml')
|
||||||
\|| filereadable(l:path . '/.tool-versions')
|
\|| filereadable(l:path . '/.tool-versions')
|
||||||
\|| filereadable(l:path . '/uv.lock')
|
\|| filereadable(l:path . '/uv.lock')
|
||||||
return resolve(l:path)
|
return resolve(l:path)
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ ALE will look for configuration files with the following filenames. >
|
|||||||
Pipfile.lock
|
Pipfile.lock
|
||||||
poetry.lock
|
poetry.lock
|
||||||
pyproject.toml
|
pyproject.toml
|
||||||
|
ty.toml
|
||||||
.tool-versions
|
.tool-versions
|
||||||
uv.lock
|
uv.lock
|
||||||
<
|
<
|
||||||
@@ -2106,6 +2107,79 @@ g:ale_python_ruff_format_auto_uv
|
|||||||
executable.
|
executable.
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
ty *ale-python-ty*
|
||||||
|
|
||||||
|
`ty` will be run from a detected project root, per |ale-python-root|.
|
||||||
|
|
||||||
|
*ale-options.python_ty_executable*
|
||||||
|
*g:ale_python_ty_executable*
|
||||||
|
*b:ale_python_ty_executable*
|
||||||
|
python_ty_executable
|
||||||
|
g:ale_python_ty_executable
|
||||||
|
Type: |String|
|
||||||
|
Default: `'ty'`
|
||||||
|
|
||||||
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
Set this to `'pipenv'` to invoke `'pipenv` `run` `ty'`.
|
||||||
|
Set this to `'poetry'` to invoke `'poetry` `run` `ty'`.
|
||||||
|
Set this to `'uv'` to invoke `'uv` `run` `ty'`.
|
||||||
|
|
||||||
|
*ale-options.python_ty_use_global*
|
||||||
|
*g:ale_python_ty_use_global*
|
||||||
|
*b:ale_python_ty_use_global*
|
||||||
|
python_ty_use_global
|
||||||
|
g:ale_python_ty_use_global
|
||||||
|
Type: |Number|
|
||||||
|
Default: `get(g:, 'ale_use_global_executables', 0)`
|
||||||
|
|
||||||
|
See |ale-integrations-local-executables|
|
||||||
|
|
||||||
|
*ale-options.python_ty_auto_pipenv*
|
||||||
|
*g:ale_python_ty_auto_pipenv*
|
||||||
|
*b:ale_python_ty_auto_pipenv*
|
||||||
|
python_ty_auto_pipenv
|
||||||
|
g:ale_python_ty_auto_pipenv
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Detect whether the file is inside a pipenv, and set the executable to `pipenv`
|
||||||
|
if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
*ale-options.python_ty_auto_poetry*
|
||||||
|
*g:ale_python_ty_auto_poetry*
|
||||||
|
*b:ale_python_ty_auto_poetry*
|
||||||
|
python_ty_auto_poetry
|
||||||
|
g:ale_python_ty_auto_poetry
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Detect whether the file is inside a poetry, and set the executable to `poetry`
|
||||||
|
if true. This is overridden by a manually-set executable.
|
||||||
|
|
||||||
|
*ale-options.python_ty_auto_uv*
|
||||||
|
*g:ale_python_ty_auto_uv*
|
||||||
|
*b:ale_python_ty_auto_uv*
|
||||||
|
python_ty_auto_uv
|
||||||
|
g:ale_python_ty_auto_uv
|
||||||
|
Type: |Number|
|
||||||
|
Default: `0`
|
||||||
|
|
||||||
|
Set the executable to `uv` if true. This is overridden by a manually-set
|
||||||
|
executable.
|
||||||
|
|
||||||
|
*ale-options.python_ty_config*
|
||||||
|
*g:ale_python_ty_config*
|
||||||
|
*b:ale_python_ty_config*
|
||||||
|
python_ty_config
|
||||||
|
g:ale_python_ty_config
|
||||||
|
Type: |Dictionary|
|
||||||
|
Default: `{}`
|
||||||
|
|
||||||
|
Dictionary with language server configuration settings for `ty`.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
unimport *ale-python-unimport*
|
unimport *ale-python-unimport*
|
||||||
|
|
||||||
|
|||||||
@@ -563,6 +563,7 @@ Notes:
|
|||||||
* `reorder-python-imports`
|
* `reorder-python-imports`
|
||||||
* ruff
|
* ruff
|
||||||
* ruff-format
|
* ruff-format
|
||||||
|
* `ty`
|
||||||
* `unimport`
|
* `unimport`
|
||||||
* `vulture`!!
|
* `vulture`!!
|
||||||
* `yapf`
|
* `yapf`
|
||||||
|
|||||||
+2
-1
@@ -1944,7 +1944,7 @@ g:ale_linters
|
|||||||
\ 'jsonc': [],
|
\ 'jsonc': [],
|
||||||
\ 'perl': ['perlcritic'],
|
\ 'perl': ['perlcritic'],
|
||||||
\ 'perl6': [],
|
\ 'perl6': [],
|
||||||
\ 'python': ['flake8', 'mypy', 'pylint', 'pyright', 'ruff'],
|
\ 'python': ['flake8', 'mypy', 'pylint', 'pyright', 'ruff', 'ty'],
|
||||||
\ 'rust': ['analyzer', 'cargo'],
|
\ 'rust': ['analyzer', 'cargo'],
|
||||||
\ 'spec': [],
|
\ 'spec': [],
|
||||||
\ 'text': [],
|
\ 'text': [],
|
||||||
@@ -3882,6 +3882,7 @@ documented in additional help files.
|
|||||||
reorder-python-imports................|ale-python-reorder_python_imports|
|
reorder-python-imports................|ale-python-reorder_python_imports|
|
||||||
ruff..................................|ale-python-ruff|
|
ruff..................................|ale-python-ruff|
|
||||||
ruff-format...........................|ale-python-ruff-format|
|
ruff-format...........................|ale-python-ruff-format|
|
||||||
|
ty....................................|ale-python-ty|
|
||||||
unimport..............................|ale-python-unimport|
|
unimport..............................|ale-python-unimport|
|
||||||
vulture...............................|ale-python-vulture|
|
vulture...............................|ale-python-vulture|
|
||||||
yapf..................................|ale-python-yapf|
|
yapf..................................|ale-python-yapf|
|
||||||
|
|||||||
@@ -573,6 +573,7 @@ formatting.
|
|||||||
* [reorder-python-imports](https://github.com/asottile/reorder_python_imports)
|
* [reorder-python-imports](https://github.com/asottile/reorder_python_imports)
|
||||||
* [ruff](https://github.com/charliermarsh/ruff)
|
* [ruff](https://github.com/charliermarsh/ruff)
|
||||||
* [ruff-format](https://docs.astral.sh/ruff/formatter/)
|
* [ruff-format](https://docs.astral.sh/ruff/formatter/)
|
||||||
|
* [ty](https://github.com/astral-sh/ty) :speech_balloon:
|
||||||
* [unimport](https://github.com/hakancelik96/unimport)
|
* [unimport](https://github.com/hakancelik96/unimport)
|
||||||
* [vulture](https://github.com/jendrikseipp/vulture) :warning: :floppy_disk:
|
* [vulture](https://github.com/jendrikseipp/vulture) :warning: :floppy_disk:
|
||||||
* [yapf](https://github.com/google/yapf)
|
* [yapf](https://github.com/google/yapf)
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('python', 'ty')
|
||||||
|
Save b:ale_python_auto_virtualenv
|
||||||
|
|
||||||
|
let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
|
||||||
|
|
||||||
|
After:
|
||||||
|
unlet! b:bin_dir
|
||||||
|
unlet! b:executable
|
||||||
|
|
||||||
|
call ale#test#SetFilename('..')
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The default ty command should be correct):
|
||||||
|
call ale#test#SetFilename('./foo.py')
|
||||||
|
|
||||||
|
AssertLinter 'ty', ale#Escape('ty') . ' server'
|
||||||
|
|
||||||
|
Execute(The ty executable should be configurable):
|
||||||
|
let g:ale_python_ty_executable = '~/.local/bin/ty'
|
||||||
|
|
||||||
|
AssertLinter '~/.local/bin/ty',
|
||||||
|
\ ale#Escape('~/.local/bin/ty') . ' server'
|
||||||
|
|
||||||
|
Execute(The cwd and project root should be detected correctly):
|
||||||
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
||||||
|
|
||||||
|
AssertLinterCwd ale#test#GetFilename('../test-files/python/with_virtualenv/subdir')
|
||||||
|
AssertLSPProject ale#test#GetFilename('../test-files/python/with_virtualenv/subdir')
|
||||||
|
|
||||||
|
Execute(FindProjectRoot should detect the project root directory via ty.toml):
|
||||||
|
call ale#test#SetFilename('../test-files/python/namespace_package_ty/namespace/foo/bar.py')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_ty'),
|
||||||
|
\ ale#python#FindProjectRoot(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The ty executable should be run from the virtualenv path):
|
||||||
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
||||||
|
|
||||||
|
let b:executable = ale#path#Simplify(
|
||||||
|
\ g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/ty'
|
||||||
|
\)
|
||||||
|
|
||||||
|
AssertLinter b:executable, ale#Escape(b:executable) . ' server'
|
||||||
|
|
||||||
|
Execute(You should be able to override the ty virtualenv lookup):
|
||||||
|
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
|
||||||
|
|
||||||
|
let g:ale_python_ty_use_global = 1
|
||||||
|
|
||||||
|
AssertLinter 'ty', ale#Escape('ty') . ' server'
|
||||||
|
|
||||||
|
Execute(Setting executable to 'pipenv' appends 'run ty'):
|
||||||
|
let g:ale_python_ty_executable = 'path/to/pipenv'
|
||||||
|
call ale#test#SetFilename('../test-files/dummy')
|
||||||
|
|
||||||
|
AssertLinter 'path/to/pipenv',
|
||||||
|
\ ale#Escape('path/to/pipenv') . ' run ty server'
|
||||||
|
|
||||||
|
Execute(Pipenv is detected when python_ty_auto_pipenv is set):
|
||||||
|
let g:ale_python_ty_auto_pipenv = 1
|
||||||
|
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
|
||||||
|
|
||||||
|
AssertLinter 'pipenv',
|
||||||
|
\ ale#Escape('pipenv') . ' run ty server'
|
||||||
|
|
||||||
|
Execute(Setting executable to 'poetry' appends 'run ty'):
|
||||||
|
let g:ale_python_ty_executable = 'path/to/poetry'
|
||||||
|
|
||||||
|
AssertLinter 'path/to/poetry',
|
||||||
|
\ ale#Escape('path/to/poetry') . ' run ty server'
|
||||||
|
|
||||||
|
Execute(Poetry is detected when python_ty_auto_poetry is set):
|
||||||
|
let g:ale_python_ty_auto_poetry = 1
|
||||||
|
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
|
||||||
|
|
||||||
|
AssertLinter 'poetry',
|
||||||
|
\ ale#Escape('poetry') . ' run ty server'
|
||||||
|
|
||||||
|
Execute(uv is detected when python_ty_auto_uv is set):
|
||||||
|
let g:ale_python_ty_auto_uv = 1
|
||||||
|
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
|
||||||
|
|
||||||
|
AssertLinter 'uv',
|
||||||
|
\ ale#Escape('uv') . ' run ty server'
|
||||||
|
|
||||||
|
Execute(Should accept configuration settings):
|
||||||
|
AssertLSPConfig {}
|
||||||
|
let b:ale_python_ty_config = {'ty': {'diagnosticMode': 'workspace'}}
|
||||||
|
AssertLSPConfig {'ty': {'diagnosticMode': 'workspace'}}
|
||||||
@@ -83,7 +83,7 @@ Execute(The defaults for the perl6 filetype should be correct):
|
|||||||
AssertEqual [], GetLinterNames('perl6')
|
AssertEqual [], GetLinterNames('perl6')
|
||||||
|
|
||||||
Execute(The defaults for the python filetype should be correct):
|
Execute(The defaults for the python filetype should be correct):
|
||||||
AssertEqual ['flake8', 'mypy', 'pylint', 'pyright', 'ruff'], GetLinterNames('python')
|
AssertEqual ['flake8', 'mypy', 'pylint', 'pyright', 'ruff', 'ty'], GetLinterNames('python')
|
||||||
|
|
||||||
let g:ale_linters_explicit = 1
|
let g:ale_linters_explicit = 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user