Skip to content

Commit d073791

Browse files
author
hedy
committed
fix: No-op keymaps when there is no provider
1 parent 2dd9ea2 commit d073791

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

lua/outline/preview.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function Preview:show()
191191
return
192192
end
193193

194-
if not vim.api.nvim_win_is_valid(self.s.code.win) then
194+
if not vim.api.nvim_win_is_valid(self.s.code.win) or not self.s.provider then
195195
return
196196
end
197197

@@ -296,6 +296,7 @@ function LivePreview:show()
296296
if
297297
not vim.api.nvim_win_is_valid(self.s.code.win)
298298
or (self.codewin and not vim.api.nvim_win_is_valid(self.codewin))
299+
or not self.s.provider
299300
then
300301
return
301302
end

lua/outline/providers/nvim-lsp.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ function M.rename_symbol(sidebar)
105105
end
106106

107107
local node = sidebar:_current_node()
108+
if not node then
109+
return false
110+
end
108111

109112
-- Using fn.input so it's synchronous
110113
local new_name = vim.fn.input({ prompt = 'New Name: ', default = node.name })
@@ -140,6 +143,9 @@ function M.show_hover(sidebar)
140143
end
141144

142145
local node = sidebar:_current_node()
146+
if not node then
147+
return false
148+
end
143149
local params = {
144150
textDocument = { uri = vim.uri_from_bufnr(sidebar.code.buf) },
145151
position = { line = node.line, character = node.character },

lua/outline/sidebar.lua

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ function Sidebar:setup_buffer_autocmd()
194194
vim.api.nvim_create_autocmd('CursorMoved', {
195195
buffer = 0,
196196
callback = function()
197-
-- Don't use _goto_location because we don't want to auto-close
198-
self:__goto_location(false)
197+
if self.provider then
198+
-- Don't use _goto_location because we don't want to auto-close
199+
self:__goto_location(false)
200+
end
199201
end,
200202
})
201203
end
@@ -363,15 +365,24 @@ function Sidebar:no_providers_ui()
363365
end
364366

365367
---Currently hovered node in outline
366-
---@return outline.FlatSymbol
368+
---@return outline.FlatSymbol?
367369
function Sidebar:_current_node()
368370
local current_line = vim.api.nvim_win_get_cursor(self.view.win)[1]
369-
return self.flats[current_line]
371+
if self.flats then
372+
return self.flats[current_line]
373+
end
370374
end
371375

372376
---@param change_focus boolean Whether to switch to code window after setting cursor
373377
function Sidebar:__goto_location(change_focus)
378+
if not self.provider then
379+
return
380+
end
374381
local node = self:_current_node()
382+
if not node then
383+
return
384+
end
385+
375386
vim.api.nvim_win_set_cursor(self.code.win, { node.line + 1, node.character })
376387

377388
if cfg.o.outline_window.center_on_jump then
@@ -426,20 +437,28 @@ function Sidebar:_move_and_jump(direction)
426437
end
427438

428439
---@param move_cursor boolean
429-
---@param node_index integer Index for self.flats
430-
function Sidebar:_toggle_fold(move_cursor, node_index)
431-
local node = self.flats[node_index] or self:_current_node()
440+
function Sidebar:_toggle_fold(move_cursor)
441+
if not self.provider then
442+
return
443+
end
444+
local node = self:_current_node()
445+
if not node then
446+
return
447+
end
432448
local is_folded = folding.is_folded(node)
433449

434450
if folding.is_foldable(node) then
435-
self:_set_folded(not is_folded, move_cursor, node_index)
451+
self:_set_folded(not is_folded, move_cursor)
436452
end
437453
end
438454

439455
---@param folded boolean
440456
---@param move_cursor? boolean
441457
---@param node_index? integer
442458
function Sidebar:_set_folded(folded, move_cursor, node_index)
459+
if not self.provider then
460+
return
461+
end
443462
local node = self.flats[node_index] or self:_current_node()
444463
local changed = (folded ~= folding.is_folded(node))
445464

@@ -462,6 +481,9 @@ end
462481

463482
---@param nodes outline.Symbol[]
464483
function Sidebar:_toggle_all_fold(nodes)
484+
if not self.provider then
485+
return
486+
end
465487
nodes = nodes or self.items
466488
local folded = true
467489

@@ -478,8 +500,14 @@ end
478500
---@param folded boolean?
479501
---@param nodes? outline.Symbol[]
480502
function Sidebar:_set_all_folded(folded, nodes)
503+
if not self.provider then
504+
return
505+
end
481506
local stack = { nodes or self.items }
482507
local current = self:_current_node()
508+
if not current then
509+
return
510+
end
483511

484512
while #stack > 0 do
485513
local current_nodes = table.remove(stack, #stack)

0 commit comments

Comments
 (0)