0

I have a project that is structured something like this

--project_name
|- bin/main.py
|- some_module
    |- file_a.py
    |- file_b.py
    |- ...
|- .vscode/launch.json
import sys
from some_module.file_a import func

print("\n".join(sys.path))

print(func())

I use nvim with lspconfig and dap/dap-python for development/debugging. I have a launch.json, which configures the debugging of the project for dap-python. It looks something like this

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Main.py",
            "type": "python",
            "request": "launch",
            "console": "integratedTerminal",
            "justMyCode": true,
            "cwd": "${fileDirname}",
            "env": {"PYTHONPATH": "${workspaceFolder}:${env:PYTHONPATH}"},
            "program": "${workspaceFolder}/bin/main.py"
        }
    ]
}

Assuming I am in the project_name directory and run vim . and then open bin/main.py I can set breakpoints and debug as one would expect. Also, if I print the PYTHONPATH, everything has been adjusted as per the launch.json file.

The problem is that pyright is complaining about the import statement from some_module.file_a import func. It says MissingImport. My lspconfig.lua looks like this

local capabilities = vim.lsp.protocol.make_client_capabilities()

local servers = { "pyright", ... }

for _, lsp in ipairs(servers) do
    require("lspconfig")[lsp].setup {
        on_attach = on_attach,
        capabilities = capabilities,
    }
end

Is there an easy way to adjust the lspconfig for pyright in such a way that it looks for modules anywhere in the current-working-directory and all of its subdirectories?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.