簡體   English   中英

Neovim LSP:pyright 服務器不會動態識別子文件夾中的更改

[英]Neovim LSP: pyright server does not dynamically regognize changes in sub folders

我使用nvim-lspconfiglsp-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__.pyprogram/文件夾中
  • 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM