Git Product home page Git Product logo

hiphish / nvim-ts-rainbow2 Goto Github PK

View Code? Open in Web Editor NEW
339.0 5.0 36.0 1.25 MB

Rainbow delimiters for Neovim through Tree-sitter

Home Page: https://gitlab.com/HiPhish/nvim-ts-rainbow2

License: Apache License 2.0

Lua 45.94% Vim Script 2.90% Scheme 28.67% JavaScript 1.68% TypeScript 2.99% Shell 0.39% C 0.86% C# 4.16% C++ 1.21% CSS 0.09% Java 0.39% TeX 1.18% Makefile 0.43% Python 0.81% Racket 0.92% Common Lisp 0.27% HTML 0.71% Rust 3.95% Go 2.22% Clojure 0.22%
neovim rainbow treesitter

nvim-ts-rainbow2's Introduction

Rainbow delimiters for Neovim

Warning

This plugin is deprecated! Please use rainbow-delimiters.nvim instead (GitHub mirror). This plugin is implemented as a module for nvim-treesitter, but nvim-treesitter has deprecated the module feature. Hence why I have created a new standalone plugin which does not depend on nvim-treesitter.

This Neovim plugin provides alternating syntax highlighting (“rainbow parentheses”) for Neovim, powered by Tree-sitter. The goal is to have a hackable plugin which allows for different configuration of queries and strategies, both globally and per file type. Users can override and extend the built-in defaults through their own configuration.

Installation and setup

Installation

The plugin depends on nvim-treesitter. Other than that it is installed like any other Neovim plugin.

Setup

Since this is a module for nvim-treesitter you need to setup everything in its configuration. Here is an example:

require('nvim-treesitter.configs').setup {
  rainbow = {
    enable = true,
    -- list of languages you want to disable the plugin for
    disable = { 'jsx', 'cpp' }, 
    -- Which query to use for finding delimiters
    query = 'rainbow-parens',
    -- Highlight the entire buffer all at once
    strategy = require('ts-rainbow').strategy.global,
  }
}

Please refer to the manual for more details.

Help wanted

There are only so many languages which I understand to the point that I can write queries for them. If you want support for a new language please consider contributing code. See the CONTRIBUTING for details.

Status of the plugin

Tree-sitter support in Neovim is still experimental. This plugin and its API should be considered stable insofar as breaking changes will only happen if changes to Neovim necessitates them.

Warning

There is currently a shortcoming in Neovim's Tree-sitter API which makes it so that only the first node of a capture group can be highlighted. Please see neovim/neovim#17099 for details. Affected queries:

  • HTML rainbow-parens
  • JSX (Javascript + React.js) rainbow-parens-react (affects React tags only)
  • Python (rainbow-parens) (affects only the for ... in inside comprehensions)
  • TSX (Typescript + React.js) rainbow-parens-react (affects React tags only)
  • Vue.js rainbow-parens

Most of these are related to HTML-like tags, so you can use an alternative query instead. See the manual (:h ts-rainbow-query) for a list of extra queries.

Screenshots

Bash

image

C

image

Common Lisp

image

Java

image

LaTeX

Using the blocks query to highlight the entire \begin and \end instructions.

image

License

Licensed under the Apache-2.0 license. Please see the LICENSE file for details.

Attribution

This is a fork of a previous Neovim plugin, the original repository is available under https://sr.ht/~p00f/nvim-ts-rainbow/.

Attributions from the original author

Huge thanks to @vigoux, @theHamsta, @sogaiu, @bfredl and @sunjon and @steelsojka for all their help

nvim-ts-rainbow2's People

Contributors

akhilrobert avatar akinsho avatar alexander-p30 avatar aspeddro avatar baleksa avatar brokenbyte avatar c-a-v-a avatar catthingy avatar delphinus avatar dffdff2423 avatar gelio avatar github-actions[bot] avatar hiphish avatar jcapblancq avatar luozhiya avatar max397574 avatar mrcjkb avatar p00f avatar patrick96 avatar perigord-kleisli avatar qsdrqs avatar ram02z avatar reo101 avatar s-zymon avatar sunjon avatar tbttfox avatar thehamsta avatar tuanha168 avatar tzachar avatar v1adhope avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nvim-ts-rainbow2's Issues

[Bug]: Error when opening javascript file

