diff --git a/README.md b/README.md index fc3ad95..de838e0 100644 --- a/README.md +++ b/README.md @@ -280,6 +280,7 @@ require("flutter-tools").setup { notify_errors = false, -- if there is an error whilst running then notify the user open_cmd = "15split", -- command to use to open the log buffer focus_on_open = true, -- focus on the newly opened log window + win_opts = nil, -- window-local options for the log window, e.g. { winfixheight = true } to keep its size when the terminal resizes }, dev_tools = { autostart = false, -- autostart devtools server if not detected @@ -302,6 +303,7 @@ require("flutter-tools").setup { open_cmd = "30vnew", -- command to use to open the outline buffer auto_open = false, -- if true this will open the outline automatically when it is first populated icons = true, -- false hides the icons (e.g. without a Nerd Font); a table overrides icons per kind, e.g. { CLASS = "C", DEFAULT = "*" } + win_opts = nil, -- window-local options for the outline window, e.g. { wrap = true } }, lsp = { on_attach = my_custom_on_attach, diff --git a/lua/flutter-tools/config.lua b/lua/flutter-tools/config.lua index fc1a289..d07e080 100644 --- a/lua/flutter-tools/config.lua +++ b/lua/flutter-tools/config.lua @@ -47,7 +47,7 @@ local utils = lazy.require("flutter-tools.utils") ---@module "flutter-tools.util ---@field debugger? {enabled: boolean, exception_breakpoints?: table, evaluate_to_string_in_debug_views?: boolean, register_configurations?: fun(paths: table)} ---@field closing_tags? {highlight: string, prefix: string, priority: number, enabled: boolean} ---@field lsp? {debug?: number, color?: {enabled: boolean, background: boolean, foreground: boolean, virtual_text: boolean, virtual_text_str: string, background_color?: string}, settings?: table} ----@field outline? {auto_open: boolean, open_cmd?: string, icons?: boolean|table} +---@field outline? {auto_open: boolean, open_cmd?: string, icons?: boolean|table, win_opts?: table} ---@field dev_log? flutter.DevLogOpts ---@field dev_tools? {autostart: boolean, auto_open_browser: boolean} ---@field widget_preview? {web_server: boolean} @@ -77,8 +77,10 @@ local function validate_prefs(prefs) vim.validate("outline", prefs.outline, "table", true) if prefs.outline then vim.validate("outline.icons", prefs.outline.icons, { "boolean", "table" }, true) + vim.validate("outline.win_opts", prefs.outline.win_opts, "table", true) end vim.validate("dev_log", prefs.dev_log, "table", true) + if prefs.dev_log then vim.validate("dev_log.win_opts", prefs.dev_log.win_opts, "table", true) end vim.validate("closing_tags", prefs.closing_tags, "table", true) end diff --git a/lua/flutter-tools/log.lua b/lua/flutter-tools/log.lua index 58453a0..3153c87 100644 --- a/lua/flutter-tools/log.lua +++ b/lua/flutter-tools/log.lua @@ -44,6 +44,7 @@ local function create(config) filetype = "log", open_cmd = config.open_cmd, focus_on_open = config.focus_on_open, + win_opts = config.win_opts, } ui.open_win(opts, function(buf, win) if not buf then diff --git a/lua/flutter-tools/outline.lua b/lua/flutter-tools/outline.lua index 860629b..3cd6afb 100644 --- a/lua/flutter-tools/outline.lua +++ b/lua/flutter-tools/outline.lua @@ -384,6 +384,7 @@ function M.open(opts) filetype = outline_filetype, filename = outline_filename, focus_on_open = true, + win_opts = options.win_opts, }, function(buf, win) setup_outline_window(buf, win, lines, highlights, opts.go_back) vim.b[buf].outline_uri = outline.uri diff --git a/lua/flutter-tools/ui.lua b/lua/flutter-tools/ui.lua index 4be3638..130e08f 100644 --- a/lua/flutter-tools/ui.lua +++ b/lua/flutter-tools/ui.lua @@ -16,6 +16,7 @@ local entry_type = { ---@field filename? string Name to give the buffer ---@field filetype string Filetype to set for the buffer ---@field focus_on_open? boolean Whether to focus the window after opening +---@field win_opts? table Window-local options to set on the window ---@enum local M = { @@ -129,6 +130,10 @@ function M.open_win(opts, on_open) vim.bo[buf].buftype = "nofile" vim.bo[buf].buflisted = false if on_open then on_open(buf, win) end + for name, value in pairs(opts.win_opts or {}) do + local ok, err = pcall(api.nvim_set_option_value, name, value, { scope = "local", win = win }) + if not ok then M.notify(fmt("Invalid window option %q: %s", name, err), M.WARN) end + end if not opts.focus_on_open then -- Switch back to the previous window vim.cmd("wincmd p")