telescope.nvim icon indicating copy to clipboard operation
telescope.nvim copied to clipboard

Folds are not applied when opening with Telescope

Open danielnehrig opened this issue 2 years ago • 6 comments

Description

When opening a file with Telescope folds are not applied but when opening a file with :e path/to/file.lua folds are applied as they should

note: this is using the treesitter folding method

Neovim version

NVIM v0.5.0 Build type: Release LuaJIT 2.1.0-beta3 Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210702-14987-rep9di/neovim-0.5.0/build/config -I/tmp/neovim-20210702-14987-rep9di/neovim-0.5.0/src -I/usr/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20210702-14987-rep9di/neovim-0.5.0/build/src/nvim/auto -I/tmp/neovim-20210702-14987-rep9di/neovim-0.5.0/build/include Compiled by brew@BigSur

Features: +acl +iconv +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/local/Cellar/neovim/0.5.0/share/nvim"

Run :checkhealth for more info

Operating system and version

big sur 11.2.3 and Arch linux

checkhealth telescope

1 health#telescope#check
 2 ========================================================================
 3 ## Checking for required plugins
 4 ▏ - OK: plenary installed.
 5 ▏ - OK: nvim-treesitter installed.
 6
 7 ## Checking external dependencies
 8 ▏ - OK: rg: found ripgrep 12.1.1
 9 ▏ - OK: fd: found fd 8.2.1
10
11 ## ===== Installed extensions =====
12
13 ## Telescope Extension: `dotfiles`
14 ▏ - INFO: No healthcheck provided
15
16 ## Telescope Extension: `file_create`
17 ▏ - INFO: No healthcheck provided
18
19 ## Telescope Extension: `fzf`
20 ▏ - INFO: No healthcheck provided
21
22 ## Telescope Extension: `project`
23 ▏ - INFO: No healthcheck provided
 1 health#telescope#check
 2 ========================================================================
 3 ## Checking for required plugins
 4 ▏ - OK: plenary installed.
 5 ▏ - OK: nvim-treesitter installed.
 6
 7 ## Checking external dependencies
 8 ▏ - OK: rg: found ripgrep 12.1.1
 9 ▏ - OK: fd: found fd 8.2.1
10
11 ## ===== Installed extensions =====
12
13 ## Telescope Extension: `dotfiles`
14 ▏ - INFO: No healthcheck provided
15
16 ## Telescope Extension: `file_create`
17 ▏ - INFO: No healthcheck provided
18
19 ## Telescope Extension: `fzf`
20 ▏ - INFO: No healthcheck provided
21
22 ## Telescope Extension: `project`
23 ▏ - INFO: No healthcheck provided

Steps to reproduce

  1. nvim -nu minimal.lua
  2. apply folding settings from treesitter
    -- fold settings
    vim.wo.foldmethod = "expr"
    vim.wo.foldexpr = "nvim_treesitter#foldexpr()"
    vim.wo.foldtext =
        [[substitute(getline(v:foldstart),'\\t',repeat('\ ',&tabstop),'g').'...'.trim(getline(v:foldend)) ]]
    vim.wo.fillchars = "fold:\\"
    vim.wo.foldnestmax = 3
    vim.wo.foldminlines = 1
  1. open a file with telescope

Expected behavior

Buffer is folded when buffer is opened

Actual behavior

When buffer is opened the folds are not applied

Minimal config

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
    require("packer").startup({
        {
            "wbthomason/packer.nvim",
            {
                "nvim-telescope/telescope.nvim",
                requires = {
                    "nvim-lua/plenary.nvim",
                    {
                        "nvim-telescope/telescope-fzf-native.nvim",
                        run = "make",
                    },
                },
            },
            {
                "nvim-treesitter/nvim-treesitter",
            },
            -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
        },
        config = {
            package_root = package_root,
            compile_path = install_path .. "/plugin/packer_compiled.lua",
            display = { non_interactive = true },
        },
    })
end
_G.load_config = function()
    require("telescope").setup()
    require("telescope").load_extension("fzf")
    vim.wo.foldmethod = "expr"
    vim.wo.foldexpr = "nvim_treesitter#foldexpr()"
    vim.wo.foldtext =
        [[substitute(getline(v:foldstart),'\\t',repeat('\ ',&tabstop),'g').'...'.trim(getline(v:foldend)) ]]
    vim.wo.fillchars = "fold:\\"
    vim.wo.foldnestmax = 3
    vim.wo.foldminlines = 1

    require("nvim-treesitter.configs").setup({
        ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
        highlight = {
            enable = true,
        },
        indent = {
            enable = true,
        },
        autotag = {
            enable = true,
        },
    })
end
if vim.fn.isdirectory(install_path) == 0 then
    print("Installing Telescope and dependencies.")
    vim.fn.system({
        "git",
        "clone",
        "--depth=1",
        "https://github.com/wbthomason/packer.nvim",
        install_path,
    })
end
load_plugins()
require("packer").sync()
vim.cmd(
    [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
)

danielnehrig avatar Sep 22 '21 01:09 danielnehrig

dup of #559

TLDR: i dont know how to fix it and the workaround that worked in the past no longer works.

Conni2461 avatar Sep 22 '21 06:09 Conni2461

fixed by #1643 Closing

Conni2461 avatar Jan 09 '22 17:01 Conni2461

I had to revert the PR :(

Conni2461 avatar Jan 09 '22 20:01 Conni2461

Any progress here? I'm surprised to see this bug and the lack of interest. Perhaps you have all found a workaround?

lervag avatar Aug 18 '22 12:08 lervag

I am using the workaround described here: https://github.com/tmhedberg/SimpylFold/issues/130#issuecomment-1074049490

christoph-blessing avatar Aug 18 '22 12:08 christoph-blessing

Thanks; I found the same solution in #559 as well and it works for me. But it is silly that we need this at all. :\

lervag avatar Aug 18 '22 12:08 lervag

I have the same issue as well

DasOhmoff avatar Oct 27 '22 15:10 DasOhmoff

@lervag I agree. this is also ruining indent lines for me. Can someone please look into it.

chaudry-786 avatar Jan 06 '23 16:01 chaudry-786

+1. very annoying

tummetott avatar Feb 13 '23 20:02 tummetott

I guess this might not be a problem of telescope, and instead it might be a bug of neovim (or treesitter):

this is a minimal example:

suppose I am at my neovim root directory (~/.config/nvim), and I have defined the following command:

vim.o.foldmethod = 'expr'
vim.o.foldexpr = 'nvim_treesitter#foldexpr()'
vim.keymap.set('i', '<C-x>', function() vim.cmd.edit 'lua/conf/builtin_extend.lua' end)

and typing <C-x> within any file (say init.lua) and then the fold is not activated in the builtin_extend.lua just opened.

It is also worthy to note that telescope plays nicely with set foldmethod=indent.

milanglacier avatar May 04 '23 06:05 milanglacier

folds were fixed in https://github.com/nvim-telescope/telescope.nvim/pull/2726 fix is applied to latest master, 0.1.x and the latest stable release 0.1.4

Conni2461 avatar Oct 11 '23 06:10 Conni2461