-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
the 'else' is not show in context bar #356
Comments
This looks like C, does it? Generally this plugin just uses the hierarchical tree structure that the treesitter parser for the language provides. For example with python or rust, this works fine. You can inspect what the parser provides using the So my hunch would be that this should actually be an issue / request to the treesitter C parser. |
thanks syphar No it is a cc file. I copy it as a c file, the
|
The queries for C (and thus C++ since it inherits the C queries and adds a few more) don't seem to contain anything catching (I wrote a wrong solution before, see update.) UPDATE: The above doesn't work as I expected. I have made a fork and tested a bit now. I think that replacing the
behaves more like what I would expect. This caputures ![]() ![]() ![]() |
thanks Danielkonge. The behavior in your screenshot is just as what I expected. |
Note: If you want to always include
or
seems to work fine for that. With the formatting of my previous comment, these queries behave the same. |
Hi Danielkonge, I am wondering if you will pull your new context.scm code to pull request ? |
I can make a pull request that includes the |
Hi Danielkonge, I personally perfer the "Previous queries" in your comment, i.e., NOT to always include |
To have an option like that is probably not worth it to try to implement and maintain just for c. Instead it would probably make more sense to allow use of custom queries, though I am not sure if that is already possible to do? Also, I have made a pull request now. |
That is already possible. |
This has to be defined for every language? Can it be generalized? I think the |
You'd have to dig into the code and investigate. |
Description
A test code as below it is a simple
if ... else
, when navigating theelse
part the context shows only theif
withoutelse
.This is misleading.
neovim version version 0.9.1, Build type: Release
nvim-treesitter-context is download on 2023.10.20
packer.nvim lua config:
use 'nvim-treesitter/nvim-treesitter-context'
nvim-treesitter-context.lua :
Neovim version
0.9.1
Expected behavior
in
if ... else
context, show theelse
context.Actual behavior
in
if ... else
context, noelse
context is shownMinimal config
require 'treesitter-context'.setup {
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit.
line_numbers = true,
multiline_threshold = 20, -- Maximum number of lines to show for a single context
trim_scope = 'outer', -- Which context lines to discard if
max_lines
is exceeded. Choices: 'inner', 'outer'mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline'
-- Separator between context and content. Should be a single character string, like '-'.
-- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
separator = nil,
zindex = 20, -- The Z-index of the context window
on_attach = nil, -- (fun(buf: integer): boolean) return false to disable attaching
}
Steps to reproduce
install nvim-treesitter-context, then use neovim to review below code, go to the last
else
line.The text was updated successfully, but these errors were encountered: