Skip to content

Commit 39f537a

Browse files
committed
fix(outline): improve outline URI handling
- Refactor outline URI storage to buffer level variable - Add outline URI validation in get_outline_content checks - Pass outline URI consistently through refresh_outline function
1 parent d135e1d commit 39f537a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lua/flutter-tools/outline.lua

+13-9
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,13 @@ end
208208
---@param buf integer the buf number
209209
---@param lines table the lines to append
210210
---@param highlights? table the highlights to apply
211-
local function refresh_outline(buf, lines, highlights)
211+
---@param outline_uri string the uri of the outline
212+
local function refresh_outline(buf, lines, highlights, outline_uri)
212213
vim.bo[buf].modifiable = true
213214
local ok = pcall(api.nvim_buf_set_lines, buf, 0, -1, false, lines)
214215
if not ok then return end
215216
vim.bo[buf].modifiable = false
217+
vim.b[buf].outline_uri = outline_uri
216218
if highlights then ui.add_highlights(state.outline_buf, highlights) end
217219
end
218220

@@ -282,9 +284,9 @@ local function setup_autocommands()
282284
pattern = utils.events.OUTLINE_CHANGED,
283285
callback = function()
284286
if not utils.buf_valid(state.outline_buf) then return end
285-
local ok, lines, highlights = get_outline_content()
286-
if not ok or not lines then return end
287-
refresh_outline(state.outline_buf, lines, highlights)
287+
local ok, lines, highlights, outline = get_outline_content()
288+
if not ok or not lines or not outline then return end
289+
refresh_outline(state.outline_buf, lines, highlights, outline.uri)
288290
end,
289291
})
290292
autocmd({ "CursorHold" }, {
@@ -358,7 +360,7 @@ end
358360
function M.open(opts)
359361
opts = opts or {}
360362
local ok, lines, highlights, outline = get_outline_content()
361-
if not ok or not lines then
363+
if not ok or not lines or not outline then
362364
ui.notify("Sorry! There is no outline for this file")
363365
return
364366
end
@@ -369,12 +371,14 @@ function M.open(opts)
369371
open_cmd = options.open_cmd,
370372
filetype = outline_filetype,
371373
filename = outline_filename,
372-
}, function(buf, win) setup_outline_window(buf, win, lines, highlights, opts.go_back) end)
374+
focus_on_open = true,
375+
}, function(buf, win)
376+
setup_outline_window(buf, win, lines, highlights, opts.go_back)
377+
vim.b[buf].outline_uri = outline.uri
378+
end)
373379
else
374-
refresh_outline(state.outline_buf, lines, highlights)
380+
refresh_outline(state.outline_buf, lines, highlights, outline.uri)
375381
end
376-
if not outline then return end
377-
vim.b.outline_uri = outline.uri
378382
if opts.go_back and api.nvim_win_is_valid(parent_win) then
379383
api.nvim_set_current_win(parent_win)
380384
end

0 commit comments

Comments
 (0)