Problem:
`LanguageTree:for_each_tree` calls itself for child nodes, so when we
calls `for_each_tree` inside `for_each_tree`, this quickly leads to
exponential tree calls.
Solution:
Use `pairs(child:trees())` directly in this case, as we don't need the
extra callback for each children, this is already handled from the outer
`for_each_tree` call
(cherry picked from commit 0712a4c085)
Co-authored-by: Pham Huy Hoang <hoangtun0810@gmail.com>
`LanguageTree:parse` is recursive, and calls
`LanguageTree:for_each_child`, which is also recursive.
That means that, starting from the third level (child of child of root),
nodes will be parsed twice.
Which then means that if the tree is N layers deep, there will be ~2^N
parses even if the branching factor is 1.
Fixes: #25104
Problem:
'endofline' can be used to detect if a file ends of <EOL>, however
editorconfig can break this.
Solution:
Set 'endofline' during BufWritePre
Fixes: #24869
(cherry picked from commit 84376afc72)
When an injection has not set include children, make sure not to add
the injection if no ranges are determined.
This could happen when there is an injection with a child that has the
same range as itself. e.g. consider this Makefile snippet
```make
foo:
$(VAR)
```
Line 2 has an injection for bash and a make variable reference. If
include-children isn't set (default), then there is no range on line 2
to inject since the variable reference needs to be excluded.
This caused the language tree to return an empty range, which the parser
now interprets to mean the full buffer. This caused makefiles to have
completely broken highlighting.
Backports #24550.
Adjusts test to expect that didChangeWatchedFiles is *not* registered if
client `capabilities` is nil (as it's not enabled by default for v0.9).
fix(fs): make `normalize()` work with '/' path
Problem: Current implementation of "remove trailing /" doesn't
account for the case of literal '/' as path.
Solution: Remove trailing / only if it preceded by something else.
(cherry picked from commit 80ff66118a)
Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
fix(codelens): add buffer and line checks before displaying codelens
(cherry picked from commit 928dc33053)
Co-authored-by: Rohit Sukumaran <rohit.sukumaran@kredx.com>
fix(lsp): don't register didChangeWatchedFiles when capability not set
Some LSP servers (tailwindcss, rome) are known to request registration
for `workspace/didChangeWatchedFiles` even when the corresponding client
capability does not advertise support. This change adds an extra check
in the `client/registerCapability` handler not to start a watch unless
the client capability is set appropriately.
(cherry picked from commit 78510add5b)
Co-authored-by: Jon Huhn <huhnjon@gmail.com>
fix(lsp): fix relative patterns for `workspace/didChangeWatchedFiles`
(cherry picked from commit 10f102a3a3)
Co-authored-by: Jon Huhn <huhnjon@gmail.com>
Current behaviour of `:Man` is to only work with "number" sections.
This is caused by wrong assumptions about man sections naming.
Also, there was similar assumption about length of section dirs
in `paths` variable.
fixes#23485
Signed-off-by: Vadim Misbakh-Soloviov <git@mva.name>
(cherry picked from commit 209ed16f57)
perf(lsp): load buffer contents once when processing semantic token responses
Using _get_line_byte_from_position() for each token's boundaries was a
pretty huge bottleneck, since that function would load individual buffer
lines via nvim_buf_get_lines() (plus a lot of extra overhead). So each
token caused two calls to nvim_buf_get_lines() (once for the start
position, and once for the end position).
For semantic tokens, we only attach to buffers that have already been
loaded, so we can safely just get all the lines for the entire buffer at
once, and lift the rest of the _get_line_byte_from_position()
implementation directly while bypassing the part that loads the buffer
line.
While I was looking at get_lines (used by _get_line_byte_from_position),
I noticed that we were checking for non-file URIs before we even looked
to see if we already had the buffer loaded. Moving the buffer-loaded
check to be the first thing done in get_lines() more than halved the
average time spent transforming the token list into highlight ranges vs
when it was still using _get_line_byte_from_position. I ended up
improving that loop more by not using get_lines, but figured the
performance improvement it provided was worth leaving in.
(cherry picked from commit dc38eafab5)
Co-authored-by: John Drouhard <john@drouhard.dev>
fix(treesitter): redraw added/removed injections properly
When injections are added or removed make sure to:
- invoke 'changedtree' callbacks for when new trees are added.
- invoke 'changedtree' callbacks for when trees are invalidated
- redraw regions when languagetree children are removed
(cherry picked from commit b68157834a)
Co-authored-by: Lewis Russell <lewis6991@gmail.com>
fix(treesitter): do not calc folds on unloaded buffers
Fixes#23423
(cherry picked from commit 2e08228a16)
Co-authored-by: Lewis Russell <lewis6991@gmail.com>
perf(lsp): process semantic tokens response in a coroutine that yields every 5ms
(cherry picked from commit 46cd1d957c)
Co-authored-by: John Drouhard <john@drouhard.dev>
Problem:
`vim.split('a:::', ':', {trimempty=true})` trims inner empty items.
Regression from 9c49c10470
Solution:
Set `empty_start=false` when first non-empty item is found.
close#23212
(cherry picked from commit 622b1ae38a)
fix(treesitter playground): wrong range of a node displayed in playground
The call parameters order of the function `get_range_str` is flipped for the last two arguments compared to the declaration.
(cherry picked from commit 8613ba118c)
Co-authored-by: William <50717946+BIKA-C@users.noreply.github.com>
fix(loader): only keep hashes for the current loop iteration
(cherry picked from commit e12cfa567f)
Co-authored-by: Lewis Russell <lewis6991@gmail.com>
fix(treesitter): use the correct replacement args for #gsub! directive
(cherry picked from commit 07db1f7432)
Co-authored-by: scottming <therealscottming@gmail.com>
Problem:
Codebase inconsistently binds vim.api onto a or api.
Solution:
Use api everywhere. a as an identifier is too short to have at the
module level.