kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.3k stars 47 forks source link

Imports not foldable in Python #142

Closed brokencode64 closed 10 months ago

brokencode64 commented 1 year ago

Neovim version

Nvim v0.9.1

Operating system/version

Arch Linux - Kernel 6.4.1

How to reproduce the issue

Ufo plugin installation:

use{ 'kevinhwang91/nvim-ufo',
    requires = {
        'kevinhwang91/promise-async',
    },
    config = function()
        require('config.ufo').setup()
    end
 }

Ufo configuration:

local M = {}

function M.setup()

  local handler = function(virtText, lnum, endLnum, width, truncate)
    . . .
  end

  require('ufo').setup({
    fold_virt_text_handler = handler,
    close_fold_kinds = {
      'imports',
      'comment'
    },
  })
end

return M

Lsp client setup:

local M = {}

local coq = require('coq')
local icons = require('config.icons')

function M.setup()
  local signs = {
   . . .

end

function M.on_attach(client, bufnr)
 vim.api.nvim_buf_set_option(bufnr, "formatexpr", "v:lua.vim.lsp.formatexpr()")

  -- Key mappings
  require('config.lsp.maps').setup(client, bufnr)

  -- Highlighting
  require("config.lsp.highlighter").setup(client, bufnr)

  -- Formatting
  --require("config.lsp.null-ls.formatters").setup(client, bufnr)

  -- Tagfunc
  if client.server_capabilities.definitionProvider then
    vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc")
  end
end

M.capabilities = vim.lsp.protocol.make_client_capabilities()
M.capabilities.textDocument.completion.completionItem.snippetSupport = true
M.capabilities.textDocument.foldingRange = {dynamicRegistration = false, lineFoldingOnly = true}
M.capabilities = coq.lsp_ensure_capabilities()

return M

Neovim fold options (I have tried different settings here):

opt.foldcolumn     = '1'
opt.foldlevel      = 99
opt.foldlevelstart = -1
opt.foldenable     = true

Running Lspinfo confirms pylsp is connected.

Running UfoInspect shows this:

Buffer: 33
Fold Status: start
Main provider: lsp
Fallback provider: indent
Selected provider: lsp
Fold kinds:

Expected behavior

Import lines should be foldable in python files.

Actual behavior

Trying to fold imports results in "no fold found" when editing python files.

Everything else will fold.

Imports do work for typescript.

rockyzhang24 commented 1 year ago

Maybe the kind field doesn't include imports for your language server (use UFO_LOG=info nvim, tail -f ~/.cache/nvim/ufo.log to double check`). So it cannot be folded automatically by default due to no support by LSP itself. Instead, you may define your own provider to include the range of code you want to fold. I think this (https://github.com/kevinhwang91/nvim-ufo/issues/125) may be a good reference for you.

fecet commented 1 year ago

Sorry can I disable https://github.com/kevinhwang91/nvim-ufo/issues/64 on start? I check https://github.com/kevinhwang91/nvim-ufo/issues/136 but have no idea

rockyzhang24 commented 1 year ago

@fecet Disable what? Disable "automatically fold the imports"? If so, remove imports from close_fold_kinds in your ufo config.

fecet commented 1 year ago

Thanks! Sorry for not reading doc carefully

kevinhwang91 commented 10 months ago

stale