Open gregorias opened 5 months ago
duplicate of #66
This is not a duplicate. #66 is about a failure by none-ls to create a temporary in a nonexistent path. This issue is about Mypy’s configuration being setup in such a way that none-ls sends a non-existent file name to Mypy. These two issues have most likely different causes.
Ah, my bad. Sorry for that.
I have the same problem in my windows installation of neovim. I thought this could be a problem with mypy, and cheched the source code for the mypy.lua file in diagnostics (https://github.com/nvimtools/none-ls.nvim/blob/main/lua/null-ls/builtins/diagnostics/mypy.lua). the default "args" option for mypy is the following function:
args = function(params)
return {
"--hide-error-codes",
"--hide-error-context",
"--no-color-output",
"--show-absolute-path",
"--show-column-numbers",
"--show-error-codes",
"--no-error-summary",
"--no-pretty",
"--shadow-file",
params.bufname,
params.temp_path,
params.bufname,
}
end,
I think the last flag, --shadow-file
, is causing the problem.
--shadow-file
has the following structure in mypy: --shadow-file SOURCE_FILE SHADOW_FILE
It is supposed to make mypy typecheck the SHADOW_FILE, while diagnostics still refer to SOURCE_FILE. However, in the repository of mypy there is a bug report open (https://github.com/python/mypy/issues/4746), that shows mypy complaining if the SOURCE_FILE doesn't exist when using --shadow-file
.
the report uses the following example:
mypy --shadow-file error.py shadow.py error.py
mypy: can't read file 'error.py': No such file or directory
and the structure of the default args in mypy.lua is equivalent to:
mypy <other flags>... --shadow-file bufname, temp_path, bufname
mypy complains that bufname does not exist, given that neovim opens a new buffer without saving by default, the same way it happens in the report. It is a issue with mypy and not null-ls/none-ls.
removing the --shadow-file
flag, and changing the positional args to only params.temp_path
, solves the issue.
local null_ls = require("null-ls")
local opts = {
sources = {
null_ls.builtins.diagnostics.mypy,
}
}
return opts
the error happens:
and mypy isn't active:
local null_ls = require("null-ls")
local opts = {
sources = {
null_ls.builtins.diagnostics.mypy.with({
args = function (params)
return {
"--hide-error-codes",
"--hide-error-context",
"--no-color-output",
"--show-absolute-path",
"--show-column-numbers",
"--show-error-codes",
"--no-error-summary",
"--no-pretty",
params.temp_path,
}
end
}),
}
}
return opts
the error is gone, and mypy is active:
The solution above partially worked for me. I still had to modify the diagnostic message to make sure it got linked to the correct buffer.
The cleanest solution as it would ideally be handled by the builtin internals.
null_ls.builtins.diagnostics.mypy.with({
-- see issue https://github.com/nvimtools/none-ls.nvim/issues/97
args = function (params)
return {
"--hide-error-codes",
"--hide-error-context",
"--no-color-output",
"--show-absolute-path",
"--show-column-numbers",
"--show-error-codes",
"--no-error-summary",
"--no-pretty",
params.temp_path,
}
end,
on_output = function(line, params)
line = line:gsub(params.temp_path:gsub("([^%w])", "%%%1"), params.bufname)
return null_ls.builtins.diagnostics.mypy._opts.on_output(line, params)
end,
}),
FAQ
Issues
Neovim Version
v0.9.5
Dev Version?
Operating System
macOS Sonoma 14.4
Minimal Config
Steps to Reproduce
nvim --clean -u minimal_init.lua
:e bar.py
.Reproducibility Check
minimal_init.lua
template and that my issue is reproducible by runningnvim --clean -u minimal_init.lua
and following the steps above.Expected Behavior
No warning is displayed.
Actual Behavior
A warning message gets displayed:
Debug Log
Help
Yes
Implementation Help
Hints for how to change the default Mypy config to work with buffers not backed by files.
Requirements