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

Discussão em 'Python' iniciado por Stack, Agosto 2, 2025.

  1. Stack

    Stack Membro Participativo

    I setup Neovim LSP using the nvim-lspconfig and the lsp-installer where I also installed the pyright server.

    Without any further configuration it worked out of the box. However when I have a class in a subfolder and add a new method, pyright does not recognize this method when I want to access it in a different file. When I restart neovim, or open and close the file, pyright suddenly recognizes the newly added method.

    I also tried :LspRestart with no effect.

    I tried to add some settings to the pyright server:

    return {
    settings = {
    python = {
    analysis = {
    autoSearchPaths = true,
    diagnosticMode = "workspace",
    useLibraryCodeForTypes = true,
    }
    }

    },
    }


    But this also had no effect.

    :LspLog also does not show anything which could point to the issue:

    [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"


    I also could not find any setting regarding to this issue here which could solve this.

    Since I am new to python, the way I import and structure classes might not be common and might be an issue which could cause this problem.

    • As a main entry point I have main.py in the root folder
    • All other source files are in a program/ folder which does not have a __init__.py
    • Inside program/ there are folders which each have a __init__.py file f.e. core/

    core/__init__.py:

    from .myClass import myClass


    and in main.py I import it like this:

    from subfolder.core import myClass
    myClass.newMethod() # this is only recognized by lsp/pyright after the file is closed and reopen


    Is the issue a bug in pyright (not likely I guess), a missing setting or my strange folder/import structure?

    Continue reading...

Compartilhe esta Página