Neovim version

0.9.1

Language affected

Javascript

Query

No response

Strategy

No response

Description

When I try to edit a js file (even a new one) like `nvim new.js` I get this error:


Fehler beim Ausführen von "BufReadPost Autokommandos für "*"":
Error executing lua callback: /usr/local/share/nvim/runtime/filetype.lua:21: Error executing lua: /usr/local/share/nvim/runtime/filetype.lua:22: BufReadPost Autokommandos für "*"..FileType Autokommandos für "*":
 Vim(append):Error executing lua callback: /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 478 for language javascript
stack traceback:
        [C]: in function '_ts_parse_query'
        /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:259: in function 'get_query'
        ...im/plugged/nvim-treesitter/lua/nvim-treesitter/query.lua:108: in function 'get_query'
        ...local/share/nvim/plugged/nvim-ts-rainbow/lua/rainbow.lua:8: in function 'is_supported'
        .../plugged/nvim-treesitter/lua/nvim-treesitter/configs.lua:387: in function 'is_enabled'
        .../plugged/nvim-treesitter/lua/nvim-treesitter/configs.lua:507: in function 'attach_module'
        .../plugged/nvim-treesitter/lua/nvim-treesitter/configs.lua:532: in function 'reattach_module'
        .../plugged/nvim-treesitter/lua/nvim-treesitter/configs.lua:133: in function <.../plugged/nvim-treesitter/lua/nvim-treesitter/configs.lua:132>
        [C]: in function 'nvim_cmd'
        /usr/local/share/nvim/runtime/filetype.lua:22: in function </usr/local/share/nvim/runtime/filetype.lua:21>
        [C]: in function 'nvim_buf_call'
        /usr/local/share/nvim/runtime/filetype.lua:21: in function </usr/local/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_cmd'
        /usr/local/share/nvim/runtime/filetype.lua:22: in function </usr/local/share/nvim/runtime/filetype.lua:21>
        [C]: in function 'nvim_buf_call'
        /usr/local/share/nvim/runtime/filetype.lua:21: in function </usr/local/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        /usr/local/share/nvim/runtime/filetype.lua:21: in function </usr/local/share/nvim/runtime/filetype.lua:10>

[Bug]: LanguageTree:for_each_child is deprecated

Neovim version

v0.10.0-dev-1105+g2e9206568

Language affected

No response

Query

No response

Strategy

No response

Description

Since neovim#25118, LanguageTree:for_each_child is deprecated

Simply open a file and see the deprecation notification

[Bug]: color doesn't change

Neovim version

0.9.1

Language affected

cpp

Query

No response

Strategy

No response

Description

The plugin change the parenthesis colors for lua but c, cpp.
Do I need to set-up another Query?

Feature request: custom colors

I could be mistaken and missed the option for this somewhere, but with the old ts-rainbow plugin I had my colors defined as a colors key like so:

colors = {
	"royalblue3",
	"darkorange3",
	"seagreen3",
	"firebrick",
	"darkorchid3",
},

This was convenient as I liked these colors, only wanted 5 (not all 7 of the rainbow colors), and was easy to add.

