Skip to content

Latest commit

 

History

History
431 lines (331 loc) · 7.62 KB

File metadata and controls

431 lines (331 loc) · 7.62 KB

Python

:::info You can enable the extra with the :LazyExtras command. Plugins marked as optional will only be configured if they are installed. :::

Options

Additional options for this extra can be configured in your lua/config/options.lua file:

-- LSP Server to use for Python.
-- Set to "basedpyright" to use basedpyright instead of pyright.
vim.g.lazyvim_python_lsp = "basedpyright"
-- Set to "ruff_lsp" to use the old LSP implementation version.
vim.g.lazyvim_python_ruff = "ruff"

Below you can find a list of included plugins and their default settings.

:::caution You don't need to copy the default settings to your config. They are only shown here for reference. :::

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

opts = { ensure_installed = { "ninja", "rst" } }
{
  "nvim-treesitter/nvim-treesitter",
  opts = { ensure_installed = { "ninja", "rst" } },
}
opts = {
  servers = {
    ruff = {
      cmd_env = { RUFF_TRACE = "messages" },
      init_options = {
        settings = {
          logLevel = "error",
        },
      },
      keys = {
        {
          "<leader>co",
          LazyVim.lsp.action["source.organizeImports"],
          desc = "Organize Imports",
        },
      },
    },
    ruff_lsp = {
      keys = {
        {
          "<leader>co",
          LazyVim.lsp.action["source.organizeImports"],
          desc = "Organize Imports",
        },
      },
    },
  },
  setup = {
    [ruff] = function()
      Snacks.util.lsp.on({ name = ruff }, function(_, client)
        -- Disable hover in favor of Pyright
        client.server_capabilities.hoverProvider = false
      end)
    end,
  },
}
{
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      ruff = {
        cmd_env = { RUFF_TRACE = "messages" },
        init_options = {
          settings = {
            logLevel = "error",
          },
        },
        keys = {
          {
            "<leader>co",
            LazyVim.lsp.action["source.organizeImports"],
            desc = "Organize Imports",
          },
        },
      },
      ruff_lsp = {
        keys = {
          {
            "<leader>co",
            LazyVim.lsp.action["source.organizeImports"],
            desc = "Organize Imports",
          },
        },
      },
    },
    setup = {
      [ruff] = function()
        Snacks.util.lsp.on({ name = ruff }, function(_, client)
          -- Disable hover in favor of Pyright
          client.server_capabilities.hoverProvider = false
        end)
      end,
    },
  },
}
opts = function(_, opts)
  local servers = { "pyright", "basedpyright", "ruff", "ruff_lsp", ruff, lsp }
  for _, server in ipairs(servers) do
    opts.servers[server] = opts.servers[server] or {}
    opts.servers[server].enabled = server == lsp or server == ruff
  end
end
{
  "neovim/nvim-lspconfig",
  opts = function(_, opts)
    local servers = { "pyright", "basedpyright", "ruff", "ruff_lsp", ruff, lsp }
    for _, server in ipairs(servers) do
      opts.servers[server] = opts.servers[server] or {}
      opts.servers[server].enabled = server == lsp or server == ruff
    end
  end,
}
opts = nil
{
  "nvim-neotest/neotest-python",
}
opts = {}
{
  "mfussenegger/nvim-dap-python",
  -- stylua: ignore
  keys = {
    { "<leader>dPt", function() require('dap-python').test_method() end, desc = "Debug Method", ft = "python" },
    { "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" },
  },
  config = function()
    require("dap-python").setup("debugpy-adapter")
  end,
}
opts = {
  options = {
    notify_user_on_venv_activation = true,
  },
}
{
  "linux-cultist/venv-selector.nvim",
  cmd = "VenvSelect",
  opts = {
    options = {
      notify_user_on_venv_activation = true,
    },
  },
  --  Call config for Python files and load the cached venv automatically
  ft = "python",
  keys = { { "<leader>cv", "<cmd>:VenvSelect<cr>", desc = "Select VirtualEnv", ft = "python" } },
}

neotest (optional)

opts = {
  adapters = {
    ["neotest-python"] = {
      -- Here you can specify the settings for the adapter, i.e.
      -- runner = "pytest",
      -- python = ".venv/bin/python",
    },
  },
}
{
  "nvim-neotest/neotest",
  optional = true,
  dependencies = {
    "nvim-neotest/neotest-python",
  },
  opts = {
    adapters = {
      ["neotest-python"] = {
        -- Here you can specify the settings for the adapter, i.e.
        -- runner = "pytest",
        -- python = ".venv/bin/python",
      },
    },
  },
}

nvim-dap (optional)

opts = nil
{
  "mfussenegger/nvim-dap",
  optional = true,
  dependencies = {
    "mfussenegger/nvim-dap-python",
    -- stylua: ignore
    keys = {
      { "<leader>dPt", function() require('dap-python').test_method() end, desc = "Debug Method", ft = "python" },
      { "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" },
    },
    config = function()
      require("dap-python").setup("debugpy-adapter")
    end,
  },
}

nvim-cmp (optional)

opts = function(_, opts)
  opts.auto_brackets = opts.auto_brackets or {}
  table.insert(opts.auto_brackets, "python")
end
{
  "hrsh7th/nvim-cmp",
  optional = true,
  opts = function(_, opts)
    opts.auto_brackets = opts.auto_brackets or {}
    table.insert(opts.auto_brackets, "python")
  end,
}

Don't mess up DAP adapters provided by nvim-dap-python

opts = {
  handlers = {
    python = function() end,
  },
}
{
  "jay-babu/mason-nvim-dap.nvim",
  optional = true,
  opts = {
    handlers = {
      python = function() end,
    },
  },
}