[英]Finding definitions of modules which are parameters with LSP (pyright)
[英]Neovim LSP: pyright server does not dynamically regognize changes in sub folders
我使用nvim-lspconfig和lsp-installer設置 Neovim LSP,我還安裝了pyright
服務器。
沒有任何進一步的配置,它開箱即用。 但是,當我在子文件夾中有 class 並添加新方法時,當我想在不同的文件中訪問它時,pyright 無法識別此方法。 當我重新啟動neovim,或者打開和關閉文件時,pyright突然識別出新添加的方法。
我也試過:LspRestart
沒有效果。
我嘗試向 pyright 服務器添加一些設置:
return {
settings = {
python = {
analysis = {
autoSearchPaths = true,
diagnosticMode = "workspace",
useLibraryCodeForTypes = true,
}
}
},
}
但這也沒有效果。
:LspLog
也沒有顯示任何可能指向問題的內容:
[START][2022-07-15 11:11:05] LSP logging initiated
[WARN][2022-07-15 11:11:09] ...lsp/handlers.lua:109 "The language server pyright triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[WARN][2022-07-15 11:11:09] ...lsp/handlers.lua:456 "stubPath typings is not a valid directory."
[WARN][2022-07-15 11:11:20] ...lsp/handlers.lua:109 "The language server pyright triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"
我在這里也找不到任何關於這個問題的設置來解決這個問題。
由於我是 python 的新手,因此我導入和構造類的方式可能並不常見,並且可能是導致此問題的問題。
main.py
__init__.py
的program/
文件夾中program/
里面有文件夾,每個文件夾都有一個__init__.py
文件 fe core/
core/__init__.py
:
from .myClass import myClass
在main.py
我像這樣導入它:
from subfolder.core import myClass
myClass.newMethod() # this is only recognized by lsp/pyright after the file is closed and reopen
問題是 pyright 中的錯誤(我猜不太可能),缺少設置還是我奇怪的文件夾/導入結構?
你可以試試這個:創建(或修改)pyproject.toml,把它放在項目根目錄下。 在 pyproject.toml 中,添加以下行:
[tool.pyright]
extraPaths = ["program/core" ,"program/directory_2", "program/directory_3"]
這個想法是您必須手動添加子目錄,這確實很乏味,但至少它適用於我的情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.