It'd be nice to see similar functionality added here if it doesn't already exist (again I might've completely missed it)

Thanks!

More clear instructions for custom color definitions

Hello, I'm just trying to create a simple yellow-magenta-cyan color scheme. I recognize I must reorder the entries in hlgroups, however I have no idea how to set my own color hex definitions, and I've looked through the documentation. I am not advanced with lua, and I don't care about advanced dynamically pairing colors with themes, I just want to set the simple color scheme of "#ffd700", "#da70d6", "#179fff". I've set the hlgroups variable to this, and I'm not sure how to move forward:

hlgroups = {
    'TSRainbowYellow',
    'TSRainbowMagenta',
    'TSRainbowBlue',
}

ts-rainbow not found

Describe the bug

I'm trying to use this module with lunarvim setup. However, on startup I get this error:

16:43:36 [WARN ] lvim: "Invalid configuration: /home/cova/.config/lvim/config.lua:311: module 'ts-rainbow' not found:\n\tno field package.preload['ts-rainbow']\n\tno file './ts-rainbow.lua'\n\tno file
 '/usr/share/luajit-2.1.0-beta3/ts-rainbow.lua'\n\tno file '/usr/local/share/lua/5.1/ts-rainbow.lua'\n\tno file '/usr/local/share/lua/5.1/ts-rainbow/init.lua'\n\tno file '/usr/share/lua/5.1/ts-rainbow
.lua'\n\tno file '/usr/share/lua/5.1/ts-rainbow/init.lua'\n\tno file './ts-rainbow.so'\n\tno file '/usr/local/lib/lua/5.1/ts-rainbow.so'\n\tno file '/usr/lib64/lua/5.1/ts-rainbow.so'\n\tno file '/usr/
local/lib/lua/5.1/loadall.so'" file="[C]", line=-1

And it seems not completely off, as the ts-rainbow.lua is not present, only rainbow.ts can be found searching in plugins directory.
Please note that lunarvim uses Lazy to load plugins, not Packer. I can investigate if the issue can be related to Lazy, not sure if the error above can be related to Lazy, though.
Steps to reproduce
I use this configuration in config.lua:

  { "HiPhish/nvim-ts-rainbow2",
    lazy = true,
    require('nvim-treesitter.configs').setup {
      rainbow = {
        enable = true,
        -- list of languages you want to disable the plugin for
        disable = { 'jsx', 'cpp' },
        -- Which query to use for finding delimiters
        query = 'rainbow-parens',
        -- Highlight the entire buffer all at once
        strategy = require('ts-rainbow').strategy.global,
      },
    },
  },

Expected behavior

No error in loading plugin.

Screenshots
rainbow

Treesitter detach callback: Vim:Error executing lua callback: Vim:E315: ml_get: Invalid lnum: 1

Hi,

Describe the bug

When using Bdelete to delete a buffer, rainbow will throw an error.
In my opinion rainbow needs to register a detach callback.

Thanks.

Error executing Lua callback: ...te/pack/paqs/start/bufdelete.nvim/lua/bufdelete/init.lua:159: Vim:Error executing lua callback: Vim:E315: m
l_get: Invalid lnum: 1
stack traceback:
        [C]: in function 'bufload'
        vim/_editor.lua: in function 'region'
        /usr/local/share/nvim/runtime/lua/vim/highlight.lua:30: in function 'range'
        .../pack/paqs/start/nvim-ts-rainbow2/lua/ts-rainbow/lib.lua:92: in function 'highlight'
        ...tart/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:29: in function 'highlight_matches'
        ...tart/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:79: in function 'update_range'
        ...tart/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:104: in function 'cb'
        ...l/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:736: in function '_do_callback'
        ...l/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:176: in function 'invalidate'
        ...l/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:877: in function '_on_detach'
        /usr/local/share/nvim/runtime/lua/vim/treesitter.lua:73: in function </usr/local/share/nvim/runtime/lua/vim/treesitter.lua:69>

Neovim Version

NVIM v0.10.0-dev-282+gca5a810c4

Steps to reproduce

  • nvim -u minimal.lua
  • PaqInstall
  • open two .lua files
  • Bdelete one file

minimal

local fn = vim.fn
local install_path = fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim'

if fn.empty(fn.glob(install_path)) > 0 then
  fn.system({ 'git', 'clone', '--depth=1', 'https://github.com/savq/paq-nvim.git', install_path })
end

require('paq')({
  'savq/paq-nvim',
  'nvim-treesitter/nvim-treesitter',
  'HiPhish/nvim-ts-rainbow2',
  'famiu/bufdelete.nvim',
})

require('nvim-treesitter.configs').setup {
  ensure_installed = {
    'lua',
  },
  rainbow = {
    enable = true,
  }
}

Expected behavior

delete buffer without throw an error.

References

share/nvim/runtime/lua/vim/treesitter/languagetree.lua:877

---@package
function LanguageTree:_on_detach(...)
  self:invalidate(true)
  self:_do_callback('detach', ...)
end

neovim/neovim#21416

Mismatched brackets in .tex file editing (LaTeX)

Describe the bug
NVIM v0.8.3
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

I use VimTeX to edit .tex files. In most cases, rainbow works well.

However, in some cases, the mismatched brackets occur as follows.

Imgur

  • In the first line, the two pairs of curly brackets do not match correctly.
  • In the second line, the color of the inner pair of brackets is mismatched and one of them has the same color as the outer pair.

Steps to reproduce
For now, I'm not sure if there is any other case causing curly brackets mismatched.
Presently, the following combination of commands may occur such mismatches.
\footnote{... \ref{... (...) ...}}
and
\footnote{... \ref{... }}

Expected behavior

  1. Match the brackets correctly.
  2. Enrich the color of paired brackets like rainbow supporting C language.
    supporting C

[Bug]: LanguageTree:for_each_child() is deprecated in neovim 0.10

Neovim version

0.10.0

Language affected

No response

Query

No response

Strategy

No response

Description

Deprecation warning in neovim 0.10


LanguageTree:for_each_child() is deprecated, use LanguageTree:children() in
stead. :help deprecated
Feature will be removed in Nvim 0.11
stack traceback:
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:473: in
 function 'for_each_child'
        ...lazy/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:98: in
function 'setup_parser'
        ...lazy/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:135: in
 function <...lazy/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:133>

        [C]: in function 'pcall'
        ...e/nvim/lazy/nvim-ts-rainbow2/lua/ts-rainbow/internal.lua:82: in
function 'attach'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:509: in
 function 'attach_module'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:532: in
 function 'reattach_module'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:133: in
 function <...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:132>

        [C]: in function 'nvim_cmd'
        ...rew/Cellar/neovim/0.10.0/share/nvim/runtime/filetype.lua:36: in
function <...rew/Cellar/neovim/0.10.0/share/nvim/runtime/filetype.lua:35>
        [C]: in function 'nvim_buf_call'
        ...rew/Cellar/neovim/0.10.0/share/nvim/runtime/filetype.lua:35: in
function <...rew/Cellar/neovim/0.10.0/share/nvim/runtime/filetype.lua:10>

add matlab language supoort

Neovim version

No response

Language affected

No response

Query

No response

Strategy

No response

Description

This adds matlab language support

Top level brackets are not highlighted when toggling rainbow

Describe the bug

I disable rainbow on InsertEnter for Zen Mode. When I re-enable it on InsertLeave, top-level brackets are not highlighted, especially on function lines.

Steps to reproduce

1). Open a Lua document with top-level functions.
2). Disable rainbow with TSBufDisable rainbow.
3). Enable rainbow with TSBufEnable rainbow.
4). Brackets on the function line are not highlighted.

