Skip to content

Commit

Permalink
feat: integrate with nvim-tree to avoid collisions
Browse files Browse the repository at this point in the history
close #163
  • Loading branch information
j-hui committed Dec 9, 2023
1 parent b26cdb2 commit 72be8c6
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 24 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Extensible UI for Neovim notifications and LSP progress messages.
<details>
<summary>Demo setup</summary>

*Note that this demo may not always reflect the exact behavior of the latest release.*
_Note that this demo may not always reflect the exact behavior of the latest release._

This screen recording was taken as I opened a Rust file I'm working on,
triggering `rust-analyzer` to send me some LSP progress messages.
Expand Down Expand Up @@ -45,12 +45,12 @@ rendering and make the demo look glitchy...)

Visible elements:

- Terminal + font: [Kitty](https://sw.kovidgoyal.net/kitty/) + [Comic Shanns Mono](https://github.com/shannpersand/comic-shanns)
- Editor: [Neovim v0.9.4](https://github.com/neovim/neovim/tree/v0.9.4)
- Theme: [catppuccin/nvim (mocha, dark)](https://github.com/catppuccin/nvim)
- Status line: [nvim-lualine/lualine.nvim](https://github.com/nvim-lualine/lualine.nvim)
- Color columns: `:set colorcolumn=81,121,+1,+2` (sorry)
- Scrollbar: [petertriho/nvim-scrollbar](https://github.com/petertriho/nvim-scrollbar)
- Terminal + font: [Kitty](https://sw.kovidgoyal.net/kitty/) + [Comic Shanns Mono](https://github.com/shannpersand/comic-shanns)
- Editor: [Neovim v0.9.4](https://github.com/neovim/neovim/tree/v0.9.4)
- Theme: [catppuccin/nvim (mocha, dark)](https://github.com/catppuccin/nvim)
- Status line: [nvim-lualine/lualine.nvim](https://github.com/nvim-lualine/lualine.nvim)
- Color columns: `:set colorcolumn=81,121,+1,+2` (sorry)
- Scrollbar: [petertriho/nvim-scrollbar](https://github.com/petertriho/nvim-scrollbar)

</details>

Expand Down Expand Up @@ -221,6 +221,13 @@ For instance, using [Lazy](https://github.com/folke/lazy.nvim):
},
},

-- Options related to integrating with other plugins
integration = {
["nvim-tree"] = {
enable = true, -- Integrate with nvim-tree/nvim-tree.lua (if installed)
},
},

-- Options related to logging
logger = {
level = vim.log.levels.WARN, -- Minimum logging level
Expand Down
19 changes: 19 additions & 0 deletions doc/fidget-option.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Nvim LSP client options ......................... |fidget.option.progress.lsp|
Notification options ............................ |fidget.option.notification|
Notifications rendering options ............ |fidget.option.notification.view|
Notifications window options ............. |fidget.option.notification.window|
nvim-tree integration .................. |fidget.option.integration.nvim-tree|
Logging options ....................................... |fidget.option.logger|


Expand Down Expand Up @@ -721,6 +722,24 @@ notification.window.relative *fidget.option.notification.window.relative*
`"editor"`


==============================================================================
nvim-tree integration *fidget.option.integration.nvim-tree*


integration.nvim-tree.enable *fidget.option.integration.nvim-tree.enable*

Integrate with nvim-tree/nvim-tree.lua (if installed)

Dynamically offset Fidget's notifications window when the nvim-tree window
is open on the right side + the Fidget window is "editor"-relative.

Type: ~
`boolean`

Default: ~
`true`


==============================================================================
Logging options *fidget.option.logger*

Expand Down
1 change: 1 addition & 0 deletions lua/fidget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fidget.options = {
progress = fidget.progress,
notification = fidget.notification,
logger = fidget.logger,
integration = require("fidget.integration")
}
---@options ]]

Expand Down
9 changes: 9 additions & 0 deletions lua/fidget/integration.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local M = {}

M.options = {
["nvim-tree"] = require("fidget.integration.nvim-tree")
}

require("fidget.options").declare(M, "integration", M.options)

return M
57 changes: 42 additions & 15 deletions lua/fidget/integration/nvim-tree.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,53 @@
local M = {}

require("fidget.options").declare(M, "integration.nvim-tree", {
enable = false,
}, function()
if M.option.enable == true then
local ntree = require("nvim-tree")
local win = require("fidget.notification.window")
-- Only register one callback, so setup() can be called multiple times.
local already_subscribed = false

ntree.api.events.subscribe(ntree.api.events.TreeOpen, function()
if win.relative == "editor" then
---@options integration.nvim-tree [[
--- nvim-tree integration
M.options = {
--- Integrate with nvim-tree/nvim-tree.lua (if installed)
---
--- Dynamically offset Fidget's notifications window when the nvim-tree window
--- is open on the right side + the Fidget window is "editor"-relative.
---
---@type boolean
enable = true,
}
---@options ]]

end
end)
require("fidget.options").declare(M, "integration.nvim-tree", M.options, function()
if not M.options.enable or already_subscribed then
return
end

local ok, api = pcall(function() return require("nvim-tree.api") end)
if not ok then
return
end

ntree.api.events.subscribe(ntree.api.events.TreeClose, function()
win.set_x_offset(0)
end)
already_subscribed = true

ntree.api.events.subscripe(ntree.api.events.Resize, function(size)
local win = require("fidget.notification.window")

end)
local function resize()
if win.options.relative == "editor" then
local winid = api.tree.winid()
local col = vim.api.nvim_win_get_position(winid)[2]
if col > 1 then
local width = vim.api.nvim_win_get_width(winid)
win.set_x_offset(width)
end
end
end

local function reset()
win.set_x_offset(0)
end

api.events.subscribe(api.events.Event.TreeOpen, resize)
api.events.subscribe(api.events.Event.Resize, resize)
api.events.subscribe(api.events.Event.TreeClose, reset)
end)

return M
2 changes: 1 addition & 1 deletion lua/fidget/notification/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ local state = {
--- Useful for temporarily adding additional padding to account for space
--- taken up by other plugins' windows.
---
---@type number|nil
---@type number
x_offset = 0,
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/build-options-docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ for _, filename in ipairs(files) do
done = false

-- Look for ---@options (prefix) [[
found, _, cap1 = string.find(line, "%-%-%-@options%s*([%w%.]*)%s*%[%[")
found, _, cap1 = string.find(line, "%-%-%-@options%s*([%w%._-]*)%s*%[%[")
if found then
if module.prefix ~= nil then
print("Error: file contains multiple @options tags: " .. filename)
Expand Down
1 change: 1 addition & 0 deletions scripts/build-options-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ $lua scripts/build-options-docs.lua --strip 1 --tag fidget.option \
lua/fidget/notification.lua \
lua/fidget/notification/view.lua \
lua/fidget/notification/window.lua \
lua/fidget/integration/nvim-tree.lua \
lua/fidget/logger.lua \
>> "$txt"

Expand Down

0 comments on commit 72be8c6

Please sign in to comment.