Skip to content
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

feature: add togglability and documentation #18

Merged
merged 3 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ require('nvim-biscuits').setup({
EOF
```

## Configuration (Keybinding to toggle visibility)

You can show or hide the biscuits by placing a `toggle_keybind` at the root of your config or inside a language config.

```lua
lua <<EOF
require('nvim-biscuits').setup({
toggle_keybind = "<leader>cb"
})
EOF
```

OR

```lua
lua <<EOF
require('nvim-biscuits').setup({
language_config = {
rust = {
toggle_keybind = "<leader>cb"
}
}
})
EOF
```

If you prefer to bind manually, the function is exposed as:
```lua
require('nvim-biscuits').toggle_biscuits()
```

## Supported Languages

We currently support all the languages supported in tree-sitter. Not all languages have specialized support, though most will probably need some.
Expand Down
24 changes: 24 additions & 0 deletions lua/nvim-biscuits/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ local ts_parsers = require('nvim-treesitter.parsers')
local ts_utils = require('nvim-treesitter.ts_utils')
local nvim_biscuits = {}

local should_render_biscuits = true

local make_biscuit_hl_group = function(lang) return 'BiscuitColor' .. lang end

nvim_biscuits.decorate_nodes = function(bufnr, lang)
if config.get_language_config(final_config, lang, "disabled") then return end

if not should_render_biscuits then
vim.api.nvim_buf_clear_namespace(bufnr, 0, 0, -1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when I try toggle biscuits, it disables all virtual text. I think this line is the cause. Maybe you can see this as reference. And sorry for the late reply.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its because of the highlight group I am using. I can change that.
It is also an issue in another PR, so I will do that first. I will let you know when I have done that. Thinking Sunday seems likely.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the fix merged in now. Let me know if that helps.

return
end

utils.console_log("decorating nodes")

local parser = ts_parsers.get_parser(bufnr, lang)
Expand Down Expand Up @@ -138,6 +145,16 @@ nvim_biscuits.BufferAttach = function(bufnr)
attached_buffers[bufnr] = true

local lang = ts_parsers.get_buf_lang(bufnr)

local toggle_keybind = config.get_language_config(final_config, lang,
"toggle_keybind")
if toggle_keybind ~= nil and
not config.get_language_config(final_config, lang, "disabled") then
vim.api.nvim_set_keymap("n", toggle_keybind,
":lua require('nvim-biscuits').toggle_biscuits()<CR>",
{noremap = false})
end

local on_lines = function() nvim_biscuits.decorate_nodes(bufnr, lang) end

vim.cmd("highlight default link " .. make_biscuit_hl_group(lang) ..
Expand All @@ -164,4 +181,11 @@ nvim_biscuits.BufferAttach = function(bufnr)
end
end

nvim_biscuits.toggle_biscuits = function()
should_render_biscuits = not should_render_biscuits
local bufnr = vim.api.nvim_get_current_buf()
local lang = ts_parsers.get_buf_lang(bufnr)
nvim_biscuits.decorate_nodes(bufnr, lang)
end

return nvim_biscuits