See the video below for an illustration.

Expected behavior

Rainbow should correctly highlight all brackets during toggles.

Video

rainbow_bug.mp4

Long freezes when opening/editing zig files

Describe the bug

I get huge freezes when opening a .zig source file (around 0.8-1.0 seconds), even when adding "zig" to disabled languages. I found this delay to be caused by nvim-ts-rainbow2 and for me only occurs with zig files so far.

Steps to reproduce

Open any .zig file, including the hello world example generated by zig init-exe:

const std = @import("std");

pub fn main() !void {
    // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
    std.debug.print("All your {s} are belong too us.\n", .{"codebase"});

    // stdout is for the actual output of your application, for example if you
    // are implementing gzip, then only the compressed bytes should be sent to
    // stdout, not any debugging messages.
    const stdout_file = std.io.getStdOut().writer();
    var bw = std.io.bufferedWriter(stdout_file);
    const stdout = bw.writer();

    try stdout.print("Run `zig build test` to run the tests.\n", .{});

    try bw.flush(); // don't forget to flush!
}

test "simple test" {
    var list = std.ArrayList(i32).init(std.testing.allocator);
    // defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
    try list.append(42);
    try std.testing.expectEqual(@as(i32, 42), list.pop());
}

Expected behavior

Either no freezes when editing a (simple) zig file (lag occurs on multiple events, like inserting new text or removing lines etc), or no freeze at all when adding zig to disabled languages.

Bracket coloring inconsistent

Describe the bug

I've noticed that some highlighting is inconsistent: Sometimes a bracket gets highlighted, sometimes it doesn't, sometimes the order of colors is not what is expected. So far I've tested this on TypeScript (+ TSReact) and Rust files.

