diff options
| author | Jędrzej Boczar <yendreij@gmail.com> | 2021-01-08 00:52:30 +0100 |
|---|---|---|
| committer | Thomas Vigouroux <tomvig38@gmail.com> | 2021-01-14 13:54:43 +0100 |
| commit | 252472081ebad7190002a0aa2560481cef426721 (patch) | |
| tree | 7a7ccb86b3729cccbd58935923c55515ba3eb090 /lua | |
| parent | indent: add Python @return queries (diff) | |
| download | nvim-treesitter-252472081ebad7190002a0aa2560481cef426721.tar nvim-treesitter-252472081ebad7190002a0aa2560481cef426721.tar.gz nvim-treesitter-252472081ebad7190002a0aa2560481cef426721.tar.bz2 nvim-treesitter-252472081ebad7190002a0aa2560481cef426721.tar.lz nvim-treesitter-252472081ebad7190002a0aa2560481cef426721.tar.xz nvim-treesitter-252472081ebad7190002a0aa2560481cef426721.tar.zst nvim-treesitter-252472081ebad7190002a0aa2560481cef426721.zip | |
indent: introduce @ignore to avoid indenting some nodes (e.g. comments)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/indent.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lua/nvim-treesitter/indent.lua b/lua/nvim-treesitter/indent.lua index 5f346d643..83b706730 100644 --- a/lua/nvim-treesitter/indent.lua +++ b/lua/nvim-treesitter/indent.lua @@ -35,6 +35,7 @@ local get_indents = utils.memoize_by_buf_tick(function(bufnr) indents = get_map('@indent.node'), branches = get_map('@branch.node'), returns = get_map('@return.node'), + ignores = get_map('@ignore.node'), } end) @@ -85,15 +86,24 @@ function M.get_indent(lnum) node = node:parent() end + local first = true local prev_row = node:start() while node do - node = node:parent() - local row = node and node:start() or prev_row - if q.indents[node_fmt(node)] and prev_row ~= row then + -- do not indent if we are inside an @ignore block + if q.ignores[node_fmt(node)] and node:start() < lnum-1 and node:end_() > lnum-1 then + return -1 + end + + -- do not indent the starting node, do not add multiple indent levels on single line + local row = node:start() + if not first and q.indents[node_fmt(node)] and prev_row ~= row then indent = indent + indent_size prev_row = row end + + node = node:parent() + first = false end return indent |
