I have pyright set up as an lsp in neovim and my configuration is like this:

  on_attach = on_attach,
  capabilities = capabilities,
  root_dir = function(fname)
    local root_files = {
    return util.root_pattern(table.unpack(root_files))(fname)
        or util.find_git_ancestor(fname)
        or util.path.dirname(fname)
  flags = { debounce_text_changes = 300 },
  settings = {
    python = {
      analysis = {
        autoSearchPaths = true,
        diagnosticMode = "openFilesOnly",
        useLibraryCodeForTypes = true,
        typeCheckingMode = "basic",

I have some questions regarding the configuration above:

1- When I set root_dir = util.root_pattern(vim.loop.cwd()) the root_dir in LspInfo is always set as / even if my current working directory is somewhere else. Why does that happen?

2- What's the function of debounce_text_changes = 300 flag?

3- In this configuration, it sets the root_dir current working directory if there's no project file found. However I want it to run in single file mode when there are no project files/folders (eg .git/setup.py) exist. How do I accomplish that?

4- What does autoSearchPaths = true do?

5- What does using LibraryCode for Types mean? What is LibraryCode and what are Types?

Thank you in advance! All the best

  • Never ever paste any code/configuration/anything you don't understand into your system.
    – Friedrich
    Jan 23 at 8:19

2 Answers 2


I would try:

root_dir = vim.loop.cwd()

The debounce_text_changes parameter control how often the server is query (if set to 300 the LSP server will be query maximum every 300 ms even if you type three character in that interval)

The autoSearchPath is an option that make the LSP server looking for some additional locations to resolve import (it seems that currently it is only the src subfolder see code)

The LSP server needs to deduce the signature of the library function you ate using in your code (e.g. to deduce/check the type compatibility) it can deduce it from stub if any or from an analysis of the library code.


The workspaces mechanism is one of the worst mechanisms in neovim. You don't want it to be the root folder. I used to add a folder to workspaces folders, but then it came back to me whenever I switched project.

How I solved it?

function _G.set_workspace_dir(dir)
    local folders = vim.lsp.buf.list_workspace_folders()
    for i = 1, #folders do
        if dir ~= folders[i] then

path = vim.fn.stdpath("data") .. "/workspaces",
 hooks = {
        open =  function()
 print("workspace dir is " .. require'workspaces'.path())
    vim.keymap.set('n', '_ws', function() 
        _G.set_workspace_dir(vim.fn.input('Directory: ',vim.fn.getcwd())) 

Uses natecraddock/workspaces.nvim to provide a single folder path to each project (called workspace). So when I open the workspace ,it sets the right path. And I use this function to set manually the workspace dir if needed.

Regarding 3, you can remove all folders from workspaces list(accessible by vim.lsp.buf.list_workspace_folders()) , using a code similar to the defined function.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.