(also it seems the magenta color is actually more greenish but that's out of scope for this problem)
Steps to reproduce

Steps to reproduce the behavior.

I've defined some custom colors:

vim.api.nvim_set_hl(0, "TSRainbowYellow", { fg = "#FFD700" })
vim.api.nvim_set_hl(0, "TSRainbowMagenta", { fg = "#DA70D6" })
vim.api.nvim_set_hl(0, "TSRainbowBlue", { fg = "#87CEFA" })

and then set the plugin up like so:

local opts = {
	rainbow = {
		enable = true,
		strategy = require("ts-rainbow").strategy.global,
		hlgroups = {
			"TSRainbowYellow",
			"TSRainbowMagenta",
			"TSRainbowBlue",
		},
		query = {
			"rainbow-parens",
			tsx = "rainbow-tags",
		},
	},
}
require("nvim-treesitter.configs").setup(opts)

Expected behavior
All brackets shoudlbe highlighted, and cycle through the defined colors yellow -> magenta -> blue -> yellow etc.

Screenshots
Rust
image

TypeScript
image

vim.treesitter.query.get_query() is deprecated, use vim.treesitter.query.get() instead.

I am getting this error on launch:

vim.treesitter.query.get_query() is deprecated, use vim.treesitter.query.get() instead. :help deprecated
This feature will be removed in Nvim version 0.10
stack traceback:
        ...-4863ca6/share/nvim/runtime/lua/vim/treesitter/query.lua:200: in function 'get_query'
        ...ages/start/nvim-treesitter/lua/nvim-treesitter/query.lua:108: in function 'get_query'
        ...ackages/start/nvim-ts-rainbow2/lua/ts-rainbow/module.lua:36: in function 'is_supported'
        ...es/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:387: in function 'is_enabled'
        ...es/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:507: in function 'attach_module'
        ...es/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:532: in function 'reattach_module'

[Bug]: LanguageTree:for_each_child() is deprecated

Neovim version

v0.10.0-dev-ccd1a84a9

Language affected

No response

Query

No response

Strategy

No response

Description

2023-09-25T21:21:53 WARN LanguageTree:for_each_child() is deprecated, use LanguageTree:children() instead. :help deprecated
This feature will be removed in Nvim version 0.11
2023-09-25T21:21:53 WARN stack traceback:
        ...l/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:466: in function 'for_each_child'
        ...lazy/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:98: in function 'setup_parser'
        ...lazy/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:135: in function <...lazy/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:133>
        [C]: in function 'pcall'
        ...e/nvim/lazy/nvim-ts-rainbow2/lua/ts-rainbow/internal.lua:82: in function 'attach'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:509: in function 'attach_module'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:532: in function 'reattach_module'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:133: in function <...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:132>
        [C]: in function 'nvim_cmd'
        /usr/local/share/nvim/runtime/filetype.lua:31: in function </usr/local/share/nvim/runtime/filetype.lua:30>
        [C]: in function 'nvim_buf_call'
        /usr/local/share/nvim/runtime/filetype.lua:30: in function </usr/local/share/nvim/runtime/filetype.lua:10>

[Bug]: highlighting broken after lsp format

Neovim version

v0.10.0-dev-510+g3c4890d1e

Language affected

clojure

Query

No response

Strategy

No response

Description

In a clojure file, using the clojure-lsp formatting, the rainbow delimiters become out of sync until the file is edited again.

This can be seen in the below asciicast (which I hopefully formatted correctly).
asciicast

I can reproduce the issue using the following clojure file, deps.edn, and minimal config by opening the file with nvim -u init.lua minimal.clj and running :lua vim.lsp.buf.format()

init.lua

local lazypath = "/tmp/rainbow/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"https://github.com/folke/lazy.nvim.git",
		"--branch=stable", -- latest stable release
		lazypath,
	})
end
vim.opt.rtp:prepend(lazypath)
vim.cmd.colorscheme("retrobox")

require("lazy").setup({
	{
		"nvim-treesitter/nvim-treesitter",
		build = ":TSUpdate",
		event = { "BufReadPost", "BufNewFile" },
		opts = {
			ensure_installed = {
				"clojure",
			},
			highlight = {
				enable = true,
			},
			rainbow = {
				enable = true,
			},
		},
		config = function(_, opts)
			if type(opts.ensure_installed) == "table" then
				---@type table<string, boolean>
				local added = {}
				opts.ensure_installed = vim.tbl_filter(function(lang)
					if added[lang] then
						return false
					end
					added[lang] = true
					return true
				end, opts.ensure_installed)
			end
			require("nvim-treesitter.configs").setup(opts)
		end,
	},
	"HiPhish/nvim-ts-rainbow2",
	{
		"neovim/nvim-lspconfig",
		event = { "BufReadPre", "BufNewFile" },
		dependencies = {
			"mason.nvim",
			"williamboman/mason-lspconfig.nvim",
		},
		autoformat = true,
		config = function(_, opts)
			require("lspconfig").clojure_lsp.setup(opts)
		end,
	},
	{
		"williamboman/mason.nvim",
		cmd = "Mason",
		config = true,
	},
	{
		"williamboman/mason-lspconfig.nvim",
		opts = {
			ensure_installed = { "clojure_lsp" },
		},
	},
})

