lsp-pyright
官方文档
// Settings in here override those in "LSP-pyright/LSP-pyright.sublime-settings"
{
"settings": {
// Use a predefined setup from this plugin, valid values are:
// - "": An empty string does nothing.
// - "sublime_text": Suitable for people who are developing ST Python plugins.
// The Python version which this plugin runs on will be used.
// `sys.path` from plugin_host will be added into "python.analysis.extraPaths"
// so ST package dependecies can be resolved by the LSP server.
// - "sublime_text_33": Similar to "sublime_text" but Python 3.3 forced.
// - "sublime_text_38": Similar to "sublime_text" but Python 3.8 forced.
"pyright.dev_environment": "sublime_text_38",
// Offer auto-import completions.
"python.analysis.autoImportCompletions": true,
// Automatically add common search paths like 'src'?
"python.analysis.autoSearchPaths": true,
// Additional import search resolution paths
"python.analysis.extraPaths": [],
// Path to directory containing custom type stub files.
"python.analysis.stubPath": "./typings",
// "openFilesOnly" or "workspace"
"python.analysis.diagnosticMode": "openFilesOnly",
// Allows a user to override the severity levels for individual diagnostics.
// @see https://github.com/microsoft/pyright/blob/master/docs/configuration.md#type-check-diagnostics-settings
"python.analysis.diagnosticSeverityOverrides": {
"reportDuplicateImport ": "warning",
"reportImplicitStringConcatenation": "warning",
"reportUnboundVariable": "warning",
"reportUninitializedInstanceVariable": "none",
"reportUnusedClass": "information",
"reportUnusedFunction": "information",
"reportUnusedImport": "information",
"reportUnusedVariable": "information",
"reportGeneralTypeIssues": "none"
},
// Specifies the level of logging for the Output panel
"python.analysis.logLevel": "Information",
// Defines the default rule set for type checking.
"python.analysis.typeCheckingMode": "basic",
// Paths to look for typeshed modules.
// Hmm... doesn't seem to work on my side. May track https://github.com/microsoft/pylance-release/issues/29
"python.analysis.typeshedPaths": [],
// Use library implementations to extract type information when type stub is not present.
"python.analysis.useLibraryCodeForTypes": true,
// Disables type completion, definitions, and references.
"pyright.disableLanguageServices": false,
// Disables the "Organize Imports" command.
"pyright.disableOrganizeImports": false,
// Path to Python, you can use a custom version of Python.
// "python.pythonPath": "D:\\CPS\\python\\Python375_64\\python.exe",
"python.pythonPath": "W:/CPS/python/Python310_64/python", // 注意这里不要使用 .exe 作后缀
// Path to folder with a list of Virtual Environments.
"python.venvPath": ""
}
}
添加poetry的虚拟环境目录
首先配置poetry的配置文件,开启create
选项后,每个项目的根目录都会创建一个.venv
目录用来存放该项目要用到的环境文件。
# config.toml
[virtualenvs]
create = true # 始终使用虚拟环境
然后配置lsp-pyright
插件:Preferences > Package Settings > LSP > Servers > lsp-pyright
将对应的目录添加进扫描范围
{
"settings": {
// 在本字段添加即可
"python.analysis.extraPaths": [".venv",".venv/Lib",".venv/Lib/site-packages"],
}
}
这样lsp-pyright
就能对每个项目的虚拟环境都进行扫描了:
补充一种可以跟随项目让lsp-pyright自动扫描的配置,在项目根目录下创建:pyrightconfig.json
,添加extraPaths
字段。
{
"extraPaths": [".venv",".venv/Lib",".venv/Lib/site-packages"],
}