nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.07k stars 857 forks source link

Improve statusline / parsing for multiline node declarations #1931

Open harrisonmg opened 2 years ago

harrisonmg commented 2 years ago

I'm working in a C++ codebase that often makes multiline node declarations, such as

void
MavlinkParametersManager::handle_message(const mavlink_message_t *msg)
{

and have found that this results in M.statusline just returning "void" for that node.

I don't understand treesitter in detail, but my first idea was to increase how many lines M.statusline uses for each node and pair down the result via :gsub. That worked ok, but obviously it's quite hacky and prone to a few undesired behaviors. E.g. if your cursor is over MavlinkParametersManager, treesitter seems to think both the first and second lines are nodes, so M.statusline returns

"void MavlinkParametersManager::handle_message(const mavlink_message_t *msg) -> MavlinkParametersManager::handle_message(const mavlink_message_t *msg)"

Next, I looked for some kind of node name property to use instead, but I'm not sure if there is one.

It's unclear to me if this is a shortcoming of treesitter or this plugin, but I looking for advice on how to help improve this functionality.

Thanks!

stsewd commented 2 years ago

yeah, the current implementation doesn't work on all cases, I think we can make use of the list of definitions we already have in locals.scm https://github.com/nvim-treesitter/nvim-treesitter/pull/566#issuecomment-706605306

QikLiang commented 2 weeks ago

Since nvim-treesitter intends to remove this module in the future, I have forked my fix #6803 into a new plugin at https://github.com/QikLiang/ts-statusline.nvim