minimal.clj

(defn a-func [x y]
  (let [a 1]
  (let [b 2]
  (+ a b x y))))

(a-func 2 3)

deps.edn

{
 :paths ["."]
 }

It's possible this may be the same bug as this in which case the linked fixes might help?

Don't work

These is my treesitter config:

local nvim_treesitter_setup, nvim_treesitter = pcall(require, "nvim-treesitter")
if not nvim_treesitter_setup then
	return
end

local rainbow_setup, rainbow = pcall(require("ts-rainbow"))
if not rainbow_setup then
	return
end

nvim_treesitter.setup({
	ensure_installed = { "all" },
	sync_install = { enable = false },
	highlight = { enable = true },
	indent = { enable = true },
	autotag = { enable = true },
	auto_install = { enable = true },
	rainbow = {
		enable = true,
		query = { "rainbow-parens" },
		strategy = rainbow.strategy.global,
		hlgroups = {
			"TSRainbowBlue",
			"TSRainbowViolet",
			"TSRainbowOrange",
			"TSRainbowGreen",
			"TSRainbowYellow",
			"TSRainbowRed",
			"TSRainbowCyan",
		},
	},
})

and it doesn't work

[Bug] Punctuation highlight is changed to deprecated `TSPunctBracket`

Describe the bug

Whilst using this plugin the highlight for brackets that aren't being coloured using rainbow colours
is set to the since deprecated TSPuncBracket highlight group. There appears to be a check to see if the hl_map exists a check I think plugins used pre nvim 0.7 or 0.8 when these groups where deprecated but rather than just depending on the @punctation.bracket or using TSPunctBracket the plugin seems to overriding a users settings

if vim.treesitter.highlighter.hl_map then
vim.treesitter.highlighter.hl_map["punctuation.bracket"] = "TSPunctBracket"
else
vim.api.nvim_set_hl(0, "@punctuation.bracket", { link = "TSPunctBracket" })
end

Steps to reproduce

This is visible whilst using the local strategy and moving through a file. The highlights for un highlighted regions is mutated to TSPunctBracket. My colorscheme (which I develop) doesn't support the TS* highlight groups as it doesn't target anything lower than 0.8 (being that it's days old)

Expected behavior

Punctuation highlights should be left unchanged if not "rainbow-ed".

Screenshots

Without this plugin (brackets are a gray colour)

image

With this plugin (brackets are the same colour as the foreground)

image

TSEnable/TSDisable rainbow doesn't work

Describe the bug

Dynamically toggling rainbow with TSEnable/TSDiable no longer works.

Steps to reproduce

1). Enter the following commands:

  • TSDisable rainbow
  • TSEnable rainbow

Expected behavior

Rainbow colors should be toggled using TSDisable and TSEnable.

Video

rainbow_issue.mp4

bug(typescript): Custom query not working

Describe the bug

I wrote some custom queries, tested with treesitter playground. But when I add it to /after/queries/typescript/rainbow-parens.scm only a part of it is correctly highlighted.
Here is the custom query and test file. https://gist.github.com/boydaihungst/0dda7965f191977a8b376ca59646fade

Steps to reproduce

  1. add /after/queries/typescript/rainbow-parens.scm follow this guide nvim-treesitter#adding-queries.
  2. Use default plugin's config:
enable = true,
query = {
  'rainbow-parens',
  html = 'rainbow-tags'
},
strategy = {
  rainbow.strategy.global,
  -- commonlisp = rainbow.strategy['local'],
},
  1. Restart nvim

Expected behavior

Custom query should work as expected.

Screenshots

image

[Bug]: LanguageTree deprecation warning

Neovim version

0.10.0

Language affected

No response

Query

No response

Strategy

