It's minimal, but I'm posting things.
pyright-langserver
in VimCoding some Python in Vim is enhanced by the use of a LSP (language server protocol) specific to Python.
After some trial and error (there are many LSPs for Python), I find pyright from Microsoft to be the most pleasing.
However, by default, the typehint analysis is too verbose and too strict for my purpose.
Here is how you can disable most disagnostics relative to typehints for pyright
.
This assumes you are using the helpful mattn/vim-lsp-settings plugin for Vim.
If not, this page should still give you pointers.
In your configuration file, add something similar to the following, customizing where you'd like the settings file to be.
let g:lsp_settings_global_settings_dir = expand('~') . "/.lsp-settings.json"
This is what I have inside my .lsp-settings.json
file:
{
"pyright-langserver": {
"args": [
"--stdio",
"-p ~/.pyrightconfig-global.json"
]
}
}
The -p
argument allows us to specify which .pyrightconfig
to load when the pyright lsp
starts up.
By default,
pyright
only read a.pyrightconfig
file at the root of every project. This solution allows us to have a global settings file.
.pyrightconfig-global.json
fileThe full documentation for the values you may customize is available: https://github.com/microsoft/pyright/blob/1f42e17eb3a036271dd17b79a7eb5593c10aae46/docs/configuration.md
The contents of my .pyrightconfig-global.json
file are:
{
"exclude": [
"**/node_modules",
"**/__pycache__"
],
"pythonVersion": "3.10",
"pythonPlatform": "Linux",
"reportMissingImports": true,
"reportMissingTypeStubs": false,
"verboseOutput": true,
"typeCheckingMode": "off"
}
The most important setting for us is: "typeCheckingMode": "off"
As per the documentation:
The default value for this setting is "basic". If set to "off", all type-checking rules are disabled, but Python syntax and semantic errors are still reported.
That's it!