lukas-reineke / indent-blankline.nvim

Indent guides for Neovim
MIT License
4.2k stars 104 forks source link

Current context not work for new line(new code), I miss something? #268

Closed yyangdid closed 2 years ago

yyangdid commented 3 years ago

Neovim version: v0.5.1

System: openSUSE x64

Everything is ok when opening the file. When adding new code to the file, the indent line highlight not work for new line. there is a gif(need to click the picture with the mouse to play it in the new tab):

aaa (2)

this is my config:


call plug#begin(stdpath('config') . '/plugged')
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'lukas-reineke/indent-blankline.nvim' 
call plug#end()

lua << EOF
vim.g.indent_blankline_show_current_context = true
vim.g.indent_blankline_use_treesitter = 1
vim.g.indent_blankline_context_patterns = {
  'class',
  'function',
  'method',
  '^if',
  '^while',
  '^typedef',
  '^for',
  '^object',
  '^table',
  'block',
  'arguments',
  'typedef',
  'while',
  '^public',
  'return',
  'if_statement',
  'else_clause',
  'jsx_element',
  'jsx_self_closing_element',
  'try_statement',
  'catch_clause',
  'import_statement',
  'labeled_statement'
}
vim.g.indent_blankline_buftype_exclude = {"terminal"}
vim.g.indent_blankline_show_trailing_blankline_indent = false

vim.cmd [[highlight IndentBlanklineIndent1 guifg=#E06C75 gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent2 guifg=#E5C07B gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent3 guifg=#98C379 gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent4 guifg=#56B6C2 gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent5 guifg=#61AFEF gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent6 guifg=#C678DD gui=nocombine]]

require("indent_blankline").setup {
  context_highlight_list = {
    "IndentBlanklineIndent1",
    "IndentBlanklineIndent2",
    "IndentBlanklineIndent3",
    "IndentBlanklineIndent4",
    "IndentBlanklineIndent5",
    "IndentBlanklineIndent6",
  },
  show_current_context = true,
}
EOF
augroup IndentBlanklineContextAutogroup
    autocmd!
    autocmd CursorMoved * IndentBlanklineRefresh
augroup END
lukas-reineke commented 3 years ago

Doesn't look like you are doing anything wrong, this should work.

I am currently on vacation, I'll take a look once I'm back

yyangdid commented 3 years ago

Ok, thank you.

I did a test, delete most of the config, just keep base and two plugins, still not work for me.

All my config for nvim :

set expandtab
set smarttab
set tabstop=2
set shiftwidth=2
set softtabstop=2

filetype on
filetype indent on
filetype plugin on
set smartindent

" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
call plug#begin(stdpath('config') . '/plugged')
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'lukas-reineke/indent-blankline.nvim'
call plug#end()

" indent-blankline.nvim ------------------------------------------------------
lua << EOF
vim.g.indent_blankline_show_current_context = true
--vim.g.indent_blankline_context_highlight_list = {'Error', 'Warning'}
--vim.g.indent_blankline_context_pattern_highlight = {'function', 'Function'}
vim.g.indent_blankline_use_treesitter = 1
vim.g.indent_blankline_context_patterns = {
  'class',
  'function',
  'method',
  '^if',
  '^while',
  '^typedef',
  '^for',
  '^object',
  '^table',
  'block',
  'arguments',
  'typedef',
  'while',
  '^public',
  'return',
  'if_statement',
  'else_clause',
  'jsx_element',
  'jsx_self_closing_element',
  'try_statement',
  'catch_clause',
  'import_statement',
  'labeled_statement'
}

vim.g.indent_blankline_char = '│'

vim.g.indent_blankline_filetype_exclude = {'help','startify','nerdtree'}
vim.g.indent_blankline_buftype_exclude = {"terminal"}

vim.g.indent_blankline_show_trailing_blankline_indent = false

vim.cmd [[highlight IndentBlanklineIndent1 guifg=#E06C75 gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent2 guifg=#E5C07B gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent3 guifg=#98C379 gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent4 guifg=#56B6C2 gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent5 guifg=#61AFEF gui=nocombine]]
vim.cmd [[highlight IndentBlanklineIndent6 guifg=#C678DD gui=nocombine]]

require("indent_blankline").setup {
  context_highlight_list = {
    "IndentBlanklineIndent1",
    "IndentBlanklineIndent2",
    "IndentBlanklineIndent3",
    "IndentBlanklineIndent4",
    "IndentBlanklineIndent5",
    "IndentBlanklineIndent6",
  },
  show_current_context = true,
}

--vim.cmd('autocmd CursorMoved * IndentBlanklineRefresh')
EOF
augroup IndentBlanklineContextAutogroup
    autocmd!
    autocmd CursorMoved * IndentBlanklineRefresh
augroup END

We'll discuss it when your vacation is over, have a nice vacation.

lukas-reineke commented 3 years ago

I can't reproduce this.

Can you try to run this in the block that is not working? :lua print(require "indent_blankline.utils".get_current_context(vim.g.indent_blankline_context_patterns))

yyangdid commented 3 years ago

Like this? 123456

lukas-reineke commented 3 years ago

Like this?

Yes. So the plugin is updating correctly, but it is not finding the if statement. This looks like it is an issue with treesitter. I still can't reproduce this, can you try updating Neovim and treesitter? Maybe it was a bug there that is already fixed. You can also open :TSPlaygroundToggle and see what treesitter thinks this is.

yyangdid commented 2 years ago

fixed! 👍

goingtosleep commented 2 years ago

fixed! +1

@yyangdid How did you fix it? I encountered this in Python. But run:

:lua print(require "indent_blankline.utils".get_current_context(vim.g.indent_blankline_context_patterns))

shows false. The treesitter seems to not update the newly pasted code. Updated neovim and treesitter but still not working. A workaround is to run :e but that will mess up the folding 😖

yyangdid commented 2 years ago

I haven't used nvim for some time, I can't remember how it was solved at that time.

In fact, I've converted to VSCode + remote-ssh.

But I backed up my nvim configuration, you can check these two config files:

I hope it helps, good luck.