No response

Description

I've updated neovim to newest version and I am getting a deprecation warning


LanguageTree:for_each_child() is deprecated, use LanguageTree:children() instead. :help deprecated
Feature will be removed in Nvim 0.11
...
stack traceback:
        ...0/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:473: in function 'for_each_child'
        ...tart/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:98: in function 'setup_parser'
        ...tart/nvim-ts-rainbow2/lua/ts-rainbow/strategy/global.lua:135: in function <...tart/nvim-ts-rainbow2/lua/ts-rain
bow/strategy/global.lua:133>
        [C]: in function 'pcall'
        ...acker/start/nvim-ts-rainbow2/lua/ts-rainbow/internal.lua:82: in function 'attach'
        ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:509: in function 'attach_module'
        ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:532: in function 'reattach_module'
        ...er/start/nvim-treesitter/lua/nvim-treesitter/configs.lua:133: in function <...er/start/nvim-treesitter/lua/nvim
-treesitter/configs.lua:132>
        [C]: in function 'nvim_cmd'
        ...cal/Cellar/neovim/0.10.0/share/nvim/runtime/filetype.lua:36: in function <...cal/Cellar/neovim/0.10.0/share/nvi
m/runtime/filetype.lua:35>
        [C]: in function 'nvim_buf_call'
        ...cal/Cellar/neovim/0.10.0/share/nvim/runtime/filetype.lua:35: in function <...cal/Cellar/neovim/0.10.0/share/nvi
m/runtime/filetype.lua:10>
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function <vim/_editor.lua:0>
        [C]: in function 'pcall'
        ...acker/start/telescope.nvim/lua/telescope/actions/set.lua:162: in function 'run_replace_or_original'
        ...packer/start/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'run_replace_or_original'
        ...packer/start/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'run_replace_or_original'
        ...packer/start/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:253: in function <...k/packer/start/telescope.nvim/lua
/telescope/mappings.lua:252>

Highlight level calculation too slow

The current way of computing the highlight levels for matches is too slow. On
every change we first collect all matches into a tree-like structure and
allocate a lot of table in the process. These tables then immediately become
garbage that needs to be disposed of when done with the change.

Here are some rough ideas:

  • Have a pool of reusable tables so we don't have to create new tables every
    time.
  • Use a custom directive so we can associate a match and its parent within the
    match object instead of creating a new table. This still requires some sort
    of "stack" of nodes which have not yet been sorted, but we do not need to
    keep track of the entire tree.

These are just two ideas off the top of my head. I will have to try them out to
see what works and what does not.

Error on startup (neovim 0.9)

Describe the bug

I see following message occasionally:

Failed to run `config` for nvim-treesitter
...ocal/share/nvim/lazy/nvim-ts-rainbow2/lua/ts-rainbow.lua:18: loop or previous error loading module 'ts-rainbow.lib'
# stacktrace:
  - .config/nvim/init.lua:26 _in_ **config**
  - lua:1
  - vim/_editor.lua:0 _in_ **cmd**
Press ENTER or type command to continue
  - .config/nvim/init.lua:16
Press ENTER or type command to continue
Failed to source `/home/ubuntu/.local/share/nvim/lazy/nvim-ts-rainbow2/plugin/rainbow.vim`
vim/_editor.lua:0: /home/ubuntu/.config/nvim/init.lua..nvim_exec2() called at /home/ubuntu/.config/nvim/init.lua:0../home/ubuntu/.local/share/nvim/lazy/nvim-ts
-rainbow2/plugin/rainbow.vim, line 25: Vim(lua):E5108: Error executing lua ...are/nvim/lazy/nvim-ts-rainbow2/lua/ts-rainbow/module.lua:19: loop or previous err
or loading module 'ts-rainbow'
stack traceback:
^I[C]: in function 'require'
^I...are/nvim/lazy/nvim-ts-rainbow2/lua/ts-rainbow/module.lua:19: in main chunk
^I[C]: in function 'require'
^I[string ":lua"]:1: in main chunk
^I[C]: in function 'nvim_exec2'
^Ivim/_editor.lua: in function 'cmd'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:438: in function <...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:437>
^I[C]: in function 'xpcall'
^I.../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:110: in function 'try'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:437: in function 'source'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:396: in function 'source_runtime'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:364: in function 'packadd'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:304: in function '_load'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:180: in function 'load'
^I...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:115: in function 'startup'
^I...buntu/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:85: in function 'setup'
^I/home/ubuntu/.config/nvim/init.lua:16: in main chunk
# stacktrace:
  - vim/_editor.lua:0 _in_ **cmd**
Press ENTER or type command to continue

It does not occur every time, but I see it quite often.

Tried bisecting and the first bad commit is 93a5bc9.

Tested on neovim v0.9.0-dev-1291+gbad218cd6.

Steps to reproduce

Following is my minimum reproducible init.lua file:

-- reproducible .config/nvim/init.lua

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    '--branch=stable', -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require'lazy'.setup({
  { 'HiPhish/nvim-ts-rainbow2' },
  {
    'nvim-treesitter/nvim-treesitter', config = function()
      require'nvim-treesitter.configs'.setup {
        highlight = { enable = true },
        rainbow = {
          enable = true,
          extended_mode = true,
          query = 'rainbow-parens',
          strategy = require'ts-rainbow'.strategy.global,
        },
      }
    end,
  },
})

Expected behavior

There should be no error message about this plugin.

Screenshots

Screenshot 2023-03-28 at 14 30 57

Screenshot 2023-03-28 at 14 37 30

Dummy issue

I am using this issue to host images in the comments.

Highlight errors inside #if 0

Describe the bug

If brackets are inside 0 then the rainbow will highlight it.

Expected behavior

Could you please support me with a config rainbow plugin?

Screenshots

image

TSX - No handler for jsx-extended-rainbow-mode

Describe the bug

When opening .tsx files, I get the following error:

E5108: [...] Vim(append):Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:495: No handler for jsx-extended-rainbow-mode

Steps to reproduce

  1. Install nvim-ts-rainbow2 (I used packer)
  2. Use the config below
  3. Open a .tsx file, e.g. the example below

Config:

require 'nvim-treesitter.configs'.setup({
    highlight = {
        enable = true,
    },
    rainbow = {
        enable = true,
        query = {
            'rainbow-parens',
            'rainbow-tags',
        },
        extended_mode = true,
    }
})

Example code (default index.tsx from create-react-app):

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

Expected behavior

Don't throw an error on TSX files and highlight properly.

Screenshots

Proper highlight (using nvim-ts-rainbow):
image

Error message (moving through tabs, most of it is irrelevant stack trace):
image

Improper highlighting:
image

Some inner brackets are not highlighted

Describe the bug

I have the following code written in TypeScript:

export function flipColors(c: number[]): number[] {
  return c.map((channel, id) => Math.floor((c[(id + 1) % 3] + c[(id + 2) % 3]) / 2));
}

I notice that the inner brackets (parentheses covering id + 1 and id + 2 aren't colored)

Here is my config:

local rainbow = require 'ts-rainbow'

require('nvim-treesitter.configs').setup({
    rainbow = {
        enable = true,
        query = {
           'rainbow-parens'
        },
        extended_mode = true,
        strategy = rainbow.strategy.global,
        hlgroups = {
           'TSRainbowBlue',
           'TSRainbowViolet',
           'TSRainbowOrange',
           'TSRainbowGreen',
           'TSRainbowYellow',
           'TSRainbowRed',
           'TSRainbowCyan',
        },
    }
})

My color theme is gruvbox-material

Screenshots
image

Neovim 0.9.1 hangs consuming 100% CPU

Describe the bug

Since upgrading to neovim 0.9.1, I get random hangs where neovim hangs and consumes 100% CPU on one core for seconds before recovering.
I tried enabling and disabling plugins to find the culprit and it seems to be nvim-ts-rainbow2.

Steps to reproduce

I don't know yet how to trigger the issue, but it happened several times today (I upgraded neovim yesterday night).

Expected behavior

No hangs.

Config

require("nvim-treesitter.configs").setup {
  highlight = {
    enable = true,
    disable = function(lang, buf)
      local max_filesize = 100 * 1024 -- 100 KB
      local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
      if ok and stats and stats.size > max_filesize then
        return true
      end
    end,
  },

  rainbow = {
    enable = true,
    extended_mode = true,
    max_file_lines = 20000,
    query = {
      "rainbow-parens",
      html = "rainbow-tags",
      latex = "rainbow-blocks",